refactor: 大型重构

This commit is contained in:
ZacharyZcR
2024-12-20 03:46:09 +08:00
parent c0b7f4ca4f
commit bdeabec67e
27 changed files with 227 additions and 232 deletions
+2 -2
View File
@@ -29,7 +29,7 @@ func PortScan(hostslist []string, ports string, timeout int64) []string {
probePorts = excludeNoPorts(probePorts)
// 创建通道
workers := Common.Threads
workers := Common.ThreadNum
addrs := make(chan Addr, 100)
results := make(chan string, 100)
var wg sync.WaitGroup
@@ -110,7 +110,7 @@ func NoPortScan(hostslist []string, ports string) []string {
// excludeNoPorts 排除指定的端口
func excludeNoPorts(ports []int) []int {
noPorts := Common.ParsePort(Common.NoPorts)
noPorts := Common.ParsePort(Common.ExcludePorts)
if len(noPorts) == 0 {
return ports
}
+11 -11
View File
@@ -13,8 +13,8 @@ func Scan(info Common.HostInfo) {
fmt.Println("[*] 开始信息扫描...")
// 本地信息收集模块
if Common.Scantype == "localinfo" {
ch := make(chan struct{}, Common.Threads)
if Common.ScanMode == "localinfo" {
ch := make(chan struct{}, Common.ThreadNum)
wg := sync.WaitGroup{}
AddScan("localinfo", info, &ch, &wg)
wg.Wait()
@@ -25,7 +25,7 @@ func Scan(info Common.HostInfo) {
}
// 解析目标主机IP
Hosts, err := Common.ParseIP(info.Host, Common.HostFile, Common.NoHosts)
Hosts, err := Common.ParseIP(info.Host, Common.HostsFile, Common.ExcludeHosts)
if err != nil {
fmt.Printf("[!] 解析主机错误: %v\n", err)
return
@@ -33,23 +33,23 @@ func Scan(info Common.HostInfo) {
// 初始化配置
lib.Inithttp()
ch := make(chan struct{}, Common.Threads)
ch := make(chan struct{}, Common.ThreadNum)
wg := sync.WaitGroup{}
var AlivePorts []string
if len(Hosts) > 0 || len(Common.HostPort) > 0 {
// ICMP存活性检测
if (Common.NoPing == false && len(Hosts) > 1) || Common.Scantype == "icmp" {
Hosts = CheckLive(Hosts, Common.Ping)
if (Common.DisablePing == false && len(Hosts) > 1) || Common.ScanMode == "icmp" {
Hosts = CheckLive(Hosts, Common.UsePing)
fmt.Printf("[+] ICMP存活主机数量: %d\n", len(Hosts))
if Common.Scantype == "icmp" {
if Common.ScanMode == "icmp" {
Common.LogWG.Wait()
return
}
}
// 端口扫描策略
AlivePorts = executeScanStrategy(Hosts, Common.Scantype)
AlivePorts = executeScanStrategy(Hosts, Common.ScanMode)
// 处理自定义端口
if len(Common.HostPort) > 0 {
@@ -69,12 +69,12 @@ func Scan(info Common.HostInfo) {
}
info.Host, info.Ports = hostParts[0], hostParts[1]
executeScanTasks(info, Common.Scantype, &ch, &wg)
executeScanTasks(info, Common.ScanMode, &ch, &wg)
}
}
// URL扫描
for _, url := range Common.Urls {
for _, url := range Common.URLs {
info.Url = url
AddScan("web", info, &ch, &wg)
}
@@ -115,7 +115,7 @@ func executeScanTasks(info Common.HostInfo, scanType string, ch *chan struct{},
switch info.Ports {
case "135":
AddScan("findnet", info, ch, wg)
if Common.IsWmi {
if Common.EnableWmi {
AddScan("wmiexec", info, ch, wg)
}
case "445":