# 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 %} **Try Hard Security Group**
{% embed url="https://discord.gg/tryhardsecurity" %} *** ## Internet Message Access Protocol **Internet Message Access Protocol (IMAP)** je dizajniran sa ciljem omogućavanja korisnicima da **pristupaju svojim email porukama sa bilo koje lokacije**, prvenstveno putem Internet veze. U suštini, emailovi se **čuvaju na serveru** umesto da se preuzimaju i skladište na ličnom uređaju. To znači da kada se email otvori ili pročita, to se radi **direktno sa servera**. Ova mogućnost omogućava praktičnost proveravanja emailova sa **više uređaja**, osiguravajući da nijedna poruka ne bude propuštena bez obzira na korišćeni uređaj. Podrazumevano, IMAP protokol radi na dva porta: * **Port 143** - ovo je podrazumevani IMAP nekriptovani port * **Port 993** - ovo je port koji treba koristiti ako želite da se povežete koristeći IMAP sigurno ``` PORT STATE SERVICE REASON 143/tcp open imap syn-ack ``` ## Prikupljanje banera ```bash nc -nv 143 openssl s_client -connect :993 -quiet ``` ### NTLM Auth - Otkriće informacija Ako server podržava NTLM autentifikaciju (Windows), možete dobiti osetljive informacije (verzije): ``` root@kali: telnet example.com 143 * OK The Microsoft Exchange IMAP4 service is ready. >> a1 AUTHENTICATE NTLM + >> TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA= + TlRMTVNTUAACAAAACgAKADgAAAAFgooCBqqVKFrKPCMAAAAAAAAAAEgASABCAAAABgOAJQAAAA9JAEkAUwAwADEAAgAKAEkASQBTADAAMQABAAoASQBJAFMAMAAxAAQACgBJAEkAUwAwADEAAwAKAEkASQBTADAAMQAHAAgAHwMI0VPy1QEAAAAA ``` Ili **automatizujte** ovo sa **nmap** pluginom `imap-ntlm-info.nse` ### [IMAP Bruteforce](../generic-methodologies-and-resources/brute-force.md#imap) ## Sintaksa IAMP komande primeri sa [ovde](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 ``` ### Evolucija ``` apt install evolution ``` ![](<../.gitbook/assets/image (1033).png>) ### CURL Osnovna navigacija je moguća sa [CURL](https://ec.haxx.se/usingcurl/usingcurl-reademail#imap), ali je dokumentacija slaba na detaljima, pa se preporučuje da se proveri [izvor](https://github.com/curl/curl/blob/master/lib/imap.c) za precizne informacije. 1. Lista poštanskih sandučića (imap komanda `LIST "" "*"`) ```bash curl -k 'imaps://1.2.3.4/' --user user:pass ``` 2. Nabrajanje poruka u poštanskom sandučetu (imap komanda `SELECT INBOX` i zatim `SEARCH ALL`) ```bash curl -k 'imaps://1.2.3.4/INBOX?ALL' --user user:pass ``` Rezultat ove pretrage je lista indeksa poruka. Takođe je moguće pružiti složenije uslove pretrage. npr. pretraga za nacrtima sa lozinkom u telu maila: ```bash curl -k 'imaps://1.2.3.4/Drafts?TEXT password' --user user:pass ``` Lep pregled mogućih termina pretrage nalazi se [ovde](https://www.atmail.com/blog/imap-commands/). 3. Preuzimanje poruke (imap komanda `SELECT Drafts` i zatim `FETCH 1 BODY[]`) ```bash curl -k 'imaps://1.2.3.4/Drafts;MAILINDEX=1' --user user:pass ``` Mail indeks će biti isti indeks koji se vraća iz operacije pretrage. Takođe je moguće koristiti `UID` (jedinstveni identifikator) za pristup porukama, međutim to je manje praktično jer se komanda za pretragu mora ručno formatirati. Na primer. ```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 ``` Takođe, moguće je preuzeti samo delove poruke, npr. predmet i pošiljaoca prvih 5 poruka ( `-v` je obavezan da bi se videli predmet i pošiljalac): ```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 '^<' ``` Iako je verovatno čistije samo napisati malu for petlju: ```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 Automatske Komande ``` 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" %} Učite i vežbajte AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Učite i vežbajte GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Podržite HackTricks * Proverite [**planove pretplate**](https://github.com/sponsors/carlospolop)! * **Pridružite se** 💬 [**Discord grupi**](https://discord.gg/hRep4RUj7f) ili [**telegram grupi**](https://t.me/peass) ili **pratite** nas na **Twitteru** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.** * **Podelite hakerske trikove slanjem PR-ova na** [**HackTricks**](https://github.com/carlospolop/hacktricks) i [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repozitorijume.
{% endhint %}