Blind Detection of Path Traversal-Vulnerable File Uploads
Blind Detection of Path Traversal-Vulnerable File Uploads
Blind Detection of Path Traversal-Vulnerable File Uploads
Note: the payload in this scenario does not even require the document root!
Possible variants - the right payloads
• B) the upload directory is located outside the document root
• the document root: /var/www/html/example.org/
• the upload directory: /home/example/uploads/
• the payload: ../../../var/www/html/example.org/shell.php
• the result of concatenation (upload_dir+filename):
/home/example/uploads/../../../var/www/html/shell.php ->
/var/www/html/example.org/shell.php, Remote Code Execution:
http://example.org/shell.php?cmd=id
Black-box/grey-box method – a lot of
guesswork (what this is all about)
• Zero/little knowledge about the target (just a remote end-user
perspective)
• No source code available/config files available
• No information about the directory structure (upload dir?!,
document root?!)
• Sometimes this information is available/attainable (e.g. by taking
advantage of verbose error messages)... but usually it is not, what
then?!
• This is why we call such scenario “Blind”
Blackbox/greybox – hit the document root
• The document root is platform-specific
• It *might* contain the common name of the application,e.g.
/var/www/html/commonname
• Using known platform-specific document roots and possible common
names, we can generate a list of potential document root paths
• https://github.com/ewilded/get_docroots
• Inspired by sqlmap’s –os-shell feature
• We blindly try to upload a completely valid
file to all potentially valid document roots
The algorithm
1. Generate a full list of potentially valid document roots
2. Using a web browser with an intercept proxy (Burp Suite), upload a
single, legitimate file that is surely accepted by the application
(type, size, contents, name) – NO malicious contents/extensions
3. Transfer the upload request to Intruder, embedding the list of paths
in the file name holder
4. Create a second holder inside of the sent file contents, with
incrementing natural numbers (to mark the first payload)
5. Start the attack
6. Check if the file has been created by requesting it
Generating the list – basic config
Generating the list – basic config
Generating the list – evasive versions of the
payloads
Example:
./....//....//....//....//....//....//....//....///usr/local/localhost/apache/www/apache22/localhost/htdocs/test.png
./../../../../../../../..//var/lib/to
mcat7/webapps/uploadbare/
If the application is NOT vulnerable to path traversal, but the upload dir is inside of the
document root (but we still do not know what the upload directory is):
• make sure we did all the content discovery (passive and active directory
enumeration)
• check all discovered directories from the site map for existence of the uploaded file
An interesting diversion
An interesting diversion
Extract a unique list of
existing directories
An interesting diversion
An interesting diversion
Covered vulnerable scenarios summary
• Upload dir outside of the document root
• Path traversal required
• Document root full path required
• Upload dir inside of the document root, but unknown/not directly
accessible
• Path traversal required
• Document root full path NOT required
• Upload dir inside of the document root and known/enumerable +
directly accessible
• Path traversal NOT required
• Document root full path NOT required
Other things worth mentioning
• Sometimes the document root might not be writable, but one of its
subdirectories might be – this would require to generate a way longer
payloads list, using the directories from the site map
• The document root is not the only one target worth writing to:
• System binary files
• System scripts, user scripts
• Crontabs
• Autostart locations
• Blind exploitation (no way to confirm the path traversal in the first place)
• Targets are world-writable/server is running as root
• Using get_docroots.pl for other purposes (like reading files )
Possible improvements
• More document root paths?
• Support for windows!
• Improved evasive techniques?
• More automation (a Burp plugin?)
• Removable file scenario detection
• Race condition scenario detection
• How common is the upload-path-traversal today?
Thanks for attention!