-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathopt_script.go
More file actions
93 lines (80 loc) · 2.44 KB
/
opt_script.go
File metadata and controls
93 lines (80 loc) · 2.44 KB
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
package nmap
import (
"fmt"
"slices"
"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) error {
s.args = append(s.args, "-sC")
return nil
}
}
// 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) error {
s.args = append(s.args, "--script="+scriptList)
return nil
}
}
// WithScriptArguments provides arguments for scripts.
// If a value is the empty string, the key is used as a flag.
func WithScriptArguments(arguments map[string]string) Option {
// 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
scriptArgs := make([]string, 0, len(arguments))
for key, value := range arguments {
str := key
if value != "" {
str = fmt.Sprintf("%s=%s", key, value)
}
scriptArgs = append(scriptArgs, str)
}
// Ensure consistent ordering.
slices.Sort(scriptArgs)
args := strings.Join(scriptArgs, ",")
return func(s *Scanner) error {
s.args = append(s.args, "--script-args="+args)
return nil
}
}
// WithScriptArgumentsFile provides arguments for scripts from a file.
func WithScriptArgumentsFile(inputFilePath string) Option {
return func(s *Scanner) error {
s.args = append(s.args, "--script-args-file="+inputFilePath)
return nil
}
}
// WithScriptTrace makes the scripts show all data sent and received.
func WithScriptTrace() Option {
return func(s *Scanner) error {
s.args = append(s.args, "--script-trace")
return nil
}
}
// WithScriptUpdateDB updates the script database.
func WithScriptUpdateDB() Option {
return func(s *Scanner) error {
s.args = append(s.args, "--script-updatedb")
return nil
}
}
// WithScriptTimeout sets the script timeout.
func WithScriptTimeout(timeout time.Duration) Option {
return func(s *Scanner) error {
formatted, err := formatNmapDuration(timeout)
if err != nil {
return fmt.Errorf("format script timeout: %w", err)
}
s.args = append(s.args, "--script-timeout", formatted)
return nil
}
}