IERG 4851 · Week 10

In-Class Lab: Web 2 — the Backend

Five bugs in one small shop. You attack the app assigned to you.

1. Your address, and how you submit a flag

Same as every lab: there is no form and nothing goes to Blackboard. You submit a flag by redeeming it, and OK 250 is your receipt. If you still have your key from a previous lab, use it — the balance carries over.

cd ~/ierg4851/contactless-ctf
python3 score/keygen.py
wrote mykey.json
address: 3c42822cbbcfb07cac13ad9afa7555cb10fc58f7
verified: address derives from this key
registered as u1155203181

Then, for each flag you earn:

python3 score/redeem.py --flag IERG4851_WEB2_LOGIN_933e4aa8 --to 3c42822cbbcfb07cac13ad9afa7555cb10fc58f7

The new flags start with IERG4851_WEB2_. Each belongs to one account — yours. Redeem it to the address you registered; the ledger refuses a flag presented from another student's account.

OK 250
your total is now 1500 points      (example: 1250 from the earlier labs + this one)

myscore shows your points and rank. The projector page at http://<lab-machine>:8080/ shows everyone and a tick per challenge — this week it grows five new columns (user ierg4851, password given in class).

2. Where the app is, and how you reach it

Everything runs inside the lab machine, like last week. The shop listens on loopback; there is no public URL.

DO NOT use 9388! 9388 below is an example number — it is nobody's real port, and running the commands as written will connect to nothing. Run myweb2 first, then replace 9388 with the port it prints for you — in every command in this manual.
ssh <your-username>@<lab-machine>
myweb2
your shop:     http://127.0.0.1:9388/    <-- EXAMPLE ONLY — DO NOT USE 9388, use YOUR port
start:         curl -i http://127.0.0.1:9388/
your flags:    curl -s http://127.0.0.1:9388/my

Use the port myweb2 printed for you in every command — not 9388. To see the shop in your own browser, forward the port first (both numbers are your port):

ssh -L 9388:127.0.0.1:9388 <you>@<lab-machine>   <-- DO NOT use 9388 — use YOUR port
Use only your own port. The ports are consecutive, and a neighbour's shop is one digit away — a normal app, but its flags belong to that student, and the score server refuses to credit them to you. If a redeem is rejected as belonging to another student, run myweb2 again and check the number.
You have an account at your own shop. The username is your login name on this machine, and the password is the same word. Sign in at /login and look around — that is a plain customer account. The flag is not on it.
The shop runs as a service account, not as you. It can read files your shell cannot. That difference is not a mistake — three of the five challenges depend on it. Try cat on the paths the shop's own pages print, as yourself first, and see the permission denied.

3. The five bugs, one per family from the lecture

#challengefamilywhere it starts
1loginSQL injection/login
2pingcommand injection/tools/ping
3previewSSRF/settings
4downloadpath traversal/files/invoice-2001.txt
5orderaccess control/orders

Five probes to start with, straight from the lecture: a quote ' in every field, a semicolon ;id after a parameter, two dots ../ in every path, a URL scheme a browser will never follow, and an order number nobody showed you. One of them is your first flag.

4. Hints, in the order of the lecture

1 · login — SQL injection in the sign-in form

The sign-in form builds its SQL by gluing your input into the query text. The string from the lecture — ' OR 1=1 -- — logs you in as the admin account, and the flag is on the admin's page. Start with the user field. Bonus: the /products page builds its SQL the same way — with a UNION you can make it show the users table.

2 · ping — command injection in the diagnostic tool

/tools/ping builds a shell command from the host field. The page shows you the full path of the shop's flag file. First try to cat that file yourself: permission denied. Now make the ping tool cat it for you — add a second command after a semicolon, and the output appears in the page.

3 · preview — the fetcher with the shop's rights

/settings fetches any URL you paste, running as the shop service account. It accepts file:// URLs, which read files — with the shop's read permission, not yours. The shop's private files are in its data directory; the ping page prints that path, and the file you want has the obvious name.

4 · download — path traversal in the file server

/files/<name> opens the shop's files directory plus your name. Open the invoice first: its footer names the files directory you are in and the vault directory that holds the flag. You need to go from one to the other with ../. Remember to write / as %2f, or curl will rewrite your path before sending it.

5 · order — the API that checks nothing

Your orders are 2001 and 2002. The API (/api/orders/<number>) serves any order by number — it never checks whose order it is. That is the bug. The flag is in the shop owner's order, and the owner's number is not on any page. But the database knows it: read the orders table through the /products injection (hint 1's bonus), then call the API with that number. That is the smart solve — one question to the database instead of a thousand guesses. You could also try numbers one by one until the API answers; brute force works too, and the fact that it works is part of what is wrong with this API.

Stuck? Every challenge page tells you what it does with your input and where its own files are — read it again, then compare with the matching slide from the lecture.

5. Rules and the explain round

At the end, three or four of you explain one challenge: