Port scanners are essential instruments that allow directors and safety personnel — and malicious actors — to determine open and listening companies on a community and, subsequently, decide potential entry factors into computer systems.
One in style open supply is Masscan. In contrast to Nmap, arguably the most well-liked port scanner, Masscan is a quick scanner that identifies open ports however supplies little further data, making it optimum for big networks, together with the web.
Let’s take a look at methods to use Masscan for penetration testing, community auditing and basic troubleshooting.
The significance of port scanning
Port scanning is a vital a part of system administration and safety. Utilizing port scanners permits IT professionals to find out the next:
- Open ports and out there companies.
- Potential vulnerabilities associated to misconfigurations or outdated insurance policies.
- Community gadget and asset inventories.
- Firewall settings.
- Modifications to community configurations.
Masscan is amongst a number of port scanners out there, together with Nmap, which could be extra detailed, complicated and slower than some use circumstances require, and Indignant IP Scanner, a quick, user-friendly port scanner tailor-made to determine open ports and dwell hosts on smaller networks.
Masscan’s velocity on massive networks makes it a sexy possibility for admins who desire a fast and primary scan of accessible hosts and open ports. It avoids extra in-depth evaluation, reminiscent of OS detection or scan scripting, which permits it to realize primary scanning objectives.
Methods to compile and run Masscan
Masscan works on Linux, macOS and Home windows. Relying in your most popular OS, you would possibly have to compile it your self. Anticipate the very best efficiency on Linux, particularly for very massive scan jobs. In response to the seller, macOS and Home windows solely ship round 300,000 packets per second, whereas Linux can ship 1.5 million packets per second.
You have got a number of choices for getting Masscan. For those who’re not assured in compiling it your self, you could find precompiled variations on-line. Be certain you belief the supply and all the time search for the present model.
To compile it on a Linux system, sort:
sudo apt-get –assume-yes set up git make gcc
git clone https://github.com/robertdavidgraham/masscan
cd masscan
make
make set up
Use related processes on macOS and Home windows. For the reason that utility is written in C, it is transportable. You too can use Kali Linux, ParrotOS or BlackArch to run Masscan.
Instance Masscan scans
Masscan’s simplicity means there aren’t many choices or variations to study. When studying methods to use Masscan, you may discover that operating it primarily requires specifying goal addresses and ports. You too can redirect the usual output to a file.
Use the next examples to assemble your individual scans.
Methods to scan a single port
Scan a single port on an IPv4 community phase by typing:
masscan -p80 10.0.0.0/8

Outcomes seem on the display screen, although you possibly can redirect the output to a file for later evaluation (extra on this under).
Methods to scan a number of ports
Goal a number of ports by utilizing the -p possibility and separating the specified port numbers with commas. For instance, to scan for internet companies, sort -p80,443.
masscan -p80,443 10.0.0.0/8
Methods to scan a variety of ports
Scan a variety of ports by utilizing a worth reminiscent of -p6000-7000 to cowl all ports between 6000 and 7000. This characteristic is especially helpful in case you have a number of purposes utilizing customized or nonstandard ports.
masscan -p6000-7000 10.0.0.0/8
Methods to use a configuration file for repeatable scans
Masscan presents a number of primary choices to change scan capabilities. For instance, set a –max-rate worth to outline the variety of packets per second despatched within the scan. The default is a lowly 100 packets per second, so it could be price modifying that to –max-rate 100000 or extra. Keep in mind that Home windows and macOS are extra restricted than Linux on this respect.
You might additionally use a textual content file to exclude explicit ports if you want to conduct very particular scans or keep away from explicit ports. Be particularly cautious for those who’re scanning the web as a result of your scan may get you denylisted.
Specify an exclude.txt file by utilizing the –excludefile flag.
masscan 0.0.0.0/0 -p-65365 –excludefile exclude.txt
Once more, fastidiously replace that file to specify areas of the web to keep away from. Keep away from scanning the web itself and as an alternative conduct extra focused assessments inside your individual community’s boundaries.
Since community scanning is commonly a recurring process in auditing and vulnerability detection, you would possibly need to specify detailed settings in a configuration file after which name the file while you’re able to scan. You might even schedule that process utilizing cron, a time-based scheduler in Unix-like OSes that lets you schedule instructions to run at particular dates and occasions.
Start by creating the configuration file:
# Fundamental scan ports 0-1023 for my inner community
price = 100000
output-format = xml
output-status = all
output-filename = internal-scan.xml
ports = 0-1023
vary = 0.0.0.0-255.255.255.255
excludefile = exclude-ports.txt
Identify the file customscan.conf — or no matter you favor.
Subsequent, specify the configuration file as a part of your masscan command:
masscan -c customscan.conf
IPv6 compatibility
You should use Masscan to scan IPv6 handle ranges with none further flags, even in the identical scan. Keep in mind that IPv6 networks could be immense, so fastidiously plan and restrict your scans.
Methods to outline output codecs
Masscan can output ends in a number of frequent codecs. Use the next abstract to find out which possibility most accurately fits your wants:
- Binary. The default format, which is readable utilizing the –-readscan possibility.
- Grepable. Use the -oG
choice to render the output in a format simply searched with grep and related instruments. - Listing. Use the -oL
choice to render output as a line-by-line listing containing the host and a port. - XML. Use the -oX
choice to render output in XML. - JSON. Use the -oJ
choice to render output in JSON.

Keep in mind that these information may very well be massive relying on the scan choices chosen.
Masscan vs. Nmap
Most community and safety professionals have used Nmap; Masscan intentionally mimics this ubiquitous software. Nmap has way more choices and suppleness, however Masscan depends on many parallel settings and approaches. Think about the next:
- Nmap is able to title decision; Masscan shouldn’t be.
- Masscan requires the -p
parameter. - Output choices, reminiscent of -oX or -oG, are the identical.
Use the masscan –nmap command to see an inventory of particular settings shared between the 2.
Masscan presents high-speed, easy scans of enormous networks. Whereas instruments like Nmap present extra choices, they’re additionally slower and extra complicated to make use of. Most community and safety professionals will doubtless use each instruments, maximizing the strengths of every.
Damon Garn owns Cogspinner Coaction and supplies freelance IT writing and modifying companies. He has written a number of CompTIA research guides, together with the Linux+, Cloud Necessities+ and Server+ guides, and contributes extensively to Informa TechTarget, The New Stack and CompTIA Blogs.