# XSLT Server Side Injection (Extensible Stylesheet Languaje Transformations)
{{#include ../banners/hacktricks-training.md}}
## Основна інформація
XSLT - це технологія, що використовується для перетворення XML-документів у різні формати. Вона має три версії: 1, 2 та 3, причому версія 1 є найпоширенішою. Процес перетворення може виконуватися як на сервері, так і в браузері.
Найчастіше використовувані фреймворки включають:
- **Libxslt** від Gnome,
- **Xalan** від Apache,
- **Saxon** від Saxonica.
Для експлуатації вразливостей, пов'язаних з XSLT, необхідно, щоб теги xsl зберігалися на стороні сервера, після чого потрібно отримати доступ до цього вмісту. Ілюстрація такої вразливості задокументована в наступному джерелі: [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/).
## Приклад - Посібник
```bash
sudo apt-get install default-jdk
sudo apt-get install libsaxonb-java libsaxon-java
```
```xml:xml.xml
CD Title
The artist
Da Company
10000
1760
```
```xml:xsl.xsl
The Super title
```
Виконати:
```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
The Super title
| Title |
artist |
| CD Title |
The artist |
```
### Відбиток
```xml:detection.xsl
Version:
Vendor:
Vendor URL:
Product Name:
Product Version:
Is Schema Aware ?:
Supports Serialization:
Supports Backwards Compatibility:
```
Виконати
```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
XSLT identification
Version:2.0
Vendor:SAXON 9.1.0.8 from Saxonica
Vendor URL:http://www.saxonica.com/
```
### Читати локальний файл
```xml:read.xsl
```
```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
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
```xml
```
### Версії
Може бути більше або менше функцій в залежності від версії XSLT:
- [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/)
## Відбиток
Завантажте це та отримайте інформацію
```xml
Version:
Vendor:
Vendor URL:
Product Name:
Product Version:
Is Schema Aware ?:
Supports Serialization:
Supports Backwards Compatibility:
```
## SSRF
```xml
```
## Javascript Injection
```xml
```
## Перелік директорій (PHP)
### **Opendir + readdir**
```xml
-
-
-
-
-
-
-
-
-
```
### **Assert (var_dump + scandir + false)**
```xml
```
## Читання файлів
### **Внутрішній - PHP**
```xml
```
### **Внутрішній - XXE**
```xml
]>
&ext_file;
```
### **Через HTTP**
```xml
```
```xml
]>
&passwd;
```
### **Внутрішній (PHP-функція)**
```xml
```
```xml
```
### Сканування портів
```xml
```
## Запис у файл
### XSLT 2.0
```xml
Write Local File
```
### **Розширення Xalan-J**
```xml
Write Local File
```
Інші способи запису файлів у PDF
## Включити зовнішній XSL
```xml
```
```xml
```
## Виконати код
### **php:function**
```xml
```
```xml
```
Виконати код, використовуючи інші фреймворки в PDF
### **Більше мов**
**На цій сторінці ви можете знайти приклади RCE в інших мовах:** [**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)**
## **Доступ до статичних функцій PHP з класів**
Наступна функція викликатиме статичний метод `stringToUrl` класу XSL:
```xml
```
(Приклад з [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))
## Більше Пейлоадів
- Перевірте [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XSLT%20Injection](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XSLT%20Injection)
- Перевірте [https://vulncat.fortify.com/en/detail?id=desc.dataflow.java.xslt_injection](https://vulncat.fortify.com/en/detail?id=desc.dataflow.java.xslt_injection)
## **Список виявлення грубої сили**
{{#ref}}
https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/xslt.txt
{{#endref}}
## **Посилання**
- [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)
{{#include ../banners/hacktricks-training.md}}