mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
170 lines
6.7 KiB
Markdown
170 lines
6.7 KiB
Markdown
# 143,993 - Pentesting IMAP
|
||
|
||
{{#include ../banners/hacktricks-training.md}}
|
||
|
||
## インターネットメッセージアクセスプロトコル
|
||
|
||
**インターネットメッセージアクセスプロトコル (IMAP)** は、ユーザーが**任意の場所からメールメッセージにアクセスできるようにする**ことを目的として設計されています。主にインターネット接続を通じて行われます。要するに、メールは**サーバーに保持され**、個人のデバイスにダウンロードして保存されることはありません。これは、メールにアクセスまたは読む際に、**サーバーから直接行われる**ことを意味します。この機能により、**複数のデバイス**からメールを確認する便利さが提供され、使用するデバイスに関係なくメッセージを見逃すことがありません。
|
||
|
||
デフォルトでは、IMAPプロトコルは2つのポートで動作します:
|
||
|
||
- **ポート 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
|
||
```
|
||
Or **automate** this with **nmap** plugin `imap-ntlm-info.nse`
|
||
|
||
### [IMAP Bruteforce](../generic-hacking/brute-force.md#imap)
|
||
|
||
## Syntax
|
||
|
||
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.wiki/en/network-services-pentesting/pentesting-imap.html
|
||
|
||
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}}
|