refactor: context 穿透扫描生命周期,修复长驻插件阻塞和 Web Stop 无效

- RunScan 接受 context.Context,创建可取消上下文并穿透到所有策略和插件
- 长驻插件(forwardshell/socks5proxy/reverseshell)不再进入 scan WaitGroup,
  通过 ctx.Done() 管理生命周期,解除 wg.Wait() 死锁
- Web Stop API 从 stopChan 改为 context.CancelFunc,取消信号真正传播到扫描链路
- ExecuteScanTasks 和 executeScanTask 支持 context 取消检查,停止分发新任务
- CLI 模式传 context.Background(),行为完全不变
This commit is contained in:
ZacharyZcR
2026-04-27 19:04:26 +08:00
parent 1fe8bb5182
commit d7749c4766
8 changed files with 85 additions and 25 deletions
+3 -2
View File
@@ -1,6 +1,7 @@
package core
import (
"context"
"sync"
"github.com/shadow1ng/fscan/common"
@@ -41,7 +42,7 @@ func (s *LocalScanStrategy) Description() string {
}
// Execute 执行本地扫描策略
func (s *LocalScanStrategy) Execute(config *common.Config, state *common.State, info common.HostInfo, ch chan struct{}, wg *sync.WaitGroup) {
func (s *LocalScanStrategy) Execute(ctx context.Context, config *common.Config, state *common.State, info common.HostInfo, ch chan struct{}, wg *sync.WaitGroup) {
// 输出扫描开始信息
s.LogScanStart()
@@ -66,7 +67,7 @@ func (s *LocalScanStrategy) Execute(config *common.Config, state *common.State,
targets := s.PrepareTargets(info)
// 执行扫描任务
ExecuteScanTasks(config, state, targets, s, ch, wg)
ExecuteScanTasks(ctx, config, state, targets, s, ch, wg)
}
// PrepareTargets 准备本地扫描目标