fix: 让 -gt 全局超时参数真正生效

-gt 参数之前是死代码:flag 定义了 GlobalTimeout 但从未被使用。
现在在 RunScan 中用它创建带 deadline 的 context,
超时后所有扫描任务(端口扫描、插件执行)被取消。
This commit is contained in:
ZacharyZcR
2026-06-13 23:04:22 +08:00
parent b085df1878
commit 0356485595
3 changed files with 15 additions and 3 deletions
+9 -3
View File
@@ -94,10 +94,16 @@ func selectStrategy(config *common.Config, state *common.State, info common.Host
// RunScan 执行整体扫描流程
func RunScan(ctx context.Context, info common.HostInfo, session *common.ScanSession) (ScanReport, error) {
start := time.Now()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
config := session.Config
// 全局超时:-gt 参数设置整个扫描的硬性截止时间
var cancel context.CancelFunc
if config.GlobalTimeout > 0 {
ctx, cancel = context.WithTimeout(ctx, config.GlobalTimeout)
} else {
ctx, cancel = context.WithCancel(ctx)
}
defer cancel()
state := session.State
// 设置全局 State(兼容旧代码路径中未传 state 的调用)