• Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
AnonyViet - English Version
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
AnonyViet - English Version
No Result
View All Result
Home Security

Exploiting XSS with Javascript/JPEG Polyglot

AnonyViet by AnonyViet
September 8, 2023
in Security
0
0
SHARES
Share on FacebookShare on Twitter

Just as PNG, JPEG, and DOC are valid file types, polyglot is a combination of two different file types. Example: Phar + JPEG (PHP archive and JPEG file), GIFAR (Gif and Rar file) Javascript + JPEG, etc.

Join the channel Telegram belong to AnonyViet ???? Link ????

Exploiting XSS with Javascript/JPEG Polyglot

Apps that only allow certain file types on features like file uploads and disallow other file types like .php or .js files because they could allow attackers to upload malicious files on the app. Applications perform checks for evicting files with double extensions (.jpg.php) or using empty bytes in extensions (.php%00.jpg), filenames (.htaccess, .config,…), and if the signature of the uploaded file also matches its content type.

Different applications use different methods, and polyglot can be used to bypass some of these authentication checks.

JPEG Architecture

A JPEG image is represented as a series of segments where each segment begins with a header. Each header starts with a byte number. Payload by header is different depending on the header type. Common types of JPEG markers are as listed below:

0xffd8: “Start of Image”,
0xffe0: “Application Default Header”,
0xffdb: “Quantization Table”,
0xffc0: “Start of Frame”,
0xffc4: “Define Huffman Table”,
0xffda: “Start of Scan”,
0xffd9: “End of Image”

Each binary file contains several headers. They are important to the file because they identify file-specific information. Most headers are followed by length information. This tells us how long that particular segment is.

The header of the image header contains FF D8. If we don’t see it, we can assume this is another file. Another important marker is FF D9 which indicates the end of the image.

To make the payload look like a legitimate JPEG file, we’ll add the length of the header, the comment header, the empty bytes to the pad, and then the javascript attack vector.

Suppose the attack vector is one XSS vulnerability */=alert(“XSS”)/* Converting it to hexadecimal would look like this.

Exploiting XSS with Javascript/JPEG Polyglot 11

Payload in hex:

2A 2F 3D 61 6C 65 72 74 28 22 58 53 53 2E 22 29

We can use a hex editor to include javascript in the image’s metadata. This works because browsers interpret the code when they display images as HTML.

Exploiting XSS with Javascript/JPEG Polyglot 12

I received an image test.jpg and below is the hexdump of test.jpg. With the help of a ghex editor, we will replace some hex characters and save them.

Exploiting XSS with Javascript/JPEG Polyglot 13

As we know FF D8 is the start of the image, the next two bytes represent the upcoming two bytes, 00 10 represents the length of the JPEG header which is equivalent to a decimal number of 16 bytes.

Injection time

We will inject the payload between FF E0 and FF DB. Let’s start with 2F 2A, which is the hex representation of /*

Exploiting XSS with Javascript/JPEG Polyglot 14

We just replaced the previous 00 10 with 2F 2A and the decimal equivalent of hex 2F 2A is 12074 bytes. So now header. header image is changed from 16 bytes to 12074 bytes.

Exploiting XSS with Javascript/JPEG Polyglot 15

From the screenshot above, we can see the size of the payload is 18 bytes, so we have to remove the remaining bytes with null which is 12074–16–18 = 12040 bytes.

Exploiting XSS with Javascript/JPEG Polyglot 16

The above commands will read test.jpg, insert the payload between 2F 2A FF DB change hexadecimal into the buffer, add 12040 null bytes and write it to file test_new.jpg. Now in the ghex editor close the comment tag before FF D9

Exploiting XSS with Javascript/JPEG Polyglot 17

Code to execute image as javascript:-<script charset="ISO-8859-1" src="https://anonyviet.com/khai-thac-xss-voi-javascript-jpeg-polyglot/test_new.jpeg">

On Firefox when using the UTF-8 character set it will corrupt the polyglot when included as a script. So for the script to work we need to specify the ISO-8859–1 character set on the script tag and it executes fine.

And this is when testing in the browser.

Exploiting XSS with Javascript/JPEG Polyglot 18

Polyglot javascript/jpeg Ours is already working.

Update: Mozilla fixed this in Firefox 51 and later versions.

Rate this post

Tags: exploitingJavascriptJPEGPolyglotXSS
Previous Post

Free Share Chinese course for beginners

Next Post

Share professional website programming course through 5 real projects

AnonyViet

AnonyViet

Related Posts

SQL Injection Payload List
Security

SQL Injection Payload List

September 9, 2023
AnvRS – Reverse Shell Bypass Antivirus Tool
Security

AnvRS – Reverse Shell Bypass Antivirus Tool

August 29, 2023
How to find Stored XSS errors simply
Security

How to find Stored XSS errors simply

August 26, 2023
How to Find Vulnerable Vulnerabilities Using Google Dorks
Security

How to Find Vulnerable Vulnerabilities Using Google Dorks

August 26, 2023
BigBountyRecon: Google Dork Spying Tool
Security

BigBountyRecon: Google Dork Spying Tool

August 12, 2023
Phishing method by attaching malicious files on Office 365
Security

Phishing method by attaching malicious files on Office 365

August 11, 2023
Next Post
Share professional website programming course through 5 real projects

Share professional website programming course through 5 real projects

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent News

Use Aquarium on the browser to check if the computer configuration is strong

September 22, 2023
Download Panel TMV: Free photo editing panel for Photoshop

Download Panel TMV: Free photo editing panel for Photoshop

September 21, 2023
Download 64 professional standard Powerpoint templates for 2017 for free

Download 64 professional standard Powerpoint templates for 2017 for free

September 21, 2023
Instructions for using Google Duet – AI in Sheets

Instructions for using Google Duet – AI in Sheets

September 20, 2023

Use Aquarium on the browser to check if the computer configuration is strong

September 22, 2023
Download Panel TMV: Free photo editing panel for Photoshop

Download Panel TMV: Free photo editing panel for Photoshop

September 21, 2023
Download 64 professional standard Powerpoint templates for 2017 for free

Download 64 professional standard Powerpoint templates for 2017 for free

September 21, 2023
AnonyViet - English Version

AnonyViet

AnonyViet is a website share knowledge that you have never learned in school!

We are ready to welcome your comments, as well as your articles sent to AnonyViet.

Follow Us

Contact:

Email: anonyviet.com[@]gmail.com

Main Website: https://anonyviet.com

Recent News

Use Aquarium on the browser to check if the computer configuration is strong

September 22, 2023
Download Panel TMV: Free photo editing panel for Photoshop

Download Panel TMV: Free photo editing panel for Photoshop

September 21, 2023
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.