TryHackMe: Cross-Site Scripting (XSS) Deep Dive
Understanding XSS
Cross-Site Scripting (XSS) allows attackers to inject malicious scripts into web pages viewed by other users.
Types of XSS
1. Stored (Persistent) XSS
- Malicious script is stored in the database
- Affects all users who view the page
- More dangerous than reflected XSS
2. Reflected XSS
- Malicious script is reflected in the URL
- Requires user interaction (clicking a link)
- Affects only that user
3. DOM-based XSS
- Vulnerability exists in client-side code
- JavaScript processes user input unsafely
Real-world Impact
- Session hijacking
- Credential theft
- Malware distribution
- Defacement
Mitigation Strategies
- Input validation and sanitization
- Output encoding
- Content Security Policy (CSP)
- HTTPOnly and Secure flags on cookies
- Regular security testing
Testing for XSS
<script>alert('XSS Vulnerability')</script>
<img src=x onerror="alert('XSS')">
<svg onload="alert('XSS')">
