Beginner s Guide to Nmap

Embed Size (px)

DESCRIPTION

Guide

Citation preview

  • Home News Linux Community Learn Linux Directory Jobs

    Home Learn Linux Linux Tutorials Beginner's Guide to Nmap

    Beginner's Guide to Nmap

    Ever wondered how attackers know what ports are open on a system? Or how to find out what services acomputer is running without just asking the site admin? You can do all this and more with a handy little toolcalled Nmap.What is Nmap? Short for "network mapper," nmap is a veritable toolshed of functionality to perform networkscans. It can be used for security scans, simply to identify what services a host is running, to "fingerprint" theoperating system and applications on a host, the type of firewall a host is using, or to do a quick inventory ofa local network. It is, in short, a very good tool to know.It's famous, too. Once you get to know Nmap a bit, you'll notice that it makes all types of cameoappearances in movies.In this tutorial, I'll cover some of the basics of using Nmap and provide some examples you can use quickly.Getting Nmap and Basic UseYou'll find Nmap packaged for most major Linux distros. The most recent release of Nmap came out in early2010, so the most recent version (5.21) might not be in the current stable releases. You can find the sourcesand some binaries on the download page.The basic syntax for Nmap is Nmap Scan Type Options target. Let's say you want to scan a host to seewhat operating system it is running. To do this, run the following:

    nmap -O target.host.com

    Note that Nmap requires root privileges to run this type of scan. The scan might take a minute or so to run,so be patient. When it finishes, you'll see something like this:

    Starting Nmap 5.21 ( http://nmap.org ) at 2010-02-27 23:52 ESTNmap scan report for 10.0.0.1

    Upcoming Linux FoundationLFD312 Developing Applicati17 Nov

    DETAILSLFD405 Embedded Linux Dev17 Nov

    DETAILSLFS540 Linux KVM Virtualiza02 Dec

    DETAILS

    View All Upcoming Courses

    Wednesday, 03 March 2010 09:13 Joe 'Zonker' Brockmeier | ExclusiveTweetTweet 21 175LikeLike

    search linux.com

    Linux Foundation Training Events Video

    Beginner's Guide to Nmap | Linux.com http://www.linux.com/learn/tutorials/290879-begi...

    1 of 7 11/08/2014 12:57 AM

  • Host is up (0.0015s latency).Not shown: 997 closed portsPORT STATE SERVICE53/tcp open domain5009/tcp open airport-admin10000/tcp open snet-sensor-mgmtMAC Address: 00:11:24:6B:43:E2 (Apple Computer)Device type: WAP|printerRunning: Apple embedded, Canon embedded, Kyocera embedded, Xerox embeddedOS details: VxWorks: Apple AirPort Extreme v5.7 or AirPort Express v6.3; Canon imageRUNNER printer (5055, C3045, C3380, or C5185); Kyocera FS-4020DN printer; or Xerox Phaser 8860MFP printerNetwork Distance: 1 hop

    OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .Nmap done: 1 IP address (1 host up) scanned in 10.21 seconds

    As you can see, Nmap provides a lot of data. Here it takes a guess at the operating system that might berunning on the system. I ran this particular scan against an Apple Airport Extreme router. As an addedbonus, Nmap tells me that the device is one hop away, the MAC address of the device and manufacturer ofthe NIC, the open ports, and how long the scan took.Here's the result of another scan, against a desktop machine running Ubuntu 9.10:

    Starting Nmap 5.21 ( http://nmap.org ) at 2010-02-28 00:00 ESTNmap scan report for 10.0.0.6Host is up (0.0039s latency).Not shown: 999 closed portsPORT STATE SERVICE22/tcp open sshMAC Address: 00:17:08:2A:D6:F0 (Hewlett Packard)Device type: general purposeRunning: Linux 2.6.XOS details: Linux 2.6.19 - 2.6.31Network Distance: 1 hop

    OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .Nmap done: 1 IP address (1 host up) scanned in 3.40 seconds

    Here we see that the system has an HP NIC (it's an HP workstation), running the Linux kernel somewherebetween Linux 2.6.19 and 2.6.31. You may not be able to get an explicit identification of the operatingsystem down to the version of Linux.Practice HostsIn the examples above, I chose a local router and one of my workstations in part because I have thepermission to scan them. You can use Nmap to scan virtually any host. However, it's a bad idea to run many

    Tweets

    Compose new Tweet

    Latest Tutorials

    The Perfect Server - Ubuntu 14ISPConfig 3)Intro to Systemd Runlevels andCommandsMonitor Ubuntu 14.04 and DebLinux-Dash

    Beginner's Guide to Nmap | Linux.com http://www.linux.com/learn/tutorials/290879-begi...

    2 of 7 11/08/2014 12:57 AM

  • scans against hosts you're not in control of or don't have permission to scan. The Nmap folks have a testhost at scanme.nmap.org that can be used for testing, so long as you're not running any tests of exploits orDenial of Service (DoS) attacks.Some admins don't appreciate unexpected scans, so use best judgment and restrict scans to hosts that areon your own network or that you have permission to scan. It may also be against your ISP's terms of serviceto use some of Nmap's more aggressive scan features, so be careful out there!Multiple HostsYou can scan more than one host at a time using nmap. If you're using IP addresses, you can specify arange like 10.0.0.1-6 or a range like 10.0.0.0/24. The 10.0.0.1-6 would scan hosts 10.0.0.1, 10.0.0.2,10.0.0.3 through 10.0.0.6. Using the /24 notation would scan the whole range of hosts from 10.0.0.0 to10.0.0.255. For example, to scan 10.0.0.1 through 10.0.0.42 to learn what OS they might be running I'd usenmap -O 10.0.0.1-42.If you have hostnames instead of IP addresses, you can separate them with a space on the command line,like so:

    nmap -O host1.target.com host2.target.com

    Checking Open PortsIf you give Nmap no options at all and just point it at a given host it will scan for open ports and report backthose that are open, and what service is running on them. For instance, running nmaptarget.hostname.com might yield something like this:

    Interesting ports on target.hostname.com (10.0.0.88):Not shown: 1711 closed portsPORT STATE SERVICE22/tcp open ssh80/tcp open http3306/tcp open mysql

    Nmap done: 1 IP address (1 host up) scanned in 0.228 seconds

    Here you can see that there are three ports open: 22, 80, and 3306 which run SSH, HTTP, and MySQLrespectively. Nmap recognizes six states: open, closed, filtered, unfiltered, open|filtered, and closed|filtered.These are mostly self-explanatory. See the Nmap docs for more on these states. If Nmap can tell whatservice is running, it will report it under the SERVICE column.If you'd like a little more information, crank it up a notch by adding one or two -v options to the command.For example, using nmap -vv host.target.com would produce something like this:

    Initiating Ping Scan at 11:44Scanning 10.0.0.28 [1 port]Completed Ping Scan at 11:44, 0.00s elapsed (1 total hosts)Initiating Parallel DNS resolution of 1 host. at 11:44Completed Parallel DNS resolution of 1 host. at 11:44, 0.00s elapsed

    How to Use NumPy for ScientifHow to Find the Best Linux Dis

    Sign Up For the Linux.com

    First NameLast Name

    Country

    Latest Software News

    Companies Are Finally LearninWayUbuntu, ownCloud, and a HiddRepositoriesRaided for Hosting a Tor Node?New Kernel Live Patching ComDebian 8.0 Jessie Now Under

    Beginner's Guide to Nmap | Linux.com http://www.linux.com/learn/tutorials/290879-begi...

    3 of 7 11/08/2014 12:57 AM

  • Initiating Connect Scan at 11:44Scanning host.target.com (10.0.0.28) [1714 ports]Discovered open port 22/tcp on 10.0.0.28Discovered open port 80/tcp on 10.0.0.28Discovered open port 3306/tcp on 10.0.0.28Completed Connect Scan at 11:44, 0.08s elapsed (1714 total ports)Host host.target.com (10.0.0.28) appears to be up ... good.Interesting ports on host.target.com (10.0.0.28):Not shown: 1711 closed portsPORT STATE SERVICE22/tcp open ssh80/tcp open http3306/tcp open mysql

    Read data files from: /usr/share/nmapNmap done: 1 IP address (1 host up) scanned in 0.104 seconds

    Nmap provides a lot more information when using the verbose (-v) option.Service ScansIf you're really curious about what services a host might be running, try the -sV options. This will do a moreaggressive scan to try to figure out what versions of services are running on a given host, and also mighthelp determine more specifically what OS a host is running. For instance, I ran nmap -sV against a testserver and got this in response:Starting Nmap 5.21 ( http://nmap.org ) at 2010-02-28 00:15 EST

    Nmap scan report for test.host.net (XX.XXX.XXX.XX)Host is up (0.090s latency).Not shown: 965 closed ports, 33 filtered portsPORT STATE SERVICE VERSION22/tcp open ssh OpenSSH 4.7p1 Debian 8ubuntu1.2 (protocol 2.0)80/tcp open http Apache httpd 2.2.8 ((Ubuntu) PHP/5.2.4-2ubuntu5.10 with Suhosin-Patch)Service Info: OS: Linux

    Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .Nmap done: 1 IP address (1 host up) scanned in 11.43 seconds

    As you can see, Nmap can "fingerprint" the packets and identify the versions of the software running on theSSH and HTTP ports. Here you can see that the system being pinged is a Ubuntu box with Apache 2.2.8and OpenSSH 4.7p1. This can be useful for a number of reasons. A quick Nmap scan can identify systemsthat are running unpatched systems and therefore ones that might be vulnerable to known exploits.What's on My Network?Not quite sure what might be running on your network? Try using nmap -sP, which will run a ping scan onthe specified network. For instance, nmap -sP 10.0.0.0/24 will scan the 256 hosts from 10.0.0.0 through

    Beginner's Guide to Nmap | Linux.com http://www.linux.com/learn/tutorials/290879-begi...

    4 of 7 11/08/2014 12:57 AM

  • 10.0.0.255 to see if they're available, and report back. You can also use a range, such as nmap -sP10.0.0.1-15.ZenmapFinally, if all this command line fun is not your bag, Nmap has a GUI that you can use to build and executecommands. Called Zenmap, the GUI will let you specify targets, run scans, display the results and even saveand compare them against one another.When you open Zenmap, you can give it a target to scan and select one of the profile scans to get started. Itincludes your basic ping scan, quick scans, some more intense scans that include UDP services, and soforth. The Zenmap GUI is a good way to get acquainted with Nmap, but it's also a good idea to know how touse Nmap from the command line if you're going to be working with it often.In a future tutorial we'll take a more in-depth look at Nmap and specific tasks you might want to do withNmap. I hope this overview gave a good sense what Nmap can do and helps you get started working withNmap.

    Joe 'Zonker' Brockmeier

    Comments

    20 Nov 12Khalifa :This is really helpful, thank you very much for your efforts in making it easy to read &understand specially for non-english readers.

    Report Reply

    13 Dec 12Edward Mwangile :The tutorial is very helpful for beginners.

    Report Reply

    09 Apr 13Hadi :

    Beginner's Guide to Nmap | Linux.com http://www.linux.com/learn/tutorials/290879-begi...

    5 of 7 11/08/2014 12:57 AM

  • very newbie friendly, people should learn to explain stuff in this way to beginners.Thanks

    Report Reply

    13 Sep 13Lily :I wrote a blog post titled: "3 easy quick resources and nmap tutorials" which readersmight find helpful! Thought I'd share: http://www.concise-courses.com/security/nmap-tutorial-and-help/ Thanks - Lily

    Report Reply

    26 FebNandan :The content is very helpful. Thanks for explaining it in simple way

    Report Reply

    04 AprVaidik :If it is showing that the host is down then what should we do?

    Report Reply

    30 AprAaron :This is a very good post...It explained the concepts in a very beginner friendly way.

    Report Reply

    08 SepAlvaro :Hello, my name is Alvaro Valenzuela, actually i am working in my thesis project formy bachelor degree in informatic engineer and i have to analyze the behavior ofsome IP's that operate as free WiFi hotspots. My question has to do with thedifference between 1) and 2) at the moment of detecting on one of them the SSL andin the another one not. I hope you can help me with that! Regards, 1) PORT STATESERVICE VERSION 443/tcp open ssl/https? 2) PORT STATE SERVICE VERSION443/tcp open https?

    Report Reply

    Beginner's Guide to Nmap | Linux.com http://www.linux.com/learn/tutorials/290879-begi...

    6 of 7 11/08/2014 12:57 AM

  • WHO WE ARE ?

    The Linux Foundation is a non-profitconsortium dedicated to the growth ofLinux.More About the foundation...Frequent QuestionsJoin / Linux Training / Board

    EXPLORE

    AnswersBlogsForumsDirectory

    STAY CURRENT

    NetbooksCloud ComputingEnterpriseEmbedded & Mobile

    Linux.com 2012 Linux.com. All rights reserved.The Linux Foundation Symbol is a trademark of the Linux Foundation.Linux is a registered trademark of Linus Torvalds.

    Post Comment

    Name :

    Email :

    Comment :

    Subscribe to Comments

    4 days agowalex :Very interesting

    Report Reply

    Beginner's Guide to Nmap | Linux.com http://www.linux.com/learn/tutorials/290879-begi...

    7 of 7 11/08/2014 12:57 AM