Two Tickets, One Number
HardShell Scripting30-40 minHelpdesk workers call /usr/local/bin/ticket-next to get a ticket number. It reads the counter, adds one and writes it back, with nothing stopping two workers doing that at the same moment. During the morning rush the same number went out twice, more than once. Make the script safe, find every number that was issued twice, and use that list to unlock the flag.
The contract, ticket-next FILE:
FILEholds one whole number N. Print N+1 on stdout and leave N+1 inFILE.- Safe under concurrency: K copies started at the same moment on the same
FILEprint K different numbers, N+1 to N+K, and leave N+K. - With the wrong number of arguments, a
FILEthat does not exist (do not create it), or aFILEthat does not hold a whole number, exit non-zero and leaveFILEunchanged.
Grading runs your script, including 30 copies at once on a fresh counter. Then:
1. In /var/lib/tickets/issued.log, find every ticket number that was issued (action=issue) more than once. A re-open (action=reopen) mentions an old ticket and is not a second issue. Write the numbers to /root/case/duplicates.txt, one per line.
2. /root/case/flag.enc was encrypted with openssl enc -aes-256-cbc -pbkdf2 -salt -pass pass:<KEY>, where KEY is those numbers sorted ascending and joined with commas (like 50012,50077,50310). Decrypt it and save the flag to /root/case/flag.txt.
See /root/case/brief.txt.
- Recognise a read-modify-write race and close it with flock
- Make a script refuse bad input without side effects
- Count only the records that matter in a log with look-alike events
Hands-on lab: you work on a real Linux box in your browser, graded on the machine's actual state.
