From 09d2d737aedfd73d97b503311ec9eae49d6ac8a2 Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Thu, 22 Jan 2026 10:59:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(scan):=20=E7=A7=BB=E9=99=A4=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=E9=A2=84=E8=A7=A3=E6=9E=90=EF=BC=8C=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E5=8E=9F=E5=A7=8B=E5=9F=9F=E5=90=8D=E8=BF=9B=E8=A1=8C=E6=89=AB?= =?UTF-8?q?=E6=8F=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 域名预解析会将域名转换为IP,导致虚拟主机场景下HTTP访问失败 (Host头变成IP而非域名,无法正确路由) --- core/port_scan.go | 60 ----------------------------------------------- 1 file changed, 60 deletions(-) diff --git a/core/port_scan.go b/core/port_scan.go index 59ab31a..6f8d95e 100644 --- a/core/port_scan.go +++ b/core/port_scan.go @@ -108,71 +108,11 @@ func (f *failedPortCollector) Count() int { return count } -// preResolveDomains 预解析域名列表 -// 将域名解析为 IP,解析失败的域名保留原样 -// 这样可以避免扫描过程中大量并发 DNS 查询导致系统资源耗尽 -func preResolveDomains(hosts []string, timeout time.Duration) []string { - if len(hosts) == 0 { - return hosts - } - - // 检查是否有需要解析的域名 - needResolve := false - for _, host := range hosts { - if net.ParseIP(host) == nil { - needResolve = true - break - } - } - - if !needResolve { - return hosts - } - - common.LogDebug(fmt.Sprintf("[DNS] 开始预解析 %d 个主机", len(hosts))) - - result := make([]string, 0, len(hosts)) - resolved := 0 - failed := 0 - - for _, host := range hosts { - // 如果已经是 IP,直接添加 - if net.ParseIP(host) != nil { - result = append(result, host) - continue - } - - // 尝试解析域名 - ips, err := net.LookupHost(host) - if err != nil || len(ips) == 0 { - // 解析失败,保留原域名(后续连接时会再次尝试解析) - common.LogDebug(fmt.Sprintf("[DNS] 解析失败: %s - %v", host, err)) - result = append(result, host) - failed++ - continue - } - - // 使用第一个解析结果 - result = append(result, ips[0]) - resolved++ - common.LogDebug(fmt.Sprintf("[DNS] %s -> %s", host, ips[0])) - } - - if resolved > 0 || failed > 0 { - common.LogDebug(fmt.Sprintf("[DNS] 预解析完成: 成功=%d, 失败=%d", resolved, failed)) - } - - return result -} - // EnhancedPortScan 高性能端口扫描函数 // 使用滑动窗口调度 + 自适应线程池 + 流式迭代器 func EnhancedPortScan(hosts []string, ports string, timeout int64, config *common.Config, state *common.State) []string { common.LogDebug(fmt.Sprintf("[PortScan] 开始: %d个主机, 线程数=%d", len(hosts), config.ThreadNum)) - // 预解析域名,避免扫描过程中大量 DNS 查询导致问题 - hosts = preResolveDomains(hosts, time.Duration(timeout)*time.Second) - // 解析端口和排除端口 portList := parsers.ParsePort(ports) if len(portList) == 0 {