From File Upload To LFI: A Journey To Exploitation
The file upload feature allowed uploading PHP files, and although dangerous functions were disabled, the attacker uploaded a script using include() to read local files. This led to reading a .env file containing a JWT secret, which was used to forge an admin token and gain full administrative access.
Published on medium.com
Recently I had a client that asked for a black-box pentest for a new web app that the company was about to release. The objective of this black-box penetration test is to assess the security posture of the web application developed for the client.
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
The file upload feature did not restrict file types, allowing PHP code execution, and the server's PHP configuration still permitted file inclusion functions like include().
Impact
The attacker could read sensitive files, forge admin tokens, and gain full administrative access, including the ability to dump the entire database.
What the attacker needed
File upload feature; PHP files not filtered; include() not disabled
How it was found
- Upload a PHP script that uses include() on a user-supplied file parameter.
- Access the uploaded script via curl and pass file paths to read local files.
- Bruteforce sensitive file paths using a wordlist to find the .env file.
- Extract the JWT_SECRET from the .env file.
- Forge a JWT with the role changed to admin using the secret.
- Replace the original JWT in the browser cookies with the forged token to gain admin access.
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 users upload any file, including PHP scripts that run on the server. Even though some dangerous commands were turned off, the attacker used a different PHP function to read files on the server. That let them find a secret key, which they used to pretend to be an administrator.
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.