This commit is contained in:
shadow1ng
2020-11-14 00:27:55 +08:00
parent 58ae604eea
commit f89feaf89f
10 changed files with 220 additions and 81 deletions
+9
View File
@@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"os"
"strconv"
"strings"
)
@@ -114,4 +115,12 @@ func ParseScantype(Info *HostInfo){
}
os.Exit(0)
}
if Info.Scantype != "all" && Info.Ports != DefaultPorts{
ScanPort := ParsePort(Info.Ports)[0]
Info.Ports = strconv.Itoa(ScanPort)
fmt.Println("if -m and -p only scan the first port:",Info.Ports)
for name,_:=range PORTList{
PORTList[name] = ScanPort
}
}
}
+30 -59
View File
@@ -1,60 +1,31 @@
package common
//
//import (
// "errors"
// "strconv"
// "strings"
//)
//
//var ParsePortErr error =errors.New("Port parsing error")
//
//func ParsePort(port string)([]int,error){
// RealPort,err:=strconv.Atoi(port)
// switch {
// case err==nil && CheckPort(RealPort):
// return []int{RealPort},nil
// case strings.Contains(port,","):
// return ParsePortB(port)
// case strings.Count(port,"-")==1:
// return ParsePortC(port)
// default:
// return nil,ParsePortErr
// }
//}
//
////Parsing multiple ports, for example: 22,80,3306
//func ParsePortB(port string)([]int ,error){
// var AllPort []int
// port1:=strings.Split(port,",")
// for _,p:=range port1{
// RealPort,err:=strconv.Atoi(p)
// if !CheckPort(RealPort) && err!=nil{
// return nil,ParsePortErr
// }
// AllPort=append(AllPort,RealPort)
// }
// return AllPort,nil
//}
//
////Parsing a range of port,for example: 22-3306
//func ParsePortC(port string)([]int ,error){
// var AllPort []int
// RangePort:=strings.Split(port,"-")
// port1,err1:=strconv.Atoi(RangePort[0])
// port2,err2:=strconv.Atoi(RangePort[1])
// if port1>port2 || err1!=nil || err2!=nil || !CheckPort(port1) || !CheckPort(port2){
// return nil,ParsePortErr
// }
// for i:=port1;i<=port2;i++{
// AllPort=append(AllPort,i)
// }
// return AllPort,nil
//}
//
//
//func CheckPort(port int)bool{
// if port<=0 || port >65535{
// return false
// }
// return true
//}
import (
"sort"
"strconv"
"strings"
)
func ParsePort(ports string) []int {
var scanPorts []int
slices := strings.Split(ports, ",")
for _, port := range slices {
port = strings.Trim(port, " ")
upper := port
if strings.Contains(port, "-") {
ranges := strings.Split(port, "-")
if len(ranges) < 2 {
continue
}
sort.Strings(ranges)
port = ranges[0]
upper = ranges[1]
}
start, _ := strconv.Atoi(port)
end, _ := strconv.Atoi(upper)
for i := start; i <= end; i++ {
scanPorts = append(scanPorts, i)
}
}
return scanPorts
}
+1
View File
@@ -34,6 +34,7 @@ var PORTList = map[string]int{
var Outputfile = "result.txt"
var IsSave = true
var DefaultPorts = "21,22,23,80,135,443,445,1433,1521,3306,5432,6379,7001,8080,8089,9000,9200,11211,27017"
type HostInfo struct {
+2 -3
View File
@@ -21,9 +21,8 @@ func Banner(){
func Flag(Info *HostInfo) {
Banner()
Ports := "21,22,23,80,135,443,445,1433,1521,3306,5432,6379,7001,8080,8089,9000,9200,11211,27017"
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.Ports,"p",Ports,"Select a port,for example: 22 | 1-65535 | 22,80,3306")
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")
flag.BoolVar(&Info.Isping,"np",false,"not to ping")
@@ -36,6 +35,6 @@ func Flag(Info *HostInfo) {
flag.Int64Var(&Info.Timeout,"time",3,"Set timeout")
flag.StringVar(&Info.Scantype,"m","all","Select scan type ,as: -m ssh")
flag.StringVar(&Info.RedisFile,"rf","","redis file to write sshkey file (as: -rf id_rsa.pub) ")
flag.StringVar(&Info.RedisFile,"rs","","redis shell to write cron file (as: -rs 127.0.0.1:4444) ")
flag.StringVar(&Info.RedisFile,"rs","","redis shell to write cron file (as: -rs 192.168.1.1:6666) ")
flag.Parse()
}