fix: 修复实机测试发现的可靠性问题 (v2.2.0-rc.1)

- UDP 插件在 -p 指定端口时被跳过
- Redis exploit 无超时保护 / readReply 吞没非超时错误
- service_probe 连接丢失后静默成功
- SNMP 探测成功但终端无输出
- SSH 爆破不稳定 (并发过高 + 自适应超时过短 + 限流误判)
- 进度条 isActive 竞态

新增 Config.ModuleTimeout() 协议级超时下限 (≥3s)
新增 ErrorTypeThrottle 限流错误分类
This commit is contained in:
ZacharyZcR
2026-06-14 22:14:02 +08:00
parent bc46e90d89
commit 42092d8664
51 changed files with 285 additions and 257 deletions
+11
View File
@@ -179,6 +179,17 @@ func clonePortMap(values map[int][]string) map[int][]string {
return cloned
}
const minModuleTimeout = 3 * time.Second
// ModuleTimeout 返回插件级超时(用于弱口令测试、服务交互等多轮协议)
// 保证下限 3s,避免自适应把端口扫描超时压低后影响 SSH/SNMP 等交互型协议
func (c *Config) ModuleTimeout() time.Duration {
if c.Timeout >= minModuleTimeout {
return c.Timeout
}
return minModuleTimeout
}
// NewConfig 创建带默认值的Config(后备用,正常流程使用BuildConfigFromFlags
func NewConfig() *Config {
return &Config{
+1 -1
View File
@@ -69,7 +69,7 @@ const (
// 版本信息,通过 ldflags 注入
var (
version = "2.2.0-rc"
version = "2.2.0-rc.1"
commit = "unknown"
date = "unknown"
)
+9 -9
View File
@@ -32,7 +32,7 @@ type ProgressManager struct {
current atomic.Int64
description string
startTime time.Time
isActive bool
isActive atomic.Bool
terminalHeight int
reservedLines int // 为进度条保留的行数
lastContentLine int // 最后一行内容的位置
@@ -121,7 +121,7 @@ func (pm *ProgressManager) InitProgress(total int64, description string) {
pm.current.Store(0)
pm.description = description
pm.startTime = time.Now()
pm.isActive = true
pm.isActive.Store(true)
pm.enabled = true
pm.lastActivity = time.Now()
pm.spinnerIndex = 0
@@ -139,7 +139,7 @@ func (pm *ProgressManager) InitProgress(total int64, description string) {
// UpdateProgress 更新进度
func (pm *ProgressManager) UpdateProgress(increment int64) {
if !pm.enabled || !pm.isActive {
if !pm.enabled || !pm.isActive.Load() {
return
}
@@ -171,7 +171,7 @@ func (pm *ProgressManager) UpdateProgress(increment int64) {
// FinishProgress 完成进度条
func (pm *ProgressManager) FinishProgress() {
if !pm.enabled || !pm.isActive {
if !pm.enabled || !pm.isActive.Load() {
return
}
@@ -189,7 +189,7 @@ func (pm *ProgressManager) FinishProgress() {
// 清理进度条区域,恢复正常输出
pm.clearProgressArea()
pm.isActive = false
pm.isActive.Store(false)
}
// setupProgressSpace 设置进度条空间
@@ -342,7 +342,7 @@ func (pm *ProgressManager) clearProgressArea() {
func (pm *ProgressManager) IsActive() bool {
pm.mu.RLock()
defer pm.mu.RUnlock()
return pm.isActive && pm.enabled
return pm.isActive.Load() && pm.enabled
}
// getTerminalHeight 获取终端高度
@@ -479,7 +479,7 @@ func (pm *ProgressManager) GetPercent() float64 {
pm.mu.RLock()
defer pm.mu.RUnlock()
if !pm.isActive || pm.total.Load() == 0 {
if !pm.isActive.Load() || pm.total.Load() == 0 {
return 0
}
return float64(pm.current.Load()) / float64(pm.total.Load()) * 100
@@ -517,7 +517,7 @@ func LogWithProgress(message string) {
// renderProgressUnsafe 不加锁的进度条渲染(内部使用)
func (pm *ProgressManager) renderProgressUnsafe() {
if !pm.enabled || !pm.isActive {
if !pm.enabled || !pm.isActive.Load() {
return
}
@@ -586,7 +586,7 @@ func (pm *ProgressManager) startActivityIndicator() {
select {
case <-pm.activityTicker.C:
// 只有在活跃状态下才更新指示器
if pm.isActive && pm.enabled {
if pm.isActive.Load() && pm.enabled {
pm.mu.Lock()
pm.spinnerIndex = (pm.spinnerIndex + 1) % len(spinnerChars)
pm.mu.Unlock()