File Upload Attacks
Last updated
Last updated
(my favorite)
Identify the languages used in the application.
Enumerate the upload directory
Source Code: Check for any exposed upload directory path.
Fuzzing: Use a wordlist to discover any exposed upload directory path.
Force Errors: Intentionally crash the application uploading
Upload a malicious PHP file and try to execute it, if you are lucky and there are no protection or filter you will get it.
Inspect the source code to check if file validation is done usigin JavaScript
Fuzz valid file extension either black and white list.
Use double or reverse extension (Use the below script to create the wordlist)
If the server allows SVG Uploads, attempt to upload a malicious SVG it could lead to diferent vulnerabilities such LFI and RCE.
Rewrite the configuration upload file through [[.htaccess]]
Modify the PHP file size to attempt
Some developer cipher the filename using md5, sha1 or you can try to find your malicious file using the next pattern Ex. MD5 Cypher <md5>.php
, <md5.php>.php
or md5 to the entire file.
Note: You can hit the malicious files through the LFI vulnerabilities
.htaccess files provide a way to make configuration changes on a per-directory basis."_
Now just upload a . malicious file and it will be executed as PHP.
some websites upload the file directly to the main filesystem and then remove it again if it doesn't pass validation. This kind of behavior is typical in websites that rely on anti-virus software and the like to check for malware. This may only take a few milliseconds, but for the short time that the file exists on the server, the attacker can potentially still execute it.
These vulnerabilities are often extremely subtle, making them difficult to detect during blackbox testing unless you can find a way to leak the relevant source code.
Intercept the file with burpsuite and save the request (Copy to file)
Set the payload inside the file on the parameter filename=file.FUZZ
we can utilize a Decompression Bomb
with file types that use data compression, like ZIP
archives. If a web application automatically unzips a ZIP archive, it is possible to upload a malicious archive containing nested ZIP archives within it, which can eventually lead to many Petabytes of data, resulting in a crash on the back-end server.
file; whoami.jpg
file&&id.jpg
file$(uname -a).png
"><script>alert('XSS');</script>.jpg
" onmouseover="alert('XSS')".png
file'; DROP TABLE users;--.jpg
file'; UPDATE users SET admin=1;--.png
file' OR '1'='1'.jpg
We may also try uploading a file with an overly long name (e.g., 5,000 characters). If the web application does not handle this correctly, it may also error out and disclose the upload directory.
Certain characters are reserved for special uses in Windows, and using them in file names can lead to errors, directory disclosures, or unexpected behavior.
Examples:
file|whoami.txt
file*.txt
file>.txt
Windows has a set of reserved device names that cannot be used as file names. If these are submitted, the system may throw an error or behave unexpectedly.
Examples:
CON.jpg
CON
is a reserved name for the console. If the application tries to create this file, it will likely fail or throw an error.
COM1.txt
COM1
is reserved for the first serial port. Similarly, creating this file will result in an error or cause undefined behavior.
LPT1.png
LPT1
is reserved for the first printer port. If this name is used, the system won't be able to handle it properly.
Explanation: Using these reserved names can cause the application to crash or expose internal errors, potentially revealing the directory structure or other sensitive details about the system.
Windows still supports the legacy 8.3 filename convention, where file names are shortened to a format like XXXXXX~1.EXT
. This can be exploited to overwrite files or bypass protections.
Examples:
HAC~1.TXT
Refers to a file called hackthebox.txt
. The ~1
represents the first matching file that starts with HAC
. An attacker can target this to overwrite or access files without using their full names.
WEB~.CONF
This could be used to target and overwrite web.conf
if the system still supports 8.3 names, allowing an attacker to alter the web server's configuration.
LOG~.SYS
Refers to log.sys
. An attacker could use this shortened name to overwrite important system log files, potentially covering up traces of malicious activity.
Modify the Content-Type: <file-type>
. You might use
Change the file magic numbers.
I recommend this wordlist or use the above script