From File Upload to Remote Code Execution: A Penetration Testing Case Study
A file upload feature accepted a double-extension filename and stored it in a web-accessible directory where the server executed it as a script. An attacker could run commands as the web service account and obtain an interactive shell.
Published on ayham-megdadi.medium.com
A vulnerable file upload feature may look like a relatively minor web application issue.
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 validation only checked the final extension and the upload directory allowed server-side script execution.
Impact
An attacker could execute commands as the www-data user and obtain an interactive shell, though root access was not achieved.
What the attacker needed
Network access to the target; web server executes scripts in upload directory
The fix
The upload feature should validate file content and type server-side, store uploads outside the web root, and configure the web server to prevent script execution in upload directories.
How it was found
- Discover the target host on the internal network.
- Enumerate open ports and find the HTTP service.
- Inspect the web page source and find a hidden reference to index2.html.
- Access the upload page at /jQuery/upload.php.
- Upload a file with a double extension such as shell.php.jpg.
- Access the uploaded file to execute commands and confirm RCE.
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 website let people upload files, but it only checked the end of the filename. By naming a file like 'picture.php.jpg', the upload was accepted, yet the server still treated it as a program and ran it. This let the tester run commands on the server as the web server's user.
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.