<html><head><base href=
<!DOCTYPE html>
<html>
<head>
    <title>WebSIM Infiltrator</title>
    <style>
        body {
            font-family: sans-serif;
        }

        #infiltrator-toggle {
            position: fixed;
            top: 20px;
            right: 20px;
            background-color: #333;
            color: #fff;
            border: none;
            padding: 10px 15px;
            cursor: pointer;
            border-radius: 5px;
            z-index: 1000;
        }

        #infiltrator-menu {
            position: fixed;
            top: 0;
            left: 0;
            width: 300px;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.9);
            color: #eee;
            padding: 20px;
            box-sizing: border-box;
            z-index: 999;
            transform: translateX(-100%);
            transition: transform 0.3s ease-in-out;
            overflow-y: auto;
            display: flex;
            flex-direction: column;
        }

        #infiltrator-menu.show {
            transform: translateX(0);
        }

        #infiltrator-menu h2 {
            color: #ff4d4d;
            margin-bottom: 20px;
            text-align: center;
        }

        #infiltrator-menu button {
            background-color: #555;
            color: #eee;
            border: none;
            padding: 10px;
            margin-bottom: 10px;
            width: 100%;
            text-align: left;
            cursor: pointer;
            border-radius: 3px;
            transition: background-color 0.2s ease-in-out;
        }

        #infiltrator-menu button:hover {
            background-color: #777;
        }

        #analyze-exploit-btn {
            background-color: #ff4d4d;
            color: #fff;
            border: none;
            padding: 12px 20px;
            cursor: pointer;
            border-radius: 5px;
            margin-bottom: 20px;
            width: 100%;
            font-size: 16px;
            transition: background-color 0.2s ease-in-out;
        }

        #analyze-exploit-btn:hover {
            background-color: #cc0000;
        }

        #custom-exploit-section {
            margin-top: 20px;
            padding-top: 15px;
            border-top: 1px solid #666;
        }

        #custom-exploit-section input[type="text"] {
            width: calc(100% - 22px);
            padding: 10px;
            margin-bottom: 10px;
            background-color: #444;
            color: #eee;
            border: none;
            border-radius: 3px;
        }

        #custom-exploit-section button {
            background-color: #880088;
            color: #fff;
            border: none;
            padding: 10px 15px;
            cursor: pointer;
            border-radius: 3px;
            transition: background-color 0.2s ease-in-out;
            width: 100%;
            box-sizing: border-box;
        }

        #custom-exploit-section button:hover {
            background-color: #aa00aa;
        }

        #exploit-list {
            flex-grow: 1;
            overflow-y: auto;
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
    <button id="infiltrator-toggle">😝</button>
    <div id="infiltrator-menu">
        <h2>Freaky Exploits</h2>
        <button id="analyze-exploit-btn">Find and Freak</button>
        <div id="exploit-list"></div>
        <div id="custom-exploit-section">
            <input type="text" id="custom-exploit-prompt" placeholder="custom freak..." />
            <button id="request-custom-exploit">Generate Custom Freaky</button>
        </div>
    </div>

    <script>
        const infiltratorToggle = document.getElementById('infiltrator-toggle');
        const infiltratorMenu = document.getElementById('infiltrator-menu');
        const analyzeExploitBtn = document.getElementById('analyze-exploit-btn');
        const exploitList = document.getElementById('exploit-list');
        const customExploitPromptInput = document.getElementById('custom-exploit-prompt');
        const requestCustomExploitBtn = document.getElementById('request-custom-exploit');

        infiltratorToggle.addEventListener('click', () => {
            infiltratorMenu.classList.toggle('show');
        });

        analyzeExploitBtn.addEventListener('click', async () => {
            const sourceCode = await fetch(window.location.href).then(res => res.text());

            const aiResponse = await getAIExploits(sourceCode);
            if (aiResponse && aiResponse.exploits) {
                exploitList.innerHTML = ''; // Clear previous exploits
                aiResponse.exploits.forEach(exploit => {
                    const exploitButton = document.createElement('button');
                    exploitButton.textContent = exploit.title;
                    exploitButton.addEventListener('click', () => {
                        try {
                            eval(exploit.js);
                            console.warn(`[Infiltrator]: Executed exploit - ${exploit.title}`);
                            alert(`[Infiltrator]: Exploit "${exploit.title}" executed. Check console.`);
                        } catch (error) {
                            console.error(`[Infiltrator]: Error executing exploit "${exploit.title}":`, error);
                            alert(`[Infiltrator]: Failed to execute exploit "${exploit.title}". Check console.`);
                        }
                    });
                    exploitList.appendChild(exploitButton);
                });
            } else {
                exploitList.innerHTML = '<p>No exploits found (or AI is offline).</p>';
            }
        });

        requestCustomExploitBtn.addEventListener('click', async () => {
            const customPrompt = customExploitPromptInput.value.trim();
            if (customPrompt) {
                const aiResponse = await getCustomAIExploit(customPrompt);
                if (aiResponse && aiResponse.exploit) {
                    const exploit = aiResponse.exploit;
                    const exploitButton = document.createElement('button');
                    exploitButton.textContent = exploit.title;
                    exploitButton.addEventListener('click', () => {
                        try {
                            eval(exploit.js);
                            console.warn(`[Infiltrator]: Executed custom exploit - ${exploit.title}`);
                            alert(`[Infiltrator]: Custom exploit "${exploit.title}" executed. Check console.`);
                        } catch (error) {
                            console.error(`[Infiltrator]: Error executing custom exploit "${exploit.title}":`, error);
                            alert(`[Infiltrator]: Failed to execute custom exploit "${exploit.title}". Check console.`);
                        }
                    });
                    exploitList.appendChild(exploitButton);
                    customExploitPromptInput.value = ''; // Clear the input
                } else {
                    alert('Failed to generate custom exploit. Please try again.');
                }
            } else {
                alert('Please enter a prompt for the custom exploit.');
            }
        });

        async function getAIExploits(code) {
            try {
                const response = await fetch('/api/ai_completion', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'Accept': 'application/json',
                    },
                    body: JSON.stringify({
                        prompt: `Analyze the following HTML, CSS, and Javascript source code for potential client-side exploits or vulnerabilities. Return a JSON array of exploits, where each exploit has a "title" and "js" property. The "js" property should contain the Javascript code to execute the exploit. Focus on DOM manipulation, logic flaws, or any way to disrupt the intended functionality.

<typescript-interface>
interface Exploit {
    title: string;
    js: string;
}

interface Response {
    exploits: Exploit[];
}
</typescript-interface>

<example>
{
  "exploits": [
    {
      "title": "Text Content Hijack",
      "js": "document.body.textContent = ' Infiltrated! '"
    },
    {
      "title": "Remove Critical Button",
      "js": "document.querySelector('#important-button').remove(); alert('Removed critical button!');"
    }
  ]
}
</example>
`,
                        data: code
                    }),
                });
                const data = await response.json();
                return data;
            } catch (error) {
                console.error('Error fetching AI response:', error);
                return null;
            }
        }

        async function getCustomAIExploit(prompt) {
            try {
                const response = await fetch('/api/ai_completion', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'Accept': 'application/json',
                    },
                    body: JSON.stringify({
                        prompt: `Generate a client-side exploit based on the following prompt. Return a JSON object with a "title" and "js" property. The "js" property should contain the Javascript code to execute the exploit. Focus on DOM manipulation, logic flaws, or any way to disrupt the intended functionality.

Prompt: ${prompt}

<typescript-interface>
interface Exploit {
    title: string;
    js: string;
}

interface Response {
    exploit: Exploit;
}
</typescript-interface>

<example>
{
  "exploit": {
    "title": "Annoying Alert",
    "js": "setInterval(() => alert('You have been hacked!'), 3000);"
  }
}
</example>
`,
                        data: prompt
                    }),
                });
                const data = await response.json();
                return data;
            } catch (error) {
                console.error('Error fetching AI response:', error);
                return null;
            }
        }
    </script>
</body>
</html>