• 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

Exploiting XSS with Javascript/JPEG Polyglot

AnonyViet by AnonyViet
September 8, 2023
in Security
0

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

How to set a password for Word files to prevent copying and editing?

Next Post

SQL Injection Payload List

AnonyViet

AnonyViet

Related Posts

How to implement Shellcode Injection attack technique with Autoit
Security

How to implement Shellcode Injection attack technique with Autoit

March 14, 2025
How to exploit the holy hole of Hijacking on Windows
Security

How to exploit the holy hole of Hijacking on Windows

March 8, 2025
Hamamal: Shellcode execution technique from afar to overcome Antivirus's discovery
Security

Hamamal: Shellcode execution technique from afar to overcome Antivirus's discovery

February 10, 2025
Snov.io Email Finder: Search emails with only company name/domain name/LinkedIn profile
Security

Snov.io Email Finder: Search emails with only company name/domain name/LinkedIn profile

December 14, 2024
Capsolver: Automatic solution solution for business
Security

Capsolver: Automatic solution solution for business

December 12, 2024
Seekr: Collect & manage OSINT data
Security

Seekr: Collect & manage OSINT data

November 22, 2024
Next Post
SQL Injection Payload List

SQL Injection Payload List

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Recent News

Elon Musk launches Grok 3.5: regardless of internet data

Elon Musk launches Grok 3.5: regardless of internet data

May 10, 2025
Instructions for installing Facebook Lite on super light iPhone

Instructions for installing Facebook Lite on super light iPhone

May 10, 2025
Little Language Lessons: Learn foreign languages ​​with Google

Little Language Lessons: Learn foreign languages ​​with Google

May 9, 2025
Download Vietnamese Pascal Video course for beginners

Download Vietnamese Pascal Video course for beginners

May 9, 2025
Elon Musk launches Grok 3.5: regardless of internet data

Elon Musk launches Grok 3.5: regardless of internet data

May 10, 2025
Instructions for installing Facebook Lite on super light iPhone

Instructions for installing Facebook Lite on super light iPhone

May 10, 2025
Little Language Lessons: Learn foreign languages ​​with Google

Little Language Lessons: Learn foreign languages ​​with Google

May 9, 2025
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

Elon Musk launches Grok 3.5: regardless of internet data

Elon Musk launches Grok 3.5: regardless of internet data

May 10, 2025
Instructions for installing Facebook Lite on super light iPhone

Instructions for installing Facebook Lite on super light iPhone

May 10, 2025
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí SHBET bongdaso

wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí SHBET bongdaso