Skip to content
File upload Write-up Intermediate

How I Weaponized a Simple PDF Upload and Executed Code on the Tar

The file upload feature allowed an SVG file to be saved with a .png extension by manipulating the 'extension' parameter, but the file was not accessible as .svg. The attacker then uploaded a PDF containing embedded JavaScript, which executed when the PDF was viewed, leading to code execution in the PDF viewer context.

Cookiebug Follow

Published on medium.com

Hey!! Everyone, recently I was testing on a private pentest program, where I found a lot of functionality to test, but the interesting one from all those was my favorite File Upload Functionality.

Cookiebug, on medium.com

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 application trusted a client-supplied 'extension' parameter to determine the saved file extension, and allowed PDF files with embedded JavaScript to be served without sanitisation.

Impact

An attacker could execute arbitrary JavaScript in the context of the PDF viewer when a victim opens the uploaded PDF, potentially leading to further attacks.

What the attacker needed

Access to file upload feature; victim opens the uploaded PDF

The fix

The application should not trust client-supplied file extensions and should sanitise or disallow PDFs with embedded JavaScript.

How it was found

  1. Upload a simple image file and observe the request, noting the 'extension' parameter.
  2. Try double extension, triple extension, and null byte injection, but none work.
  3. Upload an SVG file with JavaScript content and set the 'extension' parameter to 'png'.
  4. The file is saved as a .png but accessing it as .svg fails.
  5. Use JS2PDFInjector to embed JavaScript into a PDF file.
  6. Upload the malicious PDF and visit its path, triggering an alert popup.

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 lets users send files to a website. The site tried to check file types but trusted a hidden field that said what extension to use. The attacker uploaded a PDF that contained JavaScript, and when someone opened it, the script ran. This shows that trusting user input for file handling can lead to script execution.

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.

Similar reports

View all

Same bug class and techniques, clearest first.

Unrestricted file upload

The lesson behind this report.

An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.