/pcq/media/media_files/2025/08/08/cross-site-scripting-2025-08-08-11-51-49.jpg)
Cross-Site Scripting (XSS) attacks are often misunderstood as harmless glitches that display alerts in the browser, while in actuality they are one of the most powerful and malicious vulnerabilities in web security. This guide was written in the voice of an elite hacker and explains advanced exploitation methodology, demonstrates real-world code examples, and explains how a simple script injection can go from embarrassing to a full-on data breach.
The Reality of Cross site scripting (XSS)
Cross-site scripting is a client-side code injection weakness where the trusted web page executes malicious JavaScript. That code runs in the victim’s browser and runs under the same permissions as the page itself.
To put it differently, it’s like having a low-level impersonator eavesdrop and then click-talk in your voice, and everyone else treats him as you do.
There are three types of XSS:
• Stored XSS -The payload is stored on the server (e.g., profiles, comments) and served to all future visitors.
• Reflected XSS – The payload is in a crafted URL, which executes when clicked.
• DOM-based XSS – The payload is injected on the page via the browser’s Document Object Model (DOM) at run-time.
Blind XSS
Blind XSS means the attacker can’t see the payload execute in real-time. In many cases using XSS, the injected payload will only show up in an admin dashboard for your application. In this case, the payload will be stored in the application database and will sit there until the right person, in the right environment, opens the right page at which time the payload will execute fully and send the results back to the attacker.
From file names to shell access
The file upload feature is a gift to an attacker who can get access to the system through an exposed element. When file upload filenames are displayed without sanitizing the input, an attacker can add JavaScript, for example, in the name itself:
"><img src=x onerror=prompt(1)>
When the server produces the filename as HTML, the Javascript code is executed by the browser. Once this foothold is established, the attacker could look to expand their capability or access the system further, such as uploading a reverse shell embedded in a normal file type, and once executed, the reverse shell opens a terminal to the attacker's machine, providing complete control of the server system.
Chaining attacks for more impact
System exploitation
XSS can help with file uploads for malicious files such as HTA applications, which will execute PowerShell commands and open up a meterpreter session with Metasploit, and this provides complete operating control of the victim's system.
XSS + CSRF
XSS + Cross-Site Request Forgery (CSRF) = silent account takeover. By embedding a password-change request in an image tag, the victim’s browser sends the request as if it were genuine, locks them out, and lets the attacker in.
Harvesting NTLM hashes
On corporate networks, an attacker can trigger credential prompts through an injected iframe, capture NTLM authentication hashes, and crack them offline to get passwords.
Hijacking sessions and stealing credentials
With Burp Collaborator, attackers can exfiltrate session cookies or even live credentials entered in forms. Stored XSS makes this super effective. Once planted, the malicious code keeps harvesting data from every visitor until removed.
From XSS to full database dump
A pop-up might be the start, but database compromise is the endgame. Skilled attackers can pivot from XSS into SQL injection to extract sensitive data without ever touching the backend directly. They use the victim’s browser as the messenger.
Step 1 – Initial XSS foothold:
<script>alert("XSS")</script>
This proves they can run arbitrary JavaScript.
Step 2 – Targeting a vulnerable SQL endpoint:
SQL query:
SELECT * FROM products WHERE title = '$term';
Injected via browser fetch request:
<script>
fetch("/vulnerable-endpoint?title=" +
encodeURIComponent("' UNION SELECT 1,2,3,4,5,6,7-- "))
</script>
Step 3 – Injecting JavaScript via SQL output:
HEX payload:
0x3c7363726970743e616c657274282253514c20496e6a656374696f6e22293c2f7363726970743e
Decoded output:
<script>alert("SQL Injection")</script>
Enumeration query:
SELECT COUNT(*)
FROM information_schema.columns
WHERE table_schema = database();
Step 4 - Full enumeration of the database:
The results will be displayed on the page, parsed by the injected script, and shown in the browser. Since we know the database schema, table names, and fields, we can dump usernames, password hashes, payment information, or anything else that was stored.
Why this matters
This XSS-to-SQL injection chain turns a "low severity" vulnerability into a full application compromise. We can steal data, take over accounts, and even deploy permanent backdoors. The victim's browser is a courier for the attacker, sending malicious requests and bringing back everything stolen to it. That's why XSS is considered a critical risk in modern web security and why it should be patched as soon as possible.
How to stay safe?
The best defense against XSS is in layers. Escape and validate all user input before it's rendered, apply Content Security Policy (CSP) to limit script execution, sanitize server-side and client-side, and use a framework that auto-escapes output. For penetration testers and bug bounties, knowing the bad and good XSS attack chains is the difference between a "won't hurt anybody" bug and a "will destroy the business" bug.
More For You
The dark side of enterprise AI
Zuru malware slips into macOS using fake apps puts Apple developers at risk
Windows Server 2025 dMSA exploit lets hackers take domain control
Steam Game Downloads Used to Target Users with Malware