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 }