|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "./package/icmpcheck" |
| 5 | + "./package/portscan" |
| 6 | + "./package/vscan" |
| 7 | + "fmt" |
| 8 | + "github.com/malfunkt/iprange" |
| 9 | + "os" |
| 10 | + "regexp" |
| 11 | +) |
| 12 | + |
| 13 | +func main(){ |
| 14 | + var argv []string |
| 15 | + |
| 16 | + if (len(os.Args) != 4) { |
| 17 | + fmt.Println("ServerScan for Port Scaner and Service Version Detection.\nVersion: v1.0.2\nBy: Trim\n" + |
| 18 | + "HOST Host to be scanned, supports four formats:\n\t\t192.168.1.1\n\t\t192.168.1.1-10\n\t\t192.168.1.*\n\t\t192.168.1.0/24\n"+ |
| 19 | + "PORT Customize port list, separate with ',' example: 21,22,80-99,8000-8080 ...\n"+ |
| 20 | + "MODEL Scan Model: icmp or tcp") |
| 21 | + os.Exit(0) |
| 22 | + } |
| 23 | + |
| 24 | + for _, s := range os.Args { |
| 25 | + argv = append(argv,s) |
| 26 | + } |
| 27 | + |
| 28 | + hosts := argv[1] |
| 29 | + |
| 30 | + hostsPattern := `^(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\/(\d{1}|[0-2]{1}\d{1}|3[0-2])$|^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})){3}$` |
| 31 | + hostsRegexp := regexp.MustCompile(hostsPattern) |
| 32 | + checkHost := hostsRegexp.MatchString(hosts) |
| 33 | + |
| 34 | + hostsPattern2 := `\b(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})\-((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2}))\b` |
| 35 | + hostsRegexp2 := regexp.MustCompile(hostsPattern2) |
| 36 | + checkHost2 := hostsRegexp2.MatchString(hosts) |
| 37 | + |
| 38 | + hostsPattern3 := `((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(\*$)` |
| 39 | + hostsRegexp3 := regexp.MustCompile(hostsPattern3) |
| 40 | + checkHost3 := hostsRegexp3.MatchString(hosts) |
| 41 | + |
| 42 | + if hosts == "" || (checkHost == false && checkHost2 == false && checkHost3 == false){ |
| 43 | + fmt.Println("HOST Host to be scanned, supports four formats:\n\t\t192.168.1.1\n\t\t192.168.1.1-10\n\t\t192.168.1.*\n\t\t192.168.1.0/24\n") |
| 44 | + os.Exit(0) |
| 45 | + } |
| 46 | + |
| 47 | + var hostLists []string |
| 48 | + hostlist, err := iprange.ParseList(hosts) |
| 49 | + if err == nil { |
| 50 | + hostsList := hostlist.Expand() |
| 51 | + for _, host := range hostsList { |
| 52 | + host :=host.String() |
| 53 | + hostLists = append(hostLists, host) |
| 54 | + } |
| 55 | + }else { |
| 56 | + fmt.Println("HOST Host to be scanned, supports four formats:\n\t\t192.168.1.1\n\t\t192.168.1.1-10\n\t\t192.168.1.*\n\t\t192.168.1.0/24\n") |
| 57 | + os.Exit(0) |
| 58 | + } |
| 59 | + |
| 60 | + |
| 61 | + ports := argv[2] |
| 62 | + portsPattern := `^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$|^\d+(-\d+)?(,\d+(-\d+)?)*$` |
| 63 | + portsRegexp := regexp.MustCompile(portsPattern) |
| 64 | + checkPort := portsRegexp.MatchString(ports) |
| 65 | + if ports != "" && checkPort == false{ |
| 66 | + fmt.Println("PORT Error. Customize port list, separate with ',' example: 21,22,80-99,8000-8080 ...\n") |
| 67 | + os.Exit(0) |
| 68 | + } |
| 69 | + |
| 70 | + model := argv[3] |
| 71 | + |
| 72 | + var AliveHosts []string |
| 73 | + var AliveAddress []string |
| 74 | + |
| 75 | + if model == "icmp"{ |
| 76 | + AliveHosts = icmpcheck.ICMPRun(hostLists) |
| 77 | + for _,host :=range AliveHosts{ |
| 78 | + fmt.Printf("(ICMP) Target '%s' is alive\n",host) |
| 79 | + } |
| 80 | + _,AliveAddress = portscan.TCPportScan(AliveHosts,ports,model) |
| 81 | + }else if (model == "tcp"){ |
| 82 | + AliveHosts,AliveAddress = portscan.TCPportScan(hostLists,ports,model) |
| 83 | + for _,host :=range AliveHosts{ |
| 84 | + fmt.Printf("(TCP) Target '%s' is alive\n",host) |
| 85 | + } |
| 86 | + for _,addr :=range AliveAddress{ |
| 87 | + fmt.Println(addr) |
| 88 | + } |
| 89 | + }else { |
| 90 | + fmt.Println("MODEL Error. Scan Model: icmp or tcp") |
| 91 | + os.Exit(0) |
| 92 | + } |
| 93 | + |
| 94 | + if len(AliveAddress) > 0 { |
| 95 | + vscan.GetProbes(AliveAddress) |
| 96 | + } |
| 97 | + |
| 98 | +} |
0 commit comments