2020-12-29 17:17:10 +08:00
|
|
|
package common
|
|
|
|
|
|
|
|
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"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
2022-05-12 17:56:32 +08:00
|
|
|
ParseScantype(Info)
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
|
2022-07-03 23:41:39 +08:00
|
|
|
func ParseUser() {
|
|
|
|
if Username == "" && Userfile == "" {
|
2021-09-11 16:43:38 +08:00
|
|
|
return
|
|
|
|
}
|
2022-07-03 23:41:39 +08:00
|
|
|
var Usernames []string
|
|
|
|
if Username != "" {
|
|
|
|
Usernames = strings.Split(Username, ",")
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
2021-09-11 16:43:38 +08:00
|
|
|
|
2021-02-05 14:43:07 +08:00
|
|
|
if Userfile != "" {
|
2021-03-01 21:55:19 +08:00
|
|
|
users, err := Readfile(Userfile)
|
2020-12-29 17:17:10 +08:00
|
|
|
if err == nil {
|
2021-03-01 21:55:19 +08:00
|
|
|
for _, user := range users {
|
|
|
|
if user != "" {
|
2022-07-03 23:41:39 +08:00
|
|
|
Usernames = append(Usernames, user)
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-03 23:41:39 +08:00
|
|
|
Usernames = RemoveDuplicate(Usernames)
|
2021-09-11 16:43:38 +08:00
|
|
|
for name := range Userdict {
|
2022-07-03 23:41:39 +08:00
|
|
|
Userdict[name] = Usernames
|
2021-09-11 16:43:38 +08:00
|
|
|
}
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func ParsePass(Info *HostInfo) {
|
2022-07-03 23:41:39 +08:00
|
|
|
var PwdList []string
|
|
|
|
if Password != "" {
|
|
|
|
passs := strings.Split(Password, ",")
|
2020-12-29 17:17:10 +08:00
|
|
|
for _, pass := range passs {
|
|
|
|
if pass != "" {
|
2022-07-03 23:41:39 +08:00
|
|
|
PwdList = append(PwdList, pass)
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
}
|
2022-07-03 23:41:39 +08:00
|
|
|
Passwords = PwdList
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
2021-02-05 14:43:07 +08:00
|
|
|
if Passfile != "" {
|
|
|
|
passs, err := Readfile(Passfile)
|
2020-12-29 17:17:10 +08:00
|
|
|
if err == nil {
|
|
|
|
for _, pass := range passs {
|
|
|
|
if pass != "" {
|
2022-07-03 23:41:39 +08:00
|
|
|
PwdList = append(PwdList, pass)
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
}
|
2022-07-03 23:41:39 +08:00
|
|
|
Passwords = PwdList
|
2021-03-04 14:42:10 +08:00
|
|
|
}
|
|
|
|
}
|
2024-08-29 15:12:30 +08:00
|
|
|
if Hashfile != "" {
|
|
|
|
hashs, err := Readfile(Hashfile)
|
|
|
|
if err == nil {
|
|
|
|
for _, line := range hashs {
|
|
|
|
if line == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if len(line) == 32 {
|
|
|
|
Hashs = append(Hashs, line)
|
|
|
|
} else {
|
|
|
|
fmt.Println("[-] len(hash) != 32 " + line)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-06 21:42:00 +08:00
|
|
|
if URL != "" {
|
|
|
|
urls := strings.Split(URL, ",")
|
|
|
|
TmpUrls := make(map[string]struct{})
|
|
|
|
for _, url := range urls {
|
|
|
|
if _, ok := TmpUrls[url]; !ok {
|
|
|
|
TmpUrls[url] = struct{}{}
|
|
|
|
if url != "" {
|
|
|
|
Urls = append(Urls, url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-04 14:42:10 +08:00
|
|
|
if UrlFile != "" {
|
|
|
|
urls, err := Readfile(UrlFile)
|
|
|
|
if err == nil {
|
|
|
|
TmpUrls := make(map[string]struct{})
|
|
|
|
for _, url := range urls {
|
|
|
|
if _, ok := TmpUrls[url]; !ok {
|
|
|
|
TmpUrls[url] = struct{}{}
|
|
|
|
if url != "" {
|
|
|
|
Urls = append(Urls, url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
}
|
2022-04-20 17:45:27 +08:00
|
|
|
if PortFile != "" {
|
|
|
|
ports, err := Readfile(PortFile)
|
|
|
|
if err == nil {
|
|
|
|
newport := ""
|
|
|
|
for _, port := range ports {
|
|
|
|
if port != "" {
|
|
|
|
newport += port + ","
|
|
|
|
}
|
|
|
|
}
|
2023-11-13 16:23:19 +08:00
|
|
|
Ports = newport
|
2022-04-20 17:45:27 +08:00
|
|
|
}
|
|
|
|
}
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func Readfile(filename string) ([]string, error) {
|
|
|
|
file, err := os.Open(filename)
|
|
|
|
if err != nil {
|
2021-03-01 21:59:47 +08:00
|
|
|
fmt.Printf("Open %s error, %v\n", filename, err)
|
2020-12-29 17:17:10 +08:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
var content []string
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
scanner.Split(bufio.ScanLines)
|
|
|
|
for scanner.Scan() {
|
|
|
|
text := strings.TrimSpace(scanner.Text())
|
|
|
|
if text != "" {
|
|
|
|
content = append(content, scanner.Text())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return content, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ParseInput(Info *HostInfo) {
|
2021-03-04 14:42:10 +08:00
|
|
|
if Info.Host == "" && HostFile == "" && URL == "" && UrlFile == "" {
|
2020-12-29 17:17:10 +08:00
|
|
|
fmt.Println("Host is none")
|
|
|
|
flag.Usage()
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2021-03-30 22:30:16 +08:00
|
|
|
|
2022-04-28 17:02:48 +08:00
|
|
|
if BruteThread <= 0 {
|
|
|
|
BruteThread = 1
|
|
|
|
}
|
2022-11-30 10:49:02 +08:00
|
|
|
|
2021-02-05 14:43:07 +08:00
|
|
|
if TmpSave == true {
|
2020-12-29 17:17:10 +08:00
|
|
|
IsSave = false
|
|
|
|
}
|
2022-07-02 17:25:15 +08:00
|
|
|
|
2023-11-13 16:23:19 +08:00
|
|
|
if Ports == DefaultPorts {
|
|
|
|
Ports += "," + Webport
|
2021-04-21 00:13:04 +08:00
|
|
|
}
|
2021-12-07 17:01:21 +08:00
|
|
|
|
|
|
|
if PortAdd != "" {
|
2023-11-13 16:23:19 +08:00
|
|
|
if strings.HasSuffix(Ports, ",") {
|
|
|
|
Ports += PortAdd
|
2021-12-07 17:01:21 +08:00
|
|
|
} else {
|
2023-11-13 16:23:19 +08:00
|
|
|
Ports += "," + PortAdd
|
2021-12-07 17:01:21 +08:00
|
|
|
}
|
|
|
|
}
|
2022-01-07 10:51:36 +08:00
|
|
|
|
|
|
|
if UserAdd != "" {
|
|
|
|
user := strings.Split(UserAdd, ",")
|
2022-07-03 23:41:39 +08:00
|
|
|
for a := range Userdict {
|
2022-01-07 10:51:36 +08:00
|
|
|
Userdict[a] = append(Userdict[a], user...)
|
|
|
|
Userdict[a] = RemoveDuplicate(Userdict[a])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if PassAdd != "" {
|
|
|
|
pass := strings.Split(PassAdd, ",")
|
|
|
|
Passwords = append(Passwords, pass...)
|
|
|
|
Passwords = RemoveDuplicate(Passwords)
|
|
|
|
}
|
2022-07-02 17:25:15 +08:00
|
|
|
if Socks5Proxy != "" && !strings.HasPrefix(Socks5Proxy, "socks5://") {
|
2022-11-19 17:04:13 +08:00
|
|
|
if !strings.Contains(Socks5Proxy, ":") {
|
|
|
|
Socks5Proxy = "socks5://127.0.0.1" + Socks5Proxy
|
|
|
|
} else {
|
|
|
|
Socks5Proxy = "socks5://" + Socks5Proxy
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if Socks5Proxy != "" {
|
|
|
|
fmt.Println("Socks5Proxy:", Socks5Proxy)
|
|
|
|
_, err := url.Parse(Socks5Proxy)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Socks5Proxy parse error:", err)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2022-08-16 15:10:09 +08:00
|
|
|
NoPing = true
|
2022-07-02 17:25:15 +08:00
|
|
|
}
|
2022-11-19 17:04:13 +08:00
|
|
|
if Proxy != "" {
|
|
|
|
if Proxy == "1" {
|
|
|
|
Proxy = "http://127.0.0.1:8080"
|
|
|
|
} else if Proxy == "2" {
|
|
|
|
Proxy = "socks5://127.0.0.1:1080"
|
|
|
|
} else if !strings.Contains(Proxy, "://") {
|
|
|
|
Proxy = "http://127.0.0.1:" + Proxy
|
|
|
|
}
|
|
|
|
fmt.Println("Proxy:", Proxy)
|
|
|
|
if !strings.HasPrefix(Proxy, "socks") && !strings.HasPrefix(Proxy, "http") {
|
|
|
|
fmt.Println("no support this proxy")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
_, err := url.Parse(Proxy)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Proxy parse error:", err)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if Hash != "" && len(Hash) != 32 {
|
|
|
|
fmt.Println("[-] Hash is error,len(hash) must be 32")
|
|
|
|
os.Exit(0)
|
|
|
|
} else {
|
2024-08-29 15:12:30 +08:00
|
|
|
Hashs = append(Hashs, Hash)
|
|
|
|
}
|
|
|
|
Hashs = RemoveDuplicate(Hashs)
|
|
|
|
for _, hash := range Hashs {
|
|
|
|
hashbyte, err := hex.DecodeString(Hash)
|
2022-11-19 17:04:13 +08:00
|
|
|
if err != nil {
|
2024-08-29 15:12:30 +08:00
|
|
|
fmt.Println("[-] Hash is error,hex decode error ", hash)
|
|
|
|
continue
|
|
|
|
} else {
|
|
|
|
HashBytes = append(HashBytes, hashbyte)
|
2022-11-19 17:04:13 +08:00
|
|
|
}
|
|
|
|
}
|
2024-08-29 15:12:30 +08:00
|
|
|
Hashs = []string{}
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func ParseScantype(Info *HostInfo) {
|
2022-07-03 23:41:39 +08:00
|
|
|
_, ok := PORTList[Scantype]
|
2020-12-29 17:17:10 +08:00
|
|
|
if !ok {
|
2021-03-09 17:21:27 +08:00
|
|
|
showmode()
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
2023-11-13 16:23:19 +08:00
|
|
|
if Scantype != "all" && Ports == DefaultPorts+","+Webport {
|
2022-07-03 23:41:39 +08:00
|
|
|
switch Scantype {
|
2022-11-19 17:04:13 +08:00
|
|
|
case "wmiexec":
|
2023-11-13 16:23:19 +08:00
|
|
|
Ports = "135"
|
2022-11-19 17:04:13 +08:00
|
|
|
case "wmiinfo":
|
2023-11-13 16:23:19 +08:00
|
|
|
Ports = "135"
|
2022-11-19 17:04:13 +08:00
|
|
|
case "smbinfo":
|
2023-11-13 16:23:19 +08:00
|
|
|
Ports = "445"
|
2022-11-19 17:04:13 +08:00
|
|
|
case "hostname":
|
2023-11-13 16:23:19 +08:00
|
|
|
Ports = "135,137,139,445"
|
2022-11-19 17:04:13 +08:00
|
|
|
case "smb2":
|
2023-11-13 16:23:19 +08:00
|
|
|
Ports = "445"
|
2022-06-13 10:27:23 +08:00
|
|
|
case "web":
|
2023-11-13 16:23:19 +08:00
|
|
|
Ports = Webport
|
2022-06-13 10:27:23 +08:00
|
|
|
case "webonly":
|
2023-11-13 16:23:19 +08:00
|
|
|
Ports = Webport
|
2022-06-13 10:27:23 +08:00
|
|
|
case "ms17010":
|
2023-11-13 16:23:19 +08:00
|
|
|
Ports = "445"
|
2022-06-13 10:27:23 +08:00
|
|
|
case "cve20200796":
|
2023-11-13 16:23:19 +08:00
|
|
|
Ports = "445"
|
2022-06-13 10:27:23 +08:00
|
|
|
case "portscan":
|
2023-11-13 16:23:19 +08:00
|
|
|
Ports = DefaultPorts + "," + Webport
|
2022-06-13 10:27:23 +08:00
|
|
|
case "main":
|
2023-11-13 16:23:19 +08:00
|
|
|
Ports = DefaultPorts
|
2022-06-13 10:27:23 +08:00
|
|
|
default:
|
2022-07-03 23:41:39 +08:00
|
|
|
port, _ := PORTList[Scantype]
|
2023-11-13 16:23:19 +08:00
|
|
|
Ports = strconv.Itoa(port)
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
2023-11-13 16:23:19 +08:00
|
|
|
fmt.Println("-m ", Scantype, " start scan the port:", Ports)
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-11 17:58:26 +08:00
|
|
|
func CheckErr(text string, err error, flag bool) {
|
2020-12-29 17:17:10 +08:00
|
|
|
if err != nil {
|
2021-10-11 17:58:26 +08:00
|
|
|
fmt.Println("Parse", text, "error: ", err.Error())
|
|
|
|
if flag {
|
|
|
|
if err != ParseIPErr {
|
|
|
|
fmt.Println(ParseIPErr)
|
|
|
|
}
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2020-12-29 17:17:10 +08:00
|
|
|
}
|
|
|
|
}
|
2020-12-30 21:30:36 +08:00
|
|
|
|
2021-03-09 17:21:27 +08:00
|
|
|
func showmode() {
|
|
|
|
fmt.Println("The specified scan type does not exist")
|
|
|
|
fmt.Println("-m")
|
|
|
|
for name := range PORTList {
|
|
|
|
fmt.Println(" [" + name + "]")
|
|
|
|
}
|
|
|
|
os.Exit(0)
|
|
|
|
}
|