It’s Monday morning and you’ve just arrived at work and started up your workstation when in walks your boss with a disturbed look on his face:
“Hey, I just got an email from corporate. They want to know why we’re running 27 unauthorized FTP and Telnet daemons on our network. We aren’t, are we?”
If you’re like most administrators out there you’ve probably, at one time or another, had the sinking feeling that goes along with discovering services running on your network that shouldn’t be there. You may have been alerted to this fact while looking at system or IDS logs (better), or maybe even by a less-than-friendly third party (bad).
The fact is, whether you work at the system or network level, knowing what daemons are running in your environment is absolutely crucial. Few things are more embarassing than someone else finding out about new, unauthorized servers on your network before you do — especially when you end up being notified due to an incident involving one of them.
This article will attempt to provide you with a few nifty Nmap commands that can help you stay ahead of the rogue servers on your network.
Nmap allows you to find both new machines as well as new services on known machines through the use of its plethora of options. Below we’ll take a look at some of the different scans you can do and how you can get maximum use out of the results.
Discovery Sweeps Using Ping
One of the first thing that should be of concern to any network admin should be the introduction of new, unauthorized hosts onto the network. When a host comes online without the admin knowing about it, it’s often a bad thing.
This negativity can range from not knowing that a particular project has started to not knowing that a disgruntled employee is distributing illegal content at the company’s expense.
Nmap makes short work of finding new hosts on the network using a few simple options. To start with, one can simply ping every host on their network and see who answers:
nmap -n -sP -oA output_file 192.168.10.0/24
This command will print to the console the hosts that appear to be up, but more importantly it saves the output in various formats in the directory you ran the command from.
-sP says to ping the hosts only (as opposed to scanning them afterwards), and the
-oA option says to save the output in all three main Nmap output formats — human readable, grepable, and XML. The
-n was to tell Nmap not to resolved DNS names so that we got the IP addresses themselves.
cat output_file.gnmap | cut -d" " -f2 | grep ^[0-9]
What this command does is parse the output_file.gnmap file, cut out the IP address field, and make sure it’s a valid IP address. What you end up with is a nice list of hostnames that responded to your ping scan of the network. You can save this list to a file like so:
cat output_file.gnmap | cut -d” ” -f2 | grep ^[0-9] > list_of_hosts
Discovery Scanning With SYNs
In addition to traditional ping scanning, you can also elect to look for hosts on your network based on open TCP (or UDP) ports. This is done by giving the
nmap -sP -PS21,22,23,80,443 -oA output_file 192.168.10.0/24
This says to Nmap, “Ping my network for machines that are up — but use ports 21,22,23,80, and 443 as the verification ports.” In other words, if any host on the network responds on any one of those ports, it’ll be listed in the Nmap output as up. This is helpful for finding machines that think they’re sneaky by not responding to ICMP while still running traditional services.
Scanning The Machines You Find
Ok, so now that you have some decent ways to find hosts on your network, let’s take a look at how to scan them once you find them. My favorite way to do this is to combine the discovery technique we just saw with a port scan:
nmap -PS21,22,23,80,443 -p1-15000 -oA output_file 192.168.10.0/24
The command above asks Nmap to find hosts using the first set of ports, and scan anything it finds on TCP ports 1 to 15,000. This gives a somewhat decent view of at least the TCP services likely to pop up on a network over time due to rogue hosts. You can, of course, tweak the scan to include UDP and/or a larger range of ports.
The goal here is to get administrators in the habit of seeing what’s alive on their networks. Only once we know what our situation is can we actually begin to address it.
Feel free to contact me if you have any questions or comments.
** Also, stay tuned for a new tool a friend and I are writing designed to help administrators keep track of what hosts are on their networks, and what services those hosts are running. The concept is simple — perform regular scans (using
Nmap) and compare the results to each other over time. The name of the tool is
Netdiff (witty, I know), and it’s written in Python. We should have some semi-releasable code available soon.
The Nmap Manpage http://www.insecure.org/nmap/data/nmap_manpage.html