mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-07-14 05:12:36 +08:00
refactor: 端口支持改为列表
This commit is contained in:
parent
8f1c5dbae9
commit
375a1e4673
@ -317,33 +317,33 @@ func ParseInput(Info *HostInfo) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// showmode 显示所有支持的扫描类型
|
//// showmode 显示所有支持的扫描类型
|
||||||
func showmode() {
|
//func showmode() {
|
||||||
fmt.Println("[!] 指定的扫描类型不存在")
|
// fmt.Println("[!] 指定的扫描类型不存在")
|
||||||
fmt.Println("[*] 支持的扫描类型:")
|
// fmt.Println("[*] 支持的扫描类型:")
|
||||||
|
//
|
||||||
// 显示常规服务扫描类型
|
// // 显示常规服务扫描类型
|
||||||
fmt.Println("\n[+] 常规服务扫描:")
|
// fmt.Println("\n[+] 常规服务扫描:")
|
||||||
for name, plugin := range PluginManager {
|
// for name, plugin := range PluginManager {
|
||||||
if plugin.Port > 0 && plugin.Port < 1000000 {
|
// if plugin.Port > 0 && plugin.Port < 1000000 {
|
||||||
fmt.Printf(" - %-10s (端口: %d)\n", name, plugin.Port)
|
// fmt.Printf(" - %-10s (端口: %d)\n", name, plugin.Port)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// 显示特殊漏洞扫描类型
|
// // 显示特殊漏洞扫描类型
|
||||||
fmt.Println("\n[+] 特殊漏洞扫描:")
|
// fmt.Println("\n[+] 特殊漏洞扫描:")
|
||||||
for name, plugin := range PluginManager {
|
// for name, plugin := range PluginManager {
|
||||||
if plugin.Port >= 1000000 || plugin.Port == 0 {
|
// if plugin.Port >= 1000000 || plugin.Port == 0 {
|
||||||
fmt.Printf(" - %-10s\n", name)
|
// fmt.Printf(" - %-10s\n", name)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// 显示其他扫描类型
|
// // 显示其他扫描类型
|
||||||
fmt.Println("\n[+] 其他扫描类型:")
|
// fmt.Println("\n[+] 其他扫描类型:")
|
||||||
specialTypes := []string{"all", "portscan", "icmp", "main", "webonly", "webpoc"}
|
// specialTypes := []string{"all", "portscan", "icmp", "main", "webonly", "webpoc"}
|
||||||
for _, name := range specialTypes {
|
// for _, name := range specialTypes {
|
||||||
fmt.Printf(" - %s\n", name)
|
// fmt.Printf(" - %s\n", name)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
os.Exit(0)
|
// os.Exit(0)
|
||||||
}
|
//}
|
||||||
|
@ -11,10 +11,26 @@ type HostInfo struct {
|
|||||||
// ScanPlugin 定义扫描插件的结构
|
// ScanPlugin 定义扫描插件的结构
|
||||||
type ScanPlugin struct {
|
type ScanPlugin struct {
|
||||||
Name string // 插件名称
|
Name string // 插件名称
|
||||||
Port int // 关联的端口号,0表示特殊扫描类型
|
Ports []int // 关联的端口列表,空切片表示特殊扫描类型
|
||||||
ScanFunc func(*HostInfo) error // 扫描函数
|
ScanFunc func(*HostInfo) error // 扫描函数
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasPort 检查插件是否支持指定端口
|
||||||
|
func (p *ScanPlugin) HasPort(port int) bool {
|
||||||
|
// 如果没有指定端口列表,表示支持所有端口
|
||||||
|
if len(p.Ports) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查端口是否在支持列表中
|
||||||
|
for _, supportedPort := range p.Ports {
|
||||||
|
if port == supportedPort {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// PluginManager 管理插件注册
|
// PluginManager 管理插件注册
|
||||||
var PluginManager = make(map[string]ScanPlugin)
|
var PluginManager = make(map[string]ScanPlugin)
|
||||||
|
|
||||||
|
@ -9,104 +9,104 @@ func init() {
|
|||||||
// 注册标准端口服务扫描
|
// 注册标准端口服务扫描
|
||||||
Common.RegisterPlugin("ftp", Common.ScanPlugin{
|
Common.RegisterPlugin("ftp", Common.ScanPlugin{
|
||||||
Name: "FTP",
|
Name: "FTP",
|
||||||
Port: 21,
|
Ports: []int{21},
|
||||||
ScanFunc: Plugins.FtpScan,
|
ScanFunc: Plugins.FtpScan,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("ssh", Common.ScanPlugin{
|
Common.RegisterPlugin("ssh", Common.ScanPlugin{
|
||||||
Name: "SSH",
|
Name: "SSH",
|
||||||
Port: 22,
|
Ports: []int{22},
|
||||||
ScanFunc: Plugins.SshScan,
|
ScanFunc: Plugins.SshScan,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("findnet", Common.ScanPlugin{
|
Common.RegisterPlugin("findnet", Common.ScanPlugin{
|
||||||
Name: "FindNet",
|
Name: "FindNet",
|
||||||
Port: 135,
|
Ports: []int{135},
|
||||||
ScanFunc: Plugins.Findnet,
|
ScanFunc: Plugins.Findnet,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("netbios", Common.ScanPlugin{
|
Common.RegisterPlugin("netbios", Common.ScanPlugin{
|
||||||
Name: "NetBIOS",
|
Name: "NetBIOS",
|
||||||
Port: 139,
|
Ports: []int{139},
|
||||||
ScanFunc: Plugins.NetBIOS,
|
ScanFunc: Plugins.NetBIOS,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("smb", Common.ScanPlugin{
|
Common.RegisterPlugin("smb", Common.ScanPlugin{
|
||||||
Name: "SMB",
|
Name: "SMB",
|
||||||
Port: 445,
|
Ports: []int{445},
|
||||||
ScanFunc: Plugins.SmbScan,
|
ScanFunc: Plugins.SmbScan,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("mssql", Common.ScanPlugin{
|
Common.RegisterPlugin("mssql", Common.ScanPlugin{
|
||||||
Name: "MSSQL",
|
Name: "MSSQL",
|
||||||
Port: 1433,
|
Ports: []int{1433, 1434}, // 支持多个端口
|
||||||
ScanFunc: Plugins.MssqlScan,
|
ScanFunc: Plugins.MssqlScan,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("oracle", Common.ScanPlugin{
|
Common.RegisterPlugin("oracle", Common.ScanPlugin{
|
||||||
Name: "Oracle",
|
Name: "Oracle",
|
||||||
Port: 1521,
|
Ports: []int{1521, 1522, 1526}, // Oracle 可能的多个端口
|
||||||
ScanFunc: Plugins.OracleScan,
|
ScanFunc: Plugins.OracleScan,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("mysql", Common.ScanPlugin{
|
Common.RegisterPlugin("mysql", Common.ScanPlugin{
|
||||||
Name: "MySQL",
|
Name: "MySQL",
|
||||||
Port: 3306,
|
Ports: []int{3306, 3307}, // MySQL 可能的端口
|
||||||
ScanFunc: Plugins.MysqlScan,
|
ScanFunc: Plugins.MysqlScan,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("rdp", Common.ScanPlugin{
|
Common.RegisterPlugin("rdp", Common.ScanPlugin{
|
||||||
Name: "RDP",
|
Name: "RDP",
|
||||||
Port: 3389,
|
Ports: []int{3389},
|
||||||
ScanFunc: Plugins.RdpScan,
|
ScanFunc: Plugins.RdpScan,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("postgres", Common.ScanPlugin{
|
Common.RegisterPlugin("postgres", Common.ScanPlugin{
|
||||||
Name: "PostgreSQL",
|
Name: "PostgreSQL",
|
||||||
Port: 5432,
|
Ports: []int{5432, 5433}, // PostgreSQL 可能的端口
|
||||||
ScanFunc: Plugins.PostgresScan,
|
ScanFunc: Plugins.PostgresScan,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("vnc", Common.ScanPlugin{
|
Common.RegisterPlugin("vnc", Common.ScanPlugin{
|
||||||
Name: "VNC",
|
Name: "VNC",
|
||||||
Port: 5900,
|
Ports: []int{5900, 5901, 5902}, // VNC 可能的端口
|
||||||
ScanFunc: Plugins.VncScan,
|
ScanFunc: Plugins.VncScan,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("redis", Common.ScanPlugin{
|
Common.RegisterPlugin("redis", Common.ScanPlugin{
|
||||||
Name: "Redis",
|
Name: "Redis",
|
||||||
Port: 6379,
|
Ports: []int{6379, 6380}, // Redis 可能的端口
|
||||||
ScanFunc: Plugins.RedisScan,
|
ScanFunc: Plugins.RedisScan,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("fcgi", Common.ScanPlugin{
|
Common.RegisterPlugin("fcgi", Common.ScanPlugin{
|
||||||
Name: "FastCGI",
|
Name: "FastCGI",
|
||||||
Port: 9000,
|
Ports: []int{9000},
|
||||||
ScanFunc: Plugins.FcgiScan,
|
ScanFunc: Plugins.FcgiScan,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("memcached", Common.ScanPlugin{
|
Common.RegisterPlugin("memcached", Common.ScanPlugin{
|
||||||
Name: "Memcached",
|
Name: "Memcached",
|
||||||
Port: 11211,
|
Ports: []int{11211},
|
||||||
ScanFunc: Plugins.MemcachedScan,
|
ScanFunc: Plugins.MemcachedScan,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("mongodb", Common.ScanPlugin{
|
Common.RegisterPlugin("mongodb", Common.ScanPlugin{
|
||||||
Name: "MongoDB",
|
Name: "MongoDB",
|
||||||
Port: 27017,
|
Ports: []int{27017, 27018}, // MongoDB 可能的端口
|
||||||
ScanFunc: Plugins.MongodbScan,
|
ScanFunc: Plugins.MongodbScan,
|
||||||
})
|
})
|
||||||
|
|
||||||
// 注册特殊扫描类型
|
// 注册特殊扫描类型
|
||||||
Common.RegisterPlugin("ms17010", Common.ScanPlugin{
|
Common.RegisterPlugin("ms17010", Common.ScanPlugin{
|
||||||
Name: "MS17010",
|
Name: "MS17010",
|
||||||
Port: 445,
|
Ports: []int{445},
|
||||||
ScanFunc: Plugins.MS17010,
|
ScanFunc: Plugins.MS17010,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("smbghost", Common.ScanPlugin{
|
Common.RegisterPlugin("smbghost", Common.ScanPlugin{
|
||||||
Name: "SMBGhost",
|
Name: "SMBGhost",
|
||||||
Port: 445,
|
Ports: []int{445},
|
||||||
ScanFunc: Plugins.SmbGhost,
|
ScanFunc: Plugins.SmbGhost,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -122,18 +122,19 @@ func init() {
|
|||||||
|
|
||||||
Common.RegisterPlugin("smb2", Common.ScanPlugin{
|
Common.RegisterPlugin("smb2", Common.ScanPlugin{
|
||||||
Name: "SMBScan2",
|
Name: "SMBScan2",
|
||||||
Port: 445,
|
Ports: []int{445},
|
||||||
ScanFunc: Plugins.SmbScan2,
|
ScanFunc: Plugins.SmbScan2,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("wmiexec", Common.ScanPlugin{
|
Common.RegisterPlugin("wmiexec", Common.ScanPlugin{
|
||||||
Name: "WMIExec",
|
Name: "WMIExec",
|
||||||
Port: 135,
|
Ports: []int{135},
|
||||||
ScanFunc: Plugins.WmiExec,
|
ScanFunc: Plugins.WmiExec,
|
||||||
})
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("localinfo", Common.ScanPlugin{
|
Common.RegisterPlugin("localinfo", Common.ScanPlugin{
|
||||||
Name: "LocalInfo",
|
Name: "LocalInfo",
|
||||||
|
Ports: []int{}, // 本地信息收集不需要端口
|
||||||
ScanFunc: Plugins.LocalInfoScan,
|
ScanFunc: Plugins.LocalInfoScan,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ func executeScans(targets []Common.HostInfo, ch *chan struct{}, wg *sync.WaitGro
|
|||||||
if plugins := Common.GetPluginsForMode(mode); plugins != nil {
|
if plugins := Common.GetPluginsForMode(mode); plugins != nil {
|
||||||
// 使用预设模式的插件组
|
// 使用预设模式的插件组
|
||||||
for _, target := range targets {
|
for _, target := range targets {
|
||||||
targetPort := target.Ports // 目标端口
|
targetPort, _ := strconv.Atoi(target.Ports) // 转换目标端口为整数
|
||||||
for _, pluginName := range plugins {
|
for _, pluginName := range plugins {
|
||||||
// 获取插件信息
|
// 获取插件信息
|
||||||
plugin, exists := Common.PluginManager[pluginName]
|
plugin, exists := Common.PluginManager[pluginName]
|
||||||
@ -124,20 +124,19 @@ func executeScans(targets []Common.HostInfo, ch *chan struct{}, wg *sync.WaitGro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检查插件是否有默认端口配置
|
// 检查插件是否有默认端口配置
|
||||||
if plugin.Port != 0 {
|
if len(plugin.Ports) > 0 {
|
||||||
// 只有当目标端口匹配插件默认端口时才执行
|
// 只有当目标端口在插件支持的端口列表中才执行
|
||||||
if targetPort == strconv.Itoa(plugin.Port) {
|
if plugin.HasPort(targetPort) {
|
||||||
AddScan(pluginName, target, ch, wg)
|
AddScan(pluginName, target, ch, wg)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 对于没有默认端口的插件(如web扫描),始终执行
|
// 对于没有指定端口的插件,始终执行
|
||||||
AddScan(pluginName, target, ch, wg)
|
AddScan(pluginName, target, ch, wg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 使用单个插件
|
// 使用单个插件模式,直接执行不做端口检查
|
||||||
// 对于单个插件模式,不进行端口匹配检查,直接执行
|
|
||||||
for _, target := range targets {
|
for _, target := range targets {
|
||||||
AddScan(mode, target, ch, wg)
|
AddScan(mode, target, ch, wg)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user