From 1278a0355f1bb0459931927abf799d261b3346e0 Mon Sep 17 00:00:00 2001 From: ZacharyZcR <2903735704@qq.com> Date: Fri, 20 Dec 2024 14:19:23 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=A4=A7=E5=9E=8B=E9=87=8D?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/Parse.go | 45 --------------------------------------------- Common/ParsePort.go | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 45 deletions(-) diff --git a/Common/Parse.go b/Common/Parse.go index b0bfb5f..2516415 100644 --- a/Common/Parse.go +++ b/Common/Parse.go @@ -7,7 +7,6 @@ import ( "fmt" "net/url" "os" - "strconv" "strings" ) @@ -15,7 +14,6 @@ func Parse(Info *HostInfo) { ParseUser() ParsePass(Info) ParseInput(Info) - ParseScantype(Info) } // ParseUser 解析用户名配置,支持直接指定用户名列表或从文件读取 @@ -319,49 +317,6 @@ func ParseInput(Info *HostInfo) error { return nil } -// ParseScantype 解析扫描类型并设置对应的端口 -func ParseScantype(Info *HostInfo) error { - // 先处理特殊扫描类型 - specialTypes := map[string]string{ - "service": ServicePorts, - "db": DbPorts, - "web": WebPorts, - "all": AllPorts, - "main": MainPorts, - "port": MainPorts + "," + WebPorts, - "icmp": "", // ICMP不需要端口 - } - - // 如果是特殊扫描类型 - if customPorts, isSpecial := specialTypes[ScanMode]; isSpecial { - // 专门处理 all 类型 - if ScanMode == "all" { - Ports = AllPorts // 直接设置为 1-65535 - } else if Ports == MainPorts+","+WebPorts { - Ports = customPorts - } - fmt.Printf("[*] 扫描类型: %s, 目标端口: %s\n", ScanMode, Ports) - return nil - } - - // 检查是否是注册的插件类型 - plugin, validType := PluginManager[ScanMode] - if !validType { - showmode() - return fmt.Errorf("无效的扫描类型: %s", ScanMode) - } - - // 如果是插件扫描且使用默认端口配置 - if Ports == MainPorts+","+WebPorts { - if plugin.Port > 0 { - Ports = strconv.Itoa(plugin.Port) - } - fmt.Printf("[*] 扫描类型: %s, 目标端口: %s\n", plugin.Name, Ports) - } - - return nil -} - // showmode 显示所有支持的扫描类型 func showmode() { fmt.Println("[!] 指定的扫描类型不存在") diff --git a/Common/ParsePort.go b/Common/ParsePort.go index e1485dc..770b97b 100644 --- a/Common/ParsePort.go +++ b/Common/ParsePort.go @@ -9,6 +9,20 @@ import ( // ParsePort 解析端口配置字符串为端口号列表 func ParsePort(ports string) []int { + // 预定义的端口组 + portGroups := map[string]string{ + "service": ServicePorts, + "db": DbPorts, + "web": WebPorts, + "all": AllPorts, + "main": MainPorts, + } + + // 检查是否匹配预定义组 + if definedPorts, exists := portGroups[ports]; exists { + ports = definedPorts + } + if ports == "" { return nil }