Skip to content
RCE Write-up Intermediate

Local File Inclusion Via File Upload Of Jpg Png And Gif Files

The text describes a technique where an attacker uploads an image file with a PHP payload hidden in its metadata, then uses a local file inclusion (LFI) vulnerability to execute that payload. This allows remote code execution and reverse shell access.

Harsh Hatej Follow

Published on systemweakness.com

If we get the funcitonality of uploading a file to the target web server. Than we can upload our payload to the server and through local file inclusion we can call for that file :

Harsh Hatej, on systemweakness.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 allows uploading files with image extensions but does not properly validate or sanitise file contents, and a separate LFI vulnerability allows execution of uploaded files.

Impact

An attacker could execute arbitrary commands on the server, leading to full compromise and reverse shell access.

What the attacker needed

File upload functionality; LFI vulnerability; ability to upload image files

How it was found

  1. Create a PHP page with an upload form that only allows PNG, JPG, and GIF files.
  2. Use exiftool to insert a PHP payload into the comment metadata of a PNG image.
  3. Upload the crafted image to the server.
  4. Trigger the LFI vulnerability to include and execute the uploaded image file.
  5. Observe that the PHP code runs, confirming code execution.
  6. Use the same technique to run system commands or obtain a reverse shell.

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.

This is about combining two weaknesses: a file upload feature that only checks the file type, and a separate bug that lets an attacker include local files in the web server's response. By hiding malicious code inside an image's metadata, the attacker bypasses the upload check, and then the LFI bug runs that code, giving the attacker control of the server.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by Harsh Hatej

View all

3 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.