Php-Jpeg-Injector : Injects Php Payloads Into Jpeg Images

Php-Jpeg-Injector Injects php payloads into jpeg images. Related to this post.

Exploiting PHP-GD Image Create From jpeg() Function

Proof-of-concept to exploit the flaw in the PHP-GD built-in function, image create from jpeg(). Inspired by one of Reddit’s comment on my previous thread regarding exploiting the image create from gif() PHP-GD function.

Warning: This POC was tested using libJPEG v8.0 only. The image requires the same libJPEG version in order to be able to execute the PHP code.

This is the script to generate the payload

<?php
$jpg = imagecreatefromjpeg('image.jpg');
imagejpeg($jpg, 'poc.jpg');
imagedestroy($jpg);
?>

This is the hexadecimal dump for the image.jpg before the recreation. Nothing fancy here, just some junk and EXIF data.

So this is what happens after the recreation of JPEG file, all the EXIF data is removed and not much empty space where we can append the PHP backdoor.

However, there are several important parts in the JPEG file format which can be exploited.

So according to this JPEG file format, where would be the place to put the PHP backdoor?. Search for the Start of Scan (SOS) marker which is FF DA, as you can see there are Scan Header Length and Scan Header after the SOS marker. The place to be put PHP backdoor is right after the Scan Header (00 0C 03 01 00 02 11 03 11 00 3F 00).

Run through the payload script again, and then the PHP backdoor will not get removed even after multiple times going through recreation process

<?php
$jpg = imagecreatefromjpeg('poc.jpg');
imagejpeg($jpg, 'exploit.jpg');
imagedestroy($jpg);
?>

R K

Recent Posts

Kali Linux 2024.4 Released, What’s New?

Kali Linux 2024.4, the final release of 2024, brings a wide range of updates and…

19 hours ago

Lifetime-Amsi-EtwPatch : Disabling PowerShell’s AMSI And ETW Protections

This Go program applies a lifetime patch to PowerShell to disable ETW (Event Tracing for…

19 hours ago

GPOHunter – Active Directory Group Policy Security Analyzer

GPOHunter is a comprehensive tool designed to analyze and identify security misconfigurations in Active Directory…

3 days ago

2024 MITRE ATT&CK Evaluation Results – Cynet Became a Leader With 100% Detection & Protection

Across small-to-medium enterprises (SMEs) and managed service providers (MSPs), the top priority for cybersecurity leaders…

5 days ago

SecHub : Streamlining Security Across Software Development Lifecycles

The free and open-source security platform SecHub, provides a central API to test software with…

1 week ago

Hawker : The Comprehensive OSINT Toolkit For Cybersecurity Professionals

Don't worry if there are any bugs in the tool, we will try to fix…

1 week ago