Traversing the Path to RCE
The server's file read and write endpoints accepted a path parameter without restricting it to the intended directory, so an attacker could traverse to system files and to the web root. By writing a PHP shell into the web root, the attacker could run commands on the server.
Published on blog.hawkeyesecurity.com
This post will detail the steps I took to find a path traversal vulnerability, and how I paired the vulnerability with the logic of the application to achieve Remote Code Execution through a shell upload.
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 file handling endpoint used the user-supplied path directly without normalising it or confining it to an allowed directory.
Impact
An attacker could read system files and write a shell to the web root, leading to remote code execution for all users of the app.
What the attacker needed
Access to the mobile app; ability to intercept app traffic; a document upload feature
The fix
The endpoint should normalise the supplied path and reject any path that resolves outside the intended document directory.
How it was found
- Intercept the upload request and note the server checks whether the file exists.
- Change the method parameter to writeFile to encrypt and upload the file.
- Change the method parameter to readFile and set the path parameter to a document name.
- Traverse the path parameter to read the system password file.
- Traverse the path to write a PHP shell into the /api/ directory.
- Request the uploaded shell with a command parameter to run the id command.
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.
The app lets you save and open documents on a server. The server trusted the file name you sent and did not check that it stayed inside the documents folder. By using '..' to climb out of that folder, the tester could read system files and then place a small program on the web server that runs commands.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.