From 1fe8bb5182487aab5f4e10071c6b716c00b2a0a3 Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Mon, 27 Apr 2026 18:50:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Hub=20=E5=B9=BF?= =?UTF-8?q?=E6=92=AD=20data=20race=20=E5=92=8C=E7=AB=AF=E5=8F=A3=E6=89=AB?= =?UTF-8?q?=E6=8F=8F=E6=BD=9C=E5=9C=A8=E6=AD=BB=E9=94=81=EF=BC=8C=E6=B8=85?= =?UTF-8?q?=E7=90=86=E6=AD=BB=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - hub.go: broadcast 路径 RLock 改 Lock,修复并发 delete/close 竞争 - port_scan.go: pool.Invoke 失败时释放 wg 和 semaphore,防止死锁 - web_scanner.go: 删除只写不读的 fingerprintCache - webtitle.go: 移除对已删除 SetFingerprints 的调用 - keylogger.go: 删除未使用的 stopChan 和 isRunning 字段 --- core/port_scan.go | 5 ++++- core/web_scanner.go | 24 ------------------------ plugins/local/keylogger.go | 7 ------- plugins/web/webtitle.go | 5 ----- web/ws/hub.go | 4 ++-- 5 files changed, 6 insertions(+), 39 deletions(-) diff --git a/core/port_scan.go b/core/port_scan.go index 9aba364..47b4bc9 100644 --- a/core/port_scan.go +++ b/core/port_scan.go @@ -252,7 +252,10 @@ func slidingWindowSchedule(iter *SocketIterator, pool *AdaptivePool, wg *sync.Wa port: port, semaphore: semaphore, } - _ = pool.Invoke(task) + if err := pool.Invoke(task); err != nil { + <-semaphore + wg.Done() + } } // 等待所有任务完成 diff --git a/core/web_scanner.go b/core/web_scanner.go index f688e10..3e4f44d 100644 --- a/core/web_scanner.go +++ b/core/web_scanner.go @@ -276,30 +276,6 @@ func IsMarkedWebService(host string, port int) bool { return exists } -// =============================== -// 指纹缓存 -// =============================== - -// 指纹缓存 - 存储 host:port → 指纹列表的映射 -var ( - fingerprintCache = make(map[string][]string) - fingerprintCacheMutex sync.RWMutex -) - -// SetFingerprints 存储目标的指纹信息 -func SetFingerprints(host string, port int, fingerprints []string) { - if len(fingerprints) == 0 { - return - } - - cacheKey := fmt.Sprintf("%s:%d", host, port) - - fingerprintCacheMutex.Lock() - defer fingerprintCacheMutex.Unlock() - - fingerprintCache[cacheKey] = fingerprints -} - // =============================== // Web扫描策略 // =============================== diff --git a/plugins/local/keylogger.go b/plugins/local/keylogger.go index 0183915..18c07d1 100644 --- a/plugins/local/keylogger.go +++ b/plugins/local/keylogger.go @@ -23,8 +23,6 @@ import ( // - 保持原有功能逻辑 type KeyloggerPlugin struct { plugins.BasePlugin - isRunning bool - stopChan chan struct{} keyBuffer []string bufferMutex sync.RWMutex } @@ -33,7 +31,6 @@ type KeyloggerPlugin struct { func NewKeyloggerPlugin() *KeyloggerPlugin { return &KeyloggerPlugin{ BasePlugin: plugins.NewBasePlugin("keylogger"), - stopChan: make(chan struct{}), keyBuffer: make([]string, 0), } } @@ -100,10 +97,6 @@ func (p *KeyloggerPlugin) Scan(ctx context.Context, info *common.HostInfo, confi // startKeylogging 启动键盘记录 func (p *KeyloggerPlugin) startKeylogging(ctx context.Context, outputFile string) error { - p.isRunning = true - defer func() { - p.isRunning = false - }() // 根据平台启动相应的键盘记录 var err error diff --git a/plugins/web/webtitle.go b/plugins/web/webtitle.go index fd51c6f..9d0ef7b 100644 --- a/plugins/web/webtitle.go +++ b/plugins/web/webtitle.go @@ -192,11 +192,6 @@ func (p *WebTitlePlugin) identifyFingerprintsMulti(info *common.HostInfo, baseUR // 调用指纹识别 fingerprints := WebScan.InfoCheck(baseURL, &checkDataList) - // 存入缓存 - if len(fingerprints) > 0 { - core.SetFingerprints(info.Host, info.Port, fingerprints) - } - // 非全量模式下,基于指纹触发POC扫描 if !config.POC.Full && !config.POC.Disabled { p.triggerPocScan(info, fingerprints, config) diff --git a/web/ws/hub.go b/web/ws/hub.go index ad6275b..d68adb6 100644 --- a/web/ws/hub.go +++ b/web/ws/hub.go @@ -97,7 +97,7 @@ func (h *Hub) Run() { h.mu.Unlock() case message := <-h.broadcast: - h.mu.RLock() + h.mu.Lock() for client := range h.clients { select { case client.send <- message: @@ -106,7 +106,7 @@ func (h *Hub) Run() { delete(h.clients, client) } } - h.mu.RUnlock() + h.mu.Unlock() } } }