-
Notifications
You must be signed in to change notification settings - Fork 106
/
optionsScriptScan.go
83 lines (69 loc) · 2.31 KB
/
optionsScriptScan.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
package nmap
import (
"fmt"
"strings"
"time"
)
// WithDefaultScript sets the scanner to perform a script scan using the default
// set of scripts. It is equivalent to --script=default. Some of the scripts in
// this category are considered intrusive and should not be run against a target
// network without permission.
func WithDefaultScript() Option {
return func(s *Scanner) {
s.args = append(s.args, "-sC")
}
}
// WithScripts sets the scanner to perform a script scan using the enumerated
// scripts, script directories and script categories.
func WithScripts(scripts ...string) Option {
scriptList := strings.Join(scripts, ",")
return func(s *Scanner) {
s.args = append(s.args, fmt.Sprintf("--script=%s", scriptList))
}
}
// WithScriptArguments provides arguments for scripts. If a value is the empty string, the key will be used as a flag.
func WithScriptArguments(arguments map[string]string) Option {
var argList string
// Properly format the argument list from the map.
// Complex example:
// user=foo,pass=",{}=bar",whois={whodb=nofollow+ripe},xmpp-info.server_name=localhost,vulns.showall
for key, value := range arguments {
str := ""
if value == "" {
str = key
} else {
str = fmt.Sprintf("%s=%s", key, value)
}
argList = strings.Join([]string{argList, str}, ",")
}
argList = strings.TrimLeft(argList, ",")
return func(s *Scanner) {
s.args = append(s.args, fmt.Sprintf("--script-args=%s", argList))
}
}
// WithScriptArgumentsFile provides arguments for scripts from a file.
func WithScriptArgumentsFile(inputFilePath string) Option {
return func(s *Scanner) {
s.args = append(s.args, fmt.Sprintf("--script-args-file=%s", inputFilePath))
}
}
// WithScriptTrace makes the scripts show all data sent and received.
func WithScriptTrace() Option {
return func(s *Scanner) {
s.args = append(s.args, "--script-trace")
}
}
// WithScriptUpdateDB updates the script database.
func WithScriptUpdateDB() Option {
return func(s *Scanner) {
s.args = append(s.args, "--script-updatedb")
}
}
// WithScriptTimeout sets the script timeout.
func WithScriptTimeout(timeout time.Duration) Option {
milliseconds := timeout.Round(time.Nanosecond).Nanoseconds() / 1000000
return func(s *Scanner) {
s.args = append(s.args, "--script-timeout")
s.args = append(s.args, fmt.Sprintf("%dms", int(milliseconds)))
}
}