File Upload Bypass
Introduction
File upload vulnerability is a noteworthy issue with online applications. If a web application has this type of vulnerability, an aggressor can upload a file with malicious code in it that can be executed on the server. An assailant may most likely put a phishing page into the site or mutilate it to uncover internal data of the web server to other people.
Allowing file uploads by end-users, especially if done without a full understanding of the risks associated with it, is akin to opening the floodgates for server compromise. Naturally, despite the security concerns surrounding the ability for end-users to upload files, it is an increasingly common requirement in modern web applications.
File uploads carry a significant risk that not many are aware of, or how to mitigate against abuses. Worst still, several web applications contain insecure, unrestricted file upload mechanisms.
Make sure you read "First Link in the Reference!!" its a great blog then proceed further.
What can you achieve by exploiting file-upload:
Remote code execution
SSRF
XSS
LFI
XXE
Phishing
Parameter pollution
uploaders may disclose internal paths
DoS attack
Many More...
What extension can lead to what if uploaded successfully:
Extensions Impact
ASP,ASPX,PHP5,PHP,PHP3: Webshell, RCESVG: Stored XSS, SSRF, XXEGIF: Stored XSS, SSRFCSV: CSV injectionXML: XXEAVI: LFI, SSRFHTML,JS: HTML injection, XSS, Open redirectPNG,JPEG: Pixel flood attack (DoS)ZIP: RCE via LFI, DoSPDF,PPTX: SSRF, BLIND XXESCF: RCE
Types of Validation in File-Upload:
There several others too but this are the main 5 types others are like File Signature Validation,File Content Validation, File Storage Location which all comes in further protection.
1. Client-Side Validation:
Client side validation is a type of validation which takes place before the inputs are actually sent to the server. And it happens on the web browser by JavaScript, VBScript, or HTML5 attributes. Programmers use this type of validation to provide better user experience by responding quickly at the browser level.
For Example
Error only .jpg is allowed
2. File Name Validation:
File name validation is when the server validate the file that being uploaded by checking its extension, this validation happens based on many methods, but two of the most popular methods are Blacklisting File Extensions and Whitelisting File Extensions.
Blacklisting File extensions is a type of protection where only a specific extensions are being rejected from the server, Such as php, aspx. While Whitelisting File extensions is the exact opposite, which is only a few file extensions are allowed to be uploaded to the server, Such as jpg, jpeg, gif.
3. Content-type / MIME-type Validation:
Content-Type validation is when the server validate the content of the file by checking the MIME type of the file, which can be shown in the http request. For example, some image file uploads validate the images uploaded by checking if the Content-Type of the file is an image type.
For Example:
Content-type: image/png
4. Content-Length Validation:
Content-Length validation is when the server checks the length of the content of the uploaded file and restricts a file size that can’t be exceeded, Although this type of validation is not very popular, But it can be shown on some file uploads.
For Example:
Not allow file size greater than 10 bytes
5. Checking the Image Header:
When image upload only is allowed, most web applications usually validate the image header by using a server-side function such as
getimagesize()in PHP. When called, this function will return the size of an image. If the file is not a valid image, meaning that the file header is not that of an image, the function will return FALSE. Therefore, several web applications typically check if the function returns TRUE or FALSE and validate the uploaded file using this information.This can be bypassed by using magic numbers
List of file signatures - Wikipedia
Testing For File-Upload and Exploiting.

Base Step
Test Case - 1: Blacklisting Bypass.
Test Case - 2: Whitelisting Bypass
Test Case - 3: Content-type validation
Test Case - 4: Content-Length validation
Test Case - 5: Content Bypass / Using Magic Bytes
Test Case - 6: Magic Bytes and Metadata Shell
Test Case - 7: Uploading Configuration Files
Test Case - 8: Try Zip Slip Upload
Test Case -9 : Try ImageMagick
Exploitation:
XSS:
```
XXE:
]> &xxe; ```
Using excel file you can acheive not only XXE, but other vulnerability too. https://medium.com/@rezaduty/security-issues-in-import-export-functionality-5d8e4b4e9ed3
Command Injection:
LFI:
SQL Injection:
DOS:
SSTI:
Mitigation
File upload functionality is not straightforward to implement securely. Some recommendations to consider in the design of this functionality include:
Use a server-generated filename if storing uploaded files on disk.
Inspect the content of uploaded files, and enforce a whitelist of accepted, non-executable content types. Additionally, enforce a blacklist of common executable formats, to hinder hybrid file attacks.
Enforce a whitelist of accepted, non-executable file extensions.
If uploaded files are downloaded by users, supply an accurate non-generic Content-Type header, the X-Content-Type-Options: nosniff header, and also a Content-Disposition header that specifies that browsers should handle the file as an attachment.
Enforce a size limit on uploaded files (for defense-in-depth, this can be implemented both within application code and in the web server’s configuration).
Reject attempts to upload archive formats such as ZIP.
Mind-Map

Tools And Payload.
barrracud4/image-upload-exploits
Reference
Interesting Test Cases of File uploading vulnerabilities
File upload tricks and checklist
File Upload Attacks (Part 1) - Global Bug Bounty Platform
Unrestricted File Upload In PHP
File Upload - OWASP Cheat Sheet Series
Comprehensive Guide on Unrestricted File Upload
Exploiting file upload vulnerabilities in web applications
Art of Unrestricted File Upload Exploitation
Encoding Web Shells in PNG IDAT chunks
Uploading Backdoor For Fun And Profit. (RCE + DB-cred = P1)
Unrestricted File Uploading Vulnerability - Secnhack
Tips
https://pbs.twimg.com/media/EpkPLYXVgAMLhZa?format=jpg&name=medium
https://pbs.twimg.com/media/Eq9dOoaXUAAEE8n?format=jpg&name=900x900
Author:
Last updated