From 5c251b123d6079ae37287523d04444f360bd4ffd Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Fri, 12 Jun 2026 16:36:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E8=AF=AF=E5=AF=BC?= =?UTF-8?q?=E6=80=A7=E7=9A=84"=E6=97=A0=E5=8F=AF=E7=94=A8=E6=8F=92?= =?UTF-8?q?=E4=BB=B6"=E6=97=A5=E5=BF=97=20#588?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 扫描开始前的插件预检基于端口列表静态匹配,不代表实际扫描中插件 不会执行。移除"无可用插件"提示,避免用户误以为插件未工作。 --- common/output/stdout_writer.go | 18 +++++++++++++----- core/service_scanner.go | 22 ++++------------------ 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/common/output/stdout_writer.go b/common/output/stdout_writer.go index 80f38f5..b5228c2 100644 --- a/common/output/stdout_writer.go +++ b/common/output/stdout_writer.go @@ -4,7 +4,9 @@ import ( "bufio" "encoding/json" "fmt" + "net" "os" + "strconv" "strings" "sync" ) @@ -132,13 +134,19 @@ func toInt(v interface{}) (int, bool) { } func splitHostPort(target string) (string, int, bool) { - idx := strings.LastIndex(target, ":") - if idx < 0 { + host, portText, err := net.SplitHostPort(target) + if err != nil { + if strings.Count(target, ":") != 1 { + return "", 0, false + } + parts := strings.SplitN(target, ":", 2) + host, portText = parts[0], parts[1] + } + port, err := strconv.Atoi(portText) + if err != nil { return "", 0, false } - host := target[:idx] - var port int - if _, err := fmt.Sscanf(target[idx+1:], "%d", &port); err != nil { + if host == "" || port < 1 || port > 65535 { return "", 0, false } return host, port, true diff --git a/core/service_scanner.go b/core/service_scanner.go index 4668eb5..d683590 100644 --- a/core/service_scanner.go +++ b/core/service_scanner.go @@ -69,7 +69,7 @@ func (s *ServiceScanStrategy) showPluginsForSpecifiedPorts(config *common.Config applicablePlugins = append(applicablePlugins, pluginName) } - // 输出结果 + // 输出结果(仅在有匹配插件时显示,避免因预检端口不完整而输出误导性的"无可用插件") if len(applicablePlugins) > 0 { pluginStr := formatPluginList(applicablePlugins) if isCustomMode { @@ -77,8 +77,6 @@ func (s *ServiceScanStrategy) showPluginsForSpecifiedPorts(config *common.Config } else { session.LogInfo(i18n.Tr("service_plugin_info", pluginStr)) } - } else { - session.LogInfo(i18n.GetText("service_plugin_none")) } } @@ -88,18 +86,9 @@ func (s *ServiceScanStrategy) parsePortList(portStr string) []int { return []int{} } - ports := []int{} // 初始化为空切片而非nil - parts := strings.Split(portStr, ",") - for _, part := range parts { - part = strings.TrimSpace(part) - if port, err := strconv.Atoi(part); err == nil { - // 验证端口范围 1-65535(与 scanner.go 的 parsePort 保持一致) - if port >= 1 && port <= 65535 { - ports = append(ports, port) - } else { - common.LogError(i18n.Tr("port_out_of_range", port)) - } - } + ports := parsers.ParsePort(portStr) + if ports == nil { + return []int{} } return ports } @@ -340,11 +329,8 @@ func (s *ServiceScanStrategy) LogVulnerabilityPluginInfo(targets []common.HostIn servicePlugins = append(servicePlugins, pluginName) } - // 输出插件信息 if len(servicePlugins) > 0 { common.LogInfo(i18n.Tr("service_plugin_info", strings.Join(servicePlugins, ", "))) - } else { - common.LogInfo(i18n.GetText("scan_no_service_plugins")) } }