This commit is contained in:
shadow1ng
2020-11-15 22:17:57 +08:00
parent 38fc6dd0c3
commit cdbd1aebc2
10 changed files with 101 additions and 19 deletions
+10 -2
View File
@@ -74,7 +74,7 @@ func Readfile(filename string)([]string,error){
file, err := os.Open(filename)
if err!=nil{
fmt.Println("Open %s error, %v", filename,err)
return nil,err
os.Exit(0)
}
defer file.Close()
var content []string
@@ -92,7 +92,7 @@ func Readfile(filename string)([]string,error){
func ParseInput(Info *HostInfo){
if Info.Host==""{
if Info.Host=="" && Info.HostFile ==""{
fmt.Println("Host is none")
flag.Usage()
os.Exit(0)
@@ -123,4 +123,12 @@ func ParseScantype(Info *HostInfo){
PORTList[name] = ScanPort
}
}
}
func CheckErr(text string,err error){
if err!=nil{
fmt.Println(text,err.Error())
os.Exit(0)
}
}
+75 -7
View File
@@ -1,21 +1,57 @@
package common
import (
"bufio"
"errors"
"fmt"
"net"
"os"
"regexp"
"strconv"
"strings"
)
var ParseIPErr error =errors.New("host parsing error\n" +
var ParseIPErr =errors.New("host parsing error\n" +
"format: \n"+
"192.168.1.1/24\n"+
"192.168.1.1\n" +
"192.168.1.1/8\n"+
"192.168.1.1/16\n"+
"192.168.1.1/24\n"+
"192.168.1.1,192.168.1.2\n" +
"192.168.1.1-255")
func ParseIP(ip string)([]string,error){
func ParseIP(ip string,filename string)(hosts []string,err error){
if ip != ""{
hosts,err = ParseIPs(ip)
}
if filename != ""{
var filehost []string
filehost,_ = Readipfile(filename)
hosts = append(hosts,filehost...)
}
hosts = RemoveDuplicate(hosts)
return hosts,err
}
func ParseIPs(ip string)(hosts []string,err error){
if strings.Contains(ip,","){
IPList:=strings.Split(ip,",")
var ips []string
for _,ip:=range IPList{
ips,err = ParseIPone(ip)
CheckErr(ip,err)
hosts = append(hosts,ips...)
}
return hosts,err
}else {
hosts,err = ParseIPone(ip)
CheckErr(ip,err)
return hosts,err
}
}
func ParseIPone(ip string)([]string,error){
reg:=regexp.MustCompile(`[a-zA-Z]+`)
switch {
case strings.Contains(ip[len(ip)-3:len(ip)],"/24"):
@@ -24,8 +60,6 @@ func ParseIP(ip string)([]string,error){
return ParseIPD(ip)
case strings.Contains(ip[len(ip)-2:len(ip)],"/8"):
return ParseIPE(ip)
case strings.Contains(ip,","):
return ParseIPB(ip)
case strings.Count(ip,"-")==1:
return ParseIPC(ip)
case reg.MatchString(ip):
@@ -42,7 +76,6 @@ func ParseIP(ip string)([]string,error){
return []string{ip},nil
}
}
//Parsing CIDR IP
func ParseIPA(ip string)([]string,error){
realIP:=ip[:len(ip)-3]
@@ -128,4 +161,39 @@ func ParseIPE(ip string)([]string,error){
}
}
return AllIP,nil
}
}
func Readipfile(filename string)([]string,error){
file, err := os.Open(filename)
if err!=nil{
fmt.Println("Open %s error, %v", filename,err)
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 != "" {
host,err := ParseIPs(text)
CheckErr(text,err)
content=append(content,host...)
}
}
return content,nil
}
func RemoveDuplicate(old []string) ([]string) {
result := make([]string, 0, len(old))
temp := map[string]struct{}{}
for _, item := range old {
if _, ok := temp[item]; !ok {
temp[item] = struct{}{}
result = append(result, item)
}
}
return result
}
+1
View File
@@ -39,6 +39,7 @@ var DefaultPorts = "21,22,23,80,135,443,445,1433,1521,3306,5432,6379,7001,8080,8
type HostInfo struct {
Host string
HostFile string
Ports string
Url string
Timeout int64
+1
View File
@@ -22,6 +22,7 @@ func Banner(){
func Flag(Info *HostInfo) {
Banner()
flag.StringVar(&Info.Host,"h","","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")
flag.StringVar(&Info.HostFile,"hf","","host file, -hs ip.txt")
flag.StringVar(&Info.Ports,"p",DefaultPorts,"Select a port,for example: 22 | 1-65535 | 22,80,3306")
flag.StringVar(&Info.Command,"c","","exec command (ssh)")
flag.IntVar(&Info.Threads,"t",100,"Thread nums")