File Upload to Remote Code Execution

Day 12 forged a token. Today you forge a file, and if the application mishandles it, that file does not just sit on disk, it runs. Insecure file upload is the bug class with the shortest distance between finding and full compromise. Most of this series has built toward a chain: an injection that reaches something, a token that unlocks a boundary, an identifier that exposes a record. File upload can skip the chain entirely. Upload a working web shell, visit it, and you have a command line on someone else’s server.
This is the eleventh class in the series. It earns the attention, because of every bug type covered so far, this is the one most likely to end in a critical severity rating and a direct remote code execution label, not an inferred one.
Inside scope only, with the absolute minimum proof. A working web shell is a loaded weapon sitting on someone’s infrastructure. Prove execution with a single harmless command, like reading the current user or listing a directory, take a screenshot, and remove the file immediately after reporting. Never pivot further into the network, never read real data, and never leave a shell live longer than it takes to document the finding.
What the vulnerability actually is
A file upload feature almost always needs to answer three questions correctly: what kind of file is this, where does it get stored, and can it be executed later. The vulnerability shows up when any one of those three checks is missing, is done wrong, or can be tricked.
A naive upload handler checks the file extension in the filename, saves the file inside the web root, and lets the web server execute anything with a recognized server-side extension sitting in that folder. If you can get a file ending in .php, .aspx, .jsp, or similar past the extension check, and the server will execute files with that extension from wherever it landed, you have a path straight to code execution the moment you request that file’s URL.
POST /upload HTTP/1.1
Content-Type: multipart/form-data; boundary=----X
------X
Content-Disposition: form-data; name="file"; filename="shell.php"
Content-Type: image/png
<?php system($_GET['cmd']); ?>
------X--
If that lands in a web-accessible, executable directory, visiting shell.php?cmd=id runs id on the server. The entire vulnerability is contained in that one request and that one follow-up visit.
Why checks fail in practice
Developers usually do add some validation. The bug class survives because validation is frequently wrong in one of these specific, well-documented ways.
Extension blocklisting instead of allowlisting. Blocking .php is not the same as only allowing .jpg, .png, and .pdf. Attackers have a long list of alternate server-executable extensions many blocklists miss: .phtml, .php5, .pht, .asa, .cer, .aspx variants, and server-specific handler extensions that still get executed by a misconfigured web server.
Trusting the Content-Type header or the client-sent filename. Both are entirely attacker-controlled. Setting Content-Type: image/png on a request whose body is actual PHP code, exactly as shown above, defeats any check that only reads the header rather than inspecting the file’s real content.
Null byte and special character truncation. Older or poorly written parsers in some languages historically stopped reading a filename at a null byte, so a filename like shell.php%00.png could pass an extension check looking at the end of the string, .png, while the underlying filesystem call truncated it at the null byte and saved it as shell.php. This exact technique, combined with a modern twist, placing a literal null byte between the extensions in the raw multipart body rather than URL-encoded, was used in a 2023 disclosed report against a U.S. Department of Defense system, rated critical.
Double extensions and case manipulation. shell.php.jpg sometimes passes a check looking only at the last extension while a misconfigured server still executes it based on an earlier extension in the chain. shell.pHp can slip past a case-sensitive blocklist on a case-insensitive filesystem.
Insufficient image or document re-validation. Features that claim to process an uploaded file, resize an image, generate a thumbnail, extract metadata, sometimes only check that the file looks superficially valid, like having correct magic bytes at the start, without rejecting extra malicious content appended after the legitimate image data, a technique often called a polyglot file.
No execution restriction on the upload directory. Even with a perfectly validated file type, if the web server is configured to execute scripts anywhere inside the upload path, any gap elsewhere in validation becomes a full RCE rather than a harmless stored file.
Real disclosed reports
- SemRush, remote code execution via logo upload, 799 upvotes. One of the most upvoted file upload reports on HackerOne’s public Hacktivity feed, this flaw in the “My Reports” logo upload feature on semrush.com allowed an attacker to achieve remote code execution by uploading a malicious file through what was meant to be a simple branding image upload, demonstrating how an apparently low-risk cosmetic feature can carry full RCE risk.
- Starbucks, webshell via file upload on a China recruitment subdomain (ecjobs.starbucks.com.cn), 675 upvotes. A researcher found that the recruitment portal’s upload functionality allowed a webshell to be placed and executed, one of several file upload findings Starbucks received across its various subdomains, and a reminder that recruitment, HR, and other secondary subdomains are frequently less hardened than the main consumer-facing application.
- Starbucks, unrestricted file upload leading to RCE on mobile.starbucks.com.sg, 225 upvotes. A separate, related finding on a different Starbucks regional mobile domain, later covered publicly after disclosure, where an image upload endpoint failed to restrict file type, rated with a 9.8 severity score and paid $5,600 to $6,000 depending on the specific report, part of a broader pattern across Starbucks’s bug bounty history of over a thousand reports and $640,000 paid out.
- U.S. Department of Defense, RCE via file upload with a null byte truncated file extension, report #2054184, critical. Disclosed in December 2023, the researcher found that placing a literal null byte between a malicious extension and an allowed one in the raw multipart form data caused the server to save the file with the malicious extension intact while the validation logic only inspected the truncated, allowed-looking portion, and the researcher demonstrated running arbitrary commands on the resulting shell.
- Mail.ru, RCE by bypassing authentication through a redirect to upload a malicious file in an admin path, 340 upvotes. This one chained an authentication bypass, stopping a redirect meant to send unauthenticated users away from an admin upload endpoint, directly into a file upload RCE, showing how this bug class frequently sits at the end of a chain from an earlier, seemingly separate flaw.
Read the SemRush report first for the cleanest standalone example. Then read the DoD null byte report for the most technically specific bypass technique on this list, and compare it against the general extension validation mistakes described above to see exactly which check it defeated.
The main attack variants
Direct executable upload. The simplest case: no extension restriction at all, or a restriction trivially bypassed by one of the techniques above, and the uploaded script lands directly in an executable path.
Content-Type and magic byte spoofing. Setting a benign Content-Type header, and in some cases prepending real image magic bytes, GIF89a is a classic prefix, before the actual malicious payload, to pass checks that only validate the file’s apparent type rather than rejecting trailing content.
Path traversal in the filename. If the server uses the client-supplied filename to construct the storage path without sanitizing it, a filename like ../../var/www/html/shell.php can write the file somewhere entirely different from the intended upload directory, potentially into a directly web-accessible and executable location.
Upload leading to stored XSS rather than RCE. Not every vulnerable upload leads to code execution. Uploading an SVG or HTML file that a browser later renders directly, rather than as a downloaded attachment, can deliver a Day 7-style stored XSS payload instead, still a valid and often paid finding, just a different impact ceiling.
Zip slip and archive extraction attacks. If an uploaded archive, a ZIP or similar, is automatically extracted server-side, a maliciously crafted archive entry with a path traversal filename inside it can write files outside the intended extraction directory during that extraction process.
Image processing library exploitation. Some older image libraries have had their own severe parsing vulnerabilities, meaning simply getting a malformed but technically valid image file processed by a vulnerable library version can trigger code execution without ever needing to upload a script extension at all.
Where to look, pointed at your recon
- Any visible upload button, profile pictures, logos, attachments, documents, resumes, support ticket attachments. The SemRush and Starbucks reports above both involved exactly this kind of ordinary-looking feature.
- API endpoints accepting multipart form data, discovered through your recon’s parameter and JS analysis, even when no corresponding upload button is visible in the UI.
- Secondary and regional subdomains, recruitment portals, regional mobile APIs, partner portals, which your Day 1 to 3 recon should already have surfaced as the forgotten corners of the attack surface, and which the Starbucks China recruitment case and Singapore mobile case both demonstrate are frequently less hardened than the primary domain.
- Any feature that later displays or processes the uploaded file, thumbnail generation, PDF preview, document conversion, since these secondary processing steps are where polyglot files and image library exploitation become relevant even past an initial validation check.
- Admin or internal upload paths found via your JS file analysis, since the Mail.ru case shows these are sometimes reachable by bypassing an earlier access control check rather than by attacking the upload logic directly.
How to hunt it, step by step
Step 1: find the upload, and capture a baseline legitimate request. Upload a genuinely valid file first and study exactly what the request looks like, and where the resulting file ends up, if the response or your own account reveals a URL.
Step 2: test the simplest bypass first. Change only the filename extension to something server-executable, keep everything else, including the Content-Type header, identical to the legitimate request, and see what the server actually rejects versus accepts.
Step 3: if extension validation holds, test Content-Type spoofing. Send the exact same malicious filename and content, but set the Content-Type header to match an allowed type, since some validation checks the header and never inspects the body at all.
Step 4: try double extensions, case variation, and null byte style tricks. shell.php.jpg, shell.pHp, and extension confusion with a literal null byte in the raw multipart body between two extensions, the exact technique from the disclosed DoD report.
Step 5: try a polyglot file if the application processes images. Prepend valid image magic bytes to your malicious payload, or research a format-specific polyglot technique for the exact file type the feature claims to require.
Step 6: test the filename itself for path traversal. Submit a filename containing ../ sequences and observe whether the resulting storage location changes in any observable way.
Step 7: once any file lands, find out if and where it executes. If the application does not reveal the storage URL directly, this is where earlier recon pays off, guessable upload directory structures, exposed in JS files, error messages, or documentation, are often how the final file location gets found.
Step 8: prove execution with the absolute minimum command. id, whoami, or listing a single directory is enough. Screenshot the result, then remove the uploaded file immediately.
Writing the file upload report
Title: Unrestricted file upload on [endpoint] leads to remote code execution
Summary:
One sentence: which upload feature, which bypass technique, and
that code execution was achieved.
Steps to Reproduce:
1. Submit a multipart upload to [endpoint] with filename
[malicious filename] and Content-Type [spoofed type], containing
[minimal webshell payload].
2. Determine the resulting file's accessible URL at
[path/URL, from response or recon].
3. Visit [URL]?cmd=id (or equivalent) and observe the command
output confirming code execution.
4. Immediately remove the uploaded file.
(Exact request, the resulting file path, a screenshot of the single
command's output, and confirmation of file removal.)
Impact:
An attacker can upload and execute arbitrary server-side code via
[endpoint], achieving remote code execution under the privileges
of the web application process. This may allow full server
compromise, lateral movement to internal systems, or access to
other users' data stored on the same host. State the realistic
worst case without having actually pursued it.
Remediation:
Validate uploaded files using a strict allowlist of permitted
extensions and MIME types, verified against the file's actual
content, not the client-supplied filename or header. Store
uploads outside the web root, or in a location explicitly
configured to never execute scripts. Rename uploaded files to a
randomly generated name server-side, and re-encode or re-process
images rather than trusting the uploaded bytes directly.
The strongest reports on this list, SemRush and the DoD null byte case especially, share a pattern: a precise explanation of exactly which validation step failed and why, a minimal single-command proof, and immediate cleanup. A vague “I uploaded a shell” with no explanation of which specific bypass technique worked is far weaker and harder for a triager to act on quickly.
What programs often reject
- Uploads that succeed but land somewhere never executed by the server, with no demonstrated code execution or other real impact
- Findings relying on an already-authenticated admin account uploading to an admin-only feature explicitly documented as trusted
- Reports where the “malicious” file is simply a large file size or unusual but harmless format, with no actual security impact demonstrated
- A webshell left live on the target’s infrastructure well past the point needed to prove the finding, which several programs treat as a policy violation regardless of how the bug itself is rated
The mindset: never trust what a file claims to be
This series keeps returning to one lens: does a boundary enforce what it claims to enforce. A file upload boundary claims “only images, only documents, only safe content,” and the vulnerability is always some gap between that claim and what the server actually checks and executes. A filename, a header, and the first few bytes of a file are all just claims the attacker gets to write. The only question worth asking is what the server actually does with the bytes after that claim, not what the claim itself says.
Homework for Day 13
- From recon, list every upload feature on the target, including secondary subdomains, admin paths, and anything surfaced through your JS file analysis.
- Capture a baseline legitimate upload request for each, and note the resulting file’s accessible location if visible.
- Test the simplest extension swap first, then Content-Type spoofing, then double extensions and case variation, recording exactly which check each attempt passes or fails.
- If the feature processes images, attempt a polyglot file combining valid magic bytes with a minimal payload.
- Read the SemRush logo upload report and the DoD null byte report (bugboard.rsecloud.com/report/2054184) end to end. For each, note the exact validation gap exploited, and compare how each researcher proved execution with a minimal, documented command.
A confirmed file upload vulnerability leading to code execution is almost always rated critical, since it typically grants a foothold equivalent to full server compromise with no further steps required. Document it with the exact bypass technique, the minimal command proof, and the strict content-based allowlist remediation.
Day 14 moves to a bug where the application builds a command for the operating system itself to run, Command Injection, and how it differs from the file-based RCE you just learned.