robertdavidgraham / masscan

TCP port scanner, spews SYN packets asynchronously, scanning entire Internet in under 5 minutes.
GNU Affero General Public License v3.0
23k stars 3.02k forks source link

UDP port specification has an unexpected effect on "ports" setting #158

Open maxrp opened 9 years ago

maxrp commented 9 years ago
$> ./bin/masscan --version

Masscan version 1.0.3 ( https://github.com/robertdavidgraham/masscan )
Compiled on: Mar  9 2015 11:31:20
Compiler: gcc 4.9.2 20150212 (Red Hat 4.9.2-6)
OS: Linux
CPU: unknown (64 bits)
GIT version: 1.0.3

$> sudo ./bin/masscan -pU:123 10.0.0.1 --echo | grep 'ports'
ports = 65659

$> sudo ./bin/masscan --ports U:0 10.0.0.1 --echo | grep 'ports'
ports = 65536

$> sudo ./bin/masscan -p123 --script ntp-monlist 10.0.0.1 
Starting masscan 1.0.3 (http://bit.ly/14GZzcT) at 2015-03-09 19:14:04 GMT
 -- forced options: -sS -Pn -n --randomize-hosts -v --send-eth
Initiating SYN Stealth Scan
Scanning 1 hosts [4294705153 ports/host]
^Cwaiting several seconds to exit...                                            
saving resume file to: paused.conf

$> grep ports paused.conf 
ports = 262267-123

(edited to include version)

maxrp commented 9 years ago

While this is somewhat surprising the comment in src/templ-port.h explains it well:

/*                                                                              
 * Due to the asynchronous scanning architecture, we have to combine TCP        
 * and UDP ports (plus other scans) in a combined range. Thus, we make          
 * the weird decision to put UDP ports in the range 64k to 128k, and            
 * so on. We should probably make this less bizaree in the future.              
 */ 

Leaving open though as there could be benefit to revising the UI a bit to make this clearer and save users arithmetic.

githubparser commented 9 years ago

Hi. I partially resolved this in https://github.com/robertdavidgraham/masscan/pull/164 , insofar as standard port range definitions are working, however... the way the ntp-monlist script records the port range is broken by the simplistic patch that I made. I'll take a look at a better option I guess.