Nmap Intro
Nmap Intro
Ionut, Ambrosie
1 Introduction 1
1.1 Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Nmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Host Discovery 4
2.1 No Port Scan (-sP) . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 ARP Ping (-PR) . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3 No Ping (-Pn) . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3 Port Scanning 6
3.1 SYN Scan (-sS) . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2 Connect Scan (-sT) . . . . . . . . . . . . . . . . . . . . . . . . 7
3.3 NULL Scan (-sN), FIN Scan (-sF), Xmas Scan (-sX) . . . . . 8
3.4 ACK Scan (-sA) . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.5 IDLE Scan (-sI) . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.6 UDP Scan (-sU) . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4 Version Detection 12
5 OS Detection 13
6 Conclusions 15
Introduction
This guide assumes the reader has basic knowledge of the Internet Protocol
suite (how TCP and UDP are related, how they use IP, what IP addresses
and port numbers are and knowledge of the different TCP flags)1 .
1.1 Setup
In order to illustrate the techniques covered in this guide, we will be making
use of the following setup (see Figure 1.1): on our host operating system
(vm.host) we have installed a hypervisor which runs a virtual machine with
the Kali Linux distribution2 (vm.guest); the Kali Linux virtual machine’s
network connection is configured to run in NAT mode and has been assigned
192.168.60.128 as the IP address; the host operating system’s IP address, as
viewed from Kali Linux, is 192.168.60.2.
The two targets we’re selected for this guide are:
1.2 Nmap
Nmap is an open source tool designed for network exploration and security
auditing. Its output is composed of a list of scanned targets together with
1
A good reference on the Internet protocol suite is TCP/IP Illustrated, Volume 1: The
Protocols (2nd Edition) by Kevin R. Fall and W. Richard Stevens
2
Kali Linux is a Debian-derived GNU/Linux distribution designed for digital forensics
and penetration testing use. The project’s website is https://www.kali.org/
1
192.168.60.128 192.168.60.2
vmware.guest vmware.host
Internet
scanme.nmap.org
Open means that an application on the target machine is listening for con-
nections/packets on that port
2
Unfiltered means the ports are responsive to Nmap’s probes, but Nmap
cannot determine whether they are open or closed
By default, Nmap scans the most commonly used 1000 TCP ports on the
target host. The -p option can be used for specifying which ports should
be scanned (e.g. the argument -pU:53,111,137,T:21-25,80,139,8080 in-
structs Nmap to scan UDP ports 53, 111 and 137, as well as TCP ports from
21 to 25, 80, 139 and 8080).
3
Detailed information about specifying Nmap targets is available at http://nmap.org/
book/man-target-specification.html
3
Host Discovery
Network scans usually begin by discovering which targets on the network are
online and thus worth deeper investigation.
4
MAC Address: 00:50:56:F3:FC:6F (VMware)
Nmap done: 1 IP address (1 host up) scanned in 0.14 seconds
A sample Nmap scan using the ARP Ping option
5
Port Scanning
After making sure the target system is alive, the natural next step is try-
ing to identify the system’s ports states. And while Nmap has evolved in
functionality over the years, port scanning remains its core function.
When port scanning target hosts with Nmap, it’s important to keep in
mind only one method may be used at a time, except that, for example, a
UDP scan (-sU) may be combined with any one of the TCP scan types.
As a memory aid, port scan type options are generally of the form -sC,
where C is a prominent character in the scan name, usually the first.
6
Host is up (0.00040s latency).
PORT STATE SERVICE
20/tcp filtered ftp-data
80/tcp open http
514/tcp filtered shell
9929/tcp filtered nping-echo
7
3.3 NULL Scan (-sN), FIN Scan (-sF), Xmas
Scan (-sX)
These three scan types exploit a subtle loophole in the TCP RFC1 in order
to differentiate between port states.
When scanning systems compliant with the TCP RFC text (i.e. most
Unix-based systems), any TCP segment not having the SYN, RST, or ACK
flags set will result in receiving a TCP segment with the RST flag set, if the
port is closed, or no response at all, if the port is open|filtered. If a TCP
segment with the RST flag set is received, the port is considered closed, while
no response means it is open|filtered. The port is marked filtered if an ICMP
unreachable error (type 3, code 1, 2, 3, 9, 10, or 13) is received.
While none of SYN, RST, or ACK flags should be set on the outgoing
segments, any combination of the other three (FIN, PSH and URG) are O.K.
Thus, TCP NULL Scan (-sN) works by sending TCP segments without
any flags set, TCP FIN Scan (-sF) works by sending TCP segments with just
the FIN flag set, and TCP Xmas Scan (-sX) works by sending TCP segments
with the FIN, PSH and URG flags set.
An important thing to note here is that some systems do not follow RFC
793 to the letter, the most prominent ones being Microsoft Windows and
many Cisco devices. These systems send RST responses to probes employed
by these scan types, regardless of whether the port is open or not. This
causes all of the ports to be labeled as closed.
root@kali:~# nmap -sN -p20,80,514,9929 scanme.nmap.org
1
RFC 793, http://www.rfc-editor.org/rfc/rfc793.txt
8
Starting Nmap 6.47 ( http://nmap.org ) at 2014-11-10 17:09 EET
Nmap scan report for scanme.nmap.org (74.207.244.221)
Host is up (0.00030s latency).
PORT STATE SERVICE
20/tcp open|filtered ftp-data
80/tcp open|filtered http
514/tcp open|filtered shell
9929/tcp open|filtered nping-echo
9
Host is up (0.00030s latency).
PORT STATE SERVICE
20/tcp unfiltered ftp-data
80/tcp unfiltered http
514/tcp unfiltered shell
9929/tcp unfiltered nping-echo
10
Nmap done: 1 IP address (1 host up) scanned in 70.11 seconds
80/tcp open http
11
Version Detection
1
A detailed resource on using Nmap for the purposes of OS detection is http://nmap.
org/book/vscan.html
12
OS Detection
13
SP3 (96%), BlueArc Titan 2100 NAS device (91%), Pirelli DP-10 VoIP
phone (88%)
No exact OS matches for host (test conditions non-ideal).
14
Conclusions
1
About half of the book’s content is available for free at http://nmap.org/book/toc.
html
15