mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
170 lines
6.2 KiB
Markdown
170 lines
6.2 KiB
Markdown
# 143,993 - Pentesting IMAP
|
|
|
|
{{#include ../banners/hacktricks-training.md}}
|
|
|
|
## 인터넷 메시지 접근 프로토콜
|
|
|
|
**인터넷 메시지 접근 프로토콜 (IMAP)**은 사용자가 **어떤 위치에서든 이메일 메시지에 접근할 수 있도록** 설계되었습니다. 주로 인터넷 연결을 통해 이루어집니다. 본질적으로, 이메일은 **서버에 보관**되며 개인 장치에 다운로드되어 저장되지 않습니다. 이는 이메일에 접근하거나 읽을 때 **서버에서 직접** 이루어진다는 것을 의미합니다. 이 기능은 **여러 장치**에서 이메일을 확인할 수 있는 편리함을 제공하여, 사용되는 장치에 관계없이 메시지를 놓치지 않도록 합니다.
|
|
|
|
기본적으로 IMAP 프로토콜은 두 개의 포트에서 작동합니다:
|
|
|
|
- **포트 143** - 기본 IMAP 비암호화 포트입니다.
|
|
- **포트 993** - IMAP을 안전하게 연결하려면 사용해야 하는 포트입니다.
|
|
```
|
|
PORT STATE SERVICE REASON
|
|
143/tcp open imap syn-ack
|
|
```
|
|
## 배너 수집
|
|
```bash
|
|
nc -nv <IP> 143
|
|
openssl s_client -connect <IP>:993 -quiet
|
|
```
|
|
### NTLM Auth - 정보 유출
|
|
|
|
서버가 NTLM 인증(Windows)을 지원하는 경우, 민감한 정보(버전)를 얻을 수 있습니다:
|
|
```
|
|
root@kali: telnet example.com 143
|
|
* OK The Microsoft Exchange IMAP4 service is ready.
|
|
>> a1 AUTHENTICATE NTLM
|
|
+
|
|
>> TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=
|
|
+ TlRMTVNTUAACAAAACgAKADgAAAAFgooCBqqVKFrKPCMAAAAAAAAAAEgASABCAAAABgOAJQAAAA9JAEkAUwAwADEAAgAKAEkASQBTADAAMQABAAoASQBJAFMAMAAxAAQACgBJAEkAUwAwADEAAwAKAEkASQBTADAAMQAHAAgAHwMI0VPy1QEAAAAA
|
|
```
|
|
또는 **nmap** 플러그인 `imap-ntlm-info.nse`로 이를 **자동화**합니다.
|
|
|
|
### [IMAP Bruteforce](../generic-hacking/brute-force.md#imap)
|
|
|
|
## 구문
|
|
|
|
IMAP 명령어 예시는 [여기](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
|
|
```
|
|
### 진화
|
|
```
|
|
apt install evolution
|
|
```
|
|
.png>)
|
|
|
|
### CURL
|
|
|
|
기본 탐색은 [CURL](https://ec.haxx.se/usingcurl/usingcurl-reademail#imap)로 가능하지만, 문서에 세부 정보가 부족하므로 정확한 세부 정보를 위해 [소스](https://github.com/curl/curl/blob/master/lib/imap.c)를 확인하는 것이 좋습니다.
|
|
|
|
1. 메일박스 나열 (imap 명령 `LIST "" "*"`)
|
|
```bash
|
|
curl -k 'imaps://1.2.3.4/' --user user:pass
|
|
```
|
|
2. 메일박스에서 메시지 나열하기 (imap 명령어 `SELECT INBOX` 및 그 다음 `SEARCH ALL`)
|
|
```bash
|
|
curl -k 'imaps://1.2.3.4/INBOX?ALL' --user user:pass
|
|
```
|
|
이 검색의 결과는 메시지 인덱스 목록입니다.
|
|
|
|
더 복잡한 검색어를 제공하는 것도 가능합니다. 예: 메일 본문에 비밀번호가 포함된 초안 검색:
|
|
```bash
|
|
curl -k 'imaps://1.2.3.4/Drafts?TEXT password' --user user:pass
|
|
```
|
|
가능한 검색어에 대한 좋은 개요는 [여기](https://www.atmail.com/blog/imap-commands/)에서 확인할 수 있습니다.
|
|
|
|
3. 메시지 다운로드 (imap 명령 `SELECT Drafts` 및 그 다음 `FETCH 1 BODY[]`)
|
|
```bash
|
|
curl -k 'imaps://1.2.3.4/Drafts;MAILINDEX=1' --user user:pass
|
|
```
|
|
메일 인덱스는 검색 작업에서 반환된 동일한 인덱스가 됩니다.
|
|
|
|
`UID` (고유 ID)를 사용하여 메시지에 접근하는 것도 가능하지만, 검색 명령을 수동으로 형식화해야 하므로 덜 편리합니다. 예:
|
|
```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
|
|
```
|
|
메시지의 일부만 다운로드하는 것도 가능합니다. 예를 들어, 첫 5개의 메시지의 제목과 발신자 (제목과 발신자를 보려면 `-v`가 필요합니다):
|
|
```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 '^<'
|
|
```
|
|
아마도 작은 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`
|
|
|
|
## 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'
|
|
```
|
|
{{#include ../banners/hacktricks-training.md}}
|