Home The Hackable Castle
⚡ Module 03 · Intermediate

The Hackable Castle: Web Vulnerabilities

Ever wonder how websites protect themselves? What if you could peek behind the curtain and see the secret spells and hidden doors that hackers use? Today, we’re not just visitors—we're becoming the castle's royal security testers! Ready? 🏰✨

🛡️ WHITE HAT OATH: A true digital detective protects the realm. Never test, scan, or attack websites you do not own. We are learning to build stronger shields, not bigger weapons!
💉

Dark Arts Spellcasting 101

Imagine a website is a magic castle. The comment box is a scroll where you can write messages for everyone to see. But what if instead of a message like "Cool castle!", you wrote a *mischievous spell*? 📜✨

If the castle's magic shield isn't strong enough, it might read your spell and accidentally cast it for every visitor! This is an **"Injection Attack"**—you're injecting your own magic where it doesn't belong. The most common type is called Cross-Site Scripting (XSS).

🔬 Pro-Tip: In the industry, this is called "improper input validation and output encoding." It's a fancy way of saying the castle (the server) is trusting user-supplied data without cleaning ("sanitizing") it before showing it to other people.
📺 PwnFunction — "Cross-Site Scripting (XSS) Explained" — A fantastic animated look at how these "spells" work under the hood.

⚡ Security Check: Input Sanitization

How do web developers prevent Injection Attacks like XSS?

By building a bigger firewall around the castle.
By carefully checking ("sanitizing") every message before showing it.

🧪 The Royal Spellchecker's Test

The king's sorcerer needs to see why the "Royal Spellchecker" is so important! Below are two message boards. One is shielded, the other is not. Try typing this simple spell in both: <b>Make this BOLD!</b> and see what happens!

Output:

Output:

Whoa! Notice how the shielded site just shows you the text, while the unshielded one actually runs the code! This is *why* sanitization is critical. For a more mischievous test, try this spell in both boxes: <img src=x onerror=alert('oops')>

🕵️‍♂️ Secret Decoder Mission

Digital detectives look for clues hidden deep inside a website's code. Every browser has a set of secret 'developer tools' that let you see a website's skeleton. In Chrome or Firefox, try right-clicking on the boxes below and looking for an 'Inspect' option to get started!

LEVEL 1: The Hidden Comment

A secret message is hidden in the code for the box below. Can you find the secret password to open the treasure chest?

> searching for treasure...

LEVEL 2: The Secret Attribute

Awesome! Now for a trickier one. This time, the flag isn't in a comment. Use the Inspector to examine the element below and look closely at its "attributes" to find the secret data.

> terminal simulator online...
Why `data-secret`? Developers often use custom `data-*` attributes to store information in the HTML without affecting its appearance. It's a common place for security researchers to find interesting clues!

LEVEL 3: The Royal Art Gallery - Live Spellcasting!

🛡️ Safety Check: This is a safe simulation! We've built this box so you can see how an XSS attack works without any real danger. Remember the White Hat Oath: Never, ever try this on a website you don't own.

The comments section below is connected to the Royal Art Gallery, but its magic shield is weak! Can you cast spells to change what people see? Start with Challenge 1 and see how far you can get!

Comments Section:
Challenge 1: The Big Message

Can you post a comment that makes the text HUGE? Hint: Use an `<h1>` tag!

Challenge 2: The Ghost in the Machine

Can you make an alert box pop up? Hint: Some HTML tags can run JavaScript if they fail to load something. Can you think of a tag that loads an external file? What happens if that file doesn't exist?

Challenge 3: The Master Painter 🎨

An alert is one thing, but can you change the art gallery itself? Inject a spell that changes the comments section background to bright red! Hint: You'll need an HTML tag, an event like `onerror`, and some `style` magic.

📚 Go Deeper

You've just tested the castle's defenses. Ready to become a master architect? These are the real-world blueprints and training grounds.

👨‍👩‍👧 Parent Corner: The Smart Home Security Audit

This lesson's "hackable castle" is a great metaphor for your own "smart home." Many devices—from smart speakers to cameras to thermostats—are like little comment boxes that need strong shields. This is a perfect opportunity to do a "Smart Home Security Audit" together! Ask questions like: Does our Wi-Fi have a strong password? Did we change the default passwords on our smart devices? It's a fun way to apply these digital lessons to the real world and learn together.