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

Fix bug in --echo for IPv6 ranges & add --echo-cidr option #691

Closed Frky closed 8 months ago

Frky commented 1 year ago

This PR does 2 things:

These two things are in one PR because they modify the same parts of the code - two different PR would lead to merge conflicts.


Address Issue #677

$ bin/masscan --echo :: ::1
seed = 6069904213427194911
rate = 100       
shard = 1/1
nocapture = servername
nocapture = servername

# TARGET SELECTION (IP, PORTS, EXCLUDES)
ports = 
range = ::/127
$ bin/masscan --echo 2000:: 2000::1
seed = 2054565738792150746
rate = 100       
shard = 1/1
nocapture = servername
nocapture = servername

# TARGET SELECTION (IP, PORTS, EXCLUDES)
ports = 
range = 2000::/127
$ bin/masscan --echo 2000::/63
seed = 14647153754214998088
rate = 100       
shard = 1/1
nocapture = servername
nocapture = servername

# TARGET SELECTION (IP, PORTS, EXCLUDES)
ports = 
range = 2000::/63
$ bin/masscan --echo 2000::-2000:ffff:ffff:ffff:ffff:ffff:ffff:ffff
seed = 3141632608958804321
rate = 100       
shard = 1/1
nocapture = servername
nocapture = servername

# TARGET SELECTION (IP, PORTS, EXCLUDES)
ports = 
range = 2000::/16

Add --echo-cidr CLI option

If I am not mistaken, there is currently no option in masscan to output the list of IP ranges to be scanned:

Indeed, the option -sL outputs a list of IP addresses (not ranges) in a random order, and --echo outputs masscan configuration, including ranges but also other options, and in a non-consistent format.

This PR adds the option --echo-cidr that outputs the the ordered list of CIDR ranges. For instance, with the following list of IP addresses to scan:

10.0.0.0-10.0.1.15
192.168.0.0-192.168.0.3
192.168.1.2-192.168.1.3

TARGET SELECTION (IP, PORTS, EXCLUDES)

ports = range = 10.0.0.0-10.0.1.15 range = 192.168.0.0/30 range = 192.168.1.2/31