refactor: 引入 ScanSession,替代全局状态穿透扫描管道 (Phase 1-3)

- 新增 common/session.go: ScanSession 结构体封装 Config/State/Params/Dialer
- RunScan/Strategy/ExecuteScanTasks/executeScanTask 全部接收 session
- Plugin 接口从 Scan(ctx, info, config, state) 改为 Scan(ctx, info, session)
- 48 个插件实现统一更新签名
- Web API 构建 ScanSession 传给 RunScan
- CLI 模式通过 Initialize() 创建 session
This commit is contained in:
ZacharyZcR
2026-04-27 23:00:06 +08:00
parent 3d7cdcbe5f
commit a865e5d45e
62 changed files with 283 additions and 89 deletions
+8 -7
View File
@@ -113,10 +113,11 @@ func (s *ServiceScanStrategy) Description() string {
}
// Execute 执行服务扫描策略
func (s *ServiceScanStrategy) Execute(ctx context.Context, config *common.Config, state *common.State, info common.HostInfo, ch chan struct{}, wg *sync.WaitGroup) {
func (s *ServiceScanStrategy) Execute(ctx context.Context, session *common.ScanSession, info common.HostInfo, ch chan struct{}, wg *sync.WaitGroup) {
config := session.Config
// 验证扫描目标(需要同时检查 -h 和 -hf 参数)
fv := common.GetFlagVars()
if info.Host == "" && fv.HostsFile == "" {
if info.Host == "" && session.Params.HostsFile == "" {
common.LogError(i18n.GetText("parse_error_target_empty"))
return
}
@@ -134,13 +135,13 @@ func (s *ServiceScanStrategy) Execute(ctx context.Context, config *common.Config
s.LogPluginInfo(config)
// 执行主机扫描流程
s.performHostScan(ctx, config, state, info, ch, wg)
s.performHostScan(ctx, session, info, ch, wg)
}
// performHostScan 执行主机扫描的完整流程
func (s *ServiceScanStrategy) performHostScan(ctx context.Context, config *common.Config, state *common.State, info common.HostInfo, ch chan struct{}, wg *sync.WaitGroup) {
func (s *ServiceScanStrategy) performHostScan(ctx context.Context, session *common.ScanSession, info common.HostInfo, ch chan struct{}, wg *sync.WaitGroup) {
// 发现目标主机和端口
targetInfos, err := s.discoverTargets(info.Host, info, config, state)
targetInfos, err := s.discoverTargets(info.Host, info, session.Config, session.State)
if err != nil {
common.LogError(err.Error())
return
@@ -148,7 +149,7 @@ func (s *ServiceScanStrategy) performHostScan(ctx context.Context, config *commo
// 执行漏洞扫描
if len(targetInfos) > 0 {
ExecuteScanTasks(ctx, config, state, targetInfos, s, ch, wg)
ExecuteScanTasks(ctx, session, targetInfos, s, ch, wg)
}
}