From 3613ab9fa77142480801a9fcdd1c420652f82e99 Mon Sep 17 00:00:00 2001 From: Translator Date: Tue, 19 Aug 2025 20:35:10 +0000 Subject: [PATCH] Translated ['src/pentesting-web/xss-cross-site-scripting/iframes-in-xss- --- .../iframes-in-xss-and-csp.md | 88 +++++++++++++++---- 1 file changed, 69 insertions(+), 19 deletions(-) diff --git a/src/pentesting-web/xss-cross-site-scripting/iframes-in-xss-and-csp.md b/src/pentesting-web/xss-cross-site-scripting/iframes-in-xss-and-csp.md index ba889b692..8290b92d7 100644 --- a/src/pentesting-web/xss-cross-site-scripting/iframes-in-xss-and-csp.md +++ b/src/pentesting-web/xss-cross-site-scripting/iframes-in-xss-and-csp.md @@ -4,11 +4,11 @@ ## Iframes in XSS -有三种方式来指示一个 iframe 页面内容: +有3种方式来指示iframe页面的内容: -- 通过 `src` 指定一个 URL(该 URL 可以是跨源或同源) -- 通过 `src` 使用 `data:` 协议指示内容 -- 通过 `srcdoc` 指示内容 +- 通过`src`指示一个URL(该URL可以是跨源或同源) +- 通过`src`使用`data:`协议指示内容 +- 通过`srcdoc`指示内容 **访问父变量和子变量** ```html @@ -45,7 +45,7 @@ var secret = "child secret" alert(parent.secret) ``` -如果您通过 HTTP 服务器(如 `python3 -m http.server`)访问之前的 HTML,您会注意到所有脚本都会被执行(因为没有 CSP 阻止它)。**父级将无法访问任何 iframe 内部的 `secret` 变量**,**只有 if2 和 if3(被视为同源)可以访问原始窗口中的 secret**。\ +如果您通过 HTTP 服务器(如 `python3 -m http.server`)访问之前的 HTML,您会注意到所有脚本都会被执行(因为没有 CSP 阻止它)。**父级将无法访问任何 iframe 内部的 `secret` 变量**,**只有 if2 和 if3(被视为同站)可以访问原始窗口中的 secret**。\ 请注意 if4 被认为具有 `null` 来源。 ### 带 CSP 的 Iframes @@ -61,7 +61,7 @@ alert(parent.secret) +content="script-src 'sha256-iF/bMbiFXal+AAl9tF8N6+KagNWdMlnhLqWkjAocLsk'" /> " if __name__ == "__main__": app.run() ``` -### 在野外发现的其他有效载荷 +#### 新的(2023-2025)CSP 绕过技术与 iframes + +研究社区继续发现创造性的方法来利用 iframes 以击败限制性政策。以下是过去几年发布的最显著的技术: + +* **悬挂标记 / 命名 iframe 数据外泄 (PortSwigger 2023)** – 当一个应用程序反射 HTML 但强 CSP 阻止脚本执行时,您仍然可以通过注入一个 *悬挂* ` + + ``` ### Credentialless iframes -正如在 [this article](https://blog.slonser.info/posts/make-self-xss-great-again/) 中所解释的,iframe 中的 `credentialless` 标志用于在不发送凭据的请求下加载页面,同时保持加载页面在 iframe 中的同源策略 (SOP)。 +正如在 [this article](https://blog.slonser.info/posts/make-self-xss-great-again/) 中所解释的,iframe 中的 `credentialless` 标志用于在不发送凭据的请求的情况下加载页面,同时保持 iframe 中加载页面的同源策略 (SOP)。 -这允许 iframe 访问来自同一 SOP 中在父页面加载的另一个 iframe 的敏感信息: +自 **Chrome 110 (2023年2月) 起,该功能默认启用**,并且该规范正在以 *anonymous iframe* 的名称在各个浏览器中标准化。MDN 将其描述为:“一种机制,用于在全新的、短暂的存储分区中加载第三方 iframe,以便不与真实来源共享任何 cookies、localStorage 或 IndexedDB”。对攻击者和防御者的影响: + +* 不同的 credentialless iframes 中的脚本 **仍然共享相同的顶级来源**,并可以通过 DOM 自由交互,使多 iframe 自我 XSS 攻击成为可能(见下面的 PoC)。 +* 由于网络是 **去凭据化的**,iframe 内的任何请求实际上表现为未认证会话 – CSRF 保护的端点通常会失败,但通过 DOM 泄露的公共页面仍在范围内。 +* 从 credentialless iframe 生成的弹出窗口获得隐式的 `rel="noopener"`,破坏了一些 OAuth 流程。 ```javascript -window.top[1].document.body.innerHTML = 'Hi from credentialless'; -alert(window.top[1].document.cookie); +// PoC: two same-origin credentialless iframes stealing cookies set by a third +window.top[1].document.cookie = 'foo=bar'; // write +alert(window.top[2].document.cookie); // read -> foo=bar ``` - 利用示例:Self-XSS + CSRF @@ -181,7 +225,7 @@ let arr = [minute, minute * 60, minute * 60 * 24, ...] for (let timeout of arr) fetchLater(req,{activateAfter: timeout}) ``` -## Iframes 在 SOP 中 +## Iframes in SOP 检查以下页面: @@ -201,4 +245,10 @@ fetchLater(req,{activateAfter: timeout}) ../postmessage-vulnerabilities/steal-postmessage-modifying-iframe-location.md {{#endref}} + + +## References + +* [PortSwigger Research – Using form hijacking to bypass CSP (March 2024)](https://portswigger.net/research/using-form-hijacking-to-bypass-csp) +* [Chrome Developers – Iframe credentialless: Easily embed iframes in COEP environments (Feb 2023)](https://developer.chrome.com/blog/iframe-credentialless) {{#include ../../banners/hacktricks-training.md}}