From b17061c98ca88899ce9f902eceb9e569acc09e69 Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Sat, 17 Jan 2026 13:31:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E8=BE=93=E5=87=BA=EF=BC=8C=E7=A7=BB=E9=99=A4=E5=86=97=E4=BD=99?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除showParseSummary开局配置输出 - 移除LogPluginInfo/LogPluginInfoWithPort插件信息输出 - 移除alive_scanner冗余统计输出 - 移除port_scan_start扫描开始提示 - 移除handleUDPPorts SNMP死代码 - 移除相关i18n条目 --- common/i18n/locales/en.yaml | 2 - common/i18n/locales/zh.yaml | 2 - common/parse.go | 97 +------------------------------------ core/alive_scanner.go | 38 ++------------- core/base_scan_strategy.go | 28 +++-------- core/port_scan.go | 5 -- core/service_scanner.go | 33 ------------- 7 files changed, 14 insertions(+), 191 deletions(-) diff --git a/common/i18n/locales/en.yaml b/common/i18n/locales/en.yaml index f8de147..92f5d88 100644 --- a/common/i18n/locales/en.yaml +++ b/common/i18n/locales/en.yaml @@ -155,8 +155,6 @@ scan_vulnerability_start: other: "Starting vulnerability scan" scan_no_service_plugins: other: "No available service plugins found" -scan_snmp_udp_ports_added: - other: "Detected SNMP port 161, adding UDP ports to scan targets" # ========================= Scan Strategy Messages ========================= scan_strategy_alive_name: diff --git a/common/i18n/locales/zh.yaml b/common/i18n/locales/zh.yaml index 8490555..7f80582 100644 --- a/common/i18n/locales/zh.yaml +++ b/common/i18n/locales/zh.yaml @@ -155,8 +155,6 @@ scan_vulnerability_start: other: "开始漏洞扫描" scan_no_service_plugins: other: "未找到可用的服务插件" -scan_snmp_udp_ports_added: - other: "检测到SNMP端口161,添加UDP端口到扫描目标" # ========================= 扫描策略消息 ========================= scan_strategy_alive_name: diff --git a/common/parse.go b/common/parse.go index e95b90b..83991c2 100644 --- a/common/parse.go +++ b/common/parse.go @@ -396,102 +396,9 @@ func joinInts(slice []int, sep string) string { return strings.Join(strs, sep) } -// showParseSummary 显示解析结果摘要(精简版) +// showParseSummary 显示解析结果摘要(已精简,不再输出冗余信息) func showParseSummary(config *parsers.ParsedConfig) { - if config == nil { - return - } - - fv := GetFlagVars() - - // 1. 目标信息(合并为一行) - if config.Targets != nil { - var targetParts []string - - // 主机信息 - if len(config.Targets.Hosts) > 0 { - if len(config.Targets.Hosts) == 1 { - targetParts = append(targetParts, config.Targets.Hosts[0]) - } else { - targetParts = append(targetParts, fmt.Sprintf("%d主机", len(config.Targets.Hosts))) - } - } - - // URL信息 - if len(config.Targets.URLs) > 0 { - if len(config.Targets.URLs) == 1 { - targetParts = append(targetParts, config.Targets.URLs[0]) - } else { - targetParts = append(targetParts, fmt.Sprintf("%dURL", len(config.Targets.URLs))) - } - } - - // 端口信息 - if len(config.Targets.Ports) > 0 { - targetParts = append(targetParts, fmt.Sprintf("%d端口", len(config.Targets.Ports))) - } - - // 本地模式 - if config.Targets.LocalMode { - targetParts = append(targetParts, "本地模式") - } - - if len(targetParts) > 0 { - LogBase(fmt.Sprintf("目标: %s", strings.Join(targetParts, " x "))) - } - - // 排除端口单独显示(如果有) - if len(config.Targets.ExcludePorts) > 0 { - LogBase(fmt.Sprintf("排除: %d端口", len(config.Targets.ExcludePorts))) - } - } - - // 2. 非默认配置(只显示用户修改过的) - var customConfigs []string - - if fv.ThreadNum != 600 { - customConfigs = append(customConfigs, fmt.Sprintf("线程%d", fv.ThreadNum)) - } - if fv.TimeoutSec != 3 { - customConfigs = append(customConfigs, fmt.Sprintf("超时%ds", fv.TimeoutSec)) - } - if fv.ModuleThreadNum != 20 { - customConfigs = append(customConfigs, fmt.Sprintf("模块线程%d", fv.ModuleThreadNum)) - } - if fv.GlobalTimeout != 180 { - customConfigs = append(customConfigs, fmt.Sprintf("全局超时%ds", fv.GlobalTimeout)) - } - - // 代理配置 - if config.Network != nil { - if config.Network.HTTPProxy != "" { - customConfigs = append(customConfigs, fmt.Sprintf("HTTP代理:%s", config.Network.HTTPProxy)) - } - if config.Network.Socks5Proxy != "" { - customConfigs = append(customConfigs, fmt.Sprintf("SOCKS5:%s", config.Network.Socks5Proxy)) - } - } - - if len(customConfigs) > 0 { - LogBase(fmt.Sprintf("配置: %s", strings.Join(customConfigs, " "))) - } - - // 3. 凭据信息(合并为一行) - if config.Credentials != nil { - var credParts []string - if len(config.Credentials.Usernames) > 0 { - credParts = append(credParts, fmt.Sprintf("%d用户", len(config.Credentials.Usernames))) - } - if len(config.Credentials.Passwords) > 0 { - credParts = append(credParts, fmt.Sprintf("%d密码", len(config.Credentials.Passwords))) - } - if len(config.Credentials.HashValues) > 0 { - credParts = append(credParts, fmt.Sprintf("%d哈希", len(config.Credentials.HashValues))) - } - if len(credParts) > 0 { - LogBase(fmt.Sprintf("凭据: %s", strings.Join(credParts, " "))) - } - } + // 不再输出开局配置信息,减少干扰 } // logLevelMap 日志级别字符串到级别的映射(支持新旧格式) diff --git a/core/alive_scanner.go b/core/alive_scanner.go index fa822ca..33598bb 100644 --- a/core/alive_scanner.go +++ b/core/alive_scanner.go @@ -2,7 +2,6 @@ package core import ( "fmt" - "strings" "sync" "time" @@ -61,8 +60,6 @@ func (s *AliveScanStrategy) Execute(config *common.Config, state *common.State, return } - // 输出存活探测开始信息 - common.LogBase(i18n.GetText("scan_alive_start")) // 执行存活探测 s.performAliveScan(info, config, state) @@ -91,12 +88,6 @@ func (s *AliveScanStrategy) performAliveScan(info common.HostInfo, config *commo s.stats.AliveHosts = 0 s.stats.DeadHosts = 0 - // 显示扫描信息 - if len(hosts) == 1 { - common.LogBase(i18n.Tr("alive_scan_start_single", hosts[0])) - } else { - common.LogBase(i18n.Tr("alive_scan_start_multi", len(hosts), hosts[0])) - } // 执行存活检测 aliveList := CheckLive(hosts, false, config, state) // 使用ICMP探测 @@ -112,33 +103,12 @@ func (s *AliveScanStrategy) performAliveScan(info common.HostInfo, config *commo } } -// outputStats 输出详细统计信息 +// outputStats 输出统计信息(精简版) func (s *AliveScanStrategy) outputStats() { - // 输出分隔线 - common.LogBase("=" + strings.Repeat("=", 60)) - - // 输出扫描结果摘要 - common.LogBase(i18n.GetText("scan_alive_summary_title")) - - // 基础统计 - common.LogBase(i18n.Tr("alive_total_hosts", s.stats.TotalHosts)) - common.LogBase(i18n.Tr("alive_hosts_count", s.stats.AliveHosts)) - common.LogBase(i18n.Tr("alive_dead_hosts", s.stats.DeadHosts)) - common.LogBase(i18n.Tr("alive_success_rate", fmt.Sprintf("%.2f%%", s.stats.SuccessRate))) - common.LogBase(i18n.Tr("alive_scan_duration", s.stats.ScanDuration.Round(time.Millisecond))) - - // 如果有存活主机,显示详细列表 - if s.stats.AliveHosts > 0 { - common.LogBase("") - common.LogBase(i18n.GetText("scan_alive_hosts_list")) - - for i, host := range s.stats.AliveHostList { - common.LogSuccess(i18n.Tr("alive_host_item", i+1, host)) - } + // 只输出存活主机列表,不输出冗余统计 + for _, host := range s.stats.AliveHostList { + common.LogSuccess(fmt.Sprintf("alive %s", host)) } - - // 输出分隔线 - common.LogBase("=" + strings.Repeat("=", 60)) } // PrepareTargets 存活探测不需要准备扫描目标 diff --git a/core/base_scan_strategy.go b/core/base_scan_strategy.go index 9603087..a4c911a 100644 --- a/core/base_scan_strategy.go +++ b/core/base_scan_strategy.go @@ -180,16 +180,10 @@ func (b *BaseScanStrategy) LogPluginInfo(config *common.Config) { prefix = i18n.GetText("concurrency_plugin") } - if len(allPlugins) > 0 { - pluginStr := formatPluginList(allPlugins) - if isCustomMode { - common.LogBase(i18n.Tr("plugins_custom_specified", prefix, pluginStr)) - } else { - common.LogBase(i18n.Tr("plugins_info", prefix, pluginStr)) - } - } else { - common.LogBase(i18n.Tr("plugins_none", prefix)) - } + // 插件信息不再输出,减少干扰 + _ = allPlugins + _ = isCustomMode + _ = prefix } // formatPluginList 格式化插件列表(超过5个时精简显示) @@ -226,16 +220,10 @@ func (b *BaseScanStrategy) LogPluginInfoWithPort(targetHost string, targetPort i } } - if len(applicablePlugins) > 0 { - pluginStr := formatPluginList(applicablePlugins) - if isCustomMode { - common.LogBase(i18n.Tr("plugins_custom_specified", prefix, pluginStr)) - } else { - common.LogBase(i18n.Tr("plugins_info", prefix, pluginStr)) - } - } else { - common.LogBase(i18n.Tr("plugins_none", prefix)) - } + // 插件信息不再输出,减少干扰 + _ = applicablePlugins + _ = isCustomMode + _ = prefix } // ValidateConfiguration 验证扫描配置 diff --git a/core/port_scan.go b/core/port_scan.go index 65d7fc4..5993c1e 100644 --- a/core/port_scan.go +++ b/core/port_scan.go @@ -155,11 +155,6 @@ func EnhancedPortScan(hosts []string, ports string, timeout int64, config *commo // 使用传入的配置 threadNum := config.ThreadNum - // 估算并显示扫描时间 - if totalTasks > 0 { - estimatedTime := estimateScanTime(totalTasks, threadNum, timeout) - common.LogBase(i18n.Tr("port_scan_start", totalTasks, estimatedTime, estimatedTime/60)) - } // 初始化端口扫描进度条 if totalTasks > 0 && config.Output.ShowProgress { diff --git a/core/service_scanner.go b/core/service_scanner.go index a98d321..50dcb47 100644 --- a/core/service_scanner.go +++ b/core/service_scanner.go @@ -264,13 +264,6 @@ func (s *ServiceScanStrategy) discoverAlivePorts(hosts []string, config *common. common.LogBase(i18n.Tr("alive_ports_count", len(alivePorts))) } - // UDP端口特殊处理(当前仅支持SNMP的161端口) - udpPorts := s.handleUDPPorts(hosts) - if len(udpPorts) > 0 { - alivePorts = append(alivePorts, udpPorts...) - common.LogBase(i18n.Tr("alive_ports_count", len(alivePorts))) - } - return alivePorts } @@ -317,29 +310,3 @@ func (s *ServiceScanStrategy) convertToTargetInfos(ports []string, baseInfo comm return infos } -// handleUDPPorts 处理UDP端口的特殊逻辑 -func (s *ServiceScanStrategy) handleUDPPorts(hosts []string) []string { - var udpPorts []string - - // 检查是否包含SNMP端口161 - portList := parsers.ParsePort(common.GetFlagVars().Ports) - hasPort161 := false - for _, port := range portList { - if port == 161 { - hasPort161 = true - break - } - } - - // 如果端口列表包含161,则为每个主机添加UDP 161端口 - if hasPort161 { - for _, host := range hosts { - udpPorts = append(udpPorts, fmt.Sprintf("%s:161", host)) - } - if len(udpPorts) > 0 { - common.LogBase(i18n.GetText("scan_snmp_udp_ports_added")) - } - } - - return udpPorts -}