Day 47 – XSS Lab Practice & WriteUp

Listen to this Post

Today, I started by completing the Cross-Site Scripting (XSS) module on Hack The Box (HTB), where I learned all about the three main types of XSS—Reflected, Stored, and DOM-based—and how to exploit and defend against them. Then, I jumped into the XSS-Labs to put my learning into practice.

From Level 1 to Level 10, each challenge felt like solving a mini puzzle. At first, it was pretty straightforward—just inserting `` would trigger the alert. But as I progressed, things got trickier: bypassing filters, closing attributes, using pseudo-protocols, and even encoding payloads. Levels 8 and 9 were particularly challenging, but also incredibly rewarding once I figured them out! Afterward, I wrote detailed write-ups in both Chinese and English, which really helped solidify my understanding.

  • (CN) CSDN: https://lnkd.in/ggUqQtGj
  • (EN) GitHub: https://lnkd.in/gwC5YTKN

You Should Know:

1. Basic XSS Payloads

  • Reflected XSS:
    <script>alert('XSS');</script>
    

    This is the simplest form of XSS, where the script is reflected off a web server.

  • Stored XSS:

    <script>document.cookie</script>
    

    This payload is stored on the server and executed when other users access the affected page.

  • DOM-based XSS:

    <img src="x" onerror="alert('DOM XSS')">
    

    This payload manipulates the Document Object Model (DOM) of a webpage.

2. Bypassing Filters

  • Encoding Payloads:

Use URL encoding or Unicode to bypass filters:

%3Cscript%3Ealert(1)%3C%2Fscript%3E
  • Using Pseudo-Protocols:
    <a href="javascript:alert('XSS')">Click Me</a>
    

  • Closing Attributes:

    "><script>alert('XSS')</script>
    

3. Advanced XSS Techniques