-
Notifications
You must be signed in to change notification settings - Fork 106
/
optionsHostDiscovery.go
161 lines (138 loc) · 4.8 KB
/
optionsHostDiscovery.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package nmap
import (
"fmt"
"strings"
)
// WithListScan sets the discovery mode to simply list the targets to scan and not scan them.
func WithListScan() Option {
return func(s *Scanner) {
s.args = append(s.args, "-sL")
}
}
// WithPingScan sets the discovery mode to simply ping the targets to scan and not scan them.
func WithPingScan() Option {
return func(s *Scanner) {
s.args = append(s.args, "-sn")
}
}
// WithSkipHostDiscovery disables host discovery and considers all hosts as online.
func WithSkipHostDiscovery() Option {
return func(s *Scanner) {
s.args = append(s.args, "-Pn")
}
}
// WithSYNDiscovery sets the discovery mode to use SYN packets.
// If the portList argument is empty, this will enable SYN discovery
// for all ports. Otherwise, it will be only for the specified ports.
func WithSYNDiscovery(ports ...string) Option {
portList := strings.Join(ports, ",")
return func(s *Scanner) {
s.args = append(s.args, fmt.Sprintf("-PS%s", portList))
}
}
// WithACKDiscovery sets the discovery mode to use ACK packets.
// If the portList argument is empty, this will enable ACK discovery
// for all ports. Otherwise, it will be only for the specified ports.
func WithACKDiscovery(ports ...string) Option {
portList := strings.Join(ports, ",")
return func(s *Scanner) {
s.args = append(s.args, fmt.Sprintf("-PA%s", portList))
}
}
// WithUDPDiscovery sets the discovery mode to use UDP packets.
// If the portList argument is empty, this will enable UDP discovery
// for all ports. Otherwise, it will be only for the specified ports.
func WithUDPDiscovery(ports ...string) Option {
portList := strings.Join(ports, ",")
return func(s *Scanner) {
s.args = append(s.args, fmt.Sprintf("-PU%s", portList))
}
}
// WithSCTPDiscovery sets the discovery mode to use SCTP packets
// containing a minimal INIT chunk.
// If the portList argument is empty, this will enable SCTP discovery
// for all ports. Otherwise, it will be only for the specified ports.
// Warning: on Unix, only the privileged user root is generally
// able to send and receive raw SCTP packets.
func WithSCTPDiscovery(ports ...string) Option {
portList := strings.Join(ports, ",")
return func(s *Scanner) {
s.args = append(s.args, fmt.Sprintf("-PY%s", portList))
}
}
// WithICMPEchoDiscovery sets the discovery mode to use an ICMP type 8
// packet (an echo request), like the standard packets sent by the ping
// command.
// Many hosts and firewalls block these packets, so this is usually not
// the best for exploring networks.
func WithICMPEchoDiscovery() Option {
return func(s *Scanner) {
s.args = append(s.args, "-PE")
}
}
// WithICMPTimestampDiscovery sets the discovery mode to use an ICMP type 13
// packet (a timestamp request).
// This query can be valuable when administrators specifically block echo
// request packets while forgetting that other ICMP queries can be used
// for the same purpose.
func WithICMPTimestampDiscovery() Option {
return func(s *Scanner) {
s.args = append(s.args, "-PP")
}
}
// WithICMPNetMaskDiscovery sets the discovery mode to use an ICMP type 17
// packet (an address mask request).
// This query can be valuable when administrators specifically block echo
// request packets while forgetting that other ICMP queries can be used
// for the same purpose.
func WithICMPNetMaskDiscovery() Option {
return func(s *Scanner) {
s.args = append(s.args, "-PM")
}
}
// WithIPProtocolPingDiscovery sets the discovery mode to use the IP
// protocol ping.
// If no protocols are specified, the default is to send multiple IP
// packets for ICMP (protocol 1), IGMP (protocol 2), and IP-in-IP
// (protocol 4).
func WithIPProtocolPingDiscovery(protocols ...string) Option {
protocolList := strings.Join(protocols, ",")
return func(s *Scanner) {
s.args = append(s.args, fmt.Sprintf("-PO%s", protocolList))
}
}
// WithDisabledDNSResolution disables DNS resolution in the discovery
// step of the nmap scan.
func WithDisabledDNSResolution() Option {
return func(s *Scanner) {
s.args = append(s.args, "-n")
}
}
// WithForcedDNSResolution enforces DNS resolution in the discovery
// step of the nmap scan.
func WithForcedDNSResolution() Option {
return func(s *Scanner) {
s.args = append(s.args, "-R")
}
}
// WithCustomDNSServers sets custom DNS servers for the scan.
// List format: dns1[,dns2],...
func WithCustomDNSServers(dnsServers ...string) Option {
dnsList := strings.Join(dnsServers, ",")
return func(s *Scanner) {
s.args = append(s.args, "--dns-servers")
s.args = append(s.args, dnsList)
}
}
// WithSystemDNS sets the scanner's DNS to the system's DNS.
func WithSystemDNS() Option {
return func(s *Scanner) {
s.args = append(s.args, "--system-dns")
}
}
// WithTraceRoute enables the tracing of the hop path to each host.
func WithTraceRoute() Option {
return func(s *Scanner) {
s.args = append(s.args, "--traceroute")
}
}