# 143,993 - Pentesting IMAP
{% hint style="success" %}
Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\
Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** π¬ [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** π¦ [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}
## μΈν°λ· λ©μμ§ μ κ·Ό νλ‘ν μ½
**μΈν°λ· λ©μμ§ μ κ·Ό νλ‘ν μ½ (IMAP)**μ μ¬μ©μκ° **μ΄λ€ μμΉμμλ μ΄λ©μΌ λ©μμ§μ μ κ·Όν μ μλλ‘** μ€κ³λμμ΅λλ€. μ£Όλ‘ μΈν°λ· μ°κ²°μ ν΅ν΄ μ΄λ£¨μ΄μ§λλ€. λ³Έμ§μ μΌλ‘ μ΄λ©μΌμ **μλ²μ 보κ΄**λλ©° κ°μΈ μ₯μΉμ λ€μ΄λ‘λλμ΄ μ μ₯λμ§ μμ΅λλ€. μ΄λ μ΄λ©μΌμ μ κ·Όνκ±°λ μ½μ λ **μλ²μμ μ§μ ** μ΄λ£¨μ΄μ§λ€λ κ²μ μλ―Έν©λλ€. μ΄ κΈ°λ₯μ **μ¬λ¬ μ₯μΉμμ μ΄λ©μΌμ νμΈνλ** νΈλ¦¬ν¨μ μ 곡νμ¬ μ¬μ©λ μ₯μΉμ κ΄κ³μμ΄ λ©μμ§λ₯Ό λμΉμ§ μλλ‘ ν©λλ€.
κΈ°λ³Έμ μΌλ‘ IMAP νλ‘ν μ½μ λ κ°μ ν¬νΈμμ μλν©λλ€:
* **ν¬νΈ 143** - κΈ°λ³Έ IMAP λΉμνΈν ν¬νΈμ
λλ€.
* **ν¬νΈ 993** - IMAPμ μμ νκ² μ°κ²°νλ €λ©΄ μ¬μ©ν΄μΌ νλ ν¬νΈμ
λλ€.
```
PORT STATE SERVICE REASON
143/tcp open imap syn-ack
```
## λ°°λ μμ§
```bash
nc -nv 143
openssl s_client -connect :993 -quiet
```
### NTLM Auth - μ 보 μ μΆ
μλ²κ° NTLM μΈμ¦(Windows)μ μ§μνλ κ²½μ°, λ―Όκ°ν μ 보(λ²μ )λ₯Ό μ»μ μ μμ΅λλ€:
```
root@kali: telnet example.com 143
* OK The Microsoft Exchange IMAP4 service is ready.
>> a1 AUTHENTICATE NTLM
+
>> TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=
+ TlRMTVNTUAACAAAACgAKADgAAAAFgooCBqqVKFrKPCMAAAAAAAAAAEgASABCAAAABgOAJQAAAA9JAEkAUwAwADEAAgAKAEkASQBTADAAMQABAAoASQBJAFMAMAAxAAQACgBJAEkAUwAwADEAAwAKAEkASQBTADAAMQAHAAgAHwMI0VPy1QEAAAAA
```
Or **μλν** this with **nmap** plugin `imap-ntlm-info.nse`
### [IMAP λΈλ£¨νΈν¬μ€](../generic-methodologies-and-resources/brute-force.md#imap)
## ꡬ문
IMAP λͺ
λ Ήμ΄ μμ λ [μ¬κΈ°](https://donsutherland.org/crib/imap)μμ νμΈν μ μμ΅λλ€:
```
Login
A1 LOGIN username password
Values can be quoted to enclose spaces and special characters. A " must then be escape with a \
A1 LOGIN "username" "password"
List Folders/Mailboxes
A1 LIST "" *
A1 LIST INBOX *
A1 LIST "Archive" *
Create new Folder/Mailbox
A1 CREATE INBOX.Archive.2012
A1 CREATE "To Read"
Delete Folder/Mailbox
A1 DELETE INBOX.Archive.2012
A1 DELETE "To Read"
Rename Folder/Mailbox
A1 RENAME "INBOX.One" "INBOX.Two"
List Subscribed Mailboxes
A1 LSUB "" *
Status of Mailbox (There are more flags than the ones listed)
A1 STATUS INBOX (MESSAGES UNSEEN RECENT)
Select a mailbox
A1 SELECT INBOX
List messages
A1 FETCH 1:* (FLAGS)
A1 UID FETCH 1:* (FLAGS)
Retrieve Message Content
A1 FETCH 2 body[text]
A1 FETCH 2 all
A1 UID FETCH 102 (UID RFC822.SIZE BODY.PEEK[])
Close Mailbox
A1 CLOSE
Logout
A1 LOGOUT
```
### μ§ν
```
apt install evolution
```
![](<../.gitbook/assets/image (1033).png>)
### CURL
κΈ°λ³Έ νμμ [CURL](https://ec.haxx.se/usingcurl/usingcurl-reademail#imap)λ‘ κ°λ₯νμ§λ§, λ¬Έμκ° μΈλΆ μ¬νμ΄ λΆμ‘±νλ―λ‘ μ νν μΈλΆ μ¬νμ μν΄ [μμ€](https://github.com/curl/curl/blob/master/lib/imap.c)λ₯Ό νμΈνλ κ²μ΄ μ’μ΅λλ€.
1. λ©μΌλ°μ€ λμ΄ (imap λͺ
λ Ή `LIST "" "*"`)
```bash
curl -k 'imaps://1.2.3.4/' --user user:pass
```
2. λ©μΌλ°μ€μ λ©μμ§ λμ΄νκΈ° (imap λͺ
λ Ήμ΄ `SELECT INBOX` ν `SEARCH ALL`)
```bash
curl -k 'imaps://1.2.3.4/INBOX?ALL' --user user:pass
```
κ²μ κ²°κ³Όλ λ©μμ§ μΈλ±μ€ λͺ©λ‘μ
λλ€.
λ 볡μ‘ν κ²μμ΄λ₯Ό μ 곡νλ κ²λ κ°λ₯ν©λλ€. μ: λ©μΌ λ³Έλ¬Έμ λΉλ°λ²νΈκ° ν¬ν¨λ μ΄μ κ²μ:
```bash
curl -k 'imaps://1.2.3.4/Drafts?TEXT password' --user user:pass
```
κ°λ₯ν κ²μ μ©μ΄μ λν μ’μ κ°μλ [μ¬κΈ°](https://www.atmail.com/blog/imap-commands/)μ μμ΅λλ€.
3. λ©μμ§ λ€μ΄λ‘λ (imap λͺ
λ Ή `SELECT Drafts` λ° κ·Έ λ€μ `FETCH 1 BODY[]`)
```bash
curl -k 'imaps://1.2.3.4/Drafts;MAILINDEX=1' --user user:pass
```
λ©μΌ μΈλ±μ€λ κ²μ μμ
μμ λ°νλ λμΌν μΈλ±μ€κ° λ©λλ€.
λ©μμ§μ μ κ·ΌνκΈ° μν΄ `UID`(κ³ μ ID)λ₯Ό μ¬μ©νλ κ²λ κ°λ₯νμ§λ§, κ²μ λͺ
λ Ήμ μλμΌλ‘ νμνν΄μΌ νλ―λ‘ λ νΈλ¦¬ν©λλ€. μ:
```bash
curl -k 'imaps://1.2.3.4/INBOX' -X 'UID SEARCH ALL' --user user:pass
curl -k 'imaps://1.2.3.4/INBOX;UID=1' --user user:pass
```
λν, λ©μμ§μ μΌλΆλ§ λ€μ΄λ‘λνλ κ²μ΄ κ°λ₯ν©λλ€. μλ₯Ό λ€μ΄, 첫 5κ°μ λ©μμ§μ μ λͺ©κ³Ό λ°μ μ (μ λͺ©κ³Ό λ°μ μλ₯Ό λ³΄λ €λ©΄ `-v`κ° νμν©λλ€):
```bash
$ curl -k 'imaps://1.2.3.4/INBOX' -X 'FETCH 1:5 BODY[HEADER.FIELDS (SUBJECT FROM)]' --user user:pass -v 2>&1 | grep '^<'
```
λΉλ‘, μμ for 루νλ₯Ό μμ±νλ κ²μ΄ μλ§ λ κΉλν κ²μ
λλ€:
```bash
for m in {1..5}; do
echo $m
curl "imap://1.2.3.4/INBOX;MAILINDEX=$m;SECTION=HEADER.FIELDS%20(SUBJECT%20FROM)" --user user:pass
done
```
## Shodan
* `port:143 CAPABILITY`
* `port:993 CAPABILITY`
## HackTricks μλ λͺ
λ Ή
```
Protocol_Name: IMAP #Protocol Abbreviation if there is one.
Port_Number: 143,993 #Comma separated if there is more than one.
Protocol_Description: Internet Message Access Protocol #Protocol Abbreviation Spelled out
Entry_1:
Name: Notes
Description: Notes for WHOIS
Note: |
The Internet Message Access Protocol (IMAP) is designed for the purpose of enabling users to access their email messages from any location, primarily through an Internet connection. In essence, emails are retained on a server rather than being downloaded and stored on an individual's personal device. This means that when an email is accessed or read, it is done directly from the server. This capability allows for the convenience of checking emails from multiple devices, ensuring that no messages are missed regardless of the device used.
https://book.hacktricks.xyz/pentesting/pentesting-imap
Entry_2:
Name: Banner Grab
Description: Banner Grab 143
Command: nc -nv {IP} 143
Entry_3:
Name: Secure Banner Grab
Description: Banner Grab 993
Command: openssl s_client -connect {IP}:993 -quiet
Entry_4:
Name: consolesless mfs enumeration
Description: IMAP enumeration without the need to run msfconsole
Note: sourced from https://github.com/carlospolop/legion
Command: msfconsole -q -x 'use auxiliary/scanner/imap/imap_version; set RHOSTS {IP}; set RPORT 143; run; exit'
```
{% hint style="success" %}
AWS ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\
GCP ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
HackTricks μ§μνκΈ°
* [**ꡬλ
κ³ν**](https://github.com/sponsors/carlospolop) νμΈνκΈ°!
* **π¬ [**Discord κ·Έλ£Ή**](https://discord.gg/hRep4RUj7f) λλ [**ν
λ κ·Έλ¨ κ·Έλ£Ή**](https://t.me/peass)μ μ°Έμ¬νκ±°λ **Twitter** π¦ [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**λ₯Ό νλ‘μ°νμΈμ.**
* **[**HackTricks**](https://github.com/carlospolop/hacktricks) λ° [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) κΉνλΈ λ¦¬ν¬μ§ν 리μ PRμ μ μΆνμ¬ ν΄νΉ νμ 곡μ νμΈμ.**
{% endhint %}