├── .gitignore ├── img ├── ftp_test.png ├── mem_test.png ├── smb_test.png ├── ssh_test.png ├── sub_test.png ├── url_test.png ├── apache_auth.png ├── icmp_test.png ├── mssql_test.png ├── mysql_test.png ├── redis_test.png ├── mongodb_test.png ├── portscan_test.png └── postgresql_test.png ├── .idea ├── misc.xml ├── vcs.xml ├── modules.xml ├── GScan.iml ├── watcherTasks.xml └── workspace.xml ├── config ├── icmp.ini ├── portscan.ini ├── subdomain.ini ├── url.ini ├── auth.ini └── mysql.ini ├── Misc ├── allparams.go ├── check.go ├── save.go └── infoprint.go ├── main.go ├── Parse ├── PareseConfig.go ├── ParseUrl.go ├── ParsePort.go ├── ParseFile.go ├── ParseParam.go └── ParseIP.go ├── Plugins ├── scanner.go ├── config.go ├── portscan.go ├── subdomain.go ├── icmp.go ├── redis.go ├── mgo.go ├── memcached.go ├── mssql.go ├── mysql.go ├── ftp.go ├── ssh.go ├── smb.go ├── postgresql.go ├── apacheauth.go └── urlscan.go ├── README.md └── dict ├── sub.txt └── dicc.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe 2 | *.zip -------------------------------------------------------------------------------- /img/ftp_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hack2fun/Gscan/HEAD/img/ftp_test.png -------------------------------------------------------------------------------- /img/mem_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hack2fun/Gscan/HEAD/img/mem_test.png -------------------------------------------------------------------------------- /img/smb_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hack2fun/Gscan/HEAD/img/smb_test.png -------------------------------------------------------------------------------- /img/ssh_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hack2fun/Gscan/HEAD/img/ssh_test.png -------------------------------------------------------------------------------- /img/sub_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hack2fun/Gscan/HEAD/img/sub_test.png -------------------------------------------------------------------------------- /img/url_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hack2fun/Gscan/HEAD/img/url_test.png -------------------------------------------------------------------------------- /img/apache_auth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hack2fun/Gscan/HEAD/img/apache_auth.png -------------------------------------------------------------------------------- /img/icmp_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hack2fun/Gscan/HEAD/img/icmp_test.png -------------------------------------------------------------------------------- /img/mssql_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hack2fun/Gscan/HEAD/img/mssql_test.png -------------------------------------------------------------------------------- /img/mysql_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hack2fun/Gscan/HEAD/img/mysql_test.png -------------------------------------------------------------------------------- /img/redis_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hack2fun/Gscan/HEAD/img/redis_test.png -------------------------------------------------------------------------------- /img/mongodb_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hack2fun/Gscan/HEAD/img/mongodb_test.png -------------------------------------------------------------------------------- /img/portscan_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hack2fun/Gscan/HEAD/img/portscan_test.png -------------------------------------------------------------------------------- /img/postgresql_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hack2fun/Gscan/HEAD/img/postgresql_test.png -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /config/icmp.ini: -------------------------------------------------------------------------------- 1 | [CONFIG] 2 | #Parameters are case sensitive, for example, only "Scantype", not "scantype" 3 | Scantype = icmp 4 | Host = 192.168.43.212/24 5 | Timeout = 5 6 | Thread = 1000 7 | #Output = output_file #Output results to a file 8 | #ErrShow = false #Whether to display error messages during scanning -------------------------------------------------------------------------------- /.idea/GScan.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /config/portscan.ini: -------------------------------------------------------------------------------- 1 | [CONFIG] 2 | #Parameters are case sensitive, for example, only "Scantype", not "scantype" 3 | Scantype = portscan 4 | Host = 127.0.0.1 5 | Ports = 1-1000 6 | Timeout = 5 7 | Thread = 1000 8 | #Output = output_file #Output results to a file 9 | #ErrShow = false #Whether to display error messages during scanning -------------------------------------------------------------------------------- /config/subdomain.ini: -------------------------------------------------------------------------------- 1 | [CONFIG] 2 | #Parameters are case sensitive, for example, only "Scantype", not "scantype" 3 | Scantype = subdomain 4 | Url = baidu.com 5 | UrlFile = ./dict.txt 6 | Timeout = 5 7 | Thread = 1000 8 | #Output = output_file #Output results to a file 9 | #ErrShow = false #Whether to display error messages during scanning -------------------------------------------------------------------------------- /config/url.ini: -------------------------------------------------------------------------------- 1 | [CONFIG] 2 | #Parameters are case sensitive, for example, only "Scantype", not "scantype" 3 | Scantype = urlscan 4 | Url = http://192.168.141.128:7777 5 | UrlFile = ./dict.txt 6 | Timeout = 5 7 | Thread = 1000 8 | #Output = output_file #Output results to a file 9 | #ErrShow = false #Whether to display error messages during scanning -------------------------------------------------------------------------------- /config/auth.ini: -------------------------------------------------------------------------------- 1 | [CONFIG] 2 | #Parameters are case sensitive, for example, only "Scantype", not "scantype" 3 | Scantype = auth 4 | Url = http://192.168.141.128:7777 5 | Passfile = ./password.txt 6 | Username = admin 7 | Timeout = 5 8 | Thread = 1000 9 | #Output = output_file #Output results to a file 10 | #ErrShow = false #Whether to display error messages during scanning -------------------------------------------------------------------------------- /Misc/allparams.go: -------------------------------------------------------------------------------- 1 | package Misc 2 | 3 | type HostInfo struct { 4 | INIFile string 5 | Host string 6 | Username string 7 | Password string 8 | ErrShow bool 9 | Ports string 10 | Port int 11 | Help bool 12 | Userfile string 13 | Passfile string 14 | Scantype string 15 | Thread int 16 | Timeout int64 17 | Url string 18 | UrlFile string 19 | Show bool 20 | Output string 21 | Cookie string 22 | Header string 23 | } 24 | -------------------------------------------------------------------------------- /config/mysql.ini: -------------------------------------------------------------------------------- 1 | [CONFIG] 2 | #Parameters are case sensitive, for example, only "Scantype", not "scantype" 3 | Scantype = mysql 4 | Host = 127.0.0.1 5 | Port = 3306 6 | Timeout = 5 7 | Thread = 1000 8 | Passfile = ./password.txt # or use "Password=" to specify a password 9 | Username = username # or use "Userfile=" to specify a dictionary file 10 | #Output = output_file #Output results to a file 11 | #ErrShow = false #Whether to display error messages during scanning -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "./Misc" 5 | "./Parse" 6 | "./Plugins" 7 | "flag" 8 | ) 9 | 10 | func main() { 11 | flag.Parse() 12 | var params *Misc.HostInfo 13 | allparam := Parse.Param 14 | if allparam.INIFile != "" { 15 | ini, err := Parse.GetConfig(allparam.INIFile) 16 | Misc.CheckErr(err) 17 | params = ini 18 | } else { 19 | params = allparam 20 | } 21 | 22 | var ch = make(chan int, params.Thread) 23 | switch { 24 | case params.Help || flag.NFlag() == 0: 25 | flag.Usage() 26 | case params.Show: 27 | Plugins.Show() 28 | default: 29 | Plugins.Selector(params, ch) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Parse/PareseConfig.go: -------------------------------------------------------------------------------- 1 | package Parse 2 | 3 | import ( 4 | "../Misc" 5 | "errors" 6 | "github.com/go-ini/ini" 7 | ) 8 | 9 | var ParseConfigErr = errors.New("An error occurred while parsing the configuration file, please check if your ini file format is correct or the file exists") 10 | 11 | var CONFIG = &Misc.HostInfo{} 12 | 13 | //Getting information of config file 14 | func GetConfig(filename string) (*Misc.HostInfo, error) { 15 | conf, err := ini.Load(filename) 16 | if err != nil { 17 | return nil, ParseConfigErr 18 | } 19 | err = conf.Section("CONFIG").MapTo(CONFIG) 20 | if err != nil { 21 | return nil, ParseConfigErr 22 | } 23 | return CONFIG, nil 24 | } 25 | -------------------------------------------------------------------------------- /Misc/check.go: -------------------------------------------------------------------------------- 1 | package Misc 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "os" 7 | "time" 8 | ) 9 | 10 | //Check if port is available 11 | func (h *HostInfo) CheckPort() error { 12 | InfoPrinter.Println("Checking whether the target port is open") 13 | addr := fmt.Sprintf("%s:%d", h.Host, h.Port) 14 | _, err := net.DialTimeout("tcp", addr, (time.Duration(h.Timeout))*time.Second) 15 | if err != nil { 16 | WarnPrinter.Println("Port is closed, please confirm whether the target port is open") 17 | InfoPrinter.Println("If you confirm that the port of this host is open, you can use the -bypass option to bypass port detection") 18 | return err 19 | } else { 20 | InfoPrinter.Println("Port check completed, port open") 21 | InfoPrinter.Println("Starting") 22 | return nil 23 | } 24 | } 25 | 26 | //Checking error 27 | func CheckErr(err error) { 28 | if err != nil { 29 | ErrPrinter.Println(err.Error()) 30 | os.Exit(0) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Parse/ParseUrl.go: -------------------------------------------------------------------------------- 1 | package Parse 2 | 3 | import ( 4 | "errors" 5 | "strings" 6 | ) 7 | 8 | var UrlErr = errors.New("url parse error" + 9 | "format:\n" + 10 | "www.baidu.com\n" + 11 | "https://www.baidu.com\n" + 12 | "http://www.baidu.com\n" + 13 | "http://192.168.1.1\n" + 14 | "192.168.1.1\n") 15 | 16 | //Parsing --url 17 | func ParseUrl(url string) (string, error) { 18 | if url == "" { 19 | return "", errors.New("Please specify a URL with the \"--url\"") 20 | } 21 | switch { 22 | case strings.HasPrefix(url, "http://") || 23 | strings.HasPrefix(url, "https://"): 24 | if url[len(url)-1] == '/' { 25 | return url, nil 26 | } else { 27 | return url + "/", nil 28 | } 29 | case !strings.HasPrefix(url, "http://") && 30 | !strings.HasPrefix(url, "https://"): 31 | if url[len(url)-1] == '/' { 32 | return "http://" + url, nil 33 | } else { 34 | return "http://" + url + "/", nil 35 | } 36 | 37 | default: 38 | return "", UrlErr 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Plugins/scanner.go: -------------------------------------------------------------------------------- 1 | package Plugins 2 | 3 | import ( 4 | "../Misc" 5 | "errors" 6 | "os" 7 | "reflect" 8 | ) 9 | 10 | //Reference:https://mikespook.com/2012/07/%E5%9C%A8-golang-%E4%B8%AD%E7%94%A8%E5%90%8D%E5%AD%97%E8%B0%83%E7%94%A8%E5%87%BD%E6%95%B0/ 11 | func Call_user_func(m map[string]interface{}, name string, params ...interface{}) (result []reflect.Value, err error) { 12 | f := reflect.ValueOf(m[name]) 13 | if len(params) != f.Type().NumIn() { 14 | err = errors.New("The number of params is not adapted.") 15 | Misc.CheckErr(err) 16 | } 17 | in := make([]reflect.Value, len(params)) 18 | for k, param := range params { 19 | in[k] = reflect.ValueOf(param) 20 | } 21 | result = f.Call(in) 22 | return result, nil 23 | } 24 | 25 | //根据-m参数选择要使用的功能 26 | func Selector(info *Misc.HostInfo, ch chan int) { 27 | _, ok := PluginList[info.Scantype] 28 | if !ok { 29 | Misc.ErrPrinter.Println("The specified scan type does not exist, please use the -show parameter to view all supported scan types") 30 | os.Exit(0) 31 | } 32 | Call_user_func(PluginList, info.Scantype, info, ch) 33 | } 34 | -------------------------------------------------------------------------------- /Misc/save.go: -------------------------------------------------------------------------------- 1 | package Misc 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | ) 8 | 9 | //Output the result as text to a file 10 | func (h *HostInfo) OutputTXT() { 11 | f, err := os.OpenFile(h.Output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) 12 | if err != nil { 13 | ErrPrinter.Println(err) 14 | return 15 | } 16 | var SaveFiler = log.New(f, "[*]", log.LstdFlags) 17 | 18 | switch h.Scantype { 19 | case "icmp": 20 | info := fmt.Sprintf("The host %s is up", h.Host) 21 | SaveFiler.Println(info) 22 | case "portscan": 23 | info := fmt.Sprintf("IP: %s:%d Open", h.Host, h.Port) 24 | SaveFiler.Println(info) 25 | //case "mysql","mssql","postgresql","ftp","mongodb","smb","redis","stmp" 26 | case "urlscan", "subdomain": 27 | info := fmt.Sprintf("%s", h.Url) 28 | SaveFiler.Println(info) 29 | case "auth": 30 | info := fmt.Sprintf("Type: %s URL: %s Username: %s Password: %s", h.Scantype, h.Url, h.Username, h.Password) 31 | SaveFiler.Println(info) 32 | default: 33 | info := fmt.Sprintf("Type: %s IP: %s:%d Username: %s Password: %s", h.Scantype, h.Host, h.Port, h.Username, h.Password) 34 | SaveFiler.Println(info) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Plugins/config.go: -------------------------------------------------------------------------------- 1 | package Plugins 2 | 3 | import "fmt" 4 | 5 | //Plugins List 6 | var PluginList = map[string]interface{}{ 7 | "ftp": FtpConn, 8 | "mysql": MySQLConn, 9 | "mongodb": MgoConn, 10 | "mssql": MssSQLConn, 11 | "redis": RedisConn, 12 | "smb": SmbConn, 13 | "ssh": SSHConn, 14 | "portscan": PortConn, 15 | "icmp": IcmpConn, 16 | "postgresql": PostgreSQLConn, 17 | "urlscan": UrlConn, 18 | "auth": ApacheConn, 19 | "subdomain": SDConn, 20 | "memcached": MemConn, 21 | } 22 | 23 | //Count the number of successes 24 | var success int = 0 25 | 26 | const FTPPORT = 21 27 | const MEMCACHED = 11211 28 | const MONGODBPORT = 27017 29 | const MSSQLPORT = 1433 30 | const PSQLPORT = 5432 31 | const REDISPORT = 6379 32 | const MYSQLPORT = 3306 33 | const SMBPORT = 445 34 | 35 | const URLFILE = "./dict/dicc.txt" //the dict from https://github.com/maurosoria/dirsearch/blob/master/db/dicc.txt 36 | const SUBFILE = "./dict/sub.txt" 37 | 38 | //show all Plugins 39 | func Show() { 40 | fmt.Println("-m") 41 | for name, _ := range PluginList { 42 | fmt.Println(" [" + name + "]") 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /.idea/watcherTasks.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 16 | 28 | 29 | -------------------------------------------------------------------------------- /Plugins/portscan.go: -------------------------------------------------------------------------------- 1 | package Plugins 2 | 3 | import ( 4 | "../Misc" 5 | "../Parse" 6 | "fmt" 7 | "net" 8 | "sync" 9 | "time" 10 | ) 11 | 12 | func PortScan(info Misc.HostInfo, ch chan int, wg *sync.WaitGroup) { 13 | addr := fmt.Sprintf("%s:%d", info.Host, info.Port) 14 | conn, err := net.DialTimeout("tcp", addr, (time.Duration(info.Timeout))*time.Second) 15 | if err != nil && info.ErrShow { 16 | info.PrintFailedPort() 17 | } else if err == nil { 18 | success += 1 19 | conn.Close() 20 | info.PrintSucceedPort() 21 | if info.Output != "" { 22 | info.OutputTXT() 23 | } 24 | } 25 | wg.Done() 26 | <-ch 27 | } 28 | 29 | func PortConn(info *Misc.HostInfo, ch chan int) { 30 | var wg = sync.WaitGroup{} 31 | stime := time.Now() 32 | ports, err := Parse.ParsePort(info.Ports) 33 | Misc.CheckErr(err) 34 | 35 | hosts, err := Parse.ParseIP(info.Host) 36 | Misc.CheckErr(err) 37 | wg.Add(len(hosts) * len(ports)) 38 | Misc.InfoPrinter.Println("Total length", len(hosts)*len(ports)) 39 | for _, host := range hosts { 40 | for _, port := range ports { 41 | info.Port = port 42 | info.Host = host 43 | go PortScan(*info, ch, &wg) 44 | ch <- 1 45 | } 46 | } 47 | wg.Wait() 48 | end := time.Since(stime) 49 | Misc.InfoPrinter.Println("All Done") 50 | Misc.InfoPrinter.Println("Number of successes:", success) 51 | Misc.InfoPrinter.Println("Time consumed:", end) 52 | } 53 | -------------------------------------------------------------------------------- /Parse/ParsePort.go: -------------------------------------------------------------------------------- 1 | package Parse 2 | 3 | import ( 4 | "errors" 5 | "strconv" 6 | "strings" 7 | ) 8 | 9 | var ParsePortErr error = errors.New("Port parsing error") 10 | 11 | func ParsePort(port string) ([]int, error) { 12 | RealPort, err := strconv.Atoi(port) 13 | switch { 14 | case err == nil && CheckPort(RealPort): 15 | return []int{RealPort}, nil 16 | case strings.Contains(port, ","): 17 | return ParsePortB(port) 18 | case strings.Count(port, "-") == 1: 19 | return ParsePortC(port) 20 | default: 21 | return nil, ParsePortErr 22 | } 23 | } 24 | 25 | //Parsing multiple ports, for example: 22,80,3306 26 | func ParsePortB(port string) ([]int, error) { 27 | var AllPort []int 28 | port1 := strings.Split(port, ",") 29 | for _, p := range port1 { 30 | RealPort, err := strconv.Atoi(p) 31 | if !CheckPort(RealPort) && err != nil { 32 | return nil, ParsePortErr 33 | } 34 | AllPort = append(AllPort, RealPort) 35 | } 36 | return AllPort, nil 37 | } 38 | 39 | //Parsing a range of port,for example: 22-3306 40 | func ParsePortC(port string) ([]int, error) { 41 | var AllPort []int 42 | RangePort := strings.Split(port, "-") 43 | port1, err1 := strconv.Atoi(RangePort[0]) 44 | port2, err2 := strconv.Atoi(RangePort[1]) 45 | if port1 > port2 || err1 != nil || err2 != nil || !CheckPort(port1) || !CheckPort(port2) { 46 | return nil, ParsePortErr 47 | } 48 | for i := port1; i <= port2; i++ { 49 | AllPort = append(AllPort, i) 50 | } 51 | return AllPort, nil 52 | } 53 | 54 | //pdua 55 | func CheckPort(port int) bool { 56 | if port <= 0 || port > 65535 { 57 | return false 58 | } 59 | return true 60 | } 61 | -------------------------------------------------------------------------------- /Plugins/subdomain.go: -------------------------------------------------------------------------------- 1 | package Plugins 2 | 3 | import ( 4 | "../Misc" 5 | "../Parse" 6 | "context" 7 | "net" 8 | "sync" 9 | "time" 10 | ) 11 | 12 | func SubDomain(info Misc.HostInfo, ch chan int, wg *sync.WaitGroup) { 13 | tch := make(chan int) 14 | defer func() { 15 | <-ch 16 | wg.Done() 17 | }() 18 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(info.Timeout)) 19 | defer cancel() 20 | go func() { 21 | ns, err := net.LookupHost(info.Url) 22 | if err != nil && info.ErrShow { 23 | Misc.ErrPrinter.Println(err.Error()) 24 | } else if err == nil { 25 | success += 1 26 | Misc.SucceedPrinter.Printf("URL:%s HOST:%v", info.Url, ns) 27 | if info.Output != "" { 28 | info.OutputTXT() 29 | } 30 | } 31 | tch <- 1 32 | }() 33 | select { 34 | case <-ctx.Done(): 35 | if info.ErrShow { 36 | Misc.ErrPrinter.Println(info.Url, "Time out") 37 | } 38 | return 39 | case <-tch: 40 | return 41 | } 42 | } 43 | 44 | func SDConn(info *Misc.HostInfo, ch chan int) { 45 | stime := time.Now() 46 | var wg = sync.WaitGroup{} 47 | prefixs, err := Parse.Readfile(info.UrlFile) 48 | Misc.CheckErr(err) 49 | wg.Add(len(prefixs)) 50 | domain := info.Url 51 | Misc.InfoPrinter.Println("Total length", len(prefixs)) 52 | for _, prefix := range prefixs { 53 | url := prefix + "." + domain 54 | info.Url = url 55 | go SubDomain(*info, ch, &wg) 56 | ch <- 1 57 | } 58 | wg.Wait() 59 | end := time.Since(stime) 60 | Misc.InfoPrinter.Println("All Done") 61 | Misc.InfoPrinter.Println("Number of successes:", success) 62 | Misc.InfoPrinter.Println("Time consumed:", end) 63 | } 64 | -------------------------------------------------------------------------------- /Plugins/icmp.go: -------------------------------------------------------------------------------- 1 | package Plugins 2 | 3 | import ( 4 | "../Misc" 5 | "../Parse" 6 | "io/ioutil" 7 | "os/exec" 8 | "regexp" 9 | "runtime" 10 | "strconv" 11 | "strings" 12 | "sync" 13 | "time" 14 | ) 15 | 16 | const count = 1 17 | 18 | var reg = regexp.MustCompile(`ttl=\d+`) 19 | 20 | func Ping(info Misc.HostInfo, ch chan int, wg *sync.WaitGroup) { 21 | var cmd = &exec.Cmd{} 22 | switch runtime.GOOS { 23 | case "windows": 24 | cmd = exec.Command("ping", "-n", strconv.Itoa(count), "-w", strconv.Itoa(int(info.Timeout)), info.Host) 25 | default: 26 | cmd = exec.Command("ping", "-c", strconv.Itoa(count), "-W", strconv.Itoa(int(info.Timeout)), info.Host) 27 | } 28 | c, err := cmd.StdoutPipe() 29 | Misc.CheckErr(err) 30 | defer c.Close() 31 | cmd.Start() 32 | result, err := ioutil.ReadAll(c) 33 | Misc.CheckErr(err) 34 | tolower := strings.ToLower(string(result)) 35 | ok := reg.MatchString(tolower) 36 | if ok { 37 | success += 1 38 | info.PrintSucceedHost() 39 | if info.Output != "" { 40 | info.OutputTXT() 41 | } 42 | } else if !ok && info.ErrShow { 43 | info.PrintFailedHost() 44 | } 45 | wg.Done() 46 | <-ch 47 | } 48 | 49 | func IcmpConn(info *Misc.HostInfo, ch chan int) { 50 | var wg = sync.WaitGroup{} 51 | stime := time.Now() 52 | hosts, err := Parse.ParseIP(info.Host) 53 | Misc.InfoPrinter.Println("Target IP:", info.Host) 54 | Misc.CheckErr(err) 55 | wg.Add(len(hosts)) 56 | for _, host := range hosts { 57 | info.Host = host 58 | go Ping(*info, ch, &wg) 59 | ch <- 1 60 | } 61 | wg.Wait() 62 | end := time.Since(stime) 63 | Misc.InfoPrinter.Println("All Done") 64 | Misc.InfoPrinter.Println("Number of successes:", success) 65 | Misc.InfoPrinter.Println("Time consumed:", end) 66 | } 67 | -------------------------------------------------------------------------------- /Parse/ParseFile.go: -------------------------------------------------------------------------------- 1 | package Parse 2 | 3 | import ( 4 | "../Misc" 5 | "bufio" 6 | "errors" 7 | "os" 8 | ) 9 | 10 | //Parsing -p and -P supplied parameters 11 | func ParsePass(h *Misc.HostInfo) ([]string, error) { 12 | switch { 13 | case h.Passfile != "" && h.Password != "": 14 | return nil, errors.New("-p and -P cannot exist at the same time") 15 | case h.Passfile == "" && h.Password == "": 16 | return nil, errors.New("Please use -p or -P to specify the username") 17 | case h.Passfile == "" && h.Password != "": 18 | return []string{h.Password}, nil 19 | case h.Passfile != "" && h.Password == "": 20 | file, err := Readfile(h.Passfile) 21 | return file, err 22 | } 23 | return nil, errors.New("unknown error") 24 | } 25 | 26 | //Parsing -u and -U supplied parameters 27 | func ParseUser(h *Misc.HostInfo) ([]string, error) { 28 | switch { 29 | case h.Userfile != "" && h.Username != "": 30 | return nil, errors.New("-u and -U cannot exist at the same time") 31 | case h.Userfile == "" && h.Username == "": 32 | return nil, errors.New("Please use -u or -U to specify the username") 33 | case h.Userfile == "" && h.Username != "": 34 | return []string{h.Username}, nil 35 | case h.Userfile != "" && h.Username == "": 36 | file, err := Readfile(h.Userfile) 37 | return file, err 38 | } 39 | return nil, errors.New("unknown error") 40 | } 41 | 42 | //Read the contents of the file 43 | func Readfile(filename string) ([]string, error) { 44 | file, err := os.Open(filename) 45 | if err != nil { 46 | return nil, errors.New("There was an error opening the file") 47 | } 48 | var content []string 49 | scanner := bufio.NewScanner(file) 50 | for scanner.Scan() { 51 | content = append(content, scanner.Text()) 52 | } 53 | return content, nil 54 | } 55 | -------------------------------------------------------------------------------- /Plugins/redis.go: -------------------------------------------------------------------------------- 1 | package Plugins 2 | 3 | import ( 4 | "../Misc" 5 | "../Parse" 6 | "fmt" 7 | "github.com/go-redis/redis" 8 | "strings" 9 | "sync" 10 | "time" 11 | ) 12 | 13 | func Redis(info Misc.HostInfo, ch chan int, wg *sync.WaitGroup) { 14 | ip := fmt.Sprintf("%s:%d", info.Host, info.Port) 15 | client := redis.NewClient(&redis.Options{ 16 | Addr: ip, 17 | Password: info.Password, 18 | DB: 0, 19 | }) 20 | pong, err := client.Ping().Result() 21 | if err != nil && !strings.Contains(pong, "PONG") && info.ErrShow { 22 | info.PrintFail() 23 | } else if err == nil && strings.Contains(pong, "PONG") { 24 | success += 1 25 | client.Close() 26 | info.PrintSuccess() 27 | if info.Output != "" { 28 | info.OutputTXT() 29 | } 30 | } 31 | wg.Done() 32 | <-ch 33 | } 34 | 35 | func RedisConn(info *Misc.HostInfo, ch chan int) { 36 | var hosts, passwords []string 37 | var err error 38 | var wg = sync.WaitGroup{} 39 | stime := time.Now() 40 | if info.Ports == "" { 41 | info.Port = REDISPORT 42 | } else { 43 | p, _ := Parse.ParsePort(info.Ports) 44 | info.Port = p[0] 45 | } 46 | 47 | hosts, err = Parse.ParseIP(info.Host) 48 | Misc.CheckErr(err) 49 | 50 | passwords, err = Parse.ParsePass(info) 51 | Misc.CheckErr(err) 52 | wg.Add(len(hosts) * len(passwords)) 53 | Misc.InfoPrinter.Println("Total length", len(hosts)*len(passwords)) 54 | for _, host := range hosts { 55 | for _, pass := range passwords { 56 | info.Host = host 57 | info.Password = pass 58 | go Redis(*info, ch, &wg) 59 | ch <- 1 60 | } 61 | } 62 | wg.Wait() 63 | end := time.Since(stime) 64 | Misc.InfoPrinter.Println("All Done") 65 | Misc.InfoPrinter.Println("Number of successes:", success) 66 | Misc.InfoPrinter.Println("Time consumed:", end) 67 | } 68 | -------------------------------------------------------------------------------- /Misc/infoprint.go: -------------------------------------------------------------------------------- 1 | package Misc 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | ) 8 | 9 | const REDCOLOR = "\x1B[0;40;31m[Failed] \x1B[0m" 10 | const GREEN = "\x1B[1;40;32m[Succeed] \x1B[0m" 11 | const ERR = "\x1B[0;40;31m[ERROR] \x1B[0m" 12 | const INFO = "\x1B[1;40;32m[*] \x1B[0m" 13 | const WARN = "\x1B[0;40;31m[*] \x1B[0m" 14 | 15 | var SucceedPrinter = log.New(os.Stdout, GREEN, log.LstdFlags) 16 | var FailedPrinter = log.New(os.Stdout, REDCOLOR, log.LstdFlags) 17 | var ErrPrinter = log.New(os.Stdout, ERR, log.LstdFlags) 18 | var InfoPrinter = log.New(os.Stdout, INFO, log.LstdFlags) 19 | var WarnPrinter = log.New(os.Stdout, WARN, log.LstdFlags) 20 | 21 | // Successful IP, account and password will be output here 22 | func (h *HostInfo) PrintSuccess() { 23 | info := fmt.Sprintf("Type: %s IP: %s:%d Username: %s Password: %s", h.Scantype, h.Host, h.Port, h.Username, h.Password) 24 | SucceedPrinter.Println(info) 25 | } 26 | 27 | func (h *HostInfo) PrintFail() { 28 | info := fmt.Sprintf("Type: %s IP: %s:%d Username: %s Password: %s", h.Scantype, h.Host, h.Port, h.Username, h.Password) 29 | FailedPrinter.Println(info) 30 | } 31 | 32 | //Output alive ports 33 | func (h *HostInfo) PrintSucceedPort() { 34 | info := fmt.Sprintf("IP: %s:%d", h.Host, h.Port) 35 | SucceedPrinter.Println(info) 36 | } 37 | 38 | //Output died ports 39 | func (h *HostInfo) PrintFailedPort() { 40 | info := fmt.Sprintf("IP: %s:%d", h.Host, h.Port) 41 | FailedPrinter.Println(info) 42 | } 43 | 44 | //Output alive hosts 45 | func (h *HostInfo) PrintSucceedHost() { 46 | info := fmt.Sprintf("IP: %s is aliving", h.Host) 47 | SucceedPrinter.Println(info) 48 | } 49 | 50 | //Output died hosts 51 | func (h *HostInfo) PrintFailedHost() { 52 | info := fmt.Sprintf("IP: %s is died", h.Host) 53 | FailedPrinter.Println(info) 54 | } 55 | -------------------------------------------------------------------------------- /Plugins/mgo.go: -------------------------------------------------------------------------------- 1 | package Plugins 2 | 3 | import ( 4 | "../Misc" 5 | "../Parse" 6 | "fmt" 7 | "gopkg.in/mgo.v2" 8 | _ "gopkg.in/mgo.v2" 9 | "sync" 10 | "time" 11 | ) 12 | 13 | func MongoDB(info Misc.HostInfo, ch chan int, wg *sync.WaitGroup) { 14 | 15 | url := fmt.Sprintf("mongodb://%s:%s@%s:%d", info.Username, info.Password, info.Host, info.Port) 16 | conn, err := mgo.DialWithTimeout(url, (time.Duration(info.Timeout))*time.Second) 17 | if err != nil && info.ErrShow { 18 | info.PrintFail() 19 | <-ch 20 | return 21 | } else if err == nil { 22 | success += 1 23 | conn.Close() 24 | info.PrintSuccess() 25 | if info.Output != "" { 26 | info.OutputTXT() 27 | } 28 | } 29 | wg.Done() 30 | <-ch 31 | } 32 | 33 | func MgoConn(info *Misc.HostInfo, ch chan int) { 34 | var wg = sync.WaitGroup{} 35 | var hosts, usernames, passwords []string 36 | var err error 37 | stime := time.Now() 38 | if info.Ports == "" { 39 | info.Port = MONGODBPORT 40 | } else { 41 | p, _ := Parse.ParsePort(info.Ports) 42 | info.Port = p[0] 43 | } 44 | 45 | hosts, err = Parse.ParseIP(info.Host) 46 | Misc.CheckErr(err) 47 | 48 | usernames, err = Parse.ParseUser(info) 49 | Misc.CheckErr(err) 50 | 51 | passwords, err = Parse.ParsePass(info) 52 | Misc.CheckErr(err) 53 | 54 | wg.Add(len(hosts) * len(usernames) * len(passwords)) 55 | Misc.InfoPrinter.Println("Total length", len(hosts)*len(usernames)*len(passwords)) 56 | for _, host := range hosts { 57 | for _, user := range usernames { 58 | for _, pass := range passwords { 59 | info.Host = host 60 | info.Username = user 61 | info.Password = pass 62 | go MongoDB(*info, ch, &wg) 63 | ch <- 1 64 | } 65 | } 66 | } 67 | wg.Wait() 68 | end := time.Since(stime) 69 | Misc.InfoPrinter.Println("All Done") 70 | Misc.InfoPrinter.Println("Number of successes:", success) 71 | Misc.InfoPrinter.Println("Time consumed:", end) 72 | } 73 | -------------------------------------------------------------------------------- /Plugins/memcached.go: -------------------------------------------------------------------------------- 1 | package Plugins 2 | 3 | import ( 4 | "../Misc" 5 | "../Parse" 6 | "fmt" 7 | "net" 8 | "strings" 9 | "sync" 10 | "time" 11 | ) 12 | 13 | func MemCached(info Misc.HostInfo, ch chan int, wg *sync.WaitGroup) { 14 | realhost := fmt.Sprintf("%s:%d", info.Host, info.Port) 15 | client, err := net.DialTimeout("tcp", realhost, time.Duration(info.Timeout)*time.Second) 16 | if err != nil && info.ErrShow { 17 | Misc.ErrPrinter.Println(err.Error()) 18 | <-ch 19 | wg.Done() 20 | return 21 | } else if err == nil { 22 | client.SetDeadline(time.Now().Add(time.Duration(info.Timeout))) 23 | client.Write([]byte("stats\n")) //Set the key randomly to prevent the key on the server from being overwritten 24 | rev := make([]byte, 1024) 25 | n, err := client.Read(rev) 26 | if err != nil && info.ErrShow { 27 | Misc.ErrPrinter.Println(err.Error()) 28 | } else if strings.Contains(string(rev[:n]), "STAT") { 29 | success += 1 30 | client.Close() 31 | info.PrintSuccess() 32 | 33 | } else { 34 | Misc.ErrPrinter.Println(string(rev[:n])) 35 | } 36 | } 37 | <-ch 38 | wg.Done() 39 | return 40 | } 41 | 42 | func MemConn(info *Misc.HostInfo, ch chan int) { 43 | var hosts []string 44 | var err error 45 | var wg = sync.WaitGroup{} 46 | stime := time.Now() 47 | if info.Ports == "" { 48 | info.Port = MEMCACHED 49 | } else { 50 | p, _ := Parse.ParsePort(info.Ports) 51 | info.Port = p[0] 52 | } 53 | 54 | hosts, err = Parse.ParseIP(info.Host) 55 | Misc.CheckErr(err) 56 | wg.Add(len(hosts)) 57 | Misc.InfoPrinter.Println("Total length", len(hosts)) 58 | for _, host := range hosts { 59 | info.Host = host 60 | go MemCached(*info, ch, &wg) 61 | ch <- 1 62 | } 63 | wg.Wait() 64 | end := time.Since(stime) 65 | Misc.InfoPrinter.Println("All Done") 66 | Misc.InfoPrinter.Println("Number of successes:", success) 67 | Misc.InfoPrinter.Println("Time consumed:", end) 68 | } 69 | -------------------------------------------------------------------------------- /Plugins/mssql.go: -------------------------------------------------------------------------------- 1 | package Plugins 2 | 3 | import ( 4 | "../Misc" 5 | "../Parse" 6 | "database/sql" 7 | "fmt" 8 | _ "github.com/denisenkom/go-mssqldb" 9 | "sync" 10 | "time" 11 | ) 12 | 13 | func MsSQL(info Misc.HostInfo, ch chan int, wg *sync.WaitGroup) { 14 | config := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%d;encrypt=disable;timeout=%d", 15 | info.Host, info.Username, info.Password, info.Port, info.Timeout) 16 | conn, err := sql.Open("mssql", config) 17 | if err != nil && info.ErrShow { 18 | info.PrintFail() 19 | <-ch 20 | return 21 | } 22 | err = conn.Ping() 23 | if err != nil && info.ErrShow { 24 | info.PrintFail() 25 | } else if err == nil { 26 | success += 1 27 | conn.Close() 28 | info.PrintSuccess() 29 | if info.Output != "" { 30 | info.OutputTXT() 31 | } 32 | } 33 | wg.Done() 34 | <-ch 35 | } 36 | 37 | func MssSQLConn(info *Misc.HostInfo, ch chan int) { 38 | var wg = sync.WaitGroup{} 39 | var hosts, usernames, passwords []string 40 | var err error 41 | stime := time.Now() 42 | if info.Ports == "" { 43 | info.Port = MSSQLPORT 44 | } else { 45 | p, _ := Parse.ParsePort(info.Ports) 46 | info.Port = p[0] 47 | } 48 | 49 | hosts, err = Parse.ParseIP(info.Host) 50 | Misc.CheckErr(err) 51 | 52 | usernames, err = Parse.ParseUser(info) 53 | Misc.CheckErr(err) 54 | 55 | passwords, err = Parse.ParsePass(info) 56 | Misc.CheckErr(err) 57 | wg.Add(len(hosts) * len(usernames) * len(passwords)) 58 | Misc.InfoPrinter.Println("Total length", len(hosts)*len(usernames)*len(passwords)) 59 | for _, host := range hosts { 60 | for _, user := range usernames { 61 | for _, pass := range passwords { 62 | info.Host = host 63 | info.Username = user 64 | info.Password = pass 65 | go MsSQL(*info, ch, &wg) 66 | ch <- 1 67 | } 68 | } 69 | } 70 | wg.Wait() 71 | end := time.Since(stime) 72 | Misc.InfoPrinter.Println("All Done") 73 | Misc.InfoPrinter.Println("Number of successes:", success) 74 | Misc.InfoPrinter.Println("Time consumed:", end) 75 | } 76 | -------------------------------------------------------------------------------- /Plugins/mysql.go: -------------------------------------------------------------------------------- 1 | package Plugins 2 | 3 | import ( 4 | "../Misc" 5 | "../Parse" 6 | "database/sql" 7 | "fmt" 8 | _ "github.com/go-sql-driver/mysql" 9 | "sync" 10 | "time" 11 | ) 12 | 13 | func MySQL(info Misc.HostInfo, ch chan int, wg *sync.WaitGroup) { 14 | url := fmt.Sprintf("%s:%s@tcp(%s:%d)/?charset=utf8&timeout=%ds", 15 | info.Username, info.Password, info.Host, info.Port, (time.Duration(info.Timeout))*time.Second) 16 | db, err := sql.Open("mysql", url) 17 | if err != nil && info.ErrShow { 18 | info.PrintFail() 19 | } else { 20 | err = db.Ping() 21 | if err != nil && info.ErrShow { 22 | info.PrintFail() 23 | } else if err == nil { 24 | success += 1 25 | db.Close() 26 | info.PrintSuccess() 27 | if info.Output != "" { 28 | info.OutputTXT() 29 | } 30 | } 31 | } 32 | 33 | wg.Done() 34 | <-ch 35 | } 36 | 37 | func MySQLConn(info *Misc.HostInfo, ch chan int) { 38 | var hosts, usernames, passwords []string 39 | var err error 40 | var wg = sync.WaitGroup{} 41 | stime := time.Now() 42 | if info.Ports == "" { 43 | info.Port = MYSQLPORT 44 | } else { 45 | p, _ := Parse.ParsePort(info.Ports) 46 | info.Port = p[0] 47 | } 48 | 49 | hosts, err = Parse.ParseIP(info.Host) 50 | Misc.CheckErr(err) 51 | 52 | usernames, err = Parse.ParseUser(info) 53 | Misc.CheckErr(err) 54 | 55 | passwords, err = Parse.ParsePass(info) 56 | Misc.CheckErr(err) 57 | 58 | wg.Add(len(hosts) * len(usernames) * len(passwords)) 59 | Misc.InfoPrinter.Println("Total length", len(hosts)*len(usernames)*len(passwords)) 60 | for _, host := range hosts { 61 | for _, user := range usernames { 62 | for _, pass := range passwords { 63 | info.Host = host 64 | info.Username = user 65 | info.Password = pass 66 | go MySQL(*info, ch, &wg) 67 | ch <- 1 68 | } 69 | } 70 | } 71 | wg.Wait() 72 | end := time.Since(stime) 73 | Misc.InfoPrinter.Println("All Done") 74 | Misc.InfoPrinter.Println("Number of successes:", success) 75 | Misc.InfoPrinter.Println("Time consumed:", end) 76 | } 77 | -------------------------------------------------------------------------------- /Plugins/ftp.go: -------------------------------------------------------------------------------- 1 | package Plugins 2 | 3 | import ( 4 | "../Misc" 5 | "../Parse" 6 | "fmt" 7 | "github.com/jlaffaye/ftp" 8 | "sync" 9 | "time" 10 | //"os" 11 | ) 12 | 13 | func Ftp(info Misc.HostInfo, ch chan int, wg *sync.WaitGroup) { 14 | var err error 15 | addr := fmt.Sprintf("%s:%d", info.Host, info.Port) 16 | client, err := ftp.Dial(addr, ftp.DialWithTimeout(time.Duration(info.Timeout)*time.Second)) 17 | if err != nil && info.ErrShow { 18 | Misc.ErrPrinter.Println(err.Error()) 19 | } else if err == nil { 20 | err = client.Login(info.Username, info.Password) 21 | if err != nil && info.ErrShow { 22 | info.PrintFail() 23 | } else if err == nil { 24 | client.Quit() 25 | client.Logout() 26 | success += 1 27 | info.PrintSuccess() 28 | if info.Output != "" { 29 | info.OutputTXT() 30 | } 31 | } 32 | } 33 | wg.Done() 34 | <-ch 35 | } 36 | 37 | func FtpConn(info *Misc.HostInfo, ch chan int) { 38 | var hosts, usernames, passwords []string 39 | var err error 40 | var wg = sync.WaitGroup{} 41 | stime := time.Now() 42 | if info.Ports == "" { 43 | info.Port = FTPPORT 44 | } else { 45 | p, _ := Parse.ParsePort(info.Ports) 46 | info.Port = p[0] 47 | } 48 | 49 | hosts, err = Parse.ParseIP(info.Host) 50 | Misc.CheckErr(err) 51 | 52 | usernames, err = Parse.ParseUser(info) 53 | Misc.CheckErr(err) 54 | 55 | passwords, err = Parse.ParsePass(info) 56 | Misc.CheckErr(err) 57 | 58 | wg.Add(len(hosts) * len(usernames) * len(passwords)) 59 | Misc.InfoPrinter.Println("Total length", len(hosts)*len(usernames)*len(passwords)) 60 | for _, host := range hosts { 61 | for _, user := range usernames { 62 | for _, pass := range passwords { 63 | info.Host = host 64 | info.Username = user 65 | info.Password = pass 66 | go Ftp(*info, ch, &wg) 67 | ch <- 1 68 | } 69 | } 70 | } 71 | wg.Wait() 72 | end := time.Since(stime) 73 | Misc.InfoPrinter.Println("All Done") 74 | Misc.InfoPrinter.Println("Number of successes:", success) 75 | Misc.InfoPrinter.Println("Time consumed:", end) 76 | } 77 | -------------------------------------------------------------------------------- /Plugins/ssh.go: -------------------------------------------------------------------------------- 1 | package Plugins 2 | 3 | import ( 4 | "../Misc" 5 | "../Parse" 6 | "fmt" 7 | "golang.org/x/crypto/ssh" 8 | "sync" 9 | "time" 10 | ) 11 | 12 | const SSHPORT = 22 13 | 14 | func SSH(info Misc.HostInfo, ch chan int, wg *sync.WaitGroup) { 15 | var err error 16 | config := &ssh.ClientConfig{ 17 | User: info.Username, 18 | Auth: []ssh.AuthMethod{ssh.Password(info.Password)}, 19 | Timeout: time.Duration(info.Timeout) * time.Second, 20 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 21 | } 22 | ip := fmt.Sprintf("%s:%d", info.Host, info.Port) 23 | client, err := ssh.Dial("tcp", ip, config) 24 | if err != nil && info.ErrShow { 25 | Misc.ErrPrinter.Println(err.Error()) 26 | } else if err == nil { 27 | success += 1 28 | client.Close() 29 | info.PrintSuccess() 30 | if info.Output != "" { 31 | info.OutputTXT() 32 | } 33 | } 34 | wg.Done() 35 | <-ch 36 | } 37 | 38 | func SSHConn(info *Misc.HostInfo, ch chan int) { 39 | var hosts, usernames, passwords []string 40 | var err error 41 | var wg = sync.WaitGroup{} 42 | stime := time.Now() 43 | if info.Ports == "" { 44 | info.Port = SSHPORT 45 | } else { 46 | p, _ := Parse.ParsePort(info.Ports) 47 | info.Port = p[0] 48 | } 49 | 50 | hosts, err = Parse.ParseIP(info.Host) 51 | Misc.CheckErr(err) 52 | 53 | usernames, err = Parse.ParseUser(info) 54 | Misc.CheckErr(err) 55 | 56 | passwords, err = Parse.ParsePass(info) 57 | Misc.CheckErr(err) 58 | wg.Add(len(hosts) * len(usernames) * len(passwords)) 59 | Misc.InfoPrinter.Println("Total length", len(hosts)*len(usernames)*len(passwords)) 60 | for _, host := range hosts { 61 | for _, user := range usernames { 62 | for _, pass := range passwords { 63 | info.Host = host 64 | info.Username = user 65 | info.Password = pass 66 | go SSH(*info, ch, &wg) 67 | ch <- 1 68 | } 69 | } 70 | } 71 | wg.Wait() 72 | end := time.Since(stime) 73 | Misc.InfoPrinter.Println("All Done") 74 | Misc.InfoPrinter.Println("Number of successes:", success) 75 | Misc.InfoPrinter.Println("Time consumed:", end) 76 | } 77 | -------------------------------------------------------------------------------- /Plugins/smb.go: -------------------------------------------------------------------------------- 1 | package Plugins 2 | 3 | import ( 4 | "../Misc" 5 | "../Parse" 6 | "context" 7 | "github.com/stacktitan/smb/smb" 8 | "sync" 9 | "time" 10 | ) 11 | 12 | func Smb(info Misc.HostInfo, ch chan int, wg *sync.WaitGroup) { 13 | tch := make(chan int) 14 | defer func() { 15 | <-ch 16 | wg.Done() 17 | }() 18 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(info.Timeout)) 19 | defer cancel() 20 | options := smb.Options{ 21 | Host: info.Host, 22 | Port: info.Port, 23 | User: info.Username, 24 | Domain: "", 25 | Workstation: "", 26 | Password: info.Password, 27 | } 28 | go func() { 29 | session, err := smb.NewSession(options, false) 30 | if err != nil && info.ErrShow { 31 | info.PrintFail() 32 | } else if session.IsAuthenticated { 33 | success += 1 34 | session.Close() 35 | info.PrintSuccess() 36 | if info.Output != "" { 37 | info.OutputTXT() 38 | } 39 | } 40 | <-tch 41 | }() 42 | select { 43 | case <-ctx.Done(): 44 | if info.ErrShow { 45 | Misc.ErrPrinter.Println(info.Url, "Time out") 46 | } 47 | return 48 | case <-tch: 49 | return 50 | } 51 | } 52 | 53 | func SmbConn(info *Misc.HostInfo, ch chan int) { 54 | var hosts, usernames, passwords []string 55 | var err error 56 | var wg = sync.WaitGroup{} 57 | stime := time.Now() 58 | if info.Ports == "" { 59 | info.Port = SMBPORT 60 | } else { 61 | p, _ := Parse.ParsePort(info.Ports) 62 | info.Port = p[0] 63 | } 64 | 65 | hosts, err = Parse.ParseIP(info.Host) 66 | Misc.CheckErr(err) 67 | 68 | usernames, err = Parse.ParseUser(info) 69 | Misc.CheckErr(err) 70 | 71 | passwords, err = Parse.ParsePass(info) 72 | Misc.CheckErr(err) 73 | 74 | wg.Add(len(hosts) * len(usernames) * len(passwords)) 75 | Misc.InfoPrinter.Println("Total length", len(hosts)*len(usernames)*len(passwords)) 76 | 77 | for _, host := range hosts { 78 | for _, user := range usernames { 79 | for _, pass := range passwords { 80 | info.Host = host 81 | info.Username = user 82 | info.Password = pass 83 | go Smb(*info, ch, &wg) 84 | ch <- 1 85 | } 86 | } 87 | } 88 | wg.Wait() 89 | end := time.Since(stime) 90 | Misc.InfoPrinter.Println("All Done") 91 | Misc.InfoPrinter.Println("Number of successes:", success) 92 | Misc.InfoPrinter.Println("Time consumed:", end) 93 | } 94 | -------------------------------------------------------------------------------- /Parse/ParseParam.go: -------------------------------------------------------------------------------- 1 | package Parse 2 | 3 | import ( 4 | "../Misc" 5 | "flag" 6 | "fmt" 7 | "os" 8 | ) 9 | 10 | var Param = &Misc.HostInfo{} 11 | 12 | //Initialize command line arguments 13 | func init() { 14 | flag.StringVar(&Param.INIFile, "f", "", "configuration file") 15 | flag.StringVar(&Param.Url, "url", "", "url") 16 | flag.StringVar(&Param.UrlFile, "uf", "", "Select the path to the url path dictionary") 17 | flag.BoolVar(&Param.ErrShow, "v", false, "Show details when scanning") 18 | flag.BoolVar(&Param.Help, "h", false, "Show help") 19 | flag.StringVar(&Param.Host, "host", "", "IP address of the host you want to scan,for example: 192.168.11.11 | 192.168.11.11-255 | 192.168.11.11,192.168.11.12") 20 | flag.BoolVar(&Param.Show, "show", false, "Show all scan type") 21 | flag.StringVar(&Param.Username, "u", "", "Specify a username") 22 | flag.StringVar(&Param.Password, "p", "", "Specify a password") 23 | flag.StringVar(&Param.Ports, "port", "", "Select a port,for example: 22 | 1-65535 | 22,80,3306") 24 | flag.StringVar(&Param.Userfile, "U", "", "Select the path to the username dictionary") 25 | flag.StringVar(&Param.Passfile, "P", "", "Select the path to the password dictionary") 26 | flag.StringVar(&Param.Scantype, "m", "", "Select the type you want to scan.If you don't know the scan type and you can add -show to show all scan types") 27 | flag.IntVar(&Param.Thread, "t", 300, "Set number of threads") 28 | flag.Int64Var(&Param.Timeout, "w", 2, "Set timeout") 29 | flag.StringVar(&Param.Output, "o", "", "Save the results of the scan to a file") 30 | flag.StringVar(&Param.Cookie, "cookie", "", "Set cookie") 31 | flag.StringVar(&Param.Header, "header", "", "Set http headers (format: JSON)") 32 | flag.Usage = Myusage 33 | } 34 | 35 | func Myusage() { 36 | fmt.Fprintf(os.Stdout, "Gscan [--host address|--url url] [-p port] [-u username|-U filename] [-uf urlfile] [-p password|-P filename] [-m type] [-t thread] [-w num] [-o output_file] [-v]\n") 37 | fmt.Fprintf(os.Stdout, "Examples:\n") 38 | fmt.Fprintf(os.Stdout, "Gscan --host 127.0.0.1 -p 1-65535 -m portscan\n") 39 | fmt.Fprintf(os.Stdout, "Gscan --host 127.0.0.1 -m ssh -u root -P pass.txt\n") 40 | fmt.Fprintf(os.Stdout, `Gscan --url http://www.test.com -m urlscan --cookie "PHPSESSID=abc" --header '{"X-FORWARDED-FOR":"test 41 | .com","Referer":"www.baidu.com"}'`) 42 | fmt.Println() 43 | fmt.Println("Usage:") 44 | flag.PrintDefaults() 45 | } 46 | -------------------------------------------------------------------------------- /Plugins/postgresql.go: -------------------------------------------------------------------------------- 1 | package Plugins 2 | 3 | import ( 4 | "../Misc" 5 | "../Parse" 6 | "context" 7 | "database/sql" 8 | "fmt" 9 | _ "github.com/lib/pq" 10 | "sync" 11 | "time" 12 | ) 13 | 14 | func PostgreSQL(info Misc.HostInfo, ch chan int, wg *sync.WaitGroup) { 15 | tch := make(chan int) 16 | defer func() { 17 | <-ch 18 | wg.Done() 19 | }() 20 | 21 | psqlInfo := fmt.Sprintf("host=%s port=%d user=%s password=%s sslmode=disable dbname=postgres", 22 | info.Host, info.Port, info.Username, info.Password) 23 | db, err := sql.Open("postgres", psqlInfo) 24 | if err != nil && info.ErrShow { 25 | info.PrintFail() 26 | } 27 | 28 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(info.Timeout)) 29 | defer cancel() 30 | go func() { 31 | err = db.Ping() 32 | if err != nil && info.ErrShow { 33 | info.PrintFail() 34 | } else if err == nil { 35 | db.Close() 36 | success += 1 37 | info.PrintSuccess() 38 | if info.Output != "" { 39 | info.OutputTXT() 40 | } 41 | } 42 | <-tch 43 | }() 44 | select { 45 | case <-ctx.Done(): 46 | if info.ErrShow { 47 | Misc.ErrPrinter.Println(info.Url, "Time out") 48 | } 49 | return 50 | case <-tch: 51 | return 52 | } 53 | } 54 | 55 | func PostgreSQLConn(info *Misc.HostInfo, ch chan int) { 56 | var hosts, usernames, passwords []string 57 | var err error 58 | var wg = sync.WaitGroup{} 59 | stime := time.Now() 60 | if info.Ports == "" { 61 | info.Port = PSQLPORT 62 | } else { 63 | p, _ := Parse.ParsePort(info.Ports) 64 | info.Port = p[0] 65 | } 66 | 67 | hosts, err = Parse.ParseIP(info.Host) 68 | Misc.CheckErr(err) 69 | 70 | usernames, err = Parse.ParseUser(info) 71 | Misc.CheckErr(err) 72 | 73 | passwords, err = Parse.ParsePass(info) 74 | Misc.CheckErr(err) 75 | 76 | wg.Add(len(hosts) * len(usernames) * len(passwords)) 77 | Misc.InfoPrinter.Println("Total length:", len(hosts)*len(usernames)*len(passwords)) 78 | for _, host := range hosts { 79 | for _, user := range usernames { 80 | for _, pass := range passwords { 81 | info.Host = host 82 | info.Username = user 83 | info.Password = pass 84 | go PostgreSQL(*info, ch, &wg) 85 | ch <- 1 86 | } 87 | } 88 | } 89 | wg.Wait() 90 | end := time.Since(stime) 91 | Misc.InfoPrinter.Println("All Done") 92 | Misc.InfoPrinter.Println("Number of successes:", success) 93 | Misc.InfoPrinter.Println("Time consumed:", end) 94 | } 95 | -------------------------------------------------------------------------------- /Parse/ParseIP.go: -------------------------------------------------------------------------------- 1 | package Parse 2 | 3 | import ( 4 | "errors" 5 | "net" 6 | "regexp" 7 | "strconv" 8 | "strings" 9 | ) 10 | 11 | var ParseIPErr error = errors.New("host parsing error\n" + 12 | "format: \n" + 13 | "www.baidu.com\n" + 14 | "192.168.1.1/24\n" + 15 | "192.168.1.1\n" + 16 | "192.168.1.1,192.168.1.2\n" + 17 | "192.168.1.1-255") 18 | 19 | //Choose the way to resolve IP according to IP address format 20 | func ParseIP(ip string) ([]string, error) { 21 | reg := regexp.MustCompile(`[a-zA-Z]+`) 22 | switch { 23 | case strings.Contains(ip[len(ip)-3:len(ip)], "/24"): 24 | return ParseIPA(ip) 25 | case strings.Contains(ip, ","): 26 | return ParseIPB(ip) 27 | case strings.Count(ip, "-") == 1: 28 | return ParseIPC(ip) 29 | case reg.MatchString(ip): 30 | _, err := net.LookupHost(ip) 31 | if err != nil { 32 | return nil, err 33 | } 34 | return []string{ip}, nil 35 | default: 36 | testIP := net.ParseIP(ip) 37 | if testIP == nil { 38 | return nil, ParseIPErr 39 | } 40 | return []string{ip}, nil 41 | } 42 | } 43 | 44 | //Parsing CIDR IP 45 | func ParseIPA(ip string) ([]string, error) { 46 | realIP := ip[:len(ip)-3] 47 | testIP := net.ParseIP(realIP) 48 | if testIP == nil { 49 | return nil, ParseIPErr 50 | } 51 | IPrange := strings.Join(strings.Split(realIP, ".")[0:3], ".") 52 | var AllIP []string 53 | for i := 0; i <= 255; i++ { 54 | AllIP = append(AllIP, IPrange+"."+strconv.Itoa(i)) 55 | } 56 | return AllIP, nil 57 | } 58 | 59 | //Resolving multiple IPS, for example: 192.168.111.1,192.168.111.2 60 | func ParseIPB(ip string) ([]string, error) { 61 | IPList := strings.Split(ip, ",") 62 | for _, i := range IPList { 63 | testIP := net.ParseIP(i) 64 | if testIP == nil { 65 | return nil, ParseIPErr 66 | } 67 | } 68 | return IPList, nil 69 | 70 | } 71 | 72 | //Resolving a range of IP,for example: 192.168.111.1-255 73 | func ParseIPC(ip string) ([]string, error) { 74 | IPRange := strings.Split(ip, "-") 75 | testIP := net.ParseIP(IPRange[0]) 76 | Range, err := strconv.Atoi(IPRange[1]) 77 | if testIP == nil || Range > 255 || err != nil { 78 | return nil, ParseIPErr 79 | } 80 | SplitIP := strings.Split(IPRange[0], ".") 81 | ip1, err1 := strconv.Atoi(SplitIP[3]) 82 | ip2, err2 := strconv.Atoi(IPRange[1]) 83 | PrefixIP := strings.Join(SplitIP[0:3], ".") 84 | var AllIP []string 85 | if ip1 > ip2 || err1 != nil || err2 != nil { 86 | return nil, ParseIPErr 87 | } 88 | for i := ip1; i <= ip2; i++ { 89 | AllIP = append(AllIP, PrefixIP+"."+strconv.Itoa(i)) 90 | } 91 | return AllIP, nil 92 | 93 | } 94 | -------------------------------------------------------------------------------- /Plugins/apacheauth.go: -------------------------------------------------------------------------------- 1 | package Plugins 2 | 3 | import ( 4 | "../Misc" 5 | "../Parse" 6 | "encoding/base64" 7 | "encoding/json" 8 | "fmt" 9 | "io/ioutil" 10 | "net" 11 | "net/http" 12 | "sync" 13 | "time" 14 | ) 15 | 16 | func Apache(info Misc.HostInfo, ch chan int, wg *sync.WaitGroup, client *http.Client) { 17 | auth := fmt.Sprintf("%s:%s", info.Username, info.Password) 18 | b64auth := base64.StdEncoding.EncodeToString([]byte(auth)) 19 | res, _ := http.NewRequest("GET", info.Url, nil) 20 | res.Header.Add("Authorization", "Basic "+b64auth) 21 | if info.Cookie != "" { 22 | res.Header.Add("Cookie", info.Cookie) 23 | } 24 | if info.Header != "" { 25 | var header = make(map[string]string) 26 | err := json.Unmarshal([]byte(info.Header), &header) 27 | if err != nil { 28 | Misc.CheckErr(err) 29 | } 30 | for k, v := range header { 31 | res.Header.Add(k, v) 32 | } 33 | } 34 | resp, err := client.Do(res) 35 | if err != nil && info.ErrShow { 36 | Misc.ErrPrinter.Println(err.Error()) 37 | } else if err == nil { 38 | if resp.StatusCode == 200 { 39 | success += 1 40 | info.PrintSuccess() 41 | if info.Output != "" { 42 | info.OutputTXT() 43 | } 44 | } else if resp.StatusCode != 200 && info.ErrShow { 45 | info.PrintFail() 46 | } 47 | ioutil.ReadAll(resp.Body) 48 | resp.Body.Close() 49 | } 50 | wg.Done() 51 | <-ch 52 | } 53 | 54 | func ApacheConn(info *Misc.HostInfo, ch chan int) { 55 | var usernames, passwords []string 56 | var err error 57 | var wg = sync.WaitGroup{} 58 | stime := time.Now() 59 | 60 | var client = &http.Client{ 61 | Transport: &http.Transport{ 62 | DialContext: (&net.Dialer{ 63 | Timeout: time.Second * time.Duration(info.Timeout), 64 | }).DialContext, 65 | }, 66 | CheckRedirect: func(req *http.Request, via []*http.Request) error { 67 | return http.ErrUseLastResponse 68 | }, 69 | } 70 | if info.UrlFile == "" { 71 | info.UrlFile = URLFILE 72 | } 73 | 74 | url, err := Parse.ParseUrl(info.Url) 75 | Misc.CheckErr(err) 76 | info.Url = url 77 | 78 | usernames, err = Parse.ParseUser(info) 79 | Misc.CheckErr(err) 80 | 81 | passwords, err = Parse.ParsePass(info) 82 | Misc.CheckErr(err) 83 | 84 | wg.Add(len(usernames) * len(passwords)) 85 | Misc.InfoPrinter.Println("Total length", len(usernames)*len(passwords)) 86 | for _, user := range usernames { 87 | for _, pass := range passwords { 88 | info.Username = user 89 | info.Password = pass 90 | go Apache(*info, ch, &wg, client) 91 | ch <- 1 92 | } 93 | } 94 | wg.Wait() 95 | end := time.Since(stime) 96 | Misc.InfoPrinter.Println("All Done") 97 | Misc.InfoPrinter.Println("Number of successes:", success) 98 | Misc.InfoPrinter.Println("Time consumed:", end) 99 | } 100 | -------------------------------------------------------------------------------- /Plugins/urlscan.go: -------------------------------------------------------------------------------- 1 | package Plugins 2 | 3 | import ( 4 | "../Misc" 5 | "../Parse" 6 | "encoding/json" 7 | "fmt" 8 | "io/ioutil" 9 | "net" 10 | "net/http" 11 | "sync" 12 | "time" 13 | ) 14 | 15 | func WebScan(info Misc.HostInfo, ch chan int, wg *sync.WaitGroup, client *http.Client) { 16 | res, err := http.NewRequest("GET", info.Url, nil) 17 | if err != nil && info.ErrShow { 18 | Misc.ErrPrinter.Println(err) 19 | } else if err == nil { 20 | res.Header.Add("Connection", "keep-alive") 21 | res.Header.Add("User-agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36") 22 | res.Header.Add("Accept", "*/*") 23 | res.Header.Add("Accept-Language", "en-us") 24 | res.Header.Add("Accept-Encoding", "identity") 25 | if info.Cookie != "" { 26 | res.Header.Add("Cookie", info.Cookie) 27 | } 28 | if info.Header != "" { 29 | var header = make(map[string]string) 30 | err := json.Unmarshal([]byte(info.Header), &header) 31 | if err != nil { 32 | Misc.CheckErr(err) 33 | } 34 | for k, v := range header { 35 | res.Header.Add(k, v) 36 | } 37 | } 38 | resp, err := client.Do(res) 39 | if err != nil && info.ErrShow { 40 | Misc.ErrPrinter.Println(err) 41 | } else if err == nil { 42 | UrlPrint(resp.StatusCode, info.Url, info.ErrShow, info) 43 | ioutil.ReadAll(resp.Body) 44 | resp.Body.Close() 45 | } 46 | } 47 | wg.Done() 48 | <-ch 49 | } 50 | 51 | func UrlConn(info *Misc.HostInfo, ch chan int) { 52 | stime := time.Now() 53 | var wg = sync.WaitGroup{} 54 | url, err := Parse.ParseUrl(info.Url) 55 | Misc.CheckErr(err) 56 | 57 | var client = &http.Client{ 58 | Transport: &http.Transport{ 59 | DialContext: (&net.Dialer{ 60 | Timeout: time.Second * time.Duration(info.Timeout), 61 | }).DialContext, 62 | }, 63 | CheckRedirect: func(req *http.Request, via []*http.Request) error { 64 | return http.ErrUseLastResponse 65 | }, 66 | } 67 | if info.UrlFile == "" { 68 | info.UrlFile = URLFILE 69 | } 70 | pathes, err := Parse.Readfile(info.UrlFile) 71 | Misc.CheckErr(err) 72 | wg.Add(len(pathes)) 73 | Misc.InfoPrinter.Println("Total length", len(pathes)) 74 | for _, path := range pathes { 75 | info.Url = url + path 76 | go WebScan(*info, ch, &wg, client) 77 | ch <- 1 78 | } 79 | wg.Wait() 80 | end := time.Since(stime) 81 | Misc.InfoPrinter.Println("All Done") 82 | Misc.InfoPrinter.Println("Number of successes:", success) 83 | Misc.InfoPrinter.Println("Time consumed:", end) 84 | } 85 | 86 | func UrlPrint(code int, url string, ErrShow bool, info Misc.HostInfo) { 87 | if code == 200 { 88 | urlpath := fmt.Sprintf("%s\x1B[1;40;32m[%d]\x1B[0m", url, code) 89 | fmt.Println(urlpath) 90 | if info.Output != "" { 91 | info.OutputTXT() 92 | } 93 | } else if code != 404 && code != 200 { 94 | urlpath := fmt.Sprintf("%s\x1B[1;40;33m[%d]\x1B[0m", url, code) 95 | fmt.Println(urlpath) 96 | if info.Output != "" { 97 | info.OutputTXT() 98 | } 99 | } else if ErrShow && code == 404 { 100 | urlpath := fmt.Sprintf("%s\x1B[0;40;31m[%d]\x1B[0m", url, code) 101 | fmt.Println(urlpath) 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 48 | 49 | 50 | 51 | 53 | 54 | 55 | 56 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 |