-
Notifications
You must be signed in to change notification settings - Fork 105
/
optionsTimingPerformance.go
156 lines (132 loc) · 5.16 KB
/
optionsTimingPerformance.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
package nmap
import (
"fmt"
"time"
)
// Timing represents a timing template for nmap.
// These are meant to be used with the WithTimingTemplate method.
type Timing int16
const (
// TimingSlowest also called paranoiac NO PARALLELISM | 5min timeout | 100ms to 10s round-trip time timeout | 5mn scan delay
TimingSlowest Timing = 0
// TimingSneaky NO PARALLELISM | 15sec timeout | 100ms to 10s round-trip time timeout | 15s scan delay
TimingSneaky Timing = 1
// TimingPolite NO PARALLELISM | 1sec timeout | 100ms to 10s round-trip time timeout | 400ms scan delay
TimingPolite Timing = 2
// TimingNormal PARALLELISM | 1sec timeout | 100ms to 10s round-trip time timeout | 0s scan delay
TimingNormal Timing = 3
// TimingAggressive PARALLELISM | 500ms timeout | 100ms to 1250ms round-trip time timeout | 0s scan delay
TimingAggressive Timing = 4
// TimingFastest also called insane PARALLELISM | 250ms timeout | 50ms to 300ms round-trip time timeout | 0s scan delay
TimingFastest Timing = 5
)
// WithTimingTemplate sets the timing template for nmap.
func WithTimingTemplate(timing Timing) Option {
return func(s *Scanner) {
s.args = append(s.args, fmt.Sprintf("-T%d", timing))
}
}
// WithStatsEvery periodically prints a timing status message after each interval of time.
func WithStatsEvery(interval string) Option {
return func(s *Scanner) {
s.args = append(s.args, "--stats-every")
s.args = append(s.args, interval)
}
}
// WithMinHostgroup sets the minimal parallel host scan group size.
func WithMinHostgroup(size int) Option {
return func(s *Scanner) {
s.args = append(s.args, "--min-hostgroup")
s.args = append(s.args, fmt.Sprint(size))
}
}
// WithMaxHostgroup sets the maximal parallel host scan group size.
func WithMaxHostgroup(size int) Option {
return func(s *Scanner) {
s.args = append(s.args, "--max-hostgroup")
s.args = append(s.args, fmt.Sprint(size))
}
}
// WithMinParallelism sets the minimal number of parallel probes.
func WithMinParallelism(probes int) Option {
return func(s *Scanner) {
s.args = append(s.args, "--min-parallelism")
s.args = append(s.args, fmt.Sprint(probes))
}
}
// WithMaxParallelism sets the maximal number of parallel probes.
func WithMaxParallelism(probes int) Option {
return func(s *Scanner) {
s.args = append(s.args, "--max-parallelism")
s.args = append(s.args, fmt.Sprint(probes))
}
}
// WithMinRTTTimeout sets the minimal probe round trip time.
func WithMinRTTTimeout(roundTripTime time.Duration) Option {
milliseconds := roundTripTime.Round(time.Nanosecond).Nanoseconds() / 1000000
return func(s *Scanner) {
s.args = append(s.args, "--min-rtt-timeout")
s.args = append(s.args, fmt.Sprintf("%dms", int(milliseconds)))
}
}
// WithMaxRTTTimeout sets the maximal probe round trip time.
func WithMaxRTTTimeout(roundTripTime time.Duration) Option {
milliseconds := roundTripTime.Round(time.Nanosecond).Nanoseconds() / 1000000
return func(s *Scanner) {
s.args = append(s.args, "--max-rtt-timeout")
s.args = append(s.args, fmt.Sprintf("%dms", int(milliseconds)))
}
}
// WithInitialRTTTimeout sets the initial probe round trip time.
func WithInitialRTTTimeout(roundTripTime time.Duration) Option {
milliseconds := roundTripTime.Round(time.Nanosecond).Nanoseconds() / 1000000
return func(s *Scanner) {
s.args = append(s.args, "--initial-rtt-timeout")
s.args = append(s.args, fmt.Sprintf("%dms", int(milliseconds)))
}
}
// WithMaxRetries sets the maximal number of port scan probe retransmissions.
func WithMaxRetries(tries int) Option {
return func(s *Scanner) {
s.args = append(s.args, "--max-retries")
s.args = append(s.args, fmt.Sprint(tries))
}
}
// WithHostTimeout sets the time after which nmap should give up on a target host.
func WithHostTimeout(timeout time.Duration) Option {
milliseconds := timeout.Round(time.Nanosecond).Nanoseconds() / 1000000
return func(s *Scanner) {
s.args = append(s.args, "--host-timeout")
s.args = append(s.args, fmt.Sprintf("%dms", int(milliseconds)))
}
}
// WithScanDelay sets the minimum time to wait between each probe sent to a host.
func WithScanDelay(timeout time.Duration) Option {
milliseconds := timeout.Round(time.Nanosecond).Nanoseconds() / 1000000
return func(s *Scanner) {
s.args = append(s.args, "--scan-delay")
s.args = append(s.args, fmt.Sprintf("%dms", int(milliseconds)))
}
}
// WithMaxScanDelay sets the maximum time to wait between each probe sent to a host.
func WithMaxScanDelay(timeout time.Duration) Option {
milliseconds := timeout.Round(time.Nanosecond).Nanoseconds() / 1000000
return func(s *Scanner) {
s.args = append(s.args, "--max-scan-delay")
s.args = append(s.args, fmt.Sprintf("%dms", int(milliseconds)))
}
}
// WithMinRate sets the minimal number of packets sent per second.
func WithMinRate(packetsPerSecond int) Option {
return func(s *Scanner) {
s.args = append(s.args, "--min-rate")
s.args = append(s.args, fmt.Sprint(packetsPerSecond))
}
}
// WithMaxRate sets the maximal number of packets sent per second.
func WithMaxRate(packetsPerSecond int) Option {
return func(s *Scanner) {
s.args = append(s.args, "--max-rate")
s.args = append(s.args, fmt.Sprint(packetsPerSecond))
}
}