---
title: "9. Other techniques"
date: 2024-12-04
draft: false
---


Few other techniques worth mentioning 

## File upload injections in file name

Use a malicious string for uploaded file name. 
- may get executed / processed if uploaded file name is displayed (reflected) on the webpage. 
- try injecting a command in the filename and if the webapp uses the filename within an OS command it may lead to command injection 

For example: 
`file$whoami).jpg` or 
```bash
file`whoami`.jpg 
```
or 
`file.jpg||whoami` 
webapp attempts to move uploaded file with an OS command i.e. `mv file /tmp` then our filename would inject the whoami command. this essentially leads to remote code execution 

similarly, XSS payloads in filename would also theoretically work 
such as `<script>alert(window.origin);</script>` 
- executed on target machine if filename is displayed (reflected) back on webapp 

potentially also able to inject a SQL query in filename 
- `file';select+sleep(5);--.jpg` 
leads to sql injection if filename is insecurely used in a SQL query 

----
## File upload attacks - Upload directory disclosure 

In some upload forms like a feedback or submission form we may not have access directly to the link of our uploaded file / not know upload dir. 

Fuzzing works to find it or even use other vulns like XXE / LFI to find where uploaded files are by reading source code 

Additional method to disclose upload directory is through forcing error messages as they often reveal helpful information 
- upload file with a name that already exists
- sending two identical requests simultaneously 

may lead to webserver showing an error that it could not write the file; potentially disclosing upload directory. we may also try uploading a file with a >5000char name 
- if webapp doesnt handle this correctly it could error out + reveal upload dir path 
various other techniques can be used to error the backend and disclose upload dir 

---
## windows-specific file upload attacks

Reserved characters such as:
```bash
|
<
*
?
```
- usually reserved for special uses like wildcards
- if webapp doesnt sanitize or wrap within quotes they may refer to another file (which may not exist) and cause an error that discloses upload directory

Similarly: 
`CON` , `COM1`, `LPT1`, or `NUL` may also cause errors because webapp can not write a file with those reserved names. 

Another option is to use Windows 8.3 filename convention to overwrite existing files + refer to files that do not exist. older versions of windows were limited to short length for filenames and used ~ to complete the filename which we can use to our advantage. 
https://en.wikipedia.org/wiki/8.3_filename

For ex: 
`hackthebox.txt` we can use `HAC~1.TXT` or `HAC~2.TXT` where digit represents order of matching files that start with HAC 
- Windows still supports this convention 
- We can write a file called `WEB~.CONF` to overwrite the `web.conf` file. 
- May also write a file that replaces sensitive system files. This attack can lead to several outcomes like causing info disclosure through errors or causing a DoS on the backend, or accessing private files

---
## Advanced file upload attacks

Any automatic processing that occurs to an uploaded file 
- encoding a video
- compressing a file
- renaming a file 

may be exploited if not securely coded

Commonly used libraries may have public exploits for such vulns 
- i.e. AVI upload vulnerability leading to XXE in ffmpeg 

When dealing with custom code / custom libraries detecting such vulnerabilities requires more advanced knowledge and techniques 
