hacktricks/network-services-pentesting/pentesting-imap.md

206 lines
8.5 KiB
Markdown
Raw Normal View History

2022-05-01 13:25:53 +00:00
# 143,993 - Pentesting IMAP
2022-04-28 16:01:33 +00:00
<details>
2024-02-10 13:11:20 +00:00
<summary><strong>Naučite hakovanje AWS-a od nule do heroja sa</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-02-10 13:11:20 +00:00
Drugi načini podrške HackTricks-u:
2022-04-28 16:01:33 +00:00
* Ako želite da vidite svoju **kompaniju reklamiranu na HackTricks-u** ili **preuzmete HackTricks u PDF formatu** proverite [**PLANOVE ZA PRIJAVU**](https://github.com/sponsors/carlospolop)!
2024-02-10 13:11:20 +00:00
* Nabavite [**zvanični PEASS & HackTricks swag**](https://peass.creator-spring.com)
* Otkrijte [**Porodicu PEASS**](https://opensea.io/collection/the-peass-family), našu kolekciju ekskluzivnih [**NFT-ova**](https://opensea.io/collection/the-peass-family)
* **Pridružite se** 💬 [**Discord grupi**](https://discord.gg/hRep4RUj7f) ili [**telegram grupi**](https://t.me/peass) ili nas **pratite** na **Twitteru** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
2024-02-10 13:11:20 +00:00
* **Podelite svoje hakovanje trikove slanjem PR-ova na** [**HackTricks**](https://github.com/carlospolop/hacktricks) i [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repozitorijume.
2022-04-28 16:01:33 +00:00
</details>
**Try Hard Security Group**
<figure><img src="/.gitbook/assets/telegram-cloud-document-1-5159108904864449420.jpg" alt=""><figcaption></figcaption></figure>
{% embed url="https://discord.gg/tryhardsecurity" %}
***
2024-02-10 13:11:20 +00:00
## Internet protokol za pristup porukama
**Internet protokol za pristup porukama (IMAP)** je dizajniran sa ciljem omogućavanja korisnicima da **pristupe svojim email porukama sa bilo kog mesta**, uglavnom putem internet konekcije. U osnovi, email poruke se **čuvaju na serveru** umesto da se preuzimaju i čuvaju na ličnom uređaju pojedinca. To znači da kada se pristupa ili čita email, to se radi **direktno sa servera**. Ova mogućnost omogućava praktičnost provere 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:
2024-02-10 13:11:20 +00:00
* **Port 143** - ovo je podrazumevani IMAP nešifrovani 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
```
## Preuzimanje banera
```bash
nc -nv <IP> 143
openssl s_client -connect <IP>:993 -quiet
```
### NTLM Auth - Otkrivanje informacija
Ako server podržava NTLM autentikaciju (Windows), možete dobiti osetljive informacije (verzije):
```
2024-02-10 13:11:20 +00:00
root@kali: telnet example.com 143
* OK The Microsoft Exchange IMAP4 service is ready.
>> a1 AUTHENTICATE NTLM
+
>> TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=
+ TlRMTVNTUAACAAAACgAKADgAAAAFgooCBqqVKFrKPCMAAAAAAAAAAEgASABCAAAABgOAJQAAAA9JAEkAUwAwADEAAgAKAEkASQBTADAAMQABAAoASQBJAFMAMAAxAAQACgBJAEkAUwAwADEAAwAKAEkASQBTADAAMQAHAAgAHwMI0VPy1QEAAAAA
```
Ili **automatizujte** ovo sa **nmap** dodatkom `imap-ntlm-info.nse`
### [IMAP Brute Force](../generic-methodologies-and-resources/brute-force.md#imap)
2024-02-10 13:11:20 +00:00
## Sintaksa
IMAP Komande primeri sa [ovde](https://donsutherland.org/crib/imap):
```
Login
2024-02-10 13:11:20 +00:00
A1 LOGIN username password
Values can be quoted to enclose spaces and special characters. A " must then be escape with a \
2024-02-10 13:11:20 +00:00
A1 LOGIN "username" "password"
List Folders/Mailboxes
2024-02-10 13:11:20 +00:00
A1 LIST "" *
A1 LIST INBOX *
A1 LIST "Archive" *
Create new Folder/Mailbox
2024-02-10 13:11:20 +00:00
A1 CREATE INBOX.Archive.2012
A1 CREATE "To Read"
Delete Folder/Mailbox
2024-02-10 13:11:20 +00:00
A1 DELETE INBOX.Archive.2012
A1 DELETE "To Read"
Rename Folder/Mailbox
2024-02-10 13:11:20 +00:00
A1 RENAME "INBOX.One" "INBOX.Two"
List Subscribed Mailboxes
2024-02-10 13:11:20 +00:00
A1 LSUB "" *
Status of Mailbox (There are more flags than the ones listed)
2024-02-10 13:11:20 +00:00
A1 STATUS INBOX (MESSAGES UNSEEN RECENT)
Select a mailbox
2024-02-10 13:11:20 +00:00
A1 SELECT INBOX
List messages
2024-02-10 13:11:20 +00:00
A1 FETCH 1:* (FLAGS)
A1 UID FETCH 1:* (FLAGS)
Retrieve Message Content
2024-02-10 13:11:20 +00:00
A1 FETCH 2 body[text]
A1 FETCH 2 all
A1 UID FETCH 102 (UID RFC822.SIZE BODY.PEEK[])
Close Mailbox
2024-02-10 13:11:20 +00:00
A1 CLOSE
Logout
2024-02-10 13:11:20 +00:00
A1 LOGOUT
```
2024-02-10 13:11:20 +00:00
### Evolucija
```
apt install evolution
```
![](<../.gitbook/assets/image (528).png>)
2022-05-01 13:25:53 +00:00
### CURL
2020-12-21 13:41:29 +00:00
Osnovna navigacija je moguća pomoću [CURL](https://ec.haxx.se/usingcurl/usingcurl-reademail#imap), ali dokumentacija je siromašna detaljima, pa se preporučuje provera [izvornog koda](https://github.com/curl/curl/blob/master/lib/imap.c) za precizne detalje.
1. Lista sandučića (imap komanda `LIST "" "*"`)
2024-02-08 21:36:15 +00:00
```bash
curl -k 'imaps://1.2.3.4/' --user user:pass
```
2. Prikazivanje poruka u sandučetu (imap komanda `SELECT INBOX` a zatim `SEARCH ALL`)
2024-02-10 13:11:20 +00:00
```bash
2024-02-08 21:36:15 +00:00
curl -k 'imaps://1.2.3.4/INBOX?ALL' --user user:pass
```
Rezultat ove pretrage je lista indeksa poruka.
Takođe je moguće koristiti složenije pretrage. npr. pretraga za skicama sa lozinkom u telu poruke:
2024-02-08 21:36:15 +00:00
```bash
curl -k 'imaps://1.2.3.4/Drafts?TEXT password' --user user:pass
2024-02-08 21:36:15 +00:00
```
3. Preuzimanje poruke (imap komanda `SELECT Drafts` a zatim `FETCH 1 BODY[]`)
2024-02-08 21:36:15 +00:00
```bash
curl -k 'imaps://1.2.3.4/Drafts;MAILINDEX=1' --user user:pass
```
Mail indeks će biti isti indeks koji je vraćen operacijom pretrage.
Takođe je moguće koristiti `UID` (jedinstveni identifikator) za pristup porukama, međutim to je manje praktično jer komanda pretrage mora biti ručno formatirana. Na primer:
```bash
2024-02-10 13:11:20 +00:00
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 (opcija `-v` je potrebna da bi se videli predmet i pošiljalac):
```bash
2020-12-21 13:41:29 +00:00
$ 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 jednostavno napisati mali for petlju:
2024-02-10 13:11:20 +00:00
```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
```
2022-05-01 13:25:53 +00:00
## Shodan
2020-10-05 13:04:03 +00:00
* `port:143 CAPABILITY`
* `port:993 CAPABILITY`
**Try Hard Security Group**
<figure><img src="/.gitbook/assets/telegram-cloud-document-1-5159108904864449420.jpg" alt=""><figcaption></figcaption></figure>
{% embed url="https://discord.gg/tryhardsecurity" %}
## HackTricks Automatske Komande
```
2021-08-12 13:02:06 +00:00
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
2021-08-15 17:49:05 +00:00
Entry_1:
Name: Notes
Description: Notes for WHOIS
2024-02-10 13:11:20 +00:00
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.
2021-08-15 17:49:05 +00:00
2024-02-10 13:11:20 +00:00
https://book.hacktricks.xyz/pentesting/pentesting-imap
2021-08-15 17:49:05 +00:00
Entry_2:
2024-02-10 13:11:20 +00:00
Name: Banner Grab
Description: Banner Grab 143
Command: nc -nv {IP} 143
2021-08-15 17:49:05 +00:00
Entry_3:
Name: Secure Banner Grab
2024-02-10 13:11:20 +00:00
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
2024-02-10 13:11:20 +00:00
Command: msfconsole -q -x 'use auxiliary/scanner/imap/imap_version; set RHOSTS {IP}; set RPORT 143; run; exit'
2021-08-12 13:02:06 +00:00
```
2022-04-28 16:01:33 +00:00
<details>
<summary><strong>Naučite hakovanje AWS-a od nule do heroja sa</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
Drugi načini da podržite HackTricks:
2022-04-28 16:01:33 +00:00
* Ako želite da vidite **vašu kompaniju reklamiranu na HackTricks-u** ili **preuzmete HackTricks u PDF formatu** proverite [**PLANOVE ZA PRIJATELJSTVO**](https://github.com/sponsors/carlospolop)!
* Nabavite [**zvanični PEASS & HackTricks swag**](https://peass.creator-spring.com)
* Otkrijte [**Porodicu PEASS**](https://opensea.io/collection/the-peass-family), našu kolekciju ekskluzivnih [**NFT-ova**](https://opensea.io/collection/the-peass-family)
* **Pridružite se** 💬 [**Discord grupi**](https://discord.gg/hRep4RUj7f) ili [**telegram grupi**](https://t.me/peass) ili nas **pratite** na **Twitteru** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
* **Podelite svoje hakovanje trikove slanjem PR-ova na** [**HackTricks**](https://github.com/carlospolop/hacktricks) i [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repozitorijume.
2022-04-28 16:01:33 +00:00
</details>