Detailed Technical Analysis of "Advanced JavaScript Injections"

Overview:
Brute Logic’s write-up delves into advanced techniques for performing JavaScript injections (JSI), focusing on unconventional vectors and methods to bypass modern security mechanisms. The emphasis is on situations where traditional payloads might fail, requiring more sophisticated approaches.

Key Technical Details:

  1. Single and Double Quote Injection: The article begins by covering the fundamental injection techniques using single (') and double (") quotes. These characters often serve as the foundation for various injection vectors as they can break out of existing contexts or attributes.

  2. Single Quote (') Technique: html <input value='<script>alert(1)</script>'> When the injected input is surrounded by single quotes, it effectively breaks out of the attribute value, allowing the attacker to insert arbitrary HTML or JavaScript.

  3. Double Quote (") Technique: html <input value="<script>alert(1)</script>"> Similar to single quotes, double quotes can be leveraged to inject script tags or other malicious content.

  4. Bypassing Character Encoding: Many web applications enforce character encoding to prevent straightforward JavaScript injections. The article discusses methods to exploit these scenarios by using alternative representations of malicious payloads:

  5. Hexadecimal (%) Encoding: html <input value="%3Cscript%3Ealert(1)%3C/script%3E"> The use of hex-encoded characters (%3C for < and %3E for >) can bypass some filtering mechanisms.

  6. Hexadecimal Unicode (\u) Encoding: html <input value="\u003Cscript\u003Ealert(1)\u003C/script\u003E"> Utilizing Unicode encoding (\u003C for < and \u003E for >) provides another bypass method, especially useful when dealing with JavaScript’s eval() function.

  7. Breaking out of Attribute Contexts: Breaking out of attribute contexts requires a deeper understanding of how browsers parse HTML. The writeup explores scenarios where closing out of attributes might be feasible and effectively inject scripts:

  8. Event Handlers in Attributes: html <img src=x onerror=alert(1)> Injecting event handlers directly into HTML attributes can create a vector for executing JavaScript when an error or specific event occurs, enabling the payload to run in the user’s browser.

  9. Double Escaping of Entities: html <input value="<script>alert(1)</script>"> Escaping entities twice such as converting < to <, then &lt; for double escape, allows attackers to bypass certain sanitizers.

  10. HTML5 and Advanced Contextual Escapes: HTML5 introduces new elements and attributes offering additional vectors for injection attacks. The article highlights lesser-known tags and attributes that can be beneficial for advanced exploit crafting:

  11. HTML5 Attributes: html <iframe srcdoc="<script>alert(1)</script>"></iframe> Using the srcdoc attribute of an iframe to inject JavaScript directly.

    html <input type='image' src='x' onerror='alert(1)'> Leveraging modern input types like image to introduce injection vectors via associated events.

  12. Template Literals and ES6 Features: The write-up discusses how ECMAScript 6 (ES6) features, such as template literals, introduce additional injection points.

  13. Template Literal Injection: javascript var user = "<script>alert(1)</script>"; var message = `Welcome ${user}`; document.write(message); Using backticks ( ) to insert strings can be dangerous if user input isn't properly sanitized.

  14. CSP Bypasses: Content Security Policy (CSP) is a critical defense against XSS, but misconfigurations or overly permissive policies can be bypassed with clever JSIs:

  15. JSONP endpoints and Dangerous Allowed Origins: Analysis of how JSONP endpoints combined with overly generous CSP settings can lead to XSS via JavaScript injection.

Key Takeaways:

Conclusion:

The write-up is an essential resource for understanding contemporary and advanced techniques for JavaScript injection. By exploring character encoding, context escapes, attribute injections, and modern web features, it provides valuable insights into bypassing traditional and modern security defenses, underscoring the importance of adaptive and comprehensive security measures.

For a complete guide, refer to the original blog post here.