====== File Upload Testing ====== File uploads are often filtered on extension, content-type, magic bytes, or image dimensions. Test each layer separately. ===== Extension Tricks ===== shell.php/.jpg # server may strip after slash shell.html%0d%0a.jpg # newline truncation .txt, .svg, .xml # often forgotten in filters shell.php5, shell.phtml # alternate PHP extensions ===== Content-Type Manipulation ===== * Filename ''.jpg'' but Content-Type ''text/html'' * No filename or no extension -- check what the server defaults to * Keep image magic bytes (''\xff\xd8\xff'') at start but append PHP/HTML after * Polyglot files -- simultaneously valid image and valid HTML/PHP ===== XSS in Filenames ===== 58832_300x300.jpg ">.jpg ===== What to Check ===== * **Where are uploaded files stored?** Same domain? CDN? Check CSP header * **What validation is in place?** Extension, content-type, magic bytes, image dimensions * **Is there a virus scanner?** Can you bypass it with a polyglot? * **Is the upload endpoint authenticated?** Try uploading unauthenticated ===== SVG XSS ===== SVG files are XML and support JavaScript event handlers: ===== Escalation ===== * SVG upload on same domain = XSS * Unrestricted file type = webshell if server executes * XSS in filename reflected in admin upload logs = blind XSS * SSRF via SVG: '''' ===== See Also ===== * [[zseano:xss|XSS Testing]] * [[zseano:ssrf|SSRF Testing]] * [[tbhm:07_file_upload|TBHM File Upload]] * [[zseano:start|Methodology Index]]