-
Notifications
You must be signed in to change notification settings - Fork 52
/
process.go
118 lines (112 loc) · 2.27 KB
/
process.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"bufio"
"log"
"os"
"strings"
"sync"
)
func execWorker(wg *sync.WaitGroup) {
for job := range ProcChan {
job.RunChecks()
}
wg.Done()
}
func initDispatcher(workerno int) {
wg := new(sync.WaitGroup)
for i := 0; i < workerno; i++ {
wg.Add(1)
go execWorker(wg)
}
wg.Wait()
}
func ProcessHosts() {
if len(urlFile) > 0 {
file, err := os.Open(urlFile)
if err != nil {
log.Println(err)
return
}
defer file.Close()
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
mhost := scanner.Text()
if cidrRex.MatchString(mhost) {
log.Printf("Found CIDR range: %s. Generating IP addresses...", mhost)
for _, ip := range *genCIDRxIPs(mhost) {
queueHosts(ip)
}
} else {
queueHosts(mhost)
}
}
if err := scanner.Err(); err != nil {
log.Println(err.Error())
return
}
} else {
for _, mhost := range allTargets {
if cidrRex.MatchString(mhost) {
log.Printf("Found CIDR range: %s. Generating IP addresses...", mhost)
for _, ip := range *genCIDRxIPs(mhost) {
queueHosts(ip)
}
} else {
queueHosts(mhost)
}
}
}
close(ProcChan)
}
func (p *ProcJob) RunChecks() {
wg := new(sync.WaitGroup)
// if the user hasn't already supplied a port, we generate
// combinations of every default port and spawn a process
// for each port
if p.Protocol == "SSH" {
if strings.Count(p.Host, ":") == 0 {
wg.Add(len(allSSHPorts))
for _, port := range allSSHPorts {
go p.ProcessHostSSH(port, wg)
}
} else {
wg.Add(1)
go p.ProcessHostSSH("", wg)
}
}
if p.Protocol == "HTTP" {
if strings.Count(p.Host, ":") != 2 {
wg.Add(len(allHTTPPorts))
for _, port := range allHTTPPorts {
go p.ProcessHostHTTP(port, wg)
}
} else {
wg.Add(1)
go p.ProcessHostHTTP("", wg)
}
}
if p.Protocol == "IMAP" {
if strings.Count(p.Host, ":") == 0 {
wg.Add(len(allIMAPPorts))
for _, port := range allIMAPPorts {
go p.ProcessHostIMAP(port, wg)
}
} else {
wg.Add(1)
go p.ProcessHostIMAP("", wg)
}
}
if p.Protocol == "FTP" {
if strings.Count(p.Host, ":") == 0 {
wg.Add(len(allFTPPorts))
for _, port := range allFTPPorts {
go p.ProcessHostFTP(port, wg)
}
} else {
wg.Add(1)
go p.ProcessHostFTP("", wg)
}
}
wg.Wait()
}