# 143,993 - Pentesting IMAP {% hint style="success" %} Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks * 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.
{% endhint %} ## 인터넷 λ©”μ‹œμ§€ μ ‘κ·Ό ν”„λ‘œν† μ½œ **인터넷 λ©”μ‹œμ§€ μ ‘κ·Ό ν”„λ‘œν† μ½œ (IMAP)**은 μ‚¬μš©μžκ°€ **μ–΄λ–€ μœ„μΉ˜μ—μ„œλ“  이메일 λ©”μ‹œμ§€μ— μ ‘κ·Όν•  수 μžˆλ„λ‘** μ„€κ³„λ˜μ—ˆμŠ΅λ‹ˆλ‹€. 주둜 인터넷 연결을 톡해 μ΄λ£¨μ–΄μ§‘λ‹ˆλ‹€. 본질적으둜 이메일은 **μ„œλ²„μ— 보관**되며 개인 μž₯μΉ˜μ— λ‹€μš΄λ‘œλ“œλ˜μ–΄ μ €μž₯λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. μ΄λŠ” 이메일에 μ ‘κ·Όν•˜κ±°λ‚˜ 읽을 λ•Œ **μ„œλ²„μ—μ„œ 직접** μ΄λ£¨μ–΄μ§„λ‹€λŠ” 것을 μ˜λ―Έν•©λ‹ˆλ‹€. 이 κΈ°λŠ₯은 **μ—¬λŸ¬ μž₯μΉ˜μ—μ„œ 이메일을 ν™•μΈν•˜λŠ”** νŽΈλ¦¬ν•¨μ„ μ œκ³΅ν•˜μ—¬ μ‚¬μš©λœ μž₯μΉ˜μ— 관계없이 λ©”μ‹œμ§€λ₯Ό λ†“μΉ˜μ§€ μ•Šλ„λ‘ ν•©λ‹ˆλ‹€. 기본적으둜 IMAP ν”„λ‘œν† μ½œμ€ 두 개의 ν¬νŠΈμ—μ„œ μž‘λ™ν•©λ‹ˆλ‹€: * **포트 143** - κΈ°λ³Έ IMAP λΉ„μ•”ν˜Έν™” ν¬νŠΈμž…λ‹ˆλ‹€. * **포트 993** - IMAP을 μ•ˆμ „ν•˜κ²Œ μ—°κ²°ν•˜λ €λ©΄ μ‚¬μš©ν•΄μ•Ό ν•˜λŠ” ν¬νŠΈμž…λ‹ˆλ‹€. ``` PORT STATE SERVICE REASON 143/tcp open imap syn-ack ``` ## λ°°λ„ˆ μˆ˜μ§‘ ```bash nc -nv 143 openssl s_client -connect :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 **μžλ™ν™”** this with **nmap** plugin `imap-ntlm-info.nse` ### [IMAP 브루트포슀](../generic-methodologies-and-resources/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 ``` ![](<../.gitbook/assets/image (1033).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' ``` {% hint style="success" %} AWS ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ GCP ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
HackTricks μ§€μ›ν•˜κΈ° * [**ꡬ독 κ³„νš**](https://github.com/sponsors/carlospolop) ν™•μΈν•˜κΈ°! * **πŸ’¬ [**Discord κ·Έλ£Ή**](https://discord.gg/hRep4RUj7f) λ˜λŠ” [**ν…”λ ˆκ·Έλž¨ κ·Έλ£Ή**](https://t.me/peass)에 μ°Έμ—¬ν•˜κ±°λ‚˜ **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**λ₯Ό νŒ”λ‘œμš°ν•˜μ„Έμš”.** * **[**HackTricks**](https://github.com/carlospolop/hacktricks) 및 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) κΉƒν—ˆλΈŒ 리포지토리에 PR을 μ œμΆœν•˜μ—¬ ν•΄ν‚Ή νŒμ„ κ³΅μœ ν•˜μ„Έμš”.**
{% endhint %}