From 4c03045f426ba968699b9a21f37ca0f9dfd5def6 Mon Sep 17 00:00:00 2001 From: Translator Date: Mon, 16 Oct 2023 21:15:46 +0000 Subject: [PATCH] Translated ['pentesting-web/xss-cross-site-scripting/README.md'] to cn --- .../xss-cross-site-scripting/README.md | 384 +++++++++--------- 1 file changed, 197 insertions(+), 187 deletions(-) diff --git a/pentesting-web/xss-cross-site-scripting/README.md b/pentesting-web/xss-cross-site-scripting/README.md index 0634dfc6d..2fe8a58a4 100644 --- a/pentesting-web/xss-cross-site-scripting/README.md +++ b/pentesting-web/xss-cross-site-scripting/README.md @@ -2,7 +2,7 @@ / -**赏金猎人提示**:**注册**Intigriti,一个由黑客创建的高级赏金平台,为黑客而生!立即加入我们,访问[**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks),开始赚取高达**$100,000**的赏金! +**赏金猎人提示**:**注册**Intigriti,一个由黑客创建的高级赏金平台,为黑客而生!立即加入我们:[**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks),开始赚取高达**$100,000**的赏金! {% embed url="https://go.intigriti.com/hacktricks" %} @@ -10,27 +10,27 @@ 1. 检查是否有**任何你可以控制的值**(_参数_,_路径_,_头部_?,_Cookie_?)在HTML中被**反射**或被**JS**代码使用。 2. 找到它被反射/使用的**上下文**。 -3. 如果是**反射**的 +3. 如果是**反射**的: 1. 检查你可以使用哪些符号,并根据此准备有效载荷: 1. 在**原始HTML**中: - 1. 你可以创建新的HTML标签吗? - 2. 你可以使用支持`javascript:`协议的事件或属性吗? - 3. 你可以绕过保护措施吗? - 4. HTML内容是否由任何客户端JS引擎(_AngularJS_,_VueJS_,_Mavo_...)解释,你可以滥用[**客户端模板注入**](../client-side-template-injection-csti.md)。 - 5. 如果你无法创建执行JS代码的HTML标签,你可以滥用[**悬挂标记 - HTML无脚本注入**](../dangling-markup-html-scriptless-injection/)吗? + 1. 你能创建新的HTML标签吗? + 2. 你能使用支持`javascript:`协议的事件或属性吗? + 3. 你能绕过保护措施吗? + 4. HTML内容是否由任何客户端JS引擎(_AngularJS_,_VueJS_,_Mavo_...)解释?你可以滥用[**客户端模板注入**](../client-side-template-injection-csti.md)。 + 5. 如果你无法创建执行JS代码的HTML标签,你能滥用[**悬挂标记 - HTML无脚本注入**](../dangling-markup-html-scriptless-injection/)吗? 2. 在**HTML标签内部**: - 1. 你可以退出到原始HTML上下文吗? - 2. 你可以创建新的事件/属性来执行JS代码吗? + 1. 你能退出到原始HTML上下文吗? + 2. 你能创建新的事件/属性来执行JS代码吗? 3. 你被困在的属性是否支持JS执行? - 4. 你可以绕过保护措施吗? + 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)}` `` +* 如果被反射在模板文字中,你可以使用`${ ... }`语法嵌入JS表达式:`` var greetings = `Hello, ${alert(1)}` `` * **Unicode编码**可用于编写**有效的javascript代码**: ```javascript \u{61}lert(1) @@ -163,7 +163,7 @@ parentElement ### DOM -有一些**JS代码**正在**不安全地**使用**由攻击者控制的数据**,如`location.href`。攻击者可以滥用此功能来执行任意JS代码。 +有一些**JS代码**正在**不安全地**使用由攻击者控制的一些数据,如`location.href`。攻击者可以滥用此功能来执行任意JS代码。 {% content-ref url="dom-xss.md" %} [dom-xss.md](dom-xss.md) @@ -171,7 +171,7 @@ parentElement ### **通用XSS** -这种类型的XSS可以在**任何地方**找到。它们不仅依赖于对Web应用程序的客户端利用,还依赖于**任何** **上下文**。这种**任意JavaScript执行**甚至可以被滥用以获得**RCE**,在客户端和服务器上**读取** **任意** **文件**等等。\ +这种类型的XSS可以在**任何地方**找到。它们不仅依赖于对Web应用程序的客户端利用,还依赖于**任何****上下文**。这种类型的**任意JavaScript执行**甚至可以被滥用以获得**RCE**,在客户端和服务器上**读取****任意****文件**等等。\ 一些**示例**: {% content-ref url="server-side-xss-dynamic-pdf.md" %} @@ -189,7 +189,7 @@ parentElement ## 在原始HTML中注入 当您的输入被反射**在HTML页面中**或者您可以在此上下文中转义和注入HTML代码时,**第一件**要做的事情是检查是否可以滥用`<`来创建新标签:只需尝试**反射**该**字符**并检查它是否被**HTML编码**或**删除**,或者是否**未经更改地反射**。**只有在最后一种情况下,您才能利用此情况**。\ -对于这些情况,还要**记住**[**客户端模板注入(Client Side Template Injection)**](../client-side-template-injection-csti.md)**。**\ +对于这些情况,还要**记住**[**客户端模板注入**](../client-side-template-injection-csti.md)**。**\ _**注意:HTML注释可以使用**** ****`-->`**** ****或**** ****`--!>`**_。 在这种情况下,如果没有使用黑名单/白名单,您可以使用以下有效负载: @@ -298,23 +298,19 @@ onerror=alert`1` ``` **样式事件** -Style events are a type of Cross-Site Scripting (XSS) attack that allows an attacker to inject malicious code into a website by exploiting vulnerabilities in the way the website handles user input. These events occur when the website allows user-controlled data to be included in CSS stylesheets or inline styles. +Style events are a type of Cross-Site Scripting (XSS) attack that allows an attacker to inject malicious code into a website by exploiting vulnerabilities in the way the website handles user input. These events occur when the website's code dynamically updates the style or appearance of certain elements based on user input. -攻击者可以通过利用网站处理用户输入的漏洞,将恶意代码注入网站中,从而实施样式事件(Style events)攻击。这些事件发生在网站允许用户控制的数据包含在CSS样式表或内联样式中的情况下。 +攻击者可以通过利用网站处理用户输入的漏洞,将恶意代码注入到网站中,从而实施样式事件(Style events)类型的跨站脚本攻击(Cross-Site Scripting,XSS)。这些事件发生在网站的代码根据用户输入动态更新某些元素的样式或外观时。 -By injecting malicious code into the website's stylesheets or inline styles, an attacker can manipulate the appearance and behavior of the website, potentially leading to various security risks. This can include stealing sensitive user information, performing phishing attacks, or even gaining unauthorized access to the website. +By injecting malicious code into the website's input fields, an attacker can manipulate the style events triggered by user interactions. This can lead to various consequences, such as changing the appearance of the website, redirecting users to malicious websites, or stealing sensitive information. -通过将恶意代码注入网站的样式表或内联样式中,攻击者可以操纵网站的外观和行为,可能导致各种安全风险。这可能包括窃取敏感用户信息、进行钓鱼攻击,甚至未经授权访问网站。 +通过向网站的输入字段注入恶意代码,攻击者可以操纵由用户交互触发的样式事件。这可能导致各种后果,例如改变网站的外观,将用户重定向到恶意网站,或窃取敏感信息。 -To prevent style events XSS attacks, it is important to properly sanitize and validate user input before including it in CSS stylesheets or inline styles. This can be done by implementing input validation and output encoding techniques, such as using secure frameworks or libraries that automatically handle these security measures. +To prevent style events XSS attacks, it is important for developers to properly sanitize and validate user input, especially when it is used to dynamically update the style or appearance of elements on a website. Additionally, implementing Content Security Policy (CSP) headers can help mitigate the risk of XSS attacks by restricting the sources from which the website can load external scripts. -为了防止样式事件XSS攻击,重要的是在将用户输入包含在CSS样式表或内联样式中之前,正确地对其进行清理和验证。可以通过实施输入验证和输出编码技术来实现这一点,例如使用安全的框架或库来自动处理这些安全措施。 +为了防止样式事件的跨站脚本攻击,开发人员需要正确地对用户输入进行清理和验证,特别是当用户输入用于动态更新网站上的元素的样式或外观时。此外,实施内容安全策略(Content Security Policy,CSP)头可以通过限制网站可以加载外部脚本的来源来帮助减轻跨站脚本攻击的风险。 -It is also recommended to regularly update and patch the website's software and plugins to mitigate any known vulnerabilities that could be exploited by attackers. Additionally, implementing a Content Security Policy (CSP) can help prevent style events XSS attacks by restricting the sources from which stylesheets can be loaded. - -还建议定期更新和修补网站的软件和插件,以减轻攻击者可能利用的已知漏洞。此外,实施内容安全策略(CSP)可以通过限制可以加载样式表的来源来帮助防止样式事件XSS攻击。 - -By following these security best practices, website owners can significantly reduce the risk of style events XSS attacks and protect their users' sensitive information. +It is crucial for website owners and developers to stay updated on the latest security best practices and regularly test their websites for vulnerabilities, including XSS attacks. By proactively addressing these issues, they can protect their users' data and maintain the integrity of their websites. ```python

XSS

XSS

@@ -356,69 +352,25 @@ HTML标签属性值中的**HTML编码字符**会在运行时解码。因此, ``` **使用Unicode编码绕过内部事件** ---- +In some cases, web applications may have input validation mechanisms that filter out certain characters or strings to prevent cross-site scripting (XSS) attacks. However, it is possible to bypass these filters by using Unicode encoding. -### Description +在某些情况下,Web应用程序可能具有输入验证机制,用于过滤掉某些字符或字符串,以防止跨站脚本(XSS)攻击。然而,可以通过使用Unicode编码来绕过这些过滤器。 -In some cases, web applications may have input validation mechanisms in place to prevent the execution of certain events, such as `onclick` or `onmouseover`. However, these mechanisms may not account for Unicode encoding, which can be used to bypass the validation and execute the desired event. +Unicode encoding allows us to represent characters using their corresponding Unicode code points. By encoding malicious JavaScript code using Unicode, we can evade input filters that are not designed to handle Unicode-encoded characters. -### Vulnerability +Unicode编码允许我们使用相应的Unicode代码点来表示字符。通过使用Unicode编码来编码恶意的JavaScript代码,我们可以逃避那些不能处理Unicode编码字符的输入过滤器。 -The vulnerability occurs when the web application fails to properly handle Unicode-encoded characters in user input. This allows an attacker to inject malicious code that will be executed by the browser. +To bypass an input filter that blocks certain characters or strings, we can use Unicode encoding to represent those characters in a different form. For example, the character `<` can be represented as `\u003c` in Unicode encoding. -### Exploitation +为了绕过阻止某些字符或字符串的输入过滤器,我们可以使用Unicode编码将这些字符表示为不同的形式。例如,字符`<`可以在Unicode编码中表示为`\u003c`。 -To exploit this vulnerability, an attacker can use Unicode encoding to bypass the input validation mechanism. By encoding the event name and the JavaScript code, the attacker can execute arbitrary code when the event is triggered. +By encoding the malicious JavaScript code using Unicode, we can bypass input filters that are not specifically designed to handle Unicode-encoded characters. This technique can be used to inject and execute arbitrary JavaScript code in a web application, potentially leading to XSS vulnerabilities. -For example, consider the following vulnerable code snippet: +通过使用Unicode编码来编码恶意的JavaScript代码,我们可以绕过那些没有专门设计用于处理Unicode编码字符的输入过滤器。这种技术可以用于在Web应用程序中注入和执行任意的JavaScript代码,可能导致XSS漏洞。 -```html - -``` +It is important to note that not all input filters can be bypassed using Unicode encoding. Some filters may be specifically designed to handle Unicode-encoded characters and can still detect and block malicious code. Therefore, it is crucial to thoroughly test the application's input validation mechanisms to ensure they are effective in preventing XSS attacks. -To bypass the `onmouseover` event validation, the attacker can use Unicode encoding for the event name and the JavaScript code: - -```html - -``` - -When the user hovers over the input field, the JavaScript code `\u0061\u006c\u0065\u0072\u0074('\u0058\u0053\u0053')` will be executed, resulting in an alert displaying "XSS". - -### Prevention - -To prevent this vulnerability, it is important to implement proper input validation and sanitization techniques. All user input should be properly encoded or filtered to prevent the execution of malicious code. Additionally, web application firewalls (WAFs) can be used to detect and block malicious requests. - ---- - -### 描述 - -在某些情况下,Web应用程序可能会有输入验证机制,以防止执行某些事件,例如`onclick`或`onmouseover`。然而,这些机制可能没有考虑到Unicode编码,可以用于绕过验证并执行所需的事件。 - -### 漏洞 - -当Web应用程序未能正确处理用户输入中的Unicode编码字符时,就会出现漏洞。这使得攻击者可以注入恶意代码,由浏览器执行。 - -### 利用 - -为了利用这个漏洞,攻击者可以使用Unicode编码来绕过输入验证机制。通过对事件名称和JavaScript代码进行编码,攻击者可以在触发事件时执行任意代码。 - -例如,考虑以下易受攻击的代码片段: - -```html - -``` - -为了绕过`onmouseover`事件验证,攻击者可以对事件名称和JavaScript代码使用Unicode编码: - -```html - -``` - -当用户悬停在输入字段上时,将执行JavaScript代码`\u0061\u006c\u0065\u0072\u0074('\u0058\u0053\u0053')`,导致弹出显示"XSS"的警报。 - -### 预防 - -为了防止这种漏洞,重要的是要实施适当的输入验证和净化技术。所有用户输入都应该经过适当的编码或过滤,以防止执行恶意代码。此外,可以使用Web应用程序防火墙(WAF)来检测和阻止恶意请求。 +需要注意的是,并非所有的输入过滤器都可以通过使用Unicode编码来绕过。有些过滤器可能专门设计用于处理Unicode编码字符,并且仍然可以检测和阻止恶意代码。因此,必须彻底测试应用程序的输入验证机制,以确保它们能够有效地防止XSS攻击。 ```javascript //For some reason you can use unicode to encode "alert" but not "(1)" @@ -470,7 +422,7 @@ data:image/svg+xml;base64,PHN2ZyB4bWxuczpzdmc9Imh0dH A6Ly93d3cudzMub3JnLzIwMDAvc ``` **其他混淆技巧** -_**在这种情况下,前一节中的HTML编码和Unicode编码技巧也是有效的,因为您处于属性内部。**_ +_**在这种情况下,前一节中的HTML编码和Unicode编码技巧也是有效的,因为你处于一个属性内部。**_ ```javascript ``` @@ -484,7 +436,7 @@ _**在这种情况下,前一节中的HTML编码和Unicode编码技巧也是有 **使用`javascript:`进行十六进制和八进制编码** -您可以在`iframe`的`src`属性中使用**十六进制**和**八进制编码**来声明**执行JS的HTML标签**(至少)。 +您可以在`iframe`的`src`属性中使用**十六进制**和**八进制编码**,以声明要执行的**HTML标签中的JS**: ```javascript //Encoded: // This WORKS @@ -500,9 +452,17 @@ _**在这种情况下,前一节中的HTML编码和Unicode编码技巧也是有 Reverse tab nabbing is a type of cross-site scripting (XSS) attack that targets users who have multiple tabs open in their web browser. In this attack, the attacker injects malicious code into a website that the victim is currently viewing. When the victim switches to another tab and then returns to the original tab, the injected code can modify the content of the page and trick the victim into performing unintended actions. -To execute a reverse tab nabbing attack, the attacker typically exploits a vulnerability in the target website that allows them to inject JavaScript code. This code is then used to monitor the focus of the victim's browser tabs. When the victim switches to another tab, the injected code can modify the title and content of the original tab to mimic a legitimate website or prompt the victim to enter sensitive information. +To execute a reverse tab nabbing attack, the attacker typically exploits a vulnerability in the target website that allows them to inject JavaScript code. This code is designed to detect when the victim switches tabs and then modify the content of the page accordingly. For example, the attacker may change the appearance of a login form to mimic a trusted website, leading the victim to enter their credentials unknowingly. -To protect against reverse tab nabbing attacks, website developers should implement proper input validation and output encoding to prevent XSS vulnerabilities. Users can also protect themselves by keeping their web browsers and plugins up to date, using browser extensions that block malicious scripts, and being cautious when clicking on links or entering personal information on websites. +To protect against reverse tab nabbing attacks, website developers should implement proper input validation and output encoding to prevent XSS vulnerabilities. Additionally, users should be cautious when switching between tabs and ensure that they only interact with trusted websites. + +### 反向标签劫持 + +反向标签劫持是一种针对在网络浏览器中打开多个标签的用户的跨站脚本攻击(XSS)。在这种攻击中,攻击者将恶意代码注入到受害者当前正在浏览的网站中。当受害者切换到另一个标签页,然后返回到原始标签页时,注入的代码可以修改页面内容,并欺骗受害者执行意外操作。 + +要执行反向标签劫持攻击,攻击者通常利用目标网站中的漏洞来注入JavaScript代码。该代码旨在检测受害者切换标签页的时机,并相应地修改页面内容。例如,攻击者可能会更改登录表单的外观,模仿受信任的网站,导致受害者无意中输入其凭据。 + +为了防止反向标签劫持攻击,网站开发人员应该实施适当的输入验证和输出编码,以防止XSS漏洞。此外,用户在切换标签页时应谨慎,并确保只与受信任的网站进行交互。 ```javascript ` tag is `\u003cscript\u003e`. By using this encoding, an attacker can inject JavaScript code without triggering the input validation. - -Here is an example payload that demonstrates the exploitation of this vulnerability: +For example, the Unicode encoding for the `\"/\"src=\"/\"onerror=eval(id) +(function(x){this[x+`ert`](1)})`al` +window[`al`+/e/[`ex`+`ec`]`e`+`rt`](2) +document['default'+'View'][`\u0061lert`](3) ``` ### 在302响应中进行头部注入的XSS攻击 如果你发现可以在302重定向响应中**注入头部**,你可以尝试让浏览器**执行任意的JavaScript代码**。这并不容易,因为现代浏览器在HTTP响应状态码为302时不会解析HTTP响应体,所以仅仅一个跨站脚本负载是无用的。 -在[**这份报告**](https://www.gremwell.com/firefox-xss-302)和[**这份报告**](https://www.hahwul.com/2020/10/03/forcing-http-redirect-xss/)中,你可以了解如何测试Location头部中的多个协议,并查看是否有任何协议允许浏览器检查和执行主体中的XSS负载。\ +在[**这个报告**](https://www.gremwell.com/firefox-xss-302)和[**这个报告**](https://www.hahwul.com/2020/10/03/forcing-http-redirect-xss/)中,你可以了解如何测试Location头部中的多个协议,并查看是否有任何协议允许浏览器检查和执行主体中的XSS负载。\ 已知的协议有:`mailto://`,`//x:1/`,`ws://`,`wss://`,空的Location头部,`resource://`。 ### 仅限字母、数字和点号 -如果你能指定**回调函数**将要**执行**的JavaScript代码,限制只能使用这些字符。[**阅读这篇文章的这一部分**](./#javascript-function)以了解如何滥用这种行为。 +如果你能指定**回调函数**将要**执行**的JavaScript代码,限制为这些字符。[**阅读本文的这一部分**](./#javascript-function)以了解如何滥用这种行为。 ### 可用于XSS的有效`