mirror of
https://github.com/carlospolop/hacktricks
synced 2024-11-26 14:40:37 +00:00
209 lines
8.9 KiB
Markdown
209 lines
8.9 KiB
Markdown
# 143,993 - Pentesting IMAP
|
|
|
|
{% hint style="success" %}
|
|
Learn & practice AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
|
|
Learn & practice GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
|
|
|
|
<details>
|
|
|
|
<summary>Support HackTricks</summary>
|
|
|
|
* 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.
|
|
|
|
</details>
|
|
{% endhint %}
|
|
|
|
**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" %}
|
|
|
|
***
|
|
|
|
## Protocolo de Acceso a Mensajes de Internet
|
|
|
|
El **Protocolo de Acceso a Mensajes de Internet (IMAP)** está diseñado con el propósito de permitir a los usuarios **acceder a sus mensajes de correo electrónico desde cualquier ubicación**, principalmente a través de una conexión a Internet. En esencia, los correos electrónicos son **mantenidos en un servidor** en lugar de ser descargados y almacenados en el dispositivo personal de un individuo. Esto significa que cuando se accede o se lee un correo electrónico, se hace **directamente desde el servidor**. Esta capacidad permite la conveniencia de revisar correos electrónicos desde **múltiples dispositivos**, asegurando que no se pierdan mensajes independientemente del dispositivo utilizado.
|
|
|
|
Por defecto, el protocolo IMAP funciona en dos puertos:
|
|
|
|
* **Puerto 143** - este es el puerto IMAP no cifrado por defecto
|
|
* **Puerto 993** - este es el puerto que necesitas usar si deseas conectarte de manera segura utilizando IMAP
|
|
```
|
|
PORT STATE SERVICE REASON
|
|
143/tcp open imap syn-ack
|
|
```
|
|
## Captura de banner
|
|
```bash
|
|
nc -nv <IP> 143
|
|
openssl s_client -connect <IP>:993 -quiet
|
|
```
|
|
### NTLM Auth - Divulgación de información
|
|
|
|
Si el servidor admite autenticación NTLM (Windows), puedes obtener información sensible (versiones):
|
|
```
|
|
root@kali: telnet example.com 143
|
|
* OK The Microsoft Exchange IMAP4 service is ready.
|
|
>> a1 AUTHENTICATE NTLM
|
|
+
|
|
>> TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=
|
|
+ TlRMTVNTUAACAAAACgAKADgAAAAFgooCBqqVKFrKPCMAAAAAAAAAAEgASABCAAAABgOAJQAAAA9JAEkAUwAwADEAAgAKAEkASQBTADAAMQABAAoASQBJAFMAMAAxAAQACgBJAEkAUwAwADEAAwAKAEkASQBTADAAMQAHAAgAHwMI0VPy1QEAAAAA
|
|
```
|
|
O **automate** esto con el **nmap** plugin `imap-ntlm-info.nse`
|
|
|
|
### [Fuerza Bruta IMAP](../generic-methodologies-and-resources/brute-force.md#imap)
|
|
|
|
## Sintaxis
|
|
|
|
Ejemplos de comandos IAMP de [aquí](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
|
|
```
|
|
### Evolución
|
|
```
|
|
apt install evolution
|
|
```
|
|
![](<../.gitbook/assets/image (1033).png>)
|
|
|
|
### CURL
|
|
|
|
La navegación básica es posible con [CURL](https://ec.haxx.se/usingcurl/usingcurl-reademail#imap), pero la documentación es escasa en detalles, por lo que se recomienda consultar el [código fuente](https://github.com/curl/curl/blob/master/lib/imap.c) para obtener detalles precisos.
|
|
|
|
1. Listar buzones (comando imap `LIST "" "*"`)
|
|
```bash
|
|
curl -k 'imaps://1.2.3.4/' --user user:pass
|
|
```
|
|
2. Listando mensajes en un buzón (comando imap `SELECT INBOX` y luego `SEARCH ALL`)
|
|
```bash
|
|
curl -k 'imaps://1.2.3.4/INBOX?ALL' --user user:pass
|
|
```
|
|
El resultado de esta búsqueda es una lista de índices de mensajes.
|
|
|
|
También es posible proporcionar términos de búsqueda más complejos. p.ej. buscar borradores con contraseña en el cuerpo del correo:
|
|
```bash
|
|
curl -k 'imaps://1.2.3.4/Drafts?TEXT password' --user user:pass
|
|
```
|
|
Una buena visión general de los términos de búsqueda posibles se encuentra [aquí](https://www.atmail.com/blog/imap-commands/).
|
|
|
|
3. Descargando un mensaje (comando imap `SELECT Drafts` y luego `FETCH 1 BODY[]`)
|
|
```bash
|
|
curl -k 'imaps://1.2.3.4/Drafts;MAILINDEX=1' --user user:pass
|
|
```
|
|
El índice de correo será el mismo índice devuelto de la operación de búsqueda.
|
|
|
|
También es posible usar `UID` (identificador único) para acceder a los mensajes, sin embargo, es menos conveniente ya que el comando de búsqueda necesita ser formateado manualmente. Por ejemplo:
|
|
```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
|
|
```
|
|
También es posible descargar solo partes de un mensaje, por ejemplo, el asunto y el remitente de los primeros 5 mensajes (se requiere el `-v` para ver el asunto y el remitente):
|
|
```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 '^<'
|
|
```
|
|
Aunque, probablemente sea más limpio simplemente escribir un pequeño bucle 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`
|
|
|
|
**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" %}
|
|
|
|
## Comandos Automáticos de 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" %}
|
|
Aprende y practica Hacking en AWS:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
|
|
Aprende y practica Hacking en GCP: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
|
|
|
|
<details>
|
|
|
|
<summary>Apoya a HackTricks</summary>
|
|
|
|
* Revisa los [**planes de suscripción**](https://github.com/sponsors/carlospolop)!
|
|
* **Únete al** 💬 [**grupo de Discord**](https://discord.gg/hRep4RUj7f) o al [**grupo de telegram**](https://t.me/peass) o **síguenos** en **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
|
|
* **Comparte trucos de hacking enviando PRs a los** [**HackTricks**](https://github.com/carlospolop/hacktricks) y [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repositorios de github.
|
|
|
|
</details>
|
|
{% endhint %}
|