Hacking Buku Tamu: Eksperimen Sederhana Membedah Celah XSS
A PHP guestbook stored user comments in a session and echoed them back without escaping, so a script tag in a comment ran in the browser. An attacker could run JavaScript in other visitors' browsers, potentially stealing cookies or redirecting to phishing sites.
medium.com
Published on medium.com
Pernah dengar akun orang tiba-tiba kena hack cuma gara-gara ngeklik sebuah link? Atau lagi asyik buka web, eh malah dibombardir pop-up aneh?
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
The application echoed user-supplied comment text into HTML without escaping special characters, so the browser interpreted it as markup and script.
Impact
An attacker could run JavaScript in other users' browsers, potentially stealing login cookies, hijacking accounts, or redirecting users to phishing sites.
What the attacker needed
Victim views the guestbook page; attacker can post a comment
The fix
The code was fixed by escaping comment output with htmlspecialchars() so special characters are rendered as harmless text.
How it was found
- Create a PHP guestbook that stores comments in a session and echoes them without escaping.
- Submit a comment containing a script tag.
- Observe the browser executing the script and showing an alert pop-up.
- Apply htmlspecialchars() to the comment before echoing it.
- Reset the session data and submit the same script tag again.
- Observe the script is displayed as harmless text and no pop-up appears.
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.
The guestbook saved whatever a visitor typed and later printed it straight into the page. When someone typed a script tag, the browser treated it as a program and ran it, showing a pop-up. This is called cross-site scripting: a way to make a website run an attacker's code in other people's browsers.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.