# Server Side Inclusion/Edge Side Inclusion Injection {% hint style="success" %} Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks * Check the [**subscription plans**](https://github.com/sponsors/carlospolop)! * **Join the** πŸ’¬ [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.** * **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %} ## Server Side Inclusion Basic Information **(Introduction taken from [Apache docs](https://httpd.apache.org/docs/current/howto/ssi.html))** SSI (μ„œλ²„ μ‚¬μ΄λ“œ 포함)λŠ” **HTML νŽ˜μ΄μ§€μ— 배치되고, νŽ˜μ΄μ§€κ°€ μ œκ³΅λ˜λŠ” λ™μ•ˆ μ„œλ²„μ—μ„œ ν‰κ°€λ˜λŠ” μ§€μ‹œμ–΄**μž…λ‹ˆλ‹€. 이λ₯Ό 톡해 **κΈ°μ‘΄ HTML νŽ˜μ΄μ§€μ— λ™μ μœΌλ‘œ μƒμ„±λœ μ½˜ν…μΈ λ₯Ό μΆ”κ°€**ν•  수 있으며, 전체 νŽ˜μ΄μ§€λ₯Ό CGI ν”„λ‘œκ·Έλž¨μ΄λ‚˜ λ‹€λ₯Έ 동적 κΈ°μˆ μ„ 톡해 μ œκ³΅ν•  ν•„μš”κ°€ μ—†μŠ΅λ‹ˆλ‹€.\ 예λ₯Ό λ“€μ–΄, κΈ°μ‘΄ HTML νŽ˜μ΄μ§€μ— λ‹€μŒκ³Ό 같은 μ§€μ‹œμ–΄λ₯Ό λ°°μΉ˜ν•  수 μžˆμŠ΅λ‹ˆλ‹€: `` 그리고 νŽ˜μ΄μ§€κ°€ 제곡될 λ•Œ, 이 쑰각은 ν‰κ°€λ˜μ–΄ κ·Έ κ°’μœΌλ‘œ λŒ€μ²΄λ©λ‹ˆλ‹€: `Tuesday, 15-Jan-2013 19:28:54 EST` SSIλ₯Ό μ‚¬μš©ν•  μ‹œμ κ³Ό νŽ˜μ΄μ§€λ₯Ό μ™„μ „νžˆ 생성할 ν”„λ‘œκ·Έλž¨μ„ μ‚¬μš©ν•  μ‹œμ μ˜ 결정은 일반적으둜 νŽ˜μ΄μ§€μ˜ 정적 λΆ€λΆ„κ³Ό νŽ˜μ΄μ§€κ°€ 제곡될 λ•Œλ§ˆλ‹€ μž¬κ³„μ‚°ν•΄μ•Ό ν•˜λŠ” λΆ€λΆ„μ˜ 양에 따라 λ‹¬λΌμ§‘λ‹ˆλ‹€. SSIλŠ” ν˜„μž¬ μ‹œκ°„κ³Ό 같은 μž‘μ€ 정보λ₯Ό μΆ”κ°€ν•˜λŠ” ν›Œλ₯­ν•œ λ°©λ²•μž…λ‹ˆλ‹€ - μœ„μ— ν‘œμ‹œλœ κ²ƒμ²˜λŸΌ. κ·ΈλŸ¬λ‚˜ νŽ˜μ΄μ§€μ˜ λŒ€λΆ€λΆ„μ΄ 제곡될 λ•Œ μƒμ„±λœλ‹€λ©΄, λ‹€λ₯Έ μ†”λ£¨μ…˜μ„ μ°Ύμ•„μ•Ό ν•©λ‹ˆλ‹€. μ›Ή μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ΄ **`.shtml`, `.shtm` λ˜λŠ” `.stm`** ν™•μž₯자λ₯Ό 가진 νŒŒμΌμ„ μ‚¬μš©ν•œλ‹€λ©΄ SSI의 쑴재λ₯Ό μΆ”λ‘ ν•  수 μžˆμ§€λ§Œ, κ·Έκ²ƒλ§Œμ΄ μ „λΆ€λŠ” μ•„λ‹™λ‹ˆλ‹€. μ „ν˜•μ μΈ SSI ν‘œν˜„μ‹μ€ λ‹€μŒ ν˜•μ‹μ„ κ°€μ§‘λ‹ˆλ‹€: ``` ``` ### 확인 ```javascript // Document name // Date // File inclusion // Including files (same directory) // CGI Program results // Including virtual files (same directory) // Modification date of a file // Command exec // Command exec // Reverse shell // Print all variables // Setting variables ``` ## Edge Side Inclusion 정보λ₯Ό **μΊμ‹±ν•˜κ±°λ‚˜ 동적 μ• ν”Œλ¦¬μΌ€μ΄μ…˜**의 μΌλΆ€λ‘œμ„œ μ½˜ν…μΈ κ°€ λ‹€μŒ λ²ˆμ— μ½˜ν…μΈ λ₯Ό 검색할 λ•Œ **λ‹€λ₯Ό 수** μžˆλ‹€λŠ” λ¬Έμ œκ°€ μžˆμŠ΅λ‹ˆλ‹€. 이것이 **ESI**κ°€ μ‚¬μš©λ˜λŠ” 이유둜, ESI νƒœκ·Έλ₯Ό μ‚¬μš©ν•˜μ—¬ **생성해야 ν•˜λŠ” 동적 μ½˜ν…μΈ **λ₯Ό λ‚˜νƒ€λƒ…λ‹ˆλ‹€.\ λ§Œμ•½ **곡격자**κ°€ μΊμ‹œ μ½˜ν…μΈ  내에 **ESI νƒœκ·Έλ₯Ό μ£Όμž…**ν•  수 μžˆλ‹€λ©΄, κ·ΈλŠ” λ¬Έμ„œκ°€ μ‚¬μš©μžμ—κ²Œ μ „μ†‘λ˜κΈ° 전에 **μž„μ˜μ˜ μ½˜ν…μΈ λ₯Ό μ£Όμž…**ν•  수 μžˆμŠ΅λ‹ˆλ‹€. ### ESI Detection μ„œλ²„μ˜ μ‘λ‹΅μ—μ„œ λ‹€μŒ **헀더**λŠ” μ„œλ²„κ°€ ESIλ₯Ό μ‚¬μš©ν•˜κ³  μžˆμŒμ„ μ˜λ―Έν•©λ‹ˆλ‹€: ``` Surrogate-Control: content="ESI/1.0" ``` 이 헀더λ₯Ό 찾을 수 μ—†λ‹€λ©΄, μ„œλ²„λŠ” **μ–΄μ¨Œλ“  ESIλ₯Ό μ‚¬μš©ν•˜κ³  μžˆμ„ 수 μžˆμŠ΅λ‹ˆλ‹€**.\ **λΈ”λΌμΈλ“œ μ΅μŠ€ν”Œλ‘œμž‡ μ ‘κ·Ό 방식도 μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€**. μš”μ²­μ€ 곡격자의 μ„œλ²„μ— 도착해야 ν•©λ‹ˆλ‹€: ```javascript // Basic detection hello // If previous is reflected as "hello", it's vulnerable // Blind detection // XSS Exploitation Example // Cookie Stealer (bypass httpOnly flag) // Introduce private local files (Not LFI per se) // Valid for Akamai, sends debug information in the response ``` ### ESI μ•…μš© [GoSecureλŠ”](https://www.gosecure.net/blog/2018/04/03/beyond-xss-edge-side-include-injection/) λ‹€μ–‘ν•œ ESI κΈ°λŠ₯을 μ§€μ›ν•˜λŠ” μ†Œν”„νŠΈμ›¨μ–΄μ— λŒ€ν•΄ μ‹œλ„ν•  수 μžˆλŠ” κ°€λŠ₯ν•œ 곡격을 μ΄ν•΄ν•˜κΈ° μœ„ν•œ ν‘œλ₯Ό λ§Œλ“€μ—ˆμŠ΅λ‹ˆλ‹€: * **Includes**: `` μ§€μ‹œμ–΄λ₯Ό μ§€μ›ν•©λ‹ˆλ‹€. * **Vars**: `` μ§€μ‹œμ–΄λ₯Ό μ§€μ›ν•©λ‹ˆλ‹€. XSS ν•„ν„°λ₯Ό μš°νšŒν•˜λŠ” 데 μœ μš©ν•©λ‹ˆλ‹€. * **Cookie**: λ¬Έμ„œ μΏ ν‚€λŠ” ESI 엔진에 μ ‘κ·Όν•  수 μžˆμŠ΅λ‹ˆλ‹€. * **Upstream Headers Required**: μƒμœ„ μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ΄ 헀더λ₯Ό μ œκ³΅ν•˜μ§€ μ•ŠμœΌλ©΄ λŒ€λ¦¬ μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ€ ESI λ¬Έμž₯을 μ²˜λ¦¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. * **Host Allowlist**: 이 경우 ESI 포함은 ν—ˆμš©λœ μ„œλ²„ ν˜ΈμŠ€νŠΈμ—μ„œλ§Œ κ°€λŠ₯ν•˜λ―€λ‘œ, 예λ₯Ό λ“€μ–΄ SSRFλŠ” ν•΄λ‹Ή ν˜ΈμŠ€νŠΈμ— λŒ€ν•΄μ„œλ§Œ κ°€λŠ₯ν•©λ‹ˆλ‹€. | **μ†Œν”„νŠΈμ›¨μ–΄** | **Includes** | **Vars** | **Cookies** | **Upstream Headers Required** | **Host Whitelist** | | :--------------------------: | :----------: | :------: | :---------: | :---------------------------: | :----------------: | | Squid3 | Yes | Yes | Yes | Yes | No | | Varnish Cache | Yes | No | No | Yes | Yes | | Fastly | Yes | No | No | No | Yes | | Akamai ESI Test Server (ETS) | Yes | Yes | Yes | No | No | | NodeJS esi | Yes | Yes | Yes | No | No | | NodeJS nodesi | Yes | No | No | No | Optional | #### XSS λ‹€μŒ ESI μ§€μ‹œμ–΄λŠ” μ„œλ²„μ˜ 응닡 λ‚΄μ—μ„œ μž„μ˜μ˜ νŒŒμΌμ„ λ‘œλ“œν•©λ‹ˆλ‹€. ```xml ``` #### ν΄λΌμ΄μ–ΈνŠΈ XSS 보호 우회 ```xml x=>alert(/Chrome%20XSS%20filter%20bypass/);> Use to bypass WAFs: ipt>alert(1)ript> error=alert(1)> ``` #### μΏ ν‚€ ν›”μΉ˜κΈ° * 원격 μΏ ν‚€ ν›”μΉ˜κΈ° ```xml ``` * XSSλ₯Ό μ‚¬μš©ν•˜μ—¬ 응닡에 λ°˜μ˜ν•˜μ—¬ HTTP\_ONLY μΏ ν‚€λ₯Ό ν›”μΉ˜κΈ°: ```bash # This will reflect the cookies in the response # Reflect XSS (you can put '">' URL encoded and the URL encode eveyrhitng to send it in the HTTP request) # It's possible to put more complex JS code to steal cookies or perform actions ``` #### Private Local File 이것을 "둜컬 파일 포함(Local File Inclusion)"κ³Ό ν˜Όλ™ν•˜μ§€ λ§ˆμ‹­μ‹œμ˜€: ```markup ``` #### CRLF ```markup ``` #### Open Redirect λ‹€μŒμ€ 응닡에 `Location` 헀더λ₯Ό μΆ”κ°€ν•©λ‹ˆλ‹€. ```bash ``` #### Add Header * κ°•μ œ μš”μ²­μ— 헀더 μΆ”κ°€ ```xml ``` * 응닡에 헀더 μΆ”κ°€ (XSSκ°€ μžˆλŠ” μ‘λ‹΅μ—μ„œ "Content-Type: text/json" 우회λ₯Ό μœ„ν•΄ μœ μš©ν•¨) ```bash # Check the number of url_decode to know how many times you can URL encode the value ``` #### CRLF in Add header (**CVE-2019-2438**) ```xml ``` #### Akamai debug 이것은 응닡에 ν¬ν•¨λœ 디버그 정보λ₯Ό μ „μ†‘ν•©λ‹ˆλ‹€: ```xml ``` ### ESI + XSLT = XXE `_dca_` λ§€κ°œλ³€μˆ˜μ— λŒ€ν•΄ `xslt` 값을 μ§€μ •ν•¨μœΌλ‘œμ¨ **`eXtensible Stylesheet Language Transformations (XSLT)`** 기반 ESIλ₯Ό ν¬ν•¨ν•˜λŠ” 것이 κ°€λŠ₯ν•©λ‹ˆλ‹€. 이 포함은 HTTP λŒ€λ¦¬ μ„œλ²„κ°€ XML 및 XSLT νŒŒμΌμ„ κ²€μƒ‰ν•˜κ²Œ ν•˜λ©°, ν›„μžλŠ” μ „μžλ₯Ό ν•„ν„°λ§ν•©λ‹ˆλ‹€. μ΄λŸ¬ν•œ XML νŒŒμΌμ€ _XML External Entity (XXE)_ 곡격에 μ•…μš©λ  수 μžˆμ–΄ κ³΅κ²©μžκ°€ SSRF 곡격을 μ‹€ν–‰ν•  수 있게 ν•©λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ 이 μ ‘κ·Ό λ°©μ‹μ˜ μœ μš©μ„±μ€ μ œν•œμ μž…λ‹ˆλ‹€. μ™œλƒν•˜λ©΄ ESIλŠ” 이미 SSRF λ²‘ν„°λ‘œ μž‘μš©ν•˜κΈ° λ•Œλ¬Έμž…λ‹ˆλ‹€. κΈ°λ³Έ Xalan λΌμ΄λΈŒλŸ¬λ¦¬μ—μ„œ 지원이 μ—†κΈ° λ•Œλ¬Έμ— μ™ΈλΆ€ DTDλŠ” μ²˜λ¦¬λ˜μ§€ μ•Šμ•„ 둜컬 파일 μΆ”μΆœμ΄ λ°©μ§€λ©λ‹ˆλ‹€. ```xml ``` XSLT 파일: ```xml ]> &xxe; ``` Check the XSLT page: {% content-ref url="xslt-server-side-injection-extensible-stylesheet-language-transformations.md" %} [xslt-server-side-injection-extensible-stylesheet-language-transformations.md](xslt-server-side-injection-extensible-stylesheet-language-transformations.md) {% endcontent-ref %} ### References * [https://www.gosecure.net/blog/2018/04/03/beyond-xss-edge-side-include-injection/](https://www.gosecure.net/blog/2018/04/03/beyond-xss-edge-side-include-injection/) * [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/) * [https://academy.hackthebox.com/module/145/section/1304](https://academy.hackthebox.com/module/145/section/1304) * [https://infosecwriteups.com/exploring-the-world-of-esi-injection-b86234e66f91](https://infosecwriteups.com/exploring-the-world-of-esi-injection-b86234e66f91) ## Brute-Force Detection List {% embed url="https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/ssi_esi.txt" %} {% hint style="success" %} Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks * Check the [**subscription plans**](https://github.com/sponsors/carlospolop)! * **Join the** πŸ’¬ [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.** * **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}