π« Front-End Only: Bypassing JavaScript-based file validation that occurs entirely in the browser
Overview
Many web applications only rely on front-end JavaScript code to validate the selected file format before it is uploaded and would not upload it if the file is not in the required format (e.g., not an image).
However, as the file format validation is happening on the client-side, we can easily bypass it by directly interacting with the server, skipping the front-end validations altogether. We may also modify the front-end code through our browser's dev tools to disable any validation in place.
Client-Side Validation
β οΈ Security Flaw: Any code that runs on the client-side is under our control
The exercise shows a basic Profile Image functionality, frequently seen in web applications that utilize user profile features, like social media web applications.
Identifying Client-Side Validation
Common Indicators:
File dialog limited to specific formats (e.g., images only)
Error messages appear without page refresh
No HTTP requests sent during validation
Upload button gets disabled based on file type
Example Scenario:
File Selection Dialog - Limited to .jpg, .jpeg, .png formats
Invalid File Selection - "Only images are allowed!" error message
Upload Button Disabled - No server interaction occurs
No Network Activity - Validation happens entirely in browser
Why Client-Side Validation is Vulnerable
Key Vulnerability Points:
Complete Control - All code executes within our browser
Source Code Access - We can view and modify all JavaScript
Server Trust - Backend may trust that frontend validated properly
Direct Server Access - We can bypass frontend entirely
Bypass Method 1: Back-end Request Modification
π§ Direct Server Communication: Bypass frontend by modifying HTTP requests
Burp Suite Interception Method
Step 1: Capture Normal Upload Request
Step 2: Modify Request for PHP Upload
Step 3: Analyze Response
Key Modification Points
Critical Fields to Modify:
filename="HTB.png" β filename="shell.php"
[IMAGE CONTENT] β [PHP WEB SHELL CODE]
Optional Modifications:
Content-Type: Can be left as image/png or changed to application/x-php
File Extension: Try different PHP extensions (.phtml, .php5, etc.)
Complete Bypass Workflow
Step 1: Setup Interception
Step 2: Trigger Upload
Step 3: Modify Request
Step 4: Verify Upload
Bypass Method 2: Disabling Front-end Validation
π οΈ Browser DevTools: Modify JavaScript validation directly in the browser
Browser Inspector Method
Step 1: Access Page Inspector
Step 2: Analyze HTML File Input
Key Elements:
accept=".jpg,.jpeg,.png" - File dialog filter
onchange="checkFile(this)" - JavaScript validation function
This comprehensive guide demonstrates why client-side validation alone is insufficient and provides practical methods to bypass such controls for successful penetration testing.
# Step 1: Press [CTRL+SHIFT+C] in browser
# Step 2: Click on upload area to inspect
# Step 3: Remove onchange="checkFile(this)" from input
# Step 4: Upload PHP shell normally
# Step 5: Access uploaded file and execute commands
# Test normal image upload β SUCCESS
# Test PHP upload β BLOCKED with error message
# No page refresh during validation β Client-side validation confirmed
# Choose bypass method (Burp or DevTools)
# Upload PHP web shell
# Verify "File successfully uploaded" response