From 46cfa2a64daddf903464412388112193d97b68e4 Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Tue, 2 Sep 2025 00:08:17 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AE=80=E5=8C=96HTTP=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=88=86=E6=9E=90=E9=80=BB=E8=BE=91=EF=BC=8C=E6=B6=88=E9=99=A4?= =?UTF-8?q?=E8=AF=AF=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 核心修复: - 大幅简化analyzeHTTPError逻辑,移除容易误报的指示器 - 不再将SSL/TLS错误误判为HTTP服务(SSH/FTP被误报为HTTPS的根因) - 统一错误处理:HTTP请求失败一律判定为非HTTP服务 - 协议预检查+HTTP验证的两阶段检测更加可靠 修复的误报: - SSH端口22不再被误识别为HTTPS服务 - FTP端口21不再被误识别为HTTPS服务 - SMTP端口25不再被误识别为HTTPS服务 - 保持MySQL端口3306的正确识别(协议预检查直接过滤) 技术改进: - 错误分析逻辑从40+行简化到15行 - 消除硬编码的协议指示器列表 - 基于协议预检查的信任机制:如果预检查通过但HTTP失败,说明不是HTTP --- core/WebDetection.go | 45 +++++++++++--------------------------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/core/WebDetection.go b/core/WebDetection.go index 8627aa2..871c35a 100644 --- a/core/WebDetection.go +++ b/core/WebDetection.go @@ -261,49 +261,26 @@ func (w *WebPortDetector) tryHTTPConnectionDirect(ctx context.Context, host stri func (w *WebPortDetector) analyzeHTTPError(err error) bool { errStr := strings.ToLower(err.Error()) - // 先检查明确的非Web服务错误 - nonWebErrors := []string{ + // 简化逻辑:既然我们已经做了协议预检查,到这里的都应该是可能的HTTP服务 + // 只检查明确的连接错误 + connectionErrors := []string{ "connection refused", - "no such host", + "no such host", "network unreachable", - "timeout", "deadline exceeded", - "connection reset", - "eof", + "timeout", } - for _, nonWebErr := range nonWebErrors { - if strings.Contains(errStr, nonWebErr) { + for _, connErr := range connectionErrors { + if strings.Contains(errStr, connErr) { return false } } - // 这些错误表明连接到了HTTP服务器,只是协议或其他问题 - webIndicators := []string{ - "ssl handshake", - "certificate", - "tls", - "bad request", - "method not allowed", - "server gave http response", - } - - // 特别处理:malformed HTTP response通常表明是非HTTP协议 - if strings.Contains(errStr, "malformed http response") { - // 检查是否包含明显的二进制数据(如MySQL greeting包) - if strings.Contains(errStr, "\\x00") || strings.Contains(errStr, "\\x") { - common.LogDebug(fmt.Sprintf("检测到二进制协议响应,非HTTP服务: %s", err.Error())) - return false - } - // 如果是文本形式的malformed response,可能仍是HTTP服务的变种 - } - - for _, indicator := range webIndicators { - if strings.Contains(errStr, indicator) { - return true - } - } - + // 所有其他错误(包括malformed response、SSL错误等)都认为不是HTTP服务 + // 因为我们已经通过协议预检查确认目标可能是HTTP服务 + // 如果仍然出错,说明不是标准的HTTP服务 + common.LogDebug(fmt.Sprintf("HTTP请求失败,判定为非HTTP服务: %s", err.Error())) return false }