@@ -11,12 +11,22 @@ class masscan(BaseModule):
11
11
produced_events = ["OPEN_TCP_PORT" ]
12
12
meta = {"description" : "Port scan IP subnets with masscan" }
13
13
# 600 packets/s ~= entire private IP space in 8 hours
14
- options = {"ports" : "80,443" , "rate" : 600 , "wait" : 10 , "ping_first" : False , "use_cache" : False }
14
+ options = {
15
+ "top_ports" : 100 ,
16
+ "ports" : "" ,
17
+ "rate" : 600 ,
18
+ "wait" : 10 ,
19
+ "ping_first" : False ,
20
+ "ping_only" : False ,
21
+ "use_cache" : False ,
22
+ }
15
23
options_desc = {
24
+ "top_ports" : "Top ports to scan (default 100)" ,
16
25
"ports" : "Ports to scan" ,
17
26
"rate" : "Rate in packets per second" ,
18
27
"wait" : "Seconds to wait for replies after scan is complete" ,
19
28
"ping_first" : "Only portscan hosts that reply to pings" ,
29
+ "ping_only" : "Ping sweep only, no portscan" ,
20
30
"use_cache" : "Instead of scanning, use the results from the previous scan" ,
21
31
}
22
32
deps_ansible = [
@@ -51,10 +61,12 @@ class masscan(BaseModule):
51
61
_qsize = 100
52
62
53
63
async def setup (self ):
64
+ self .top_ports = self .config .get ("top_ports" , 100 )
54
65
self .ports = self .config .get ("ports" , "80,443" )
55
66
self .rate = self .config .get ("rate" , 600 )
56
67
self .wait = self .config .get ("wait" , 10 )
57
68
self .ping_first = self .config .get ("ping_first" , False )
69
+ self .ping_only = self .config .get ("ping_only" , False )
58
70
self .alive_hosts = dict ()
59
71
# make a quick dry run to validate ports etc.
60
72
self ._target_findkey = "9.8.7.6"
@@ -111,7 +123,7 @@ async def handle_event(self, event):
111
123
return
112
124
113
125
# ping scan
114
- if self .ping_first :
126
+ if self .ping_first or self . ping_only :
115
127
self .verbose ("Starting masscan (ping scan)" )
116
128
117
129
await self .masscan (targets , result_callback = self .append_alive_host , exclude = exclude , ping = True )
@@ -121,11 +133,11 @@ async def handle_event(self, event):
121
133
return
122
134
123
135
# TCP SYN scan
124
- if self .ports :
136
+ if not self .ping_only :
125
137
self .verbose ("Starting masscan (TCP SYN scan)" )
126
138
await self .masscan (targets , result_callback = self .emit_open_tcp_port , exclude = exclude )
127
139
else :
128
- self .verbose ("No ports specified , skipping TCP SYN scan" )
140
+ self .verbose ("Only ping sweep was requested , skipping TCP SYN scan" )
129
141
# save memory
130
142
self .alive_hosts .clear ()
131
143
@@ -159,7 +171,10 @@ def _build_masscan_command(self, targets=None, config=None, exclude=None, dry_ru
159
171
if ping :
160
172
command += ("--ping" ,)
161
173
elif not dry_run :
162
- command += ("-p" , self .ports )
174
+ if self .ports :
175
+ command += ("-p" , self .ports )
176
+ else :
177
+ command += ("--top-ports" , str (self .top_ports ))
163
178
if exclude is not None :
164
179
command += ("--exclude" , exclude )
165
180
if dry_run :
0 commit comments