mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-24 20:21:52 +08:00
perf: 六项性能优化
- DNS 解析缓存:sync.Map 缓存避免重复系统调用 - 凭据测试 TCP 预检:不可达目标直接跳过全部凭据 - Web 探测 HTTP Client 复用:全局共享连接池 - 端口扫描 Bloom Filter 去重:替代 map 降低内存 - 进度条 atomic 累加 + 50ms 节流渲染:消除锁竞争 - 服务探针预解码:Init 时预编译,运行时零解码开销
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -109,6 +110,7 @@ type ConcurrentTestConfig struct {
|
||||
MaxRetries int // 最大重试次数,默认 3
|
||||
RetryDelay time.Duration // 重试延迟,默认 1s
|
||||
MaxConsecutiveNetErrors int // 连续网络错误阈值,超过则认为目标不可达,默认 5
|
||||
TargetAddr string // 目标地址 host:port,用于 TCP 预检(可选)
|
||||
}
|
||||
|
||||
// DefaultConcurrentTestConfig 默认配置
|
||||
@@ -125,6 +127,13 @@ func DefaultConcurrentTestConfig(config *common.Config) ConcurrentTestConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultConcurrentTestConfigWithTarget 带目标预检的默认配置
|
||||
func DefaultConcurrentTestConfigWithTarget(config *common.Config, info *common.HostInfo) ConcurrentTestConfig {
|
||||
cfg := DefaultConcurrentTestConfig(config)
|
||||
cfg.TargetAddr = fmt.Sprintf("%s:%d", info.Host, info.Port)
|
||||
return cfg
|
||||
}
|
||||
|
||||
// TestCredentialsConcurrently 并发测试多个凭据
|
||||
// 找到成功凭据后立即通知其他 worker 停止
|
||||
func TestCredentialsConcurrently(
|
||||
@@ -142,6 +151,19 @@ func TestCredentialsConcurrently(
|
||||
}
|
||||
}
|
||||
|
||||
// TCP 预检:快速验证目标可达,避免对不可达目标浪费全部凭据尝试
|
||||
if testConfig.TargetAddr != "" {
|
||||
preConn, err := net.DialTimeout("tcp", testConfig.TargetAddr, 3*time.Second)
|
||||
if err != nil {
|
||||
return &ScanResult{
|
||||
Success: false,
|
||||
Service: serviceName,
|
||||
Error: fmt.Errorf("目标不可达: %w", err),
|
||||
}
|
||||
}
|
||||
_ = preConn.Close()
|
||||
}
|
||||
|
||||
// 调整并发数
|
||||
concurrency := testConfig.Concurrency
|
||||
if concurrency > len(credentials) {
|
||||
|
||||
Reference in New Issue
Block a user