diff --git a/common/flag.go b/common/flag.go index 50d3495..27bcf56 100644 --- a/common/flag.go +++ b/common/flag.go @@ -283,7 +283,7 @@ func checkParameterConflicts() error { // 检查 -ao 和 -m icmp 同时指定的情况(向后兼容提示) if fv.AliveOnly && fv.ScanMode == "icmp" { - LogBase(i18n.GetText("param_conflict_ao_icmp_both")) + LogInfo(i18n.GetText("param_conflict_ao_icmp_both")) } // 检查本地插件参数 diff --git a/common/logger.go b/common/logger.go index 4751ab9..0bd0307 100644 --- a/common/logger.go +++ b/common/logger.go @@ -66,9 +66,6 @@ func InitLogger() { // LogDebug 输出调试日志 func LogDebug(msg string) { getGlobalLogger().Debug(msg) } -// LogBase 输出基础日志 -func LogBase(msg string) { getGlobalLogger().Base(msg) } - // LogInfo 输出信息日志 func LogInfo(msg string) { getGlobalLogger().Info(msg) } diff --git a/common/logging/constants.go b/common/logging/constants.go index 0a0de43..919b4e2 100644 --- a/common/logging/constants.go +++ b/common/logging/constants.go @@ -60,16 +60,16 @@ const ( // ============================================================================= const ( + // PrefixDebug 调试日志前缀 + PrefixDebug = "[.]" + // PrefixInfo 信息日志前缀 + PrefixInfo = "[*]" // PrefixSuccess 成功日志前缀 PrefixSuccess = "[+]" // PrefixVuln 漏洞/重要发现前缀 PrefixVuln = "[!]" - // PrefixInfo 信息日志前缀 - PrefixInfo = "[*]" // PrefixError 错误日志前缀 PrefixError = "[-]" - // PrefixDefault 默认日志前缀 - PrefixDefault = " " ) // ============================================================================= diff --git a/common/logging/logger.go b/common/logging/logger.go index 7c78e63..c0a5dc0 100644 --- a/common/logging/logger.go +++ b/common/logging/logger.go @@ -201,15 +201,17 @@ func (l *Logger) formatElapsedTime(elapsed time.Duration) string { // getLevelPrefix 获取日志级别前缀 func (l *Logger) getLevelPrefix(level LogLevel) string { switch level { - case LevelVuln: - return PrefixVuln - case LevelSuccess: - return PrefixSuccess + case LevelDebug: + return PrefixDebug case LevelInfo: return PrefixInfo + case LevelSuccess: + return PrefixSuccess + case LevelVuln: + return PrefixVuln case LevelError: return PrefixError default: - return PrefixDefault + return PrefixInfo // 默认使用 Info 前缀 } } diff --git a/common/logging/logger_test.go b/common/logging/logger_test.go index 7c60bff..2d92b6a 100644 --- a/common/logging/logger_test.go +++ b/common/logging/logger_test.go @@ -137,14 +137,14 @@ func TestLogger_AllLevels(t *testing.T) { logFunc: logger.Debug, message: "debug message", wantMsg: "debug message", - wantPfx: PrefixDefault, + wantPfx: PrefixDebug, }, { name: "Base级别", logFunc: logger.Base, message: "base message", wantMsg: "base message", - wantPfx: PrefixDefault, + wantPfx: PrefixInfo, // Base 已废弃,默认使用 Info 前缀 }, { name: "Info级别", diff --git a/core/base_scan_strategy.go b/core/base_scan_strategy.go index a4c911a..d599d93 100644 --- a/core/base_scan_strategy.go +++ b/core/base_scan_strategy.go @@ -237,9 +237,9 @@ func (b *BaseScanStrategy) LogScanStart() { // 仅在本地/Web等特殊模式下显示 switch b.filterType { case FilterLocal: - common.LogBase(i18n.GetText("start_local_scan")) + common.LogInfo(i18n.GetText("start_local_scan")) case FilterWeb: - common.LogBase(i18n.GetText("start_web_scan")) + common.LogInfo(i18n.GetText("start_web_scan")) } } diff --git a/core/icmp.go b/core/icmp.go index bd61823..6f74590 100644 --- a/core/icmp.go +++ b/core/icmp.go @@ -137,7 +137,7 @@ func probeWithICMP(hostslist []string, chanHosts chan string, aliveHosts *[]stri } common.LogError(i18n.Tr("icmp_listen_failed", err)) - common.LogBase(i18n.GetText("trying_no_listen_icmp")) + common.LogInfo(i18n.GetText("trying_no_listen_icmp")) // 尝试无监听ICMP探测 conn2, err := net.DialTimeout("ip4:icmp", "127.0.0.1", 3*time.Second) @@ -147,9 +147,9 @@ func probeWithICMP(hostslist []string, chanHosts chan string, aliveHosts *[]stri return } - common.LogBase(i18n.Tr("icmp_connect_failed", err)) - common.LogBase(i18n.GetText("insufficient_privileges")) - common.LogBase(i18n.GetText("switching_to_ping")) + common.LogError(i18n.Tr("icmp_connect_failed", err)) + common.LogError(i18n.GetText("insufficient_privileges")) + common.LogInfo(i18n.GetText("switching_to_ping")) // 降级使用ping探测 RunPing(hostslist, chanHosts, livewg) diff --git a/core/local_scanner.go b/core/local_scanner.go index 4cdad0f..08ec528 100644 --- a/core/local_scanner.go +++ b/core/local_scanner.go @@ -24,9 +24,9 @@ func NewLocalScanStrategy() *LocalScanStrategy { func (s *LocalScanStrategy) LogPluginInfo(config *common.Config) { localPlugin := config.LocalPlugin if localPlugin != "" { - common.LogBase(i18n.Tr("local_plugin_info", localPlugin)) + common.LogInfo(i18n.Tr("local_plugin_info", localPlugin)) } else { - common.LogBase(i18n.GetText("local_plugin_not_specified")) + common.LogError(i18n.GetText("local_plugin_not_specified")) } } @@ -54,7 +54,7 @@ func (s *LocalScanStrategy) Execute(config *common.Config, state *common.State, // 验证本地插件是否存在 if config.LocalPlugin != "" { if !plugins.Exists(config.LocalPlugin) { - common.LogBase(i18n.Tr("local_plugin_not_found", config.LocalPlugin)) + common.LogError(i18n.Tr("local_plugin_not_found", config.LocalPlugin)) return } } diff --git a/core/port_scan.go b/core/port_scan.go index a549a38..54c6db0 100644 --- a/core/port_scan.go +++ b/core/port_scan.go @@ -213,7 +213,7 @@ func EnhancedPortScan(hosts []string, ports string, timeout int64, config *commo // 检查代理可靠性,如果存在全回显问题则警告 if common.IsProxyEnabled() && !common.IsProxyReliable() { - common.LogBase("[!] 检测到代理存在全回显问题,端口扫描结果可能不准确") + common.LogError("检测到代理存在全回显问题,端口扫描结果可能不准确") } // 创建流式迭代器(O(1) 内存,端口喷洒策略) @@ -226,12 +226,12 @@ func EnhancedPortScan(hosts []string, ports string, timeout int64, config *commo // 大规模扫描警告和线程数自动调整 if totalTasks > 100000 { - common.LogBase(fmt.Sprintf("[*] 大规模扫描: %d 个目标 (%d主机 × %d端口)", totalTasks, len(hosts), len(portList))) + common.LogInfo(fmt.Sprintf("大规模扫描: %d 个目标 (%d主机 × %d端口)", totalTasks, len(hosts), len(portList))) // 如果任务数超过100万且线程数大于300,自动降低线程数 if totalTasks > 1000000 && threadNum > 300 { oldThreadNum := threadNum threadNum = 300 - common.LogBase(fmt.Sprintf("[*] 自动调整线程数: %d -> %d (大规模扫描优化)", oldThreadNum, threadNum)) + common.LogInfo(fmt.Sprintf("自动调整线程数: %d -> %d (大规模扫描优化)", oldThreadNum, threadNum)) } } @@ -285,7 +285,7 @@ func EnhancedPortScan(hosts []string, ports string, timeout int64, config *commo common.FinishProgressBar() } - common.LogBase(i18n.Tr("port_scan_complete", count)) + common.LogInfo(i18n.Tr("port_scan_complete", count)) // 检查扫描失败率,如果过高则警告用户 resourceErrors := state.GetResourceExhaustedCount() diff --git a/core/scanner.go b/core/scanner.go index f1f73cb..09e8bc4 100644 --- a/core/scanner.go +++ b/core/scanner.go @@ -96,21 +96,21 @@ func RunScan(info common.HostInfo, config *common.Config, state *common.State) { // 检查是否有活跃的连接需要维持 if state.IsReverseShellActive() || state.IsSocks5ProxyActive() || state.IsForwardShellActive() { if state.IsReverseShellActive() { - common.LogBase(i18n.GetText("active_reverse_shell")) + common.LogInfo(i18n.GetText("active_reverse_shell")) } if state.IsSocks5ProxyActive() { - common.LogBase(i18n.GetText("active_socks5_proxy")) + common.LogInfo(i18n.GetText("active_socks5_proxy")) } if state.IsForwardShellActive() { - common.LogBase(i18n.GetText("active_forward_shell")) + common.LogInfo(i18n.GetText("active_forward_shell")) } - common.LogBase(i18n.GetText("press_ctrl_c_exit")) + common.LogInfo(i18n.GetText("press_ctrl_c_exit")) // 优雅等待信号 sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM) <-sigChan - common.LogBase(i18n.GetText("received_exit_signal")) + common.LogInfo(i18n.GetText("received_exit_signal")) } // 完成扫描 @@ -125,7 +125,7 @@ func finishScan(config *common.Config, state *common.State) { } // 输出扫描完成信息 - common.LogBase(i18n.Tr("scan_task_complete", time.Since(state.GetStartTime()).Round(time.Millisecond), state.GetNum())) + common.LogInfo(i18n.Tr("scan_task_complete", time.Since(state.GetStartTime()).Round(time.Millisecond), state.GetNum())) // 输出性能统计 JSON(如果启用) if config.Output.PerfStats { diff --git a/core/service_scanner.go b/core/service_scanner.go index f5e52a5..c73c320 100644 --- a/core/service_scanner.go +++ b/core/service_scanner.go @@ -70,12 +70,12 @@ func (s *ServiceScanStrategy) showPluginsForSpecifiedPorts(config *common.Config if len(applicablePlugins) > 0 { pluginStr := formatPluginList(applicablePlugins) if isCustomMode { - common.LogBase(i18n.Tr("service_plugin_custom", pluginStr)) + common.LogInfo(i18n.Tr("service_plugin_custom", pluginStr)) } else { - common.LogBase(i18n.Tr("service_plugin_info", pluginStr)) + common.LogInfo(i18n.Tr("service_plugin_info", pluginStr)) } } else { - common.LogBase(i18n.GetText("service_plugin_none")) + common.LogInfo(i18n.GetText("service_plugin_none")) } } @@ -201,9 +201,9 @@ func (s *ServiceScanStrategy) LogVulnerabilityPluginInfo(targets []common.HostIn // 输出插件信息 if len(servicePlugins) > 0 { - common.LogBase(i18n.Tr("service_plugin_info", strings.Join(servicePlugins, ", "))) + common.LogInfo(i18n.Tr("service_plugin_info", strings.Join(servicePlugins, ", "))) } else { - common.LogBase(i18n.GetText("scan_no_service_plugins")) + common.LogInfo(i18n.GetText("scan_no_service_plugins")) } } @@ -227,7 +227,7 @@ func (s *ServiceScanStrategy) discoverTargets(hostInput string, baseInfo common. // 主机存活检测 if s.shouldPerformLivenessCheck(hosts, config) { hosts = CheckLive(hosts, false, config, state) - common.LogBase(i18n.Tr("alive_hosts_count_info", len(hosts))) + common.LogInfo(i18n.Tr("alive_hosts_count_info", len(hosts))) } // 端口扫描 @@ -253,7 +253,7 @@ func (s *ServiceScanStrategy) discoverAlivePorts(hosts []string, config *common. hostPorts := state.GetHostPorts() if len(hostPorts) > 0 { alivePorts = hostPorts - common.LogBase(i18n.Tr("alive_ports_count", len(alivePorts))) + common.LogInfo(i18n.Tr("alive_ports_count", len(alivePorts))) state.ClearHostPorts() return alivePorts } diff --git a/main.go b/main.go index 58f93f6..b145efc 100644 --- a/main.go +++ b/main.go @@ -59,7 +59,7 @@ func main() { signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM) go func() { <-sigChan - common.LogBase(i18n.GetText("received_exit_signal")) + common.LogInfo(i18n.GetText("received_exit_signal")) _ = common.Cleanup() // 确保结果写入磁盘 os.Exit(130) // 128 + SIGINT(2) = 130,标准的中断退出码 }() diff --git a/plugins/local/socks5proxy.go b/plugins/local/socks5proxy.go index 4303d5f..8c74a9d 100644 --- a/plugins/local/socks5proxy.go +++ b/plugins/local/socks5proxy.go @@ -49,7 +49,7 @@ func (p *Socks5ProxyPlugin) Scan(ctx context.Context, info *common.HostInfo, con output.WriteString(fmt.Sprintf("监听端口: %d\n", port)) output.WriteString(fmt.Sprintf("平台: %s\n\n", runtime.GOOS)) - common.LogBase(i18n.Tr("socks5_starting", port)) + common.LogInfo(i18n.Tr("socks5_starting", port)) // 启动SOCKS5代理服务器 err := p.startSocks5Server(ctx, port, state) @@ -96,7 +96,7 @@ func (p *Socks5ProxyPlugin) startSocks5Server(ctx context.Context, port int, sta for { select { case <-ctx.Done(): - common.LogBase(i18n.GetText("socks5_cancelled")) + common.LogInfo(i18n.GetText("socks5_cancelled")) return ctx.Err() default: } diff --git a/web/server.go b/web/server.go index 4bf43e1..e4121bf 100644 --- a/web/server.go +++ b/web/server.go @@ -85,7 +85,7 @@ func StartServer(port int) error { go func() { <-quit - common.LogBase(i18n.GetText("web_shutting_down")) + common.LogInfo(i18n.GetText("web_shutting_down")) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -98,7 +98,7 @@ func StartServer(port int) error { // 启动服务器 common.LogSuccess(i18n.Tr("web_server_started", port)) - common.LogBase(fmt.Sprintf("http://localhost:%d", port)) + fmt.Printf(" http://localhost:%d\n", port) if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { return fmt.Errorf("server error: %w", err) diff --git a/webscan/web_scan.go b/webscan/web_scan.go index 5c337b4..25f695f 100644 --- a/webscan/web_scan.go +++ b/webscan/web_scan.go @@ -304,7 +304,7 @@ func loadPocsConcurrently(pocFiles []string, isEmbedded bool, pocPath string) { } wg.Wait() - common.LogBase(i18n.Tr("poc_load_complete", pocCount, successCount, failCount)) + common.LogInfo(i18n.Tr("poc_load_complete", pocCount, successCount, failCount)) } // directoryExists 检查目录是否存在