2024-12-18 22:00:18 +08:00
|
|
|
package Common
|
2020-12-29 17:17:10 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
2022-11-19 17:04:13 +08:00
|
|
|
"encoding/hex"
|
2020-12-29 17:17:10 +08:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
2022-11-19 17:04:13 +08:00
|
|
|
"net/url"
|
2020-12-29 17:17:10 +08:00
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2024-12-19 16:15:53 +08:00
|
|
|
func Parse(Info *HostInfo) {
|
2022-07-03 23:41:39 +08:00
|
|
|
ParseUser()
|
2020-12-29 17:17:10 +08:00
|
|
|
ParsePass(Info)
|
|
|
|
ParseInput(Info)
|
|
|
|
}
|
|
|
|
|
2024-12-18 22:06:38 +08:00
|
|
|
// ParseUser 解析用户名配置,支持直接指定用户名列表或从文件读取
|
|
|
|
func ParseUser() error {
|
|
|
|
// 如果未指定用户名和用户名文件,直接返回
|
2024-12-20 03:46:09 +08:00
|
|
|
if Username == "" && UsersFile == "" {
|
2024-12-18 22:06:38 +08:00
|
|
|
return nil
|
2021-09-11 16:43:38 +08:00
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
|
|
|
|
var usernames []string
|
|
|
|
|
|
|
|
// 处理直接指定的用户名列表
|
2022-07-03 23:41:39 +08:00
|
|
|
if Username != "" {
|
2024-12-18 22:06:38 +08:00
|
|
|
usernames = strings.Split(Username, ",")
|
|
|
|
fmt.Printf("[*] 已加载直接指定的用户名: %d 个\n", len(usernames))
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
2021-09-11 16:43:38 +08:00
|
|
|
|
2024-12-18 22:06:38 +08:00
|
|
|
// 从文件加载用户名列表
|
2024-12-20 03:46:09 +08:00
|
|
|
if UsersFile != "" {
|
|
|
|
users, err := Readfile(UsersFile)
|
2024-12-18 22:06:38 +08:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("读取用户名文件失败: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 过滤空用户名
|
|
|
|
for _, user := range users {
|
|
|
|
if user != "" {
|
|
|
|
usernames = append(usernames, user)
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
fmt.Printf("[*] 已从文件加载用户名: %d 个\n", len(users))
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
|
2024-12-18 22:06:38 +08:00
|
|
|
// 去重处理
|
|
|
|
usernames = RemoveDuplicate(usernames)
|
|
|
|
fmt.Printf("[*] 去重后用户名总数: %d 个\n", len(usernames))
|
|
|
|
|
|
|
|
// 更新用户字典
|
2021-09-11 16:43:38 +08:00
|
|
|
for name := range Userdict {
|
2024-12-18 22:06:38 +08:00
|
|
|
Userdict[name] = usernames
|
2021-09-11 16:43:38 +08:00
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
|
|
|
|
return nil
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
|
2024-12-18 22:06:38 +08:00
|
|
|
// ParsePass 解析密码、哈希值、URL和端口配置
|
2024-12-19 16:15:53 +08:00
|
|
|
func ParsePass(Info *HostInfo) error {
|
2024-12-18 22:06:38 +08:00
|
|
|
// 处理直接指定的密码列表
|
|
|
|
var pwdList []string
|
2022-07-03 23:41:39 +08:00
|
|
|
if Password != "" {
|
2024-12-18 22:06:38 +08:00
|
|
|
passes := strings.Split(Password, ",")
|
|
|
|
for _, pass := range passes {
|
2020-12-29 17:17:10 +08:00
|
|
|
if pass != "" {
|
2024-12-18 22:06:38 +08:00
|
|
|
pwdList = append(pwdList, pass)
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
Passwords = pwdList
|
|
|
|
fmt.Printf("[*] 已加载直接指定的密码: %d 个\n", len(pwdList))
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
|
|
|
|
// 从文件加载密码列表
|
2024-12-20 03:46:09 +08:00
|
|
|
if PasswordsFile != "" {
|
|
|
|
passes, err := Readfile(PasswordsFile)
|
2024-12-18 22:06:38 +08:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("读取密码文件失败: %v", err)
|
|
|
|
}
|
|
|
|
for _, pass := range passes {
|
|
|
|
if pass != "" {
|
|
|
|
pwdList = append(pwdList, pass)
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
2021-03-04 14:42:10 +08:00
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
Passwords = pwdList
|
|
|
|
fmt.Printf("[*] 已从文件加载密码: %d 个\n", len(passes))
|
2021-03-04 14:42:10 +08:00
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
|
|
|
|
// 处理哈希文件
|
2024-12-20 03:46:09 +08:00
|
|
|
if HashFile != "" {
|
|
|
|
hashes, err := Readfile(HashFile)
|
2024-12-18 22:06:38 +08:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("读取哈希文件失败: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
validCount := 0
|
|
|
|
for _, line := range hashes {
|
|
|
|
if line == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if len(line) == 32 {
|
2024-12-20 03:46:09 +08:00
|
|
|
HashValues = append(HashValues, line)
|
2024-12-18 22:06:38 +08:00
|
|
|
validCount++
|
|
|
|
} else {
|
|
|
|
fmt.Printf("[!] 无效的哈希值(长度!=32): %s\n", line)
|
2024-08-29 15:12:30 +08:00
|
|
|
}
|
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
fmt.Printf("[*] 已加载有效哈希值: %d 个\n", validCount)
|
2024-08-29 15:12:30 +08:00
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
|
|
|
|
// 处理直接指定的URL列表
|
2024-12-20 03:46:09 +08:00
|
|
|
if TargetURL != "" {
|
|
|
|
urls := strings.Split(TargetURL, ",")
|
2024-12-18 22:06:38 +08:00
|
|
|
tmpUrls := make(map[string]struct{})
|
2022-07-06 21:42:00 +08:00
|
|
|
for _, url := range urls {
|
2024-12-18 22:06:38 +08:00
|
|
|
if url != "" {
|
|
|
|
if _, ok := tmpUrls[url]; !ok {
|
|
|
|
tmpUrls[url] = struct{}{}
|
2024-12-20 03:46:09 +08:00
|
|
|
URLs = append(URLs, url)
|
2022-07-06 21:42:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-12-20 03:46:09 +08:00
|
|
|
fmt.Printf("[*] 已加载直接指定的URL: %d 个\n", len(URLs))
|
2022-07-06 21:42:00 +08:00
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
|
|
|
|
// 从文件加载URL列表
|
2024-12-20 03:46:09 +08:00
|
|
|
if URLsFile != "" {
|
|
|
|
urls, err := Readfile(URLsFile)
|
2024-12-18 22:06:38 +08:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("读取URL文件失败: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
tmpUrls := make(map[string]struct{})
|
|
|
|
for _, url := range urls {
|
|
|
|
if url != "" {
|
|
|
|
if _, ok := tmpUrls[url]; !ok {
|
|
|
|
tmpUrls[url] = struct{}{}
|
2024-12-20 03:46:09 +08:00
|
|
|
URLs = append(URLs, url)
|
2021-03-04 14:42:10 +08:00
|
|
|
}
|
|
|
|
}
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
fmt.Printf("[*] 已从文件加载URL: %d 个\n", len(urls))
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
|
|
|
|
// 从文件加载端口列表
|
2024-12-20 03:46:09 +08:00
|
|
|
if PortsFile != "" {
|
|
|
|
ports, err := Readfile(PortsFile)
|
2024-12-18 22:06:38 +08:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("读取端口文件失败: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var newport strings.Builder
|
|
|
|
for _, port := range ports {
|
|
|
|
if port != "" {
|
|
|
|
newport.WriteString(port)
|
|
|
|
newport.WriteString(",")
|
2022-04-20 17:45:27 +08:00
|
|
|
}
|
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
Ports = newport.String()
|
|
|
|
fmt.Printf("[*] 已从文件加载端口配置\n")
|
2022-04-20 17:45:27 +08:00
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
|
|
|
|
return nil
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
|
2024-12-18 22:06:38 +08:00
|
|
|
// Readfile 读取文件内容并返回非空行的切片
|
2020-12-29 17:17:10 +08:00
|
|
|
func Readfile(filename string) ([]string, error) {
|
2024-12-18 22:06:38 +08:00
|
|
|
// 打开文件
|
2020-12-29 17:17:10 +08:00
|
|
|
file, err := os.Open(filename)
|
|
|
|
if err != nil {
|
2024-12-18 22:06:38 +08:00
|
|
|
fmt.Printf("[!] 打开文件 %s 失败: %v\n", filename, err)
|
|
|
|
return nil, err
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
defer file.Close()
|
2024-12-18 22:06:38 +08:00
|
|
|
|
2020-12-29 17:17:10 +08:00
|
|
|
var content []string
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
scanner.Split(bufio.ScanLines)
|
2024-12-18 22:06:38 +08:00
|
|
|
|
|
|
|
// 逐行读取文件内容
|
|
|
|
lineCount := 0
|
2020-12-29 17:17:10 +08:00
|
|
|
for scanner.Scan() {
|
|
|
|
text := strings.TrimSpace(scanner.Text())
|
|
|
|
if text != "" {
|
2024-12-18 22:06:38 +08:00
|
|
|
content = append(content, text)
|
|
|
|
lineCount++
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
|
|
|
|
// 检查扫描过程中是否有错误
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
fmt.Printf("[!] 读取文件 %s 时出错: %v\n", filename, err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("[*] 成功读取文件 %s: %d 行\n", filename, lineCount)
|
2020-12-29 17:17:10 +08:00
|
|
|
return content, nil
|
|
|
|
}
|
|
|
|
|
2024-12-18 22:06:38 +08:00
|
|
|
// ParseInput 解析和验证输入参数配置
|
2024-12-19 16:15:53 +08:00
|
|
|
func ParseInput(Info *HostInfo) error {
|
2024-12-18 22:06:38 +08:00
|
|
|
// 检查必要的目标参数
|
2024-12-20 03:46:09 +08:00
|
|
|
if Info.Host == "" && HostsFile == "" && TargetURL == "" && URLsFile == "" {
|
2024-12-18 22:06:38 +08:00
|
|
|
fmt.Println("[!] 未指定扫描目标")
|
2020-12-29 17:17:10 +08:00
|
|
|
flag.Usage()
|
2024-12-18 22:06:38 +08:00
|
|
|
return fmt.Errorf("必须指定扫描目标")
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
2021-03-30 22:30:16 +08:00
|
|
|
|
2024-12-18 22:06:38 +08:00
|
|
|
// 配置基本参数
|
2024-12-20 03:46:09 +08:00
|
|
|
if BruteThreads <= 0 {
|
|
|
|
BruteThreads = 1
|
|
|
|
fmt.Printf("[*] 已将暴力破解线程数设置为: %d\n", BruteThreads)
|
2022-04-28 17:02:48 +08:00
|
|
|
}
|
2022-11-30 10:49:02 +08:00
|
|
|
|
2024-12-20 03:46:09 +08:00
|
|
|
if DisableSave {
|
2020-12-29 17:17:10 +08:00
|
|
|
IsSave = false
|
2024-12-18 22:06:38 +08:00
|
|
|
fmt.Println("[*] 已启用临时保存模式")
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
2022-07-02 17:25:15 +08:00
|
|
|
|
2024-12-18 22:06:38 +08:00
|
|
|
// 处理端口配置
|
2024-12-20 03:46:09 +08:00
|
|
|
if Ports == MainPorts {
|
|
|
|
Ports += "," + WebPorts
|
2021-04-21 00:13:04 +08:00
|
|
|
}
|
2021-12-07 17:01:21 +08:00
|
|
|
|
2024-12-20 03:46:09 +08:00
|
|
|
if AddPorts != "" {
|
2023-11-13 16:23:19 +08:00
|
|
|
if strings.HasSuffix(Ports, ",") {
|
2024-12-20 03:46:09 +08:00
|
|
|
Ports += AddPorts
|
2021-12-07 17:01:21 +08:00
|
|
|
} else {
|
2024-12-20 03:46:09 +08:00
|
|
|
Ports += "," + AddPorts
|
2021-12-07 17:01:21 +08:00
|
|
|
}
|
2024-12-20 03:46:09 +08:00
|
|
|
fmt.Printf("[*] 已添加额外端口: %s\n", AddPorts)
|
2021-12-07 17:01:21 +08:00
|
|
|
}
|
2022-01-07 10:51:36 +08:00
|
|
|
|
2024-12-18 22:06:38 +08:00
|
|
|
// 处理用户名配置
|
2024-12-20 03:46:09 +08:00
|
|
|
if AddUsers != "" {
|
|
|
|
users := strings.Split(AddUsers, ",")
|
2024-12-18 22:06:38 +08:00
|
|
|
for dict := range Userdict {
|
|
|
|
Userdict[dict] = append(Userdict[dict], users...)
|
|
|
|
Userdict[dict] = RemoveDuplicate(Userdict[dict])
|
2022-01-07 10:51:36 +08:00
|
|
|
}
|
2024-12-20 03:46:09 +08:00
|
|
|
fmt.Printf("[*] 已添加额外用户名: %s\n", AddUsers)
|
2022-01-07 10:51:36 +08:00
|
|
|
}
|
|
|
|
|
2024-12-18 22:06:38 +08:00
|
|
|
// 处理密码配置
|
2024-12-20 03:46:09 +08:00
|
|
|
if AddPasswords != "" {
|
|
|
|
passes := strings.Split(AddPasswords, ",")
|
2024-12-18 22:06:38 +08:00
|
|
|
Passwords = append(Passwords, passes...)
|
2022-01-07 10:51:36 +08:00
|
|
|
Passwords = RemoveDuplicate(Passwords)
|
2024-12-20 03:46:09 +08:00
|
|
|
fmt.Printf("[*] 已添加额外密码: %s\n", AddPasswords)
|
2022-01-07 10:51:36 +08:00
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
|
|
|
|
// 处理Socks5代理配置
|
2022-11-19 17:04:13 +08:00
|
|
|
if Socks5Proxy != "" {
|
2024-12-18 22:06:38 +08:00
|
|
|
if !strings.HasPrefix(Socks5Proxy, "socks5://") {
|
|
|
|
if !strings.Contains(Socks5Proxy, ":") {
|
|
|
|
Socks5Proxy = "socks5://127.0.0.1" + Socks5Proxy
|
|
|
|
} else {
|
|
|
|
Socks5Proxy = "socks5://" + Socks5Proxy
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-19 17:04:13 +08:00
|
|
|
_, err := url.Parse(Socks5Proxy)
|
|
|
|
if err != nil {
|
2024-12-18 22:06:38 +08:00
|
|
|
return fmt.Errorf("Socks5代理格式错误: %v", err)
|
2022-11-19 17:04:13 +08:00
|
|
|
}
|
2024-12-20 03:46:09 +08:00
|
|
|
DisablePing = true
|
2024-12-18 22:06:38 +08:00
|
|
|
fmt.Printf("[*] 使用Socks5代理: %s\n", Socks5Proxy)
|
2022-07-02 17:25:15 +08:00
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
|
|
|
|
// 处理HTTP代理配置
|
2024-12-20 03:46:09 +08:00
|
|
|
if HttpProxy != "" {
|
|
|
|
switch HttpProxy {
|
2024-12-18 22:06:38 +08:00
|
|
|
case "1":
|
2024-12-20 03:46:09 +08:00
|
|
|
HttpProxy = "http://127.0.0.1:8080"
|
2024-12-18 22:06:38 +08:00
|
|
|
case "2":
|
2024-12-20 03:46:09 +08:00
|
|
|
HttpProxy = "socks5://127.0.0.1:1080"
|
2024-12-18 22:06:38 +08:00
|
|
|
default:
|
2024-12-20 03:46:09 +08:00
|
|
|
if !strings.Contains(HttpProxy, "://") {
|
|
|
|
HttpProxy = "http://127.0.0.1:" + HttpProxy
|
2024-12-18 22:06:38 +08:00
|
|
|
}
|
2022-11-19 17:04:13 +08:00
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
|
2024-12-20 03:46:09 +08:00
|
|
|
if !strings.HasPrefix(HttpProxy, "socks") && !strings.HasPrefix(HttpProxy, "http") {
|
2024-12-18 22:06:38 +08:00
|
|
|
return fmt.Errorf("不支持的代理类型")
|
2022-11-19 17:04:13 +08:00
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
|
2024-12-20 03:46:09 +08:00
|
|
|
_, err := url.Parse(HttpProxy)
|
2022-11-19 17:04:13 +08:00
|
|
|
if err != nil {
|
2024-12-18 22:06:38 +08:00
|
|
|
return fmt.Errorf("代理格式错误: %v", err)
|
2022-11-19 17:04:13 +08:00
|
|
|
}
|
2024-12-20 03:46:09 +08:00
|
|
|
fmt.Printf("[*] 使用代理: %s\n", HttpProxy)
|
2022-11-19 17:04:13 +08:00
|
|
|
}
|
|
|
|
|
2024-12-18 22:06:38 +08:00
|
|
|
// 处理Hash配置
|
2024-12-20 03:46:09 +08:00
|
|
|
if HashValue != "" {
|
|
|
|
if len(HashValue) != 32 {
|
2024-12-18 22:06:38 +08:00
|
|
|
return fmt.Errorf("Hash长度必须为32位")
|
|
|
|
}
|
2024-12-20 03:46:09 +08:00
|
|
|
HashValues = append(HashValues, HashValue)
|
2024-08-29 15:12:30 +08:00
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
|
|
|
|
// 处理Hash列表
|
2024-12-20 03:46:09 +08:00
|
|
|
HashValues = RemoveDuplicate(HashValues)
|
|
|
|
for _, hash := range HashValues {
|
2024-12-18 22:06:38 +08:00
|
|
|
hashByte, err := hex.DecodeString(hash)
|
2022-11-19 17:04:13 +08:00
|
|
|
if err != nil {
|
2024-12-18 22:06:38 +08:00
|
|
|
fmt.Printf("[!] Hash解码失败: %s\n", hash)
|
2024-08-29 15:12:30 +08:00
|
|
|
continue
|
2022-11-19 17:04:13 +08:00
|
|
|
}
|
2024-12-18 22:06:38 +08:00
|
|
|
HashBytes = append(HashBytes, hashByte)
|
2022-11-19 17:04:13 +08:00
|
|
|
}
|
2024-12-20 03:46:09 +08:00
|
|
|
HashValues = []string{}
|
2024-12-18 22:06:38 +08:00
|
|
|
|
|
|
|
return nil
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
|
2024-12-18 21:56:08 +08:00
|
|
|
// showmode 显示所有支持的扫描类型
|
2021-03-09 17:21:27 +08:00
|
|
|
func showmode() {
|
2024-12-18 21:56:08 +08:00
|
|
|
fmt.Println("[!] 指定的扫描类型不存在")
|
|
|
|
fmt.Println("[*] 支持的扫描类型:")
|
|
|
|
|
|
|
|
// 显示常规服务扫描类型
|
|
|
|
fmt.Println("\n[+] 常规服务扫描:")
|
2024-12-19 16:15:53 +08:00
|
|
|
for name, plugin := range PluginManager {
|
2024-12-18 21:56:08 +08:00
|
|
|
if plugin.Port > 0 && plugin.Port < 1000000 {
|
|
|
|
fmt.Printf(" - %-10s (端口: %d)\n", name, plugin.Port)
|
|
|
|
}
|
2021-03-09 17:21:27 +08:00
|
|
|
}
|
2024-12-18 21:56:08 +08:00
|
|
|
|
|
|
|
// 显示特殊漏洞扫描类型
|
|
|
|
fmt.Println("\n[+] 特殊漏洞扫描:")
|
2024-12-19 16:15:53 +08:00
|
|
|
for name, plugin := range PluginManager {
|
2024-12-18 21:56:08 +08:00
|
|
|
if plugin.Port >= 1000000 || plugin.Port == 0 {
|
|
|
|
fmt.Printf(" - %-10s\n", name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 显示其他扫描类型
|
|
|
|
fmt.Println("\n[+] 其他扫描类型:")
|
|
|
|
specialTypes := []string{"all", "portscan", "icmp", "main", "webonly", "webpoc"}
|
|
|
|
for _, name := range specialTypes {
|
|
|
|
fmt.Printf(" - %s\n", name)
|
|
|
|
}
|
|
|
|
|
2021-03-09 17:21:27 +08:00
|
|
|
os.Exit(0)
|
|
|
|
}
|