2020-12-29 01:17:10 -08:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2021-05-28 21:13:10 -07:00
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
2020-12-29 01:17:10 -08:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Parse(Info *HostInfo) {
|
2022-07-03 08:41:39 -07:00
|
|
|
ParseUser()
|
2020-12-29 01:17:10 -08:00
|
|
|
ParsePass(Info)
|
|
|
|
ParseInput(Info)
|
2022-05-12 02:56:32 -07:00
|
|
|
ParseScantype(Info)
|
2020-12-29 01:17:10 -08:00
|
|
|
}
|
|
|
|
|
2022-07-03 08:41:39 -07:00
|
|
|
func ParseUser() {
|
|
|
|
if Username == "" && Userfile == "" {
|
2021-09-11 01:43:38 -07:00
|
|
|
return
|
|
|
|
}
|
2022-07-03 08:41:39 -07:00
|
|
|
var Usernames []string
|
|
|
|
if Username != "" {
|
|
|
|
Usernames = strings.Split(Username, ",")
|
2020-12-29 01:17:10 -08:00
|
|
|
}
|
2021-09-11 01:43:38 -07:00
|
|
|
|
2021-02-04 22:43:07 -08:00
|
|
|
if Userfile != "" {
|
2021-03-01 05:55:19 -08:00
|
|
|
users, err := Readfile(Userfile)
|
2020-12-29 01:17:10 -08:00
|
|
|
if err == nil {
|
2021-03-01 05:55:19 -08:00
|
|
|
for _, user := range users {
|
|
|
|
if user != "" {
|
2022-07-03 08:41:39 -07:00
|
|
|
Usernames = append(Usernames, user)
|
2020-12-29 01:17:10 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-03 08:41:39 -07:00
|
|
|
Usernames = RemoveDuplicate(Usernames)
|
2021-09-11 01:43:38 -07:00
|
|
|
for name := range Userdict {
|
2022-07-03 08:41:39 -07:00
|
|
|
Userdict[name] = Usernames
|
2021-09-11 01:43:38 -07:00
|
|
|
}
|
2020-12-29 01:17:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func ParsePass(Info *HostInfo) {
|
2022-07-03 08:41:39 -07:00
|
|
|
var PwdList []string
|
|
|
|
if Password != "" {
|
|
|
|
passs := strings.Split(Password, ",")
|
2020-12-29 01:17:10 -08:00
|
|
|
for _, pass := range passs {
|
|
|
|
if pass != "" {
|
2022-07-03 08:41:39 -07:00
|
|
|
PwdList = append(PwdList, pass)
|
2020-12-29 01:17:10 -08:00
|
|
|
}
|
|
|
|
}
|
2022-07-03 08:41:39 -07:00
|
|
|
Passwords = PwdList
|
2020-12-29 01:17:10 -08:00
|
|
|
}
|
2021-02-04 22:43:07 -08:00
|
|
|
if Passfile != "" {
|
|
|
|
passs, err := Readfile(Passfile)
|
2020-12-29 01:17:10 -08:00
|
|
|
if err == nil {
|
|
|
|
for _, pass := range passs {
|
|
|
|
if pass != "" {
|
2022-07-03 08:41:39 -07:00
|
|
|
PwdList = append(PwdList, pass)
|
2020-12-29 01:17:10 -08:00
|
|
|
}
|
|
|
|
}
|
2022-07-03 08:41:39 -07:00
|
|
|
Passwords = PwdList
|
2021-03-03 22:42:10 -08:00
|
|
|
}
|
|
|
|
}
|
2022-07-06 06:42:00 -07: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-03 22: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 01:17:10 -08:00
|
|
|
}
|
|
|
|
}
|
2022-04-20 02:45:27 -07:00
|
|
|
if PortFile != "" {
|
|
|
|
ports, err := Readfile(PortFile)
|
|
|
|
if err == nil {
|
|
|
|
newport := ""
|
|
|
|
for _, port := range ports {
|
|
|
|
if port != "" {
|
|
|
|
newport += port + ","
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Info.Ports = newport
|
|
|
|
}
|
|
|
|
}
|
2020-12-29 01:17:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func Readfile(filename string) ([]string, error) {
|
|
|
|
file, err := os.Open(filename)
|
|
|
|
if err != nil {
|
2021-03-01 05:59:47 -08:00
|
|
|
fmt.Printf("Open %s error, %v\n", filename, err)
|
2020-12-29 01: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-03 22:42:10 -08:00
|
|
|
if Info.Host == "" && HostFile == "" && URL == "" && UrlFile == "" {
|
2020-12-29 01:17:10 -08:00
|
|
|
fmt.Println("Host is none")
|
|
|
|
flag.Usage()
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2021-03-30 07:30:16 -07:00
|
|
|
|
2022-04-28 02:02:48 -07:00
|
|
|
if BruteThread <= 0 {
|
|
|
|
BruteThread = 1
|
|
|
|
}
|
2022-07-02 02:25:15 -07:00
|
|
|
|
2021-02-04 22:43:07 -08:00
|
|
|
if TmpOutputfile != "" {
|
2020-12-30 05:30:36 -08:00
|
|
|
if !strings.Contains(Outputfile, "/") && !strings.Contains(Outputfile, `\`) {
|
2021-02-04 22:43:07 -08:00
|
|
|
Outputfile = getpath() + TmpOutputfile
|
2020-12-30 05:30:36 -08:00
|
|
|
} else {
|
2021-02-04 22:43:07 -08:00
|
|
|
Outputfile = TmpOutputfile
|
2020-12-30 05:30:36 -08:00
|
|
|
}
|
2020-12-29 01:17:10 -08:00
|
|
|
}
|
2022-07-02 02:25:15 -07:00
|
|
|
|
2021-02-04 22:43:07 -08:00
|
|
|
if TmpSave == true {
|
2020-12-29 01:17:10 -08:00
|
|
|
IsSave = false
|
|
|
|
}
|
2022-07-02 02:25:15 -07:00
|
|
|
|
2021-04-20 09:13:04 -07:00
|
|
|
if Info.Ports == DefaultPorts {
|
2021-11-30 23:22:48 -08:00
|
|
|
Info.Ports += "," + Webport
|
2021-04-20 09:13:04 -07:00
|
|
|
}
|
2021-12-07 01:01:21 -08:00
|
|
|
|
|
|
|
if PortAdd != "" {
|
|
|
|
if strings.HasSuffix(Info.Ports, ",") {
|
|
|
|
Info.Ports += PortAdd
|
|
|
|
} else {
|
|
|
|
Info.Ports += "," + PortAdd
|
|
|
|
}
|
|
|
|
}
|
2022-01-06 18:51:36 -08:00
|
|
|
|
|
|
|
if UserAdd != "" {
|
|
|
|
user := strings.Split(UserAdd, ",")
|
2022-07-03 08:41:39 -07:00
|
|
|
for a := range Userdict {
|
2022-01-06 18: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 02:25:15 -07:00
|
|
|
if Socks5Proxy != "" && !strings.HasPrefix(Socks5Proxy, "socks5://") {
|
|
|
|
Socks5Proxy = "socks5://" + Socks5Proxy
|
2022-08-16 00:10:09 -07:00
|
|
|
NoPing = true
|
2022-07-02 02:25:15 -07:00
|
|
|
}
|
2020-12-29 01:17:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func ParseScantype(Info *HostInfo) {
|
2022-07-03 08:41:39 -07:00
|
|
|
_, ok := PORTList[Scantype]
|
2020-12-29 01:17:10 -08:00
|
|
|
if !ok {
|
2021-03-09 01:21:27 -08:00
|
|
|
showmode()
|
2020-12-29 01:17:10 -08:00
|
|
|
}
|
2022-07-03 08:41:39 -07:00
|
|
|
if Scantype != "all" && Info.Ports == DefaultPorts+","+Webport {
|
|
|
|
switch Scantype {
|
2022-06-12 19:27:23 -07:00
|
|
|
case "rdp":
|
|
|
|
Info.Ports = "3389"
|
|
|
|
case "web":
|
|
|
|
Info.Ports = Webport
|
|
|
|
case "webonly":
|
|
|
|
Info.Ports = Webport
|
|
|
|
case "ms17010":
|
|
|
|
Info.Ports = "445"
|
|
|
|
case "cve20200796":
|
|
|
|
Info.Ports = "445"
|
|
|
|
case "portscan":
|
|
|
|
Info.Ports = DefaultPorts + "," + Webport
|
|
|
|
case "main":
|
|
|
|
Info.Ports = DefaultPorts
|
|
|
|
default:
|
2022-07-03 08:41:39 -07:00
|
|
|
port, _ := PORTList[Scantype]
|
2022-06-12 19:27:23 -07:00
|
|
|
Info.Ports = strconv.Itoa(port)
|
2020-12-29 01:17:10 -08:00
|
|
|
}
|
2022-07-03 08:41:39 -07:00
|
|
|
fmt.Println("-m ", Scantype, " start scan the port:", Info.Ports)
|
2020-12-29 01:17:10 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-11 02:58:26 -07:00
|
|
|
func CheckErr(text string, err error, flag bool) {
|
2020-12-29 01:17:10 -08:00
|
|
|
if err != nil {
|
2021-10-11 02:58:26 -07:00
|
|
|
fmt.Println("Parse", text, "error: ", err.Error())
|
|
|
|
if flag {
|
|
|
|
if err != ParseIPErr {
|
|
|
|
fmt.Println(ParseIPErr)
|
|
|
|
}
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2020-12-29 01:17:10 -08:00
|
|
|
}
|
|
|
|
}
|
2020-12-30 05:30:36 -08:00
|
|
|
|
|
|
|
func getpath() string {
|
2021-05-28 21:13:10 -07:00
|
|
|
file, _ := exec.LookPath(os.Args[0])
|
|
|
|
path1, _ := filepath.Abs(file)
|
|
|
|
filename := filepath.Dir(path1)
|
2020-12-30 05:30:36 -08:00
|
|
|
var path string
|
|
|
|
if strings.Contains(filename, "/") {
|
|
|
|
tmp := strings.Split(filename, `/`)
|
|
|
|
tmp[len(tmp)-1] = ``
|
|
|
|
path = strings.Join(tmp, `/`)
|
|
|
|
} else if strings.Contains(filename, `\`) {
|
|
|
|
tmp := strings.Split(filename, `\`)
|
|
|
|
tmp[len(tmp)-1] = ``
|
|
|
|
path = strings.Join(tmp, `\`)
|
|
|
|
}
|
|
|
|
return path
|
|
|
|
}
|
2021-03-09 01: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)
|
|
|
|
}
|