Skip to content

Commit 3baa6cc

Browse files
committed
v 1.0.2
1 parent d581226 commit 3baa6cc

26 files changed

Lines changed: 3482 additions & 0 deletions

File tree

ServerScan Air/main_air.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package main
2+
3+
import (
4+
"./package/icmpcheck"
5+
"./package/portscan"
6+
"fmt"
7+
"github.com/malfunkt/iprange"
8+
"os"
9+
"regexp"
10+
)
11+
12+
func main(){
13+
var argv []string
14+
15+
if (len(os.Args) != 4) {
16+
fmt.Println("ServerScan for Port Scaner.\nVersion: v1.0.2\nBy: Trim\n" +
17+
"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"+
18+
"PORT Customize port list, separate with ',' example: 21,22,80-99,8000-8080 ...\n"+
19+
"MODEL Scan Model: icmp or tcp")
20+
os.Exit(0)
21+
}
22+
23+
for _, s := range os.Args {
24+
argv = append(argv,s)
25+
}
26+
27+
hosts := argv[1]
28+
29+
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}$`
30+
hostsRegexp := regexp.MustCompile(hostsPattern)
31+
checkHost := hostsRegexp.MatchString(hosts)
32+
33+
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`
34+
hostsRegexp2 := regexp.MustCompile(hostsPattern2)
35+
checkHost2 := hostsRegexp2.MatchString(hosts)
36+
37+
hostsPattern3 := `((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(\*$)`
38+
hostsRegexp3 := regexp.MustCompile(hostsPattern3)
39+
checkHost3 := hostsRegexp3.MatchString(hosts)
40+
41+
if hosts == "" || (checkHost == false && checkHost2 == false && checkHost3 == false){
42+
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")
43+
os.Exit(0)
44+
}
45+
46+
var hostLists []string
47+
hostlist, err := iprange.ParseList(hosts)
48+
if err == nil {
49+
hostsList := hostlist.Expand()
50+
for _, host := range hostsList {
51+
host :=host.String()
52+
hostLists = append(hostLists, host)
53+
}
54+
}else {
55+
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")
56+
os.Exit(0)
57+
}
58+
59+
60+
ports := argv[2]
61+
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+)?)*$`
62+
portsRegexp := regexp.MustCompile(portsPattern)
63+
checkPort := portsRegexp.MatchString(ports)
64+
if ports != "" && checkPort == false{
65+
fmt.Println("PORT Error. Customize port list, separate with ',' example: 21,22,80-99,8000-8080 ...\n")
66+
os.Exit(0)
67+
}
68+
69+
model := argv[3]
70+
71+
if model == "icmp"{
72+
AliveHosts := icmpcheck.ICMPRun(hostLists)
73+
for _,host :=range AliveHosts{
74+
fmt.Printf("(ICMP) Target '%s' is alive\n",host)
75+
}
76+
portscan.TCPportScan(AliveHosts,ports,model)
77+
}else if (model == "tcp"){
78+
aliveHosts,AliveAddress := portscan.TCPportScan(hostLists,ports,model)
79+
for _,host :=range aliveHosts{
80+
fmt.Printf("(TCP) Target '%s' is alive\n",host)
81+
}
82+
for _,addr :=range AliveAddress{
83+
fmt.Println(addr)
84+
}
85+
}else {
86+
fmt.Println("MODEL Error. Scan Model: icmp or tcp")
87+
os.Exit(0)
88+
}
89+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package getsysinfo
2+
3+
import (
4+
"os"
5+
"os/user"
6+
"runtime"
7+
)
8+
9+
type SystemInfo struct {
10+
OS string
11+
ARCH string
12+
HostName string
13+
Groupid string
14+
Userid string
15+
Username string
16+
UserHomeDir string
17+
}
18+
19+
func GetSys() SystemInfo {
20+
var sysinfo SystemInfo
21+
22+
sysinfo.OS = runtime.GOOS
23+
sysinfo.ARCH = runtime.GOARCH
24+
name, err := os.Hostname()
25+
if err == nil {
26+
sysinfo.HostName = name
27+
}
28+
29+
u, err := user.Current()
30+
sysinfo.Groupid = u.Gid
31+
sysinfo.Userid = u.Uid
32+
sysinfo.Username = u.Username
33+
sysinfo.UserHomeDir = u.HomeDir
34+
35+
return sysinfo
36+
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
package icmpcheck
2+
3+
import (
4+
"../getsysinfo"
5+
"bytes"
6+
"encoding/binary"
7+
"fmt"
8+
"net"
9+
"os/exec"
10+
"strings"
11+
"sync"
12+
"time"
13+
)
14+
15+
var icmp ICMP
16+
17+
var AliveHosts []string
18+
19+
type ICMP struct {
20+
Type uint8
21+
Code uint8
22+
Checksum uint16
23+
Identifier uint16
24+
SequenceNum uint16
25+
}
26+
27+
func isping(ip string) bool {
28+
icmp.Type = 8
29+
icmp.Code = 0
30+
icmp.Checksum = 0
31+
icmp.Identifier = 0
32+
icmp.SequenceNum = 0
33+
34+
recvBuf := make([]byte, 32)
35+
var buffer bytes.Buffer
36+
37+
binary.Write(&buffer, binary.BigEndian, icmp)
38+
icmp.Checksum = CheckSum(buffer.Bytes())
39+
40+
buffer.Reset()
41+
binary.Write(&buffer, binary.BigEndian, icmp)
42+
43+
Time, _ := time.ParseDuration("2s")
44+
conn, err := net.DialTimeout("ip4:icmp", ip, Time)
45+
if err != nil {
46+
return false
47+
}
48+
_, err = conn.Write(buffer.Bytes())
49+
if err != nil {
50+
return false
51+
}
52+
conn.SetReadDeadline(time.Now().Add(time.Second * 2))
53+
num, err := conn.Read(recvBuf)
54+
if err != nil {
55+
return false
56+
}
57+
58+
conn.SetReadDeadline(time.Time{})
59+
60+
if string(recvBuf[0:num]) != "" {
61+
return true
62+
}
63+
return false
64+
65+
}
66+
67+
func CheckSum(data []byte) uint16 {
68+
var (
69+
sum uint32
70+
length int = len(data)
71+
index int
72+
)
73+
for length > 1 {
74+
sum += uint32(data[index])<<8 + uint32(data[index+1])
75+
index += 2
76+
length -= 2
77+
}
78+
if length > 0 {
79+
sum += uint32(data[index])
80+
}
81+
sum += (sum >> 16)
82+
83+
return uint16(^sum)
84+
}
85+
86+
func IcmpCheck(hostslist []string) {
87+
var wg sync.WaitGroup
88+
mutex := &sync.Mutex{}
89+
for _,host :=range hostslist{
90+
wg.Add(1)
91+
go func(host string) {
92+
defer wg.Done()
93+
if isping(host){
94+
mutex.Lock()
95+
AliveHosts = append(AliveHosts, host)
96+
mutex.Unlock()
97+
}
98+
}(host)
99+
}
100+
wg.Wait()
101+
}
102+
103+
func ExecCommandPing(ip string,bsenv string) bool {
104+
command := exec.Command(bsenv, "-c", "ping -c 1 -i 0.5 -t 4 -W 2 -w 5 "+ip+" >/dev/null && echo true || echo false")
105+
outinfo := bytes.Buffer{}
106+
command.Stdout = &outinfo
107+
err := command.Start()
108+
if err != nil{
109+
return false
110+
}
111+
112+
if err = command.Wait();err!=nil{
113+
return false
114+
}else{
115+
if(strings.Contains(outinfo.String(), "true")) {
116+
return true
117+
}else {
118+
return false
119+
}
120+
}
121+
}
122+
123+
func PingCMDcheck(hostslist []string,bsenv string) {
124+
var wg sync.WaitGroup
125+
mutex := &sync.Mutex{}
126+
limiter := make(chan struct{}, 40)
127+
aliveHost := make(chan string, 20)
128+
go func() {
129+
for s := range aliveHost {
130+
fmt.Println(s)
131+
}
132+
}()
133+
for _,host :=range hostslist{
134+
wg.Add(1)
135+
limiter <- struct{}{}
136+
go func(host string) {
137+
defer wg.Done()
138+
if ExecCommandPing(host,bsenv){
139+
mutex.Lock()
140+
AliveHosts = append(AliveHosts, host)
141+
mutex.Unlock()
142+
}
143+
<-limiter
144+
}(host)
145+
}
146+
wg.Wait()
147+
close(aliveHost)
148+
}
149+
150+
func ICMPRun(hostslist []string) []string{
151+
var sysinfo getsysinfo.SystemInfo
152+
sysinfo = getsysinfo.GetSys()
153+
154+
if sysinfo.OS == "windows" {
155+
IcmpCheck(hostslist)
156+
}else if sysinfo.OS == "linux" {
157+
if (sysinfo.Groupid == "0" || sysinfo.Userid == "0" || sysinfo.Username == "root") {
158+
IcmpCheck(hostslist)
159+
}else {
160+
PingCMDcheck(hostslist,"/bin/bash")
161+
}
162+
}else if sysinfo.OS == "darwin" {
163+
if (sysinfo.Groupid == "0" || sysinfo.Userid == "0" || sysinfo.Username == "root") {
164+
IcmpCheck(hostslist)
165+
}else {
166+
PingCMDcheck(hostslist,"/usr/local/bin/bash")
167+
}
168+
}
169+
return AliveHosts
170+
}

0 commit comments

Comments
 (0)