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

-gt 参数之前是死代码:flag 定义了 GlobalTimeout 但从未被使用。
现在在 RunScan 中用它创建带 deadline 的 context,
超时后所有扫描任务(端口扫描、插件执行)被取消。
This commit is contained in:
ZacharyZcR
2026-06-14 22:23:51 +08:00
parent 6d7e6cd394
commit 2b202aa298
3 changed files with 15 additions and 3 deletions
+3
View File
@@ -61,6 +61,9 @@ type Config struct {
LocalExploit LocalExploitConfig
Target TargetConfig // 扫描目标配置
// 全局超时
GlobalTimeout time.Duration
// SOCKS5代理端口配置
Socks5ProxyPort int // SOCKS5代理端口
}
+3
View File
@@ -169,6 +169,9 @@ func BuildConfigFromFlags(fv *FlagVars) *Config {
PortMap: clonePortMap(config.DefaultPortMap),
DefaultMap: cloneStringSlice(config.DefaultProbeMap),
// 全局超时
GlobalTimeout: time.Duration(fv.GlobalTimeout) * time.Second,
// SOCKS5代理端口
Socks5ProxyPort: fv.Socks5ProxyPort,
+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 的调用)