diff --git a/Common/Flag.go b/Common/Flag.go index 8ce0fb3..34de495 100644 --- a/Common/Flag.go +++ b/Common/Flag.go @@ -43,6 +43,9 @@ func Flag(Info *HostInfo) { flag.BoolVar(&UsePing, "ping", false, "使用ping替代ICMP") flag.StringVar(&Command, "c", "", "执行命令(支持ssh|wmiexec)") + // 本地扫描配置 + flag.BoolVar(&LocalScan, "local", false, "启用本地扫描") + // 文件配置 flag.StringVar(&HostsFile, "hf", "", "主机列表文件") flag.StringVar(&UsersFile, "userf", "", "用户名字典") diff --git a/Common/Parse.go b/Common/Parse.go index c7ae2a7..651ce46 100644 --- a/Common/Parse.go +++ b/Common/Parse.go @@ -209,6 +209,11 @@ func ParseInput(Info *HostInfo) error { return fmt.Errorf("必须指定扫描目标") } + // 如果是本地扫描模式,输出提示 + if LocalScan { + fmt.Println("[*] 已启用本地扫描模式") + } + // 配置基本参数 if BruteThreads <= 0 { BruteThreads = 1 diff --git a/Common/Ports.go b/Common/Ports.go index 31440a7..2d8f2a6 100644 --- a/Common/Ports.go +++ b/Common/Ports.go @@ -1,7 +1,23 @@ package Common +import ( + "strconv" + "strings" +) + var ServicePorts = "21,22,23,135,139,445,1433,1521,2222,3306,3389,5432,6379,9000,11211,27017" var DbPorts = "1433,1521,3306,5432,6379,11211,27017" var WebPorts = "80,81,82,83,84,85,86,87,88,89,90,91,92,98,99,443,800,801,808,880,888,889,1000,1010,1080,1081,1082,1099,1118,1888,2008,2020,2100,2375,2379,3000,3008,3128,3505,5555,6080,6648,6868,7000,7001,7002,7003,7004,7005,7007,7008,7070,7071,7074,7078,7080,7088,7200,7680,7687,7688,7777,7890,8000,8001,8002,8003,8004,8006,8008,8009,8010,8011,8012,8016,8018,8020,8028,8030,8038,8042,8044,8046,8048,8053,8060,8069,8070,8080,8081,8082,8083,8084,8085,8086,8087,8088,8089,8090,8091,8092,8093,8094,8095,8096,8097,8098,8099,8100,8101,8108,8118,8161,8172,8180,8181,8200,8222,8244,8258,8280,8288,8300,8360,8443,8448,8484,8800,8834,8838,8848,8858,8868,8879,8880,8881,8888,8899,8983,8989,9000,9001,9002,9008,9010,9043,9060,9080,9081,9082,9083,9084,9085,9086,9087,9088,9089,9090,9091,9092,9093,9094,9095,9096,9097,9098,9099,9100,9200,9443,9448,9800,9981,9986,9988,9998,9999,10000,10001,10002,10004,10008,10010,10250,12018,12443,14000,16080,18000,18001,18002,18004,18008,18080,18082,18088,18090,18098,19001,20000,20720,21000,21501,21502,28018,20880" var AllPorts = "1-65535" var MainPorts = "21,22,23,80,81,135,139,443,445,1433,1521,3306,5432,6379,7001,8000,8080,8089,9000,9200,11211,27017" + +func ParsePortsFromString(portsStr string) []int { + var ports []int + portStrings := strings.Split(portsStr, ",") + for _, portStr := range portStrings { + if port, err := strconv.Atoi(portStr); err == nil { + ports = append(ports, port) + } + } + return ports +} diff --git a/Core/Registry.go b/Core/Registry.go index 0bdadc6..51e6fb1 100644 --- a/Core/Registry.go +++ b/Core/Registry.go @@ -20,7 +20,7 @@ func init() { }) Common.RegisterPlugin("telnet", Common.ScanPlugin{ - Name: "TELNET", + Name: "Telnet", Ports: []int{23}, ScanFunc: Plugins.TelnetScan, }) @@ -116,13 +116,16 @@ func init() { ScanFunc: Plugins.SmbGhost, }) + // web 相关插件添加 WebPorts 配置 Common.RegisterPlugin("web", Common.ScanPlugin{ Name: "WebTitle", + Ports: Common.ParsePortsFromString(Common.WebPorts), // 将 WebPorts 字符串解析为端口数组 ScanFunc: Plugins.WebTitle, }) Common.RegisterPlugin("webpoc", Common.ScanPlugin{ Name: "WebPoc", + Ports: Common.ParsePortsFromString(Common.WebPorts), // 将 WebPorts 字符串解析为端口数组 ScanFunc: Plugins.WebPoc, }) diff --git a/Core/Scanner.go b/Core/Scanner.go index 2b3c724..0c059da 100644 --- a/Core/Scanner.go +++ b/Core/Scanner.go @@ -19,7 +19,7 @@ func Scan(info Common.HostInfo) { wg := sync.WaitGroup{} // 本地信息收集模式 - if Common.IsLocalScan() { + if Common.LocalScan { executeScans([]Common.HostInfo{info}, &ch, &wg) finishScan(&wg) return @@ -107,38 +107,47 @@ func prepareTargetInfos(alivePorts []string, baseInfo Common.HostInfo) []Common. return infos } -// executeScans 统一执行扫描任务 func executeScans(targets []Common.HostInfo, ch *chan struct{}, wg *sync.WaitGroup) { mode := Common.GetScanMode() + var pluginsToRun []string - // 判断是否是预设模式(大写开头) + // 获取要执行的插件列表 if plugins := Common.GetPluginsForMode(mode); plugins != nil { - // 使用预设模式的插件组 - for _, target := range targets { - targetPort, _ := strconv.Atoi(target.Ports) // 转换目标端口为整数 - for _, pluginName := range plugins { - // 获取插件信息 - plugin, exists := Common.PluginManager[pluginName] - if !exists { - continue - } + // 预设模式下使用配置的插件组 + pluginsToRun = plugins + } else { + // 单插件模式下只包含指定的插件 + pluginsToRun = []string{mode} + } - // 检查插件是否有默认端口配置 - if len(plugin.Ports) > 0 { - // 只有当目标端口在插件支持的端口列表中才执行 - if plugin.HasPort(targetPort) { - AddScan(pluginName, target, ch, wg) - } - } else { - // 对于没有指定端口的插件,始终执行 + // 统一处理所有目标和插件 + for _, target := range targets { + targetPort, _ := strconv.Atoi(target.Ports) + + for _, pluginName := range pluginsToRun { + // 获取插件信息 + plugin, exists := Common.PluginManager[pluginName] + if !exists { + continue + } + + // 本地扫描模式的特殊处理 + if Common.LocalScan { + // 只执行没有端口配置的插件 + if len(plugin.Ports) == 0 { AddScan(pluginName, target, ch, wg) } + continue + } + + // 非本地扫描模式的常规处理 + if len(plugin.Ports) > 0 { + if plugin.HasPort(targetPort) { + AddScan(pluginName, target, ch, wg) + } + } else { + AddScan(pluginName, target, ch, wg) } - } - } else { - // 使用单个插件模式,直接执行不做端口检查 - for _, target := range targets { - AddScan(mode, target, ch, wg) } } }