The nmap application is a pretty easy-to-use tool that can be used to port scan objects in a network environment. To obtain mmap in an easy-to-use package installer, for OS X check out the download page at http://nmap.org/download.html#macosx (use the same page to grab it for Windows or *nix as well). Once downloaded run the package/rpm/whatever.
Before I scan a system, I like to pull the routing table and eth info to determine how scans are being run, which can be run by using the mmap command anong with the —iflist option:
nmap —iflist
Basic Scanning
To then scan a computer, just use the mmap command followed by the host name or even throw a -v option in there to see more information (you can use a hostname or an IP):
nmap -v www.apple.com
Use the -6 option if scanning via IPv6:
nmap -v -6 8a33:1a2c::83::1a
Can drop the -v for less info on these, but I usually like more than less. Shows ports, states, services (for the ports) and a MAC address for each IP being scanned.
You can also scan a range of IPs. I usually take the lazy way for this, by using a wildcard. I can replace an octet to scan all objects in that octet. For example, to scan all systems running on the 192.168.210 class B:
nmap 192.168.210.*
You can scan a subnet, which can cover more or less than one octet worth of IPs, by including the net mask:
nmap 192.168.210.0/24
You can also just list a range, which is much easier in some cases, using the —exclude option to remove an address that will be angry if port scanned:
nmap 192.168.210.1-100 —exclude 192.168.210.25
Or to do a few hosts within that range:
nmap 192.168.210.1,10,254
Of you can even use the following to read in a list of addresses and subnets where each is on its own line:
nmap -iL ~/nmaplist.txt
By default, mmap is scanning all ports. However, if you know what you’re looking for, scans can be processed much faster if you constrain it to a port or range of ports. Use the -p option to identify a port and then T: for only TCP or U: for only UDP, or neither to do both. Additionally, you can scan a range of ports or separate ports using the same syntax used for identifying multiple hosts. For example, here we’ll scan 53, 80, 110, 443 and 143:
nmap -p 53,80,110,143,443
DO OS detection using the -A option:
nmap -A www.apple.com
For true remote OS detection, use -O with —osscan-guess:
mmap -v -O —osscan-guess mail.krypted.com
We can also output to a text file, using the -o option (or of course > filename but -o is more elegant here unless you’re parsing elsewhere in the line):
mmap -v -o ~/Desktop/nmapresults.txt -O —osscan-guess mail.krypted.com
Firewalls
Next, we’ll look at trying to bypass pesky annoyances like stageful packet inspection on firewalls. First, check whether there is actually a firewall using -s:
nmap -sA www.apple.com
Scan even if the host is protected by a firewall:
nmap -PN www.apple.com
Just check to see if some devices are up even if behind a firewall:
nmap -sP 192.168.210.10-20
Run a scan using Syn and ACK scans, run mmap along with the either -PS or -PA options (shown respectively):
nmap -PS 443 www.apple.com
nmap -PA 443 www.apple.com
Try to determine why ports are in a specific state:
nmap —reason www.apple.com
Show all sent/recvd packets:
nmap —packet-trace www.apple.com
Try to read the header of remote ports to determine a version number of the software:
nmap -sV www.apple.com
Security Scanning
Next, we can look at actually using nmap to test the attacking waters a little bit. First, we’ll try and spoof another MAC address, using the —spoof-mac options. We’ll use the 0 position after that option to indicate that we’re randomly generating a Mac, although we could use a real MAC in place of the 0:
nmap -v -sT —spoof-mac 0 www.apple.com
Next, let’s try to add a decoy, which allows us to spoof some IPs and use that as decoys so our target doesn’t suspect our IP as one that’s actually scanning them (note that our IP we’re testing from is 192.168.210.210):
nmap -n -192.168.210.1,192.168.210.10,192.168.210.210,192.168.210.254
Then, send some crazy packets (not an official term like magic packets, just my own term for throwing a curve ball at things and testing for the viability of syn-flood or Xmas packet attacking):
nmap -sX www.apple.com
Configure a custom mtu:
nmap —mtu 64 www.apple.com
Fragment your packets:
nmap -f www.apple.com
Note: None of Apple’s servers were damaged in the writing of this article. I did a find/replace at the end, when I realized I didn’t want all of you hitting www.krypted.com.