File Upload To Rce
An authenticated user could upload an SVG file that executed script in the browser, and could also change the uploaded filename to end in .php so the server stored and ran a PHP web shell. This let the attacker run commands on the operating system and read or change stored data.
In this post, I will try to guide you through an example of the type of vulnerabilities you may encounter when performing a pentest. In this case, I managed to compromise a web application through a file upload and then execute remote code.
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.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the upload endpoint trusted the client-supplied filename and content type and stored files in a web-served directory without restricting executable extensions.
Impact
An authenticated user could run arbitrary commands on the server, affecting the confidentiality and integrity of stored data.
What the attacker needed
Valid low-privilege account; access to the upload page
How it was found
- Log in as a normal user and open the page that allows document uploads.
- Upload an SVG image containing a script payload and open it to confirm the script runs.
- Inspect the upload request and note the storage directory used for uploaded files.
- Intercept the upload request and change the filename so it ends in .php, adding a small PHP command-execution snippet.
- Open the uploaded file in the browser and run a command to confirm code execution.
- Download a fuller web shell onto the server and browse the filesystem through it.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A file upload feature let people send files to the server. The site did not properly check what kind of file arrived, so a file that the server could run as a program was accepted. The attacker then asked the server to run that file and got a remote shell, meaning they could type commands on the server as if sitting at its keyboard.
What is File upload?
An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.