# 143,993 - Pentesting IMAP
{% hint style="success" %}
Leer & oefen AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\
Leer & oefen GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks
* Kyk na die [**subskripsie planne**](https://github.com/sponsors/carlospolop)!
* **Sluit aan by die** 💬 [**Discord groep**](https://discord.gg/hRep4RUj7f) of die [**telegram groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Deel hacking truuks deur PRs in te dien na die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}
**Try Hard Security Group**
{% embed url="https://discord.gg/tryhardsecurity" %}
***
## Internet Message Access Protocol
Die **Internet Message Access Protocol (IMAP)** is ontwerp om gebruikers in staat te stel om **hul e-pos boodskappe van enige plek af te bekom**, hoofsaaklik deur 'n Internet-verbinding. In wese word e-posse **op 'n bediener gehou** eerder as om afgelaai en op 'n individu se persoonlike toestel gestoor te word. Dit beteken dat wanneer 'n e-pos toegang verkry of gelees word, dit **direk van die bediener** gedoen word. Hierdie vermoë maak dit gerieflik om e-posse van **meerdere toestelle** te kontroleer, wat verseker dat geen boodskappe gemis word ongeag die toestel wat gebruik word nie.
Standaard werk die IMAP-protokol op twee poorte:
* **Poort 143** - dit is die standaard IMAP nie-geënkripteerde poort
* **Poort 993** - dit is die poort wat jy moet gebruik as jy veilig met IMAP wil verbind
```
PORT STATE SERVICE REASON
143/tcp open imap syn-ack
```
## Banner gryp
```bash
nc -nv 143
openssl s_client -connect :993 -quiet
```
### NTLM Auth - Inligtingsontsluiting
As die bediener NTLM-authentisering (Windows) ondersteun, kan jy sensitiewe inligting (weergawe) verkry:
```
root@kali: telnet example.com 143
* OK The Microsoft Exchange IMAP4 service is ready.
>> a1 AUTHENTICATE NTLM
+
>> TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=
+ TlRMTVNTUAACAAAACgAKADgAAAAFgooCBqqVKFrKPCMAAAAAAAAAAEgASABCAAAABgOAJQAAAA9JAEkAUwAwADEAAgAKAEkASQBTADAAMQABAAoASQBJAFMAMAAxAAQACgBJAEkAUwAwADEAAwAKAEkASQBTADAAMQAHAAgAHwMI0VPy1QEAAAAA
```
Of **automate** dit met **nmap** plugin `imap-ntlm-info.nse`
### [IMAP Bruteforce](../generic-methodologies-and-resources/brute-force.md#imap)
## Sintaksis
IMAP Opdrag voorbeelde van [hier](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
```
### Evolusie
```
apt install evolution
```
![](<../.gitbook/assets/image (1033).png>)
### CURL
Basiese navigasie is moontlik met [CURL](https://ec.haxx.se/usingcurl/usingcurl-reademail#imap), maar die dokumentasie is lig op besonderhede, so dit word aanbeveel om die [bron](https://github.com/curl/curl/blob/master/lib/imap.c) te kontroleer vir presiese besonderhede.
1. Lys van posbusse (imap opdrag `LIST "" "*"`)
```bash
curl -k 'imaps://1.2.3.4/' --user user:pass
```
2. Lys van boodskappe in 'n posbus (imap opdrag `SELECT INBOX` en dan `SEARCH ALL`)
```bash
curl -k 'imaps://1.2.3.4/INBOX?ALL' --user user:pass
```
Die resultaat van hierdie soektog is 'n lys van boodskapindekse.
Dit is ook moontlik om meer komplekse soekterme te verskaf. bv. om te soek na konsepte met wagwoord in die e-posliggaam:
```bash
curl -k 'imaps://1.2.3.4/Drafts?TEXT password' --user user:pass
```
'n Goeie oorsig van die soekterme wat moontlik is, is [hier](https://www.atmail.com/blog/imap-commands/) geleë.
3. Laai 'n boodskap af (imap opdrag `SELECT Drafts` en dan `FETCH 1 BODY[]`)
```bash
curl -k 'imaps://1.2.3.4/Drafts;MAILINDEX=1' --user user:pass
```
Die posindeks sal dieselfde indeks wees wat van die soekoperasie teruggegee word.
Dit is ook moontlik om `UID` (unieke id) te gebruik om boodskappe te bekom, maar dit is minder gerieflik aangesien die soekopdrag handmatig geformateer moet word. Byvoorbeeld:
```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
```
Ook moontlik om net dele van 'n boodskap af te laai, bv. onderwerp en sender van die eerste 5 boodskappe (die `-v` is vereis om die onderwerp en sender te sien):
```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 '^<'
```
Alhoewel, dit is waarskynlik skoner om net 'n bietjie vir-lus te skryf:
```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`
**Try Hard Security Group**
{% embed url="https://discord.gg/tryhardsecurity" %}
## HackTricks Outomatiese Opdragte
```
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" %}
Leer & oefen AWS Hacking:[**HackTricks Opleiding AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\
Leer & oefen GCP Hacking: [**HackTricks Opleiding GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Ondersteun HackTricks
* Kyk na die [**subskripsie planne**](https://github.com/sponsors/carlospolop)!
* **Sluit aan by die** 💬 [**Discord groep**](https://discord.gg/hRep4RUj7f) of die [**telegram groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Deel hacking truuks deur PRs in te dien na die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}