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

274 lines
12 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
2024-02-10 13:11:20 +00:00
* Ako želite da vidite **vašu kompaniju reklamiranu na HackTricks-u** ili **preuzmete HackTricks u PDF formatu** proverite [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
* Nabavite [**zvanični PEASS & HackTricks swag**](https://peass.creator-spring.com)
* Otkrijte [**The PEASS Family**](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 **Twitter-u** 🐦 [**@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>
2023-09-02 23:51:32 +00:00
<figure><img src="/.gitbook/assets/image (675).png" alt=""><figcaption></figcaption></figure>
2023-09-02 23:48:41 +00:00
2024-02-10 13:11:20 +00:00
Pronađite najvažnije ranjivosti kako biste ih brže popravili. Intruder prati vašu površinu napada, pokreće proaktivne pretnje, pronalazi probleme u celokupnom tehnološkom skupu, od API-ja do veb aplikacija i cloud sistema. [**Isprobajte ga besplatno**](https://www.intruder.io/?utm\_source=referral\&utm\_campaign=hacktricks) danas.
2023-09-02 23:48:41 +00:00
{% embed url="https://www.intruder.io/?utm_campaign=hacktricks&utm_source=referral" %}
***
2024-02-10 13:11:20 +00:00
## Internet protokol za pristup porukama
2024-02-10 13:11:20 +00:00
**Internet protokol za pristup porukama (IMAP)** je dizajniran sa ciljem omogućavanja korisnicima da **pristupaju svojim email porukama sa bilo koje lokacije**, uglavnom putem internet konekcije. U suštini, 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**, obezbeđujući da nijedna poruka ne bude propuštena bez obzira na korišćeni uređaj.
2024-02-10 13:11:20 +00:00
Podrazumevano, IMAP protokol radi na dve porte:
2024-02-10 13:11:20 +00:00
* **Port 143** - ovo je podrazumevani IMAP nešifrovani port
* **Port 993** - ovo je port koji trebate koristiti ako želite da se povežete koristeći IMAP sigurno
```
PORT STATE SERVICE REASON
143/tcp open imap syn-ack
```
2024-02-10 13:11:20 +00:00
## Prepoznavanje banera
Banner grabbing je tehnika koja se koristi za prikupljanje informacija o ciljnom serveru putem njegovog banera. Banner je obično deo odgovora servera prilikom uspostavljanja veze. Ova tehnika omogućava hakerima da saznaju informacije o softveru i verziji koji se koristi na serveru, što može biti korisno za dalje napade.
Da biste izvršili banner grabbing, možete koristiti različite alate kao što su `telnet`, `nc` ili `nmap`. Ovi alati vam omogućavaju da se povežete sa serverom i dobijete odgovor koji sadrži banner.
2024-02-10 13:11:20 +00:00
Kada dobijete banner, možete ga analizirati kako biste saznali više o serveru. Na primer, možete saznati koja verzija softvera se koristi i da li postoje poznate ranjivosti koje se mogu iskoristiti.
2024-02-10 13:11:20 +00:00
Važno je napomenuti da banner grabbing može biti ilegalno ako se koristi bez dozvole vlasnika servera. Uvek se pridržavajte zakona i etičkih smernica prilikom izvođenja ovih tehnika.
```bash
nc -nv <IP> 143
openssl s_client -connect <IP>:993 -quiet
```
2024-02-10 13:11:20 +00:00
### NTLM autentifikacija - Otkrivanje informacija
2024-02-10 13:11:20 +00:00
Ukoliko server podržava NTLM autentifikaciju (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
```
2024-02-10 13:11:20 +00:00
Ili **automatizujte** ovo pomoću **nmap** dodatka `imap-ntlm-info.nse`
2022-05-01 13:25:53 +00:00
### [IMAP Bruteforce](../generic-methodologies-and-resources/brute-force.md#imap)
2024-02-10 13:11:20 +00:00
## Sintaksa
2024-02-06 03:10:38 +00:00
2024-02-10 13:11:20 +00:00
Primeri IMAP komandi 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
IMAP (Internet Message Access Protocol) je protokol koji se koristi za pristup i upravljanje elektronskom poštom na udaljenom serveru. Evolucija IMAP-a je dovela do razvoja različitih verzija protokola, kao što su IMAPv2, IMAPv3 i IMAPv4. Svaka verzija donosi poboljšanja u performansama, sigurnosti i funkcionalnostima.
2024-02-10 13:11:20 +00:00
IMAPv2 je bio prva verzija protokola koja je omogućila klijentima da pristupaju porukama na serveru i upravljaju njima. Međutim, IMAPv2 je bio ograničen u pogledu podrške za enkripciju i autentifikaciju.
2024-02-10 13:11:20 +00:00
IMAPv3 je donio značajna poboljšanja u sigurnosti i funkcionalnostima. Ova verzija je uključivala podršku za SSL/TLS enkripciju, kao i mogućnost pretrage i filtriranja poruka na serveru. Takođe je omogućila klijentima da pristupaju i upravljaju više poštanskih sandučića na istom serveru.
Najnovija verzija protokola, IMAPv4, donosi dodatne funkcionalnosti kao što su podrška za sinhronizaciju poruka između klijenta i servera, mogućnost označavanja poruka kao pročitanih ili nepročitanih, kao i mogućnost upravljanja poštanskim sandučićima na serveru.
Evolucija IMAP-a je omogućila korisnicima da efikasnije pristupaju i upravljaju svojom elektronskom poštom na udaljenom serveru, uz poboljšanu sigurnost i funkcionalnosti.
```
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
2024-02-10 13:11:20 +00:00
Osnovna navigacija je moguća pomoću [CURL-a](https://ec.haxx.se/usingcurl/usingcurl-reademail#imap), ali dokumentacija je siromašna detaljima, pa se preporučuje provera [izvora](https://github.com/curl/curl/blob/master/lib/imap.c) za precizne detalje.
2024-02-10 13:11:20 +00:00
1. Prikazivanje poštanskih 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
```
2024-02-10 13:11:20 +00:00
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
```
2024-02-08 21:36:15 +00:00
The result of this search is a list of message indicies.
2024-02-08 21:36:15 +00:00
Its also possible to provide more complex search terms. e.g. searching for drafts with password in mail body:
```bash
2024-02-10 13:11:20 +00:00
curl -k 'imaps://1.2.3.4/Drafts?TEXT lozinka' --user korisnik:lozinka
2024-02-08 21:36:15 +00:00
```
2024-02-08 21:36:15 +00:00
A nice overview of the search terms possible is located [here](https://www.atmail.com/blog/imap-commands/).
3. Downloading a message (imap command `SELECT Drafts` and then `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
```
2024-02-08 21:36:15 +00:00
The mail index will be the same index returned from the search operation.
2020-12-21 13:41:29 +00:00
It is also possible to use `UID` (unique id) to access messages, however it is less conveniant as the search command needs to be manually formatted. E.g.
```bash
2024-02-10 13:11:20 +00:00
```markdown
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
```
```html
2024-02-08 21:36:15 +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
2020-12-21 13:41:29 +00:00
```
2024-02-10 13:11:20 +00:00
```markdown
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
```
```html
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
```
```
Also, possible to download just parts of a message, e.g. subject and sender of first 5 messages (the `-v` is required to see the subject and sender):
```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 '^<'
2024-02-10 13:11:20 +00:00
```html
<pre>
$ curl -k 'imaps://1.2.3.4/INBOX' -X 'FETCH 1:5 BODY[HEADER.FIELDS (SUBJECT FROM)]' --user user:pass -v 2>&1 | grep '^&lt;'
</pre>
```
2020-12-21 13:41:29 +00:00
```
Although, its probably cleaner to just write a little for loop:
2024-02-10 13:11:20 +00:00
```bash
2024-02-08 21:36:15 +00:00
```bash
2020-12-21 13:41:29 +00:00
for m in {1..5}; do
2024-02-10 13:11:20 +00:00
echo $m
curl "imap://1.2.3.4/INBOX;MAILINDEX=$m;SECTION=HEADER.FIELDS%20(SUBJECT%20FROM)" --user user:pass
2020-12-21 13:41:29 +00:00
done
```
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`
2022-05-01 13:25:53 +00:00
## HackTricks Automatic Commands
2021-08-12 13:02:06 +00:00
```
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:
2024-02-10 13:11:20 +00:00
Name: Beleške
Description: Beleške za WHOIS
Note: |
Internet Message Access Protocol (IMAP) je dizajniran sa ciljem omogućavanja korisnicima pristupanje njihovim email porukama sa bilo koje lokacije, uglavnom putem internet konekcije. U suštini, emailovi se čuvaju na serveru umesto da se preuzimaju i skladište 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.
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:
2024-02-10 13:11:20 +00:00
Name: Bezbedan Banner Grab
Description: Banner Grab 993
Command: openssl s_client -connect {IP}:993 -quiet
Entry_4:
2024-02-10 13:11:20 +00:00
Name: Enumeracija bez korišćenja msfconsole-a
Description: Enumeracija IMAP-a bez potrebe za pokretanjem msfconsole-a
Note: preuzeto sa https://github.com/carlospolop/legion
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
2023-09-02 23:51:32 +00:00
<figure><img src="/.gitbook/assets/image (675).png" alt=""><figcaption></figcaption></figure>
2023-09-02 23:48:41 +00:00
Find vulnerabilities that matter most so you can fix them faster. Intruder tracks your attack surface, runs proactive threat scans, finds issues across your whole tech stack, from APIs to web apps and cloud systems. [**Try it for free**](https://www.intruder.io/?utm\_source=referral\&utm\_campaign=hacktricks) today.
{% embed url="https://www.intruder.io/?utm_campaign=hacktricks&utm_source=referral" %}
2022-04-28 16:01:33 +00:00
<details>
2024-01-05 22:37:11 +00:00
<summary><strong>Learn AWS hacking from zero to hero with</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-01-05 22:37:11 +00:00
Other ways to support HackTricks:
2022-04-28 16:01:33 +00:00
2024-01-05 22:37:11 +00:00
* If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
* Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
* Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
2024-02-09 12:24:06 +00:00
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
2024-01-05 22:37:11 +00:00
* **Share your hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>