How I Learnt the Importance of CSP from File Upload Vulnerability
The text describes a file upload vulnerability where an attacker can upload a PHP script disguised as a PNG image and execute system commands if the server processes it as PHP. It also explains that a Content Security Policy (CSP) can block the execution of malicious JavaScript embedded in uploaded files.
medium.com
Published on medium.com
Assume that there is an option to upload an image to your website. Scenario: Test for image file upload (.png)
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
What the attacker needed
File upload feature; server executes uploaded files as PHP
The fix
The server should be configured to not execute uploaded files as scripts, and a CSP should be used to block inline scripts.
How it was found
- Create a PHP file that runs system commands.
- Download a PNG image.
- Merge the PHP file into the PNG file to create a payload.
- Upload the payload file to the website.
- Find the URL where the uploaded file is stored.
- Access the URL with a command parameter to execute commands.
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 vulnerability lets someone upload a file that the server then runs as a program, instead of just storing it as an image. Here, the author shows how to hide a small PHP program inside a PNG image; if the server runs it, the attacker can run commands on the server. A Content Security Policy (CSP) is a browser rule that stops certain scripts from running, which can block some attacks even after a file is uploaded.
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.