Skip to content
XSS Write-up Beginner

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?

Arfiandafirsta, on medium.com

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

  1. Create a PHP guestbook that stores comments in a session and echoes them without escaping.
  2. Submit a comment containing a script tag.
  3. Observe the browser executing the script and showing an alert pop-up.
  4. Apply htmlspecialchars() to the comment before echoing it.
  5. Reset the session data and submit the same script tag again.
  6. 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.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.