EXPLOITING STORED XSS TO STEAL COOKIES
A comment section stored user input without encoding, so a script submitted as a comment ran in the browser of anyone who viewed the page. The attacker used that script to read the anti-CSRF token and post the viewer's session cookie back as a comment, then used the stolen cookie to take over an administrator session.
medium.com
Published on medium.com
In this lab, we are required to exploit a STORED XSS vulnerability on the comment section of the lab to exfiltrate the users cookies which we can then escalate to a SESSION HIJACKING attack.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the comment field stored the submitted script and rendered it without encoding, and the session cookie was readable by page scripts.
Impact
An attacker could steal a logged-in user's session cookie and use it to hijack the session, which in this lab gave administrator access; the author notes that in production a WAF or CSP would often block this.
What the attacker needed
A comment form that stores and renders input; victim views the page with the comment; no CSP or WAF blocking the script
The fix
The comment output should be HTML-encoded and the session cookie should be marked HttpOnly so scripts cannot read it.
How it was found
- Inspect the comment form and find the hidden anti-CSRF token field.
- In the browser console, read the token value from the form element to confirm it can be extracted.
- Inspect the comment submission request to learn the field names and order.
- Build a script that reads the token, builds a form with the cookie as the comment, and posts it.
- Submit that script as a comment on the target post.
- When a user views the page, the script runs and the cookie appears as a new comment.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A website that shows comments is supposed to treat them as plain text. Here it treated a comment as code, so a script hidden in a comment ran inside the browser of every visitor. That script could read the visitor's login cookie, which is like a temporary key proving who they are, and quietly post it back to the site where the attacker could collect it.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.