mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-22 03:10:42 +08:00
feat: 自适应并发调度 — 网络探测 + AIMD + 参数智能推导
扫描前自动探测网络环境(RTT、丢包率、fd limit),基于探测数据 推导 6 个关键参数,替代硬编码默认值: - Timeout: median_RTT + 4σ(覆盖 99.9% 正常连接) - ModuleThreadNum: target_concurrency / 30 - MaxRetries: ceil(log(0.01)/log(loss_rate))(全失败概率 <1%) - ICMPRate: 环境基准 × fd 系数 - PocNum: 跟随 ModuleThreadNum - DisablePing: 已有 ICMP 权限降级机制 线程池从单信号(资源耗尽率)升级为 AIMD + 慢启动: - 慢启动:target/4 起步,500ms 翻倍 - 稳态 AIMD:健康 +5%,拥塞 ×0.5 - 双信号:资源耗尽率 + RTT 趋势(双 EMA) 用户 -t 显式指定时作为 ceiling,探测仍调整其他参数。 测试:单元 + 边界 + 集成 + 真实网络,core 包 580+ 用例全通过。
This commit is contained in:
@@ -22,12 +22,13 @@ config_struct.go - 配置结构体定义
|
||||
// Config 扫描器完整配置 - 初始化后只读,可安全共享
|
||||
type Config struct {
|
||||
// 高频访问字段 - 平铺到顶层
|
||||
Timeout time.Duration // 通用超时
|
||||
ThreadNum int // 主线程数
|
||||
ModuleThreadNum int // 模块线程数
|
||||
DisableBrute bool // 禁用暴力破解
|
||||
DisablePing bool // 禁用Ping检测
|
||||
DisableTcpProbe bool // 禁用TCP补充探测
|
||||
Timeout time.Duration // 通用超时
|
||||
ThreadNum int // 主线程数
|
||||
ThreadNumExplicit bool // 用户显式指定了 -t
|
||||
ModuleThreadNum int // 模块线程数
|
||||
DisableBrute bool // 禁用暴力破解
|
||||
DisablePing bool // 禁用Ping检测
|
||||
DisableTcpProbe bool // 禁用TCP补充探测
|
||||
|
||||
// 扫描模式
|
||||
Mode string // 扫描模式
|
||||
|
||||
@@ -213,6 +213,13 @@ func Flag(Info *HostInfo) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 检测用户是否显式指定了 -t
|
||||
flag.Visit(func(f *flag.Flag) {
|
||||
if f.Name == "t" {
|
||||
fv.ThreadNumExplicit = true
|
||||
}
|
||||
})
|
||||
|
||||
// 设置语言
|
||||
i18n.SetLanguage(fv.Language)
|
||||
|
||||
|
||||
@@ -30,9 +30,10 @@ type FlagVars struct {
|
||||
PortsFile string
|
||||
|
||||
// 扫描控制
|
||||
ScanMode string
|
||||
ThreadNum int
|
||||
ModuleThreadNum int
|
||||
ScanMode string
|
||||
ThreadNum int
|
||||
ThreadNumExplicit bool // 用户显式指定了 -t
|
||||
ModuleThreadNum int
|
||||
TimeoutSec int64 // 秒,需转换为 time.Duration
|
||||
GlobalTimeout int64
|
||||
DisablePing bool
|
||||
@@ -134,9 +135,10 @@ func GetFlagVars() *FlagVars {
|
||||
func BuildConfigFromFlags(fv *FlagVars) *Config {
|
||||
return &Config{
|
||||
// 高频字段
|
||||
Timeout: time.Duration(fv.TimeoutSec) * time.Second,
|
||||
ThreadNum: fv.ThreadNum,
|
||||
ModuleThreadNum: fv.ModuleThreadNum,
|
||||
Timeout: time.Duration(fv.TimeoutSec) * time.Second,
|
||||
ThreadNum: fv.ThreadNum,
|
||||
ThreadNumExplicit: fv.ThreadNumExplicit,
|
||||
ModuleThreadNum: fv.ModuleThreadNum,
|
||||
DisableBrute: fv.DisableBrute,
|
||||
DisablePing: fv.DisablePing,
|
||||
DisableTcpProbe: fv.DisableTcpProbe,
|
||||
|
||||
@@ -541,6 +541,26 @@ icmp_debug_stable_done:
|
||||
other: "[ICMP] response stable, ending early, elapsed {{.Arg1}}, alive {{.Arg2}}/{{.Arg3}}"
|
||||
adaptive_pool_resource_exhausted:
|
||||
other: "[AdaptivePool] resource exhaustion rate {{.Arg1}}%, threads {{.Arg2}} -> {{.Arg3}}"
|
||||
adaptive_pool_decrease:
|
||||
other: "Concurrency adjusted: {{.Arg1}} -> {{.Arg2}} (pressure detected)"
|
||||
adaptive_pool_increase:
|
||||
other: "Concurrency adjusted: {{.Arg1}} -> {{.Arg2}} (network healthy)"
|
||||
adaptive_pool_slowstart_exit:
|
||||
other: "Slow start exit: current {{.Arg1}} (congestion detected)"
|
||||
net_probe_result:
|
||||
other: "Network probe: {{.Arg1}}, RTT {{.Arg2}}ms, loss {{.Arg3}}%, concurrency {{.Arg4}}/{{.Arg5}}"
|
||||
net_env_lan:
|
||||
other: "LAN"
|
||||
net_env_wan:
|
||||
other: "WAN"
|
||||
net_env_internet:
|
||||
other: "Internet"
|
||||
net_env_slow:
|
||||
other: "Slow network"
|
||||
env_tune_summary:
|
||||
other: "Adaptive params: Timeout={{.Arg1}}ms, ModuleThread={{.Arg2}}, Retry={{.Arg3}}, ICMPRate={{.Arg4}}, PocNum={{.Arg5}}"
|
||||
env_fd_limit:
|
||||
other: "fd limit constraint: threads {{.Arg1}} -> {{.Arg2}} (ulimit={{.Arg3}})"
|
||||
|
||||
# ========================= Service Plugin Messages =========================
|
||||
# Format: {service}_{type} - type: credential/unauth/service/vuln
|
||||
|
||||
@@ -541,6 +541,26 @@ icmp_debug_stable_done:
|
||||
other: "[ICMP] 响应稳定,提前结束,耗时 {{.Arg1}},存活 {{.Arg2}}/{{.Arg3}}"
|
||||
adaptive_pool_resource_exhausted:
|
||||
other: "[AdaptivePool] 资源耗尽率 {{.Arg1}}%, 线程数 {{.Arg2}} -> {{.Arg3}}"
|
||||
adaptive_pool_decrease:
|
||||
other: "并发调整: {{.Arg1}} -> {{.Arg2}} (检测到压力)"
|
||||
adaptive_pool_increase:
|
||||
other: "并发调整: {{.Arg1}} -> {{.Arg2}} (网络健康)"
|
||||
adaptive_pool_slowstart_exit:
|
||||
other: "慢启动退出: 当前 {{.Arg1}} (检测到拥塞)"
|
||||
net_probe_result:
|
||||
other: "网络探测: {{.Arg1}}, RTT {{.Arg2}}ms, 丢包 {{.Arg3}}%, 并发 {{.Arg4}}/{{.Arg5}}"
|
||||
net_env_lan:
|
||||
other: "内网"
|
||||
net_env_wan:
|
||||
other: "局域网"
|
||||
net_env_internet:
|
||||
other: "公网"
|
||||
net_env_slow:
|
||||
other: "慢速网络"
|
||||
env_tune_summary:
|
||||
other: "参数自适应: Timeout={{.Arg1}}ms, ModuleThread={{.Arg2}}, Retry={{.Arg3}}, ICMPRate={{.Arg4}}, PocNum={{.Arg5}}"
|
||||
env_fd_limit:
|
||||
other: "fd limit 约束: 线程数 {{.Arg1}} -> {{.Arg2}} (ulimit={{.Arg3}})"
|
||||
|
||||
# ========================= 服务插件通用消息 =========================
|
||||
# 格式: {service}_{type} - type: credential/unauth/service/vuln
|
||||
|
||||
Reference in New Issue
Block a user