Nmap

From aldeid
Jump to: navigation, search
French.png
This article is also available in one or more other languages
To view this article in French, click here
VoirAussi.png
You might also see: Zenmap, Nmap's graphical frontend
Nmap-network-scanning.png

Description

Nmap is certainly THE scanner to know. Thanks to its numerous parameters, it is a swiss army knife to all situations where network identification is needed. It enables among other things to list network hosts and scan their ports.

Installation

From the package

This method shows how to install Nmap-5.00 from packages. Simply run:

$ sudo apt-get install nmap

From sources

First install development sources of libpcap:

$ sudo apt-get install libpcap-dev

Installing Nmap from sources enables, among other things, to obtain the last development revision (5.35-DC1).

$ cd /data/src/
$ wget http://nmap.org/dist/nmap-5.35DC1.tar.bz2
$ bzip2 -cd nmap-5.35DC1.tar.bz2 | tar xf -
$ cd nmap-5.35DC1/
$ .configure
$ make
$ sudo make install

Without change in the configuration options, Nmap installs in /usr/local/bin/nmap.

Usage

Basic syntax

$ ./nmap [Scan Type(s)] [Options] {target specification}

Options

Target Specification

-iL <inputfilename>
Input from list of hosts/networks
-iR <num hosts>
Choose random targets
--exclude <host1[,host2][,host3],...>
Exclude hosts/networks
--excludefile <exclude_file>
Exclude list from file

Host Discovery

-sL
List Scan - simply list targets to scan
-sn
Ping Scan - disable port scan
-Pn
Treat all hosts as online -- skip host discovery
-PS/PA/PU/PY[portlist]
TCP SYN/ACK, UDP or SCTP discovery to given ports
-PE/PP/PM
ICMP echo, timestamp, and netmask request discovery probes
-PO[protocol list]
IP Protocol Ping
-n/-R
Never do DNS resolution/Always resolve [default: sometimes]
--dns-servers <serv1[,serv2],...>
Specify custom DNS servers
--system-dns
Use OS's DNS resolver
--traceroute
Trace hop path to each host

Scan techniques

-sS/sT/sA/sW/sM
TCP SYN/Connect()/ACK/Window/Maimon scans
-sU
UDP Scan
-sN/sF/sX
TCP Null, FIN, and Xmas scans
--scanflags <flags>
Customize TCP scan flags
-sI <zombie host[:probeport]>
Idle scan
-sY/sZ
SCTP INIT/COOKIE-ECHO scans
-sO
IP protocol scan
-b <FTP relay host>
FTP bounce scan

Port Specification and Scan Order

-p <port ranges>
Only scan specified ports
Ex: -p22 | -p1-65535 | -p U:53,111,137,T:21-25,80,139,8080,S:9
-F
Fast mode - Scan fewer ports than the default scan
-r
Scan ports consecutively - don't randomize
--top-ports <number>
Scan <number> most common ports
--port-ratio <ratio>
Scan ports more common than <ratio>

Service/Version Detection

-sV
Probe open ports to determine service/version info
--version-intensity <level>
Set from 0 (light) to 9 (try all probes)
--version-light
Limit to most likely probes (intensity 2)
--version-all
Try every single probe (intensity 9)
--version-trace
Show detailed version scan activity (for debugging)

Script Scan

-sC
equivalent to --script=default
--script=<Lua scripts>
<Lua scripts> is a comma separated list of directories, script-files or script-categories
--script-args=<n1=v1,[n2=v2,...]>
provide arguments to scripts
--script-trace
Show all data sent and received
--script-updatedb
Update the script database.

OS Detection

-O
Enable OS detection
--osscan-limit
Limit OS detection to promising targets
--osscan-guess
Guess OS more aggressively

Timing and Performance

Info.png
Note
Options which take
-T<0-5>
Set timing template (higher is faster)
--min-hostgroup/max-hostgroup <size>
Parallel host scan group sizes
--min-parallelism/max-parallelism <numprobes>
Probe parallelization
--min-rtt-timeout/max-rtt-timeout/initial-rtt-timeout
Specifies probe round trip time.
--max-retries <tries>
Caps number of port scan probe retransmissions.
--host-timeout
Give up on target after this long
--scan-delay/--max-scan-delay
Adjust delay between probes
--min-rate <number>
Send packets no slower than <number> per second
--max-rate <number>
Send packets no faster than <number> per second

Firewall/IDS Evasion and Spoofing

-f; --mtu <val>
fragment packets (optionally w/given MTU)
-D <decoy1,decoy2[,ME],...>
Cloak a scan with decoys
-S <IP_Address>
Spoof source address
-e <iface>
Use specified interface
-g/--source-port <portnum>
Use given port number
--data-length <num>
Append random data to sent packets
--ip-options <options>
Send packets with specified ip options
--ttl <val>
Set IP time-to-live field
--spoof-mac <mac address/prefix/vendor name>
Spoof your MAC address
--badsum
Send packets with a bogus TCP/UDP/SCTP checksum
--adler32
Use deprecated Adler32 instead of CRC32C for SCTP checksums

Output

-oN/-oX/-oS/-oG <file>
Output scan in normal, XML, s|<rIpt kIddi3, and Grepable format, respectively, to the given filename.
-oA <basename>
Output in the three major formats at once
-v
Increase verbosity level (use -vv or more for greater effect)
-d
Increase debugging level (use -dd or more for greater effect)
--reason
Display the reason a port is in a particular state
--open
Only show open (or possibly open) ports
--packet-trace
Show all packets sent and received
--iflist
Print host interfaces and routes (for debugging)
--log-errors
Log errors/warnings to the normal-format output file
--append-output
Append to rather than clobber specified output files
--resume <filename>
Resume an aborted scan
--stylesheet <path/URL>
XSL stylesheet to transform XML output to HTML
--webxml
Reference stylesheet from Nmap.Org for more portable XML
--no-stylesheet
Prevent associating of XSL stylesheet w/XML output

Miscellaneous

-6
Enable IPv6 scanning
-A
Enables OS detection and Version detection, Script scanning and Traceroute
--datadir <dirname>
Specify custom Nmap data file location
--send-eth/--send-ip
Send using raw ethernet frames or IP packets
--privileged
Assume that the user is fully privileged
--unprivileged
Assume the user lacks raw socket privileges
-V
Print version number
-h
Print this help summary page.

Examples

List hosts on a network

$ ./nmap -sP 192.168.100.0/24
Starting Nmap 5.35DC1 ( http://nmap.org ) at 2010-11-28 11:20 CET
Nmap scan report for 192.168.100.1
Host is up (0.0045s latency).
Nmap scan report for 192.168.100.13
Host is up (0.023s latency).
Nmap scan report for 192.168.100.18
Host is up (0.000096s latency).
Nmap scan report for 192.168.100.50
Host is up (0.0097s latency).
Nmap scan report for 192.168.100.51
Host is up (0.022s latency).
Nmap done: 256 IP addresses (5 hosts up) scanned in 2.59 seconds

Scan a host

This example uses a TCP/SYN scan and tries to identify installed services:

$ sudo ./nmap -sS -sV 192.168.100.18
Starting Nmap 5.35DC1 ( http://nmap.org ) at 2010-11-28 11:22 CET
Nmap scan report for 192.168.100.18
Host is up (0.0000060s latency).
Not shown: 997 closed ports
PORT   STATE SERVICE VERSION
21/tcp open  ftp     vsftpd 2.2.2
22/tcp open  ssh     OpenSSH 5.3p1 Debian 3ubuntu4 (protocol 2.0)
80/tcp open  http    Apache httpd 2.2.14 ((Ubuntu))
Service Info: OSs: Unix, Linux
Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 9.40 seconds
Info.png
Note
Notice that TCP/SYN scan requires root privileges.

Comments

Talk:Nmap