From af327ee944bb9b920e2e8c8174d97b99f7a8faaa Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Wed, 13 May 2026 00:38:08 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=85=AD=E9=A1=B9=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DNS 解析缓存:sync.Map 缓存避免重复系统调用 - 凭据测试 TCP 预检:不可达目标直接跳过全部凭据 - Web 探测 HTTP Client 复用:全局共享连接池 - 端口扫描 Bloom Filter 去重:替代 map 降低内存 - 进度条 atomic 累加 + 50ms 节流渲染:消除锁竞争 - 服务探针预解码:Init 时预编译,运行时零解码开销 --- common/dns_cache.go | 27 +++++++++++++++++ common/progress_manager.go | 43 ++++++++++++++++----------- core/icmp.go | 2 +- core/port_scan.go | 28 ++++++++++------- core/portfinger/scanner_core.go | 17 +++++++++++ core/portfinger/types.go | 1 + core/service_probe.go | 33 +++++++++++++++----- core/web_scanner.go | 31 ++++++++++++------- plugins/services/activemq.go | 2 +- plugins/services/cassandra.go | 2 +- plugins/services/credential_tester.go | 22 ++++++++++++++ plugins/services/ftp.go | 2 +- plugins/services/kafka.go | 2 +- plugins/services/ldap.go | 2 +- plugins/services/mongodb.go | 2 +- plugins/services/mssql.go | 2 +- plugins/services/mysql.go | 2 +- plugins/services/neo4j.go | 2 +- plugins/services/oracle.go | 2 +- plugins/services/postgresql.go | 2 +- plugins/services/rabbitmq.go | 2 +- plugins/services/redis.go | 2 +- plugins/services/rsync.go | 2 +- plugins/services/smb.go | 2 +- plugins/services/smtp.go | 2 +- plugins/services/ssh.go | 2 +- plugins/services/telnet.go | 2 +- plugins/services/vnc.go | 2 +- 28 files changed, 178 insertions(+), 64 deletions(-) create mode 100644 common/dns_cache.go diff --git a/common/dns_cache.go b/common/dns_cache.go new file mode 100644 index 0000000..bb91b84 --- /dev/null +++ b/common/dns_cache.go @@ -0,0 +1,27 @@ +package common + +import ( + "net" + "sync" +) + +// DNSCache 并发安全的 DNS 解析缓存 +// 对纯 IP 输入零开销(直接返回),对域名避免重复系统调用 +var DNSCache = &dnsCache{} + +type dnsCache struct { + m sync.Map // host -> *net.IPAddr +} + +// ResolveIP 解析 host 为 *net.IPAddr,结果缓存 +func (c *dnsCache) ResolveIP(host string) (*net.IPAddr, error) { + if v, ok := c.m.Load(host); ok { + return v.(*net.IPAddr), nil + } + addr, err := net.ResolveIPAddr("ip", host) + if err != nil { + return nil, err + } + c.m.Store(host, addr) + return addr, nil +} diff --git a/common/progress_manager.go b/common/progress_manager.go index 1df00f1..a940805 100644 --- a/common/progress_manager.go +++ b/common/progress_manager.go @@ -143,16 +143,24 @@ func (pm *ProgressManager) UpdateProgress(increment int64) { return } - pm.mu.Lock() - defer pm.mu.Unlock() - - pm.current += increment - if pm.current > pm.total { - pm.current = pm.total + // 原子累加,避免高并发下的锁竞争 + newCurrent := atomic.AddInt64(&pm.current, increment) + if newCurrent > pm.total { + atomic.StoreInt64(&pm.current, pm.total) } - // 更新活跃时间 - pm.lastActivity = time.Now() + // 节流渲染:距上次渲染不足 50ms 则跳过 + now := time.Now() + pm.mu.RLock() + lastAct := pm.lastActivity + pm.mu.RUnlock() + if now.Sub(lastAct) < 50*time.Millisecond { + return + } + + pm.mu.Lock() + pm.lastActivity = now + pm.mu.Unlock() pm.renderProgress() } @@ -170,7 +178,7 @@ func (pm *ProgressManager) FinishProgress() { pm.mu.Lock() defer pm.mu.Unlock() - pm.current = pm.total + atomic.StoreInt64(&pm.current, pm.total) pm.renderProgress() // 停止活跃指示器 @@ -220,11 +228,12 @@ func (pm *ProgressManager) generateProgressBar() string { return base } - percentage := float64(pm.current) / float64(pm.total) * 100 + percentage := float64(atomic.LoadInt64(&pm.current)) / float64(pm.total) * 100 elapsed := time.Since(pm.startTime) + current := atomic.LoadInt64(&pm.current) // 计算速度 - speed := float64(pm.current) / elapsed.Seconds() + speed := float64(current) / elapsed.Seconds() speedStr := "" if speed > 0 { speedStr = fmt.Sprintf(" %.0f/s", speed) @@ -232,8 +241,8 @@ func (pm *ProgressManager) generateProgressBar() string { // 计算预估剩余时间 var eta string - if pm.current > 0 && pm.current < pm.total { - totalTime := elapsed * time.Duration(pm.total) / time.Duration(pm.current) + if current > 0 && current < pm.total { + totalTime := elapsed * time.Duration(pm.total) / time.Duration(current) remaining := totalTime - elapsed if remaining > 0 { eta = fmt.Sprintf(" ETA:%s", formatDuration(remaining)) @@ -245,7 +254,7 @@ func (pm *ProgressManager) generateProgressBar() string { // 计算固定部分的宽度 fixedPart := fmt.Sprintf("%s %s %5.1f%% [] (%d/%d)%s%s %s", - pm.description, spinner, percentage, pm.current, pm.total, speedStr, eta, packetInfo) + pm.description, spinner, percentage, current, pm.total, speedStr, eta, packetInfo) fixedWidth := displayWidth(fixedPart) // 计算进度条槽位可用宽度(预留2字符余量) @@ -272,7 +281,7 @@ func (pm *ProgressManager) generateProgressBar() string { // 构建最终进度条 result := fmt.Sprintf("%s %s %5.1f%% %s (%d/%d)%s%s", - pm.description, spinner, percentage, bar, pm.current, pm.total, speedStr, eta) + pm.description, spinner, percentage, bar, current, pm.total, speedStr, eta) if packetInfo != "" { result += " " + packetInfo @@ -470,7 +479,7 @@ func (pm *ProgressManager) GetPercent() float64 { if !pm.isActive || pm.total == 0 { return 0 } - return float64(pm.current) / float64(pm.total) * 100 + return float64(atomic.LoadInt64(&pm.current)) / float64(pm.total) * 100 } // ============================================================================= @@ -512,7 +521,7 @@ func (pm *ProgressManager) renderProgressUnsafe() { // 计算当前百分比(避免除零) currentPercent := 0 if pm.total > 0 { - currentPercent = int((pm.current * 100) / pm.total) + currentPercent = int((atomic.LoadInt64(&pm.current) * 100) / pm.total) } // 只在百分比变化时更新,减少不必要的渲染 diff --git a/core/icmp.go b/core/icmp.go index 8039883..227b447 100644 --- a/core/icmp.go +++ b/core/icmp.go @@ -391,7 +391,7 @@ func RunIcmp1(hostslist []string, conn *icmp.PacketConn, chanHosts chan string, } packets := make([]icmpPacket, 0, len(hostslist)) for _, host := range hostslist { - dst, _ := net.ResolveIPAddr("ip", host) + dst, _ := common.DNSCache.ResolveIP(host) packets = append(packets, icmpPacket{data: makemsg(host), dst: dst}) } diff --git a/core/port_scan.go b/core/port_scan.go index 8c96539..b513140 100644 --- a/core/port_scan.go +++ b/core/port_scan.go @@ -39,17 +39,22 @@ var resourceExhaustedPatterns = []string{ } // resultCollector 结果收集器,用于并发安全地收集扫描结果 -// 使用 map 实现:O(1) 的添加和删除,无顺序依赖问题 +// 使用 Bloom Filter 去重 + slice 存储,大规模扫描时内存更优 type resultCollector struct { mu sync.Mutex - addrs map[string]struct{} + addrs []string + bloom *BloomFilter stream chan<- string // 可选:流式通知 channel } // newResultCollector 创建结果收集器 -func newResultCollector(stream chan<- string) *resultCollector { +func newResultCollector(stream chan<- string, expectedSize int) *resultCollector { + if expectedSize < 1024 { + expectedSize = 1024 + } return &resultCollector{ - addrs: make(map[string]struct{}), + addrs: make([]string, 0, expectedSize/10), + bloom: NewBloomFilter(expectedSize, 0.001), stream: stream, } } @@ -57,7 +62,12 @@ func newResultCollector(stream chan<- string) *resultCollector { // Add 添加一个扫描结果 func (c *resultCollector) Add(addr string) { c.mu.Lock() - c.addrs[addr] = struct{}{} + if c.bloom.Contains(addr) { + c.mu.Unlock() + return + } + c.bloom.Add(addr) + c.addrs = append(c.addrs, addr) c.mu.Unlock() if c.stream != nil { c.stream <- addr @@ -67,10 +77,8 @@ func (c *resultCollector) Add(addr string) { // GetAll 获取所有结果 func (c *resultCollector) GetAll() []string { c.mu.Lock() - result := make([]string, 0, len(c.addrs)) - for addr := range c.addrs { - result = append(result, addr) - } + result := make([]string, len(c.addrs)) + copy(result, c.addrs) c.mu.Unlock() return result } @@ -181,7 +189,7 @@ func EnhancedPortScan(ctx context.Context, hosts []string, ports string, timeout to := time.Duration(timeout) * time.Second adaptiveTO := NewAdaptiveTimeout(to) var count int64 - collector := newResultCollector(stream) + collector := newResultCollector(stream, totalTasks) failedCollector := &failedPortCollector{} var wg sync.WaitGroup diff --git a/core/portfinger/scanner_core.go b/core/portfinger/scanner_core.go index e50f4cf..a71596c 100644 --- a/core/portfinger/scanner_core.go +++ b/core/portfinger/scanner_core.go @@ -25,6 +25,23 @@ func (vs *VScan) Init() { vs.parseProbesToMapKName() vs.SetusedProbes() vs.compileFallbacks() // 编译 fallback 数组 + vs.preDecodeProbeData() // 预解码探针数据 +} + +// preDecodeProbeData 预解码所有探针的 Data 字段,避免运行时重复解码 +func (vs *VScan) preDecodeProbeData() { + for i := range vs.Probes { + if vs.Probes[i].Data != "" { + decoded, err := DecodeData(vs.Probes[i].Data) + if err == nil { + vs.Probes[i].DecodedData = decoded + } + } + } + // 同步到 map + for i := range vs.Probes { + vs.ProbesMapKName[vs.Probes[i].Name] = vs.Probes[i] + } } // compileFallbacks 编译所有探测器的 fallback 数组 diff --git a/core/portfinger/types.go b/core/portfinger/types.go index a7f8067..acd54b2 100644 --- a/core/portfinger/types.go +++ b/core/portfinger/types.go @@ -20,6 +20,7 @@ const MaxFallbacks = 20 type Probe struct { Name string // 探测器名称 Data string // 探测数据 + DecodedData []byte // 预解码的探测数据 Protocol string // 协议 Ports string // 端口范围 SSLPorts string // SSL端口范围 diff --git a/core/service_probe.go b/core/service_probe.go index baeeb83..d61c707 100644 --- a/core/service_probe.go +++ b/core/service_probe.go @@ -219,9 +219,14 @@ func (s *SmartPortInfoScanner) tryProbeList(probes []*Probe, usedProbes map[stri } usedProbes[probe.Name] = struct{}{} - probeData, err := DecodeData(probe.Data) - if err != nil { - continue + // 优先使用预解码数据 + probeData := probe.DecodedData + if probeData == nil { + var err error + probeData, err = DecodeData(probe.Data) + if err != nil { + continue + } } // 使用 TotalWaitMS 设置动态超时 @@ -282,8 +287,15 @@ func (s *SmartPortInfoScanner) performSSLSecondStage(serviceInfo *ServiceInfo) * continue } - probeData, err := DecodeData(probe.Data) - if err != nil || len(probeData) == 0 { + probeData := probe.DecodedData + if probeData == nil { + var decErr error + probeData, decErr = DecodeData(probe.Data) + if decErr != nil || len(probeData) == 0 { + continue + } + } + if len(probeData) == 0 { continue } response := s.info.Connect(probeData) @@ -317,8 +329,15 @@ func (s *SmartPortInfoScanner) tryHTTPSProbe() *ServiceInfo { return nil } - probeData, err := DecodeData(probe.Data) - if err != nil || len(probeData) == 0 { + probeData := probe.DecodedData + if probeData == nil { + var decErr error + probeData, decErr = DecodeData(probe.Data) + if decErr != nil || len(probeData) == 0 { + return nil + } + } + if len(probeData) == 0 { return nil } response := s.info.Connect(probeData) diff --git a/core/web_scanner.go b/core/web_scanner.go index 935e377..782b80d 100644 --- a/core/web_scanner.go +++ b/core/web_scanner.go @@ -19,6 +19,25 @@ import ( // Web服务检测 // =============================== +// 全局共享 HTTP Client,复用连接池减少 TLS 握手和 TCP 建连开销 +var ( + sharedHTTPClientOnce sync.Once + sharedHTTPClient *http.Client +) + +func getSharedHTTPClient(config *common.Config) *http.Client { + sharedHTTPClientOnce.Do(func() { + sharedHTTPClient = createHTTPClient(config) + // 启用 keep-alive 复用连接 + if t, ok := sharedHTTPClient.Transport.(*http.Transport); ok { + t.DisableKeepAlives = false + t.MaxIdleConns = 100 + t.MaxIdleConnsPerHost = 2 + } + }) + return sharedHTTPClient +} + // WebPortDetector 简化的Web检测器 - 保持API兼容 type WebPortDetector struct{} @@ -59,15 +78,7 @@ func DetectHTTPScheme(host string, port int, config *common.Config, session *com // TLS握手失败,记录原因 // 第二步:尝试HTTP请求(回退检测HTTP) - client := &http.Client{ - Timeout: timeout, - Transport: &http.Transport{ - DisableKeepAlives: true, - }, - CheckRedirect: func(req *http.Request, via []*http.Request) error { - return http.ErrUseLastResponse // 不跟随重定向 - }, - } + client := getSharedHTTPClient(config) // 使用HEAD请求(更轻量) httpURL := fmt.Sprintf("http://%s", addr) @@ -132,7 +143,7 @@ func (w *WebPortDetector) DetectHTTPServiceOnly(host string, port int, config *c return false } - client := createHTTPClient(config) + client := getSharedHTTPClient(config) // 尝试HTTP if w.tryHTTP(client, host, port, "http") { diff --git a/plugins/services/activemq.go b/plugins/services/activemq.go index 6782074..d9b5cbf 100644 --- a/plugins/services/activemq.go +++ b/plugins/services/activemq.go @@ -50,7 +50,7 @@ func (p *ActiveMQPlugin) Scan(ctx context.Context, info *common.HostInfo, sessio // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, session) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, credentials, authFn, "activemq", testConfig) diff --git a/plugins/services/cassandra.go b/plugins/services/cassandra.go index a54ae1c..1ad9fe7 100644 --- a/plugins/services/cassandra.go +++ b/plugins/services/cassandra.go @@ -49,7 +49,7 @@ func (p *CassandraPlugin) Scan(ctx context.Context, info *common.HostInfo, sessi // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, config, state) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, credentials, authFn, "cassandra", testConfig) diff --git a/plugins/services/credential_tester.go b/plugins/services/credential_tester.go index 97698fd..ebe8d93 100644 --- a/plugins/services/credential_tester.go +++ b/plugins/services/credential_tester.go @@ -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) { diff --git a/plugins/services/ftp.go b/plugins/services/ftp.go index 8e14788..a3513d6 100644 --- a/plugins/services/ftp.go +++ b/plugins/services/ftp.go @@ -49,7 +49,7 @@ func (p *FTPPlugin) Scan(ctx context.Context, info *common.HostInfo, session *co // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, config, state) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, credentials, authFn, "ftp", testConfig) diff --git a/plugins/services/kafka.go b/plugins/services/kafka.go index 7635639..71d0339 100644 --- a/plugins/services/kafka.go +++ b/plugins/services/kafka.go @@ -44,7 +44,7 @@ func (p *KafkaPlugin) Scan(ctx context.Context, info *common.HostInfo, session * // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, config, state) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, credentials, authFn, "kafka", testConfig) diff --git a/plugins/services/ldap.go b/plugins/services/ldap.go index 1de9c9f..0f2b94e 100644 --- a/plugins/services/ldap.go +++ b/plugins/services/ldap.go @@ -50,7 +50,7 @@ func (p *LDAPPlugin) Scan(ctx context.Context, info *common.HostInfo, session *c // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, session) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, credentials, authFn, "ldap", testConfig) diff --git a/plugins/services/mongodb.go b/plugins/services/mongodb.go index f3f3f41..78d1cd5 100644 --- a/plugins/services/mongodb.go +++ b/plugins/services/mongodb.go @@ -69,7 +69,7 @@ func (p *MongoDBPlugin) Scan(ctx context.Context, info *common.HostInfo, session // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, config, state) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, credentials, authFn, "mongodb", testConfig) diff --git a/plugins/services/mssql.go b/plugins/services/mssql.go index 47203b6..a921b79 100644 --- a/plugins/services/mssql.go +++ b/plugins/services/mssql.go @@ -45,7 +45,7 @@ func (p *MSSQLPlugin) Scan(ctx context.Context, info *common.HostInfo, session * // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, config, state) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, credentials, authFn, "mssql", testConfig) diff --git a/plugins/services/mysql.go b/plugins/services/mysql.go index 6b6a668..933fe5e 100644 --- a/plugins/services/mysql.go +++ b/plugins/services/mysql.go @@ -56,7 +56,7 @@ func (p *MySQLPlugin) Scan(ctx context.Context, info *common.HostInfo, session * // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, config, state) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, credentials, authFn, "mysql", testConfig) diff --git a/plugins/services/neo4j.go b/plugins/services/neo4j.go index 7e884f2..e67a6cc 100644 --- a/plugins/services/neo4j.go +++ b/plugins/services/neo4j.go @@ -51,7 +51,7 @@ func (p *Neo4jPlugin) Scan(ctx context.Context, info *common.HostInfo, session * // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, config, state) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, credentials, authFn, "neo4j", testConfig) diff --git a/plugins/services/oracle.go b/plugins/services/oracle.go index 386021f..2a6223f 100644 --- a/plugins/services/oracle.go +++ b/plugins/services/oracle.go @@ -50,7 +50,7 @@ func (p *OraclePlugin) Scan(ctx context.Context, info *common.HostInfo, session // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, config, state) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, credentials, authFn, "oracle", testConfig) diff --git a/plugins/services/postgresql.go b/plugins/services/postgresql.go index d7edf57..9d0c6f5 100644 --- a/plugins/services/postgresql.go +++ b/plugins/services/postgresql.go @@ -51,7 +51,7 @@ func (p *PostgreSQLPlugin) Scan(ctx context.Context, info *common.HostInfo, sess // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, config, state) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, credentials, authFn, "postgresql", testConfig) diff --git a/plugins/services/rabbitmq.go b/plugins/services/rabbitmq.go index b2dbf41..419b917 100644 --- a/plugins/services/rabbitmq.go +++ b/plugins/services/rabbitmq.go @@ -52,7 +52,7 @@ func (p *RabbitMQPlugin) Scan(ctx context.Context, info *common.HostInfo, sessio // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, config, state) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, credentials, authFn, "rabbitmq", testConfig) diff --git a/plugins/services/redis.go b/plugins/services/redis.go index 2ab5cd0..4058edd 100644 --- a/plugins/services/redis.go +++ b/plugins/services/redis.go @@ -56,7 +56,7 @@ func (p *RedisPlugin) Scan(ctx context.Context, info *common.HostInfo, session * // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, session) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) testConfig.Concurrency = 20 // Redis 默认并发度更高 result := TestCredentialsConcurrently(ctx, credentials, authFn, "redis", testConfig) diff --git a/plugins/services/rsync.go b/plugins/services/rsync.go index 3bd66d2..9256af1 100644 --- a/plugins/services/rsync.go +++ b/plugins/services/rsync.go @@ -70,7 +70,7 @@ func (p *RsyncPlugin) Scan(ctx context.Context, info *common.HostInfo, session * // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, session) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, creds, authFn, "rsync", testConfig) diff --git a/plugins/services/smb.go b/plugins/services/smb.go index c39d1aa..ff0baab 100644 --- a/plugins/services/smb.go +++ b/plugins/services/smb.go @@ -91,7 +91,7 @@ func (p *SmbPlugin) Scan(ctx context.Context, info *common.HostInfo, session *co } authFn := p.createAuthFunc(info, auth, session) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, creds, authFn, "smb", testConfig) diff --git a/plugins/services/smtp.go b/plugins/services/smtp.go index 2ccc110..4d77b12 100644 --- a/plugins/services/smtp.go +++ b/plugins/services/smtp.go @@ -57,7 +57,7 @@ func (p *SMTPPlugin) Scan(ctx context.Context, info *common.HostInfo, session *c // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, session) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, creds, authFn, "smtp", testConfig) diff --git a/plugins/services/ssh.go b/plugins/services/ssh.go index 48e6efa..d50b9a0 100644 --- a/plugins/services/ssh.go +++ b/plugins/services/ssh.go @@ -65,7 +65,7 @@ func (p *SSHPlugin) Scan(ctx context.Context, info *common.HostInfo, session *co // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, session) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, credentials, authFn, "ssh", testConfig) diff --git a/plugins/services/telnet.go b/plugins/services/telnet.go index 8832926..b131296 100644 --- a/plugins/services/telnet.go +++ b/plugins/services/telnet.go @@ -92,7 +92,7 @@ func (p *TelnetPlugin) Scan(ctx context.Context, info *common.HostInfo, session // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, session) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, creds, authFn, "telnet", testConfig) diff --git a/plugins/services/vnc.go b/plugins/services/vnc.go index 5f5d7e0..2914632 100644 --- a/plugins/services/vnc.go +++ b/plugins/services/vnc.go @@ -49,7 +49,7 @@ func (p *VNCPlugin) Scan(ctx context.Context, info *common.HostInfo, session *co // 使用公共框架进行并发凭据测试 authFn := p.createAuthFunc(info, session) - testConfig := DefaultConcurrentTestConfig(config) + testConfig := DefaultConcurrentTestConfigWithTarget(config, info) result := TestCredentialsConcurrently(ctx, credentials, authFn, "vnc", testConfig)