tags: Enumerazione_IMAP Enumerazioni_POP3
Per interagire con i server IMAP o POP3 possiamo usare o Openssl o Netcat tramite la seguente sintassi:
openssl s_client -connect 10.129.73.40:pop3s
openssl s_client -connect 10.129.73.40:imaps
Una volta interagito possiamo utilizzare le seguenti sintassi a seconda dei protocolli:
IMAP Commands
| Command | Description |
|---|---|
1 LOGIN username password | User’s login. |
1 LIST "" * | Lists all directories. |
1 CREATE "INBOX" | Creates a mailbox with a specified name. |
1 DELETE "INBOX" | Deletes a mailbox. |
1 RENAME "ToRead" "Important" | Renames a mailbox. |
1 LSUB "" * | Returns a subset of names from the set of names that the User has declared as being active or subscribed. |
1 SELECT INBOX | Selects a mailbox so that messages in the mailbox can be accessed. |
1 UNSELECT INBOX | Exits the selected mailbox. |
1 FETCH <ID> all | Retrieves data associated with a message in the mailbox. |
1 CLOSE | Removes all messages with the Deleted flag set. |
1 LOGOUT | Closes the connection with the IMAP server. |
Esempio IMAP
Segui questa sequenza esatta per leggere le email nella cartella nascosta.
1 LIST "" *
* LIST (\Noselect \HasChildren) "." DEV
* LIST (\Noselect \HasChildren) "." DEV.DEPARTMENT
* LIST (\HasNoChildren) "." DEV.DEPARTMENT.INT
* LIST (\HasNoChildren) "." INBOX
1 OK List completed (0.002 + 0.000 + 0.002 secs).Passo A: Selezionare la cartella corretta
Dall’output del tuo LIST, l’unica cartella interessante (diversa da INBOX che è vuota) e selezionabile (perché ha \HasNoChildren) è DEV.DEPARTMENT.INT.
Esegui questo comando (rispetta le virgolette e le maiuscole):
Plaintext
A1 SELECT "DEV.DEPARTMENT.INT"
Passo B: Verificare se ci sono email
Dopo aver dato invio, guarda l’output. Cerca la riga che finisce con EXISTS.
Esempio di output di successo:
Plaintext
* 2 EXISTS <-- Ci sono 2 email
* 0 RECENT
A1 OK [READ-WRITE] Select completed.
Se vedi 0 EXISTS, la cartella è vuota. Se vedi un numero > 0, procedi al passo C.
Passo C: Leggere le email (FETCH)
Per scaricare il contenuto, devi usare il comando FETCH specificando l’ID del messaggio (es. 1 per il primo, 2 per il secondo) e cosa vuoi leggere (es. BODY[] per tutto, o BODY[TEXT] per solo il testo).
Per leggere tutto il contenuto della prima email:
Plaintext
A2 FETCH 1 BODY[]
Per leggere tutte le email presenti (se ce ne sono ad esempio 2):
Plaintext
A2 FETCH 1:2 BODY[]
Per leggere solo l’intestazione (utile per vedere mittente/oggetto velocemente):
Plaintext
A2 FETCH 1 (BODY[HEADER.FIELDS (FROM TO SUBJECT DATE)])
A1 SELECT "DEV.DEPARTMENT.INT"
* OK [CLOSED] Previous mailbox closed.
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
* 1 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1636414279] UIDs valid
* OK [UIDNEXT 2] Predicted next UID
A1 OK [READ-WRITE] Select completed (0.007 + 0.000 + 0.007 secs).
A2 FETCH 1 BODY[]
* 1 FETCH (BODY[] {167}
Subject: Flag
To: Robin <[email protected]b>
From: CTO <[email protected]b>
Date: Wed, 03 Nov 2021 16:13:27 +0200
HTB{983uzn8jmfgpd8jmof8c34n7zio}
)
A2 OK Fetch completed (0.004 + 0.000 + 0.003 secs)POP3 Commands
| Command | Description |
|---|---|
USER username | Identifies the user. |
PASS password | Authentication of the user using its password. |
STAT | Requests the number of saved emails from the server. |
LIST | Requests from the server the number and size of all emails. |
RETR id | Requests the server to deliver the requested email by ID. |
DELE id | Requests the server to delete the requested email by ID. |
CAPA | Requests the server to display the server capabilities. |
RSET | Requests the server to reset the transmitted information. |
QUIT | Closes the connection with the POP3 server. |
Scenario: Enumerazione POP3 Manuale
Obiettivo: Accedere alla casella di posta, verificare la presenza di messaggi e leggerne il contenuto.
Strumento: nc (Netcat) o telnet.
Porta Standard: 110 (110 in chiaro, 995 per POP3S/SSL).
1. Connessione e Banner Grabbing
Ti connetti al servizio. Il server risponde sempre con +OK (successo) o -ERR (errore).
Bash
nc -nv 10.129.x.x 110
Output Server:
Plaintext
+OK Dovecot ready.
2. Autenticazione (USER / PASS)
In POP3, l’autenticazione avviene in due step distinti. Non si inviano user e password insieme.
Tu invii:
Plaintext
USER christine
Server:
Plaintext
+OK
Tu invii:
Plaintext
PASS password123
Server:
Plaintext
+OK Logged in.
3. Verifica Stato Casella (STAT)
Questo comando ti dice quanti messaggi ci sono e quanto spazio occupano in totale. È il primo comando da lanciare dopo il login.
Tu invii:
Plaintext
STAT
Server:
Plaintext
+OK 2 3240
Interpretazione: +OK (successo), 2 (messaggi presenti), 3240 (byte totali).
4. Lista dei Messaggi (LIST)
Per leggere un messaggio serve il suo ID numerico. LIST ti mostra l’ID e la dimensione di ogni singolo messaggio.
Tu invii:
Plaintext
LIST
Server:
Plaintext
+OK List follows
1 1200
2 2040
.
Nota: Il punto . da solo su una riga indica la fine della risposta del server.
5. Lettura Messaggi (RETR)
Per scaricare il contenuto completo (Headers + Body) si usa RETR seguito dal numero del messaggio.
Tu invii (Leggere il messaggio 1):
Plaintext
RETR 1
Server:
Plaintext
+OK 1200 octets
Return-Path: <[email protected]>
From: Admin <[email protected]>
To: Christine <[email protected]>
Subject: Credenziali DB di test
Ciao Christine,
Le credenziali temporanee per il DB sono:
User: postgres
Pass: P0stgr3s_Rul3s!
Saluti.
.
6. Anteprima (TOP) - Opzionale ma utile
Se i messaggi sono enormi (con allegati), puoi usare TOP [ID] [RIGHEL] per leggere solo gli header e le prime N righe del corpo, senza scaricare tutto.
Tu invii:
Plaintext
TOP 2 10
(Mostra l’header e le prime 10 righe del corpo del messaggio 2).
7. Chiusura (QUIT)
È importante chiudere correttamente la sessione. In POP3, se hai marcato dei messaggi per la cancellazione (comando DELE), questi vengono eliminati fisicamente solo quando invii QUIT.
Tu invii:
Plaintext
QUIT
Server:
Plaintext
+OK Logging out.
Tabella dei Comandi POP3 (Cheat Sheet)
| Comando | Descrizione | Equivalente IMAP (Approx) |
|---|---|---|
USER [nome] | Invia username | LOGIN |
PASS [pass] | Invia password | LOGIN |
STAT | Mostra numero messaggi e dimensione tot | EXISTS (in response) |
LIST | Elenca ID e dimensione singoli messaggi | FETCH ... (UID) |
RETR [ID] | Scarica l’intero messaggio | FETCH [ID] BODY[] |
TOP [ID] [N] | Scarica header + N righe | FETCH [ID] BODY[HEADER] |
DELE [ID] | Marca messaggio per cancellazione | STORE ... +FLAGS (\Deleted) |
RSET | Annulla le cancellazioni (prima di QUIT) | - |
QUIT | Chiude la connessione e applica modifiche | LOGOUT |