-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_options.go
117 lines (101 loc) · 3.22 KB
/
service_options.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
package ncrack
import (
"strconv"
"strings"
)
type ServiceOptions []string
type ServiceOption func(*ServiceOptions)
func (s ServiceOptions) String() string {
return strings.Join([]string(s), ",")
}
// WithGlobalServiceOptions apply options to all hosts
func WithGlobalServiceOptions(opts ...ServiceOption) Option {
return func(c *Cracker) {
c.args = append(c.args, "-g")
withServiceOptions(opts...)(c)
}
}
func withServiceOptions(opts ...ServiceOption) Option {
return func(c *Cracker) {
so := ServiceOptions{}
for _, opt := range opts {
opt(&so)
}
c.args = append(c.args, so.String())
}
}
// WithServiceOptionSSL enable/disable SSL over service
func WithServiceOptionSSL(enable bool) ServiceOption {
return func(s *ServiceOptions) {
*s = append(*s, "ssl="+func() string {
if enable {
return "yes"
}
return "no"
}())
}
}
// WithServiceOptionPath provides path name for relative URLs
// The path is always relative to the hostname or IP address,
// so if you want to target something like http://foobar.com/login.php
// the path must take the value path=login.php
// For more info see https://nmap.org/ncrack/man.html
func WithServiceOptionPath(path string) ServiceOption {
return func(s *ServiceOptions) {
*s = append(*s, "path="+path)
}
}
// WithServiceOptionDB provides database name to ncrack. Some services
// like MongoDB require database name
func WithServiceOptionDB(dbname string) ServiceOption {
return func(s *ServiceOptions) {
*s = append(*s, "db="+dbname)
}
}
// WithServiceOptionDomain provides specific domain. Some services
// like WinRM require domain
func WithServiceOptionDomain(domain string) ServiceOption {
return func(s *ServiceOptions) {
*s = append(*s, "domain="+domain)
}
}
// WithServiceOptionMinConnLimit provides minimum connection limit
func WithServiceOptionMinConnLimit(min uint32) ServiceOption {
return func(s *ServiceOptions) {
*s = append(*s, "cl="+strconv.Itoa(int(min)))
}
}
// WithServiceOptionMaxConnLimit provides maximum connection limit
func WithServiceOptionMaxConnLimit(max uint32) ServiceOption {
return func(s *ServiceOptions) {
*s = append(*s, "CL="+strconv.Itoa(int(max)))
}
}
// WithServiceOptionAuthTries provides maximum attempts for authentication tries
func WithServiceOptionAuthTries(tries uint32) ServiceOption {
return func(s *ServiceOptions) {
*s = append(*s, "at="+strconv.Itoa(int(tries)))
}
}
// WithServiceOptionConnDelay provides delay time between each new connection
// It's possible to specify timeout with "ms", "s", m" and "h" suffixes,
// seconds is default time unit
func WithServiceOptionConnDelay(delay string) ServiceOption {
return func(s *ServiceOptions) {
*s = append(*s, "cd="+delay)
}
}
// WithServiceOptionConnRetries procvides maximum number for connection retries
func WithServiceOptionConnRetries(retries uint32) ServiceOption {
return func(s *ServiceOptions) {
*s = append(*s, "cr="+strconv.Itoa(int(retries)))
}
}
// WithServiceOptionTimeout provides timout overall cracking process
// It's possible to specify timeout with "ms", "s", m" and "h" suffixes,
// seconds is default time unit
func WithServiceOptionTimeout(timeout string) ServiceOption {
return func(s *ServiceOptions) {
*s = append(*s, "to="+timeout)
}
}