Nmap: Port-Scanning Tool

Much of the notes for this page were derived from an article in The Linux Journal, May 2001 by Mick Bauer

Why would you want to scan your own machines?

  • Find out where your system is vulnerable
  • What services are visible
  • What may have changed since last time you checked security on your system
  • Security is an on-going process...
  • A good place to look for info on nmap: www.insecure.org/nmap/index.html
  • Written by Fyodor
  • What is a port scanner? Why should you be careful when running a scanner like nmap? Nmap supports several different ways to stealth scan Getting and Installing Nmap

    Available from http://www.insecure.org/
    grab the gzipped tarball from web http://www.insecure.org/
    unzip and explode it tar xvfz nmap-2.53.tgz
    change to nmap directory cd nmap-2.53
    configure nmap ./configure
    compile nmap make
    become root su root
    install binaries and docs make install

    Using Nmap

    Basic syntax:

    nmap -s (scan type) -p (port-range options)  (target)

    Scan Types:

    Ping sweep nmap -sP 127.0.0.1
    TCP Connect Scan nmap -sT 127.0.0.1
    TCP SYN Scan nmap -sS 127.0.0.1
    TCP FIN Scan nmap -sF 127.0.0.1
    TCP NULL Scan nmap -sN 127.0.0.1
    TCP Xmas Tree Scan nmap -sX 127.0.0.1
    UDP Scan (combined with above types) nmap -sU 127.0.0.1
    RPC Scan (combine with above types) nmap -sR[other options] 127.0.0.1
    OS Detection
    nmap [other options] -O 127.0.0.1

    Some examples

    A default scan, no flags are needed. Nmap will ping the target host(s) then scan with the TCP Connect method. This is a very fast scan but it can be detected and logged. I'll scan my home machine.

        # nmap 192.168.1.20

    Adding UDP and RPC to the default scan. Note: you will need to explicitely include the TCP Connect flags.

        # nmap -sTUR 192.168.1.20

    Above we use the T flag for TCP Connect, the U flag for UDP, and the R flag for RPC. Using the U and the R flags together makes sense because typically RPC is UDP protocol.

    Below is a command to scan all the machines on my homenet using a fast TCP and UDP scan.

        # nmap -sTU 192.168.1.0/24

    Here is a nice scan I grabbed from reading the Linux Journal paper which adds a few nicities to the scan. The -OIF is as follows:

    The -oN  tells nmap to write output to a text file.

        # nmap -sTUR -OIF -oN outfile 192.168.1.20

    Here is a very verbose stealthy scan with OS detection.

    # nmap -vv -sS -O www.example.org
    Starting nmap V. 3.00 ( www.insecure.org/nmap/ )
    Host www.example.com (192.0.34.166) appears to be up ... good.
    Initiating SYN Stealth Scan against www.example.com
    (The 1600 ports scanned but not shown below are in state: filtered)
    Port       State       Service
    80/tcp     open        http
    Remote operating system guess: Linux Kernel 2.4.0 - 2.5.20
    ...

    Use the -p option to scan for a particular port. Here we are scanning for the SQL Slammer worm.

    # nmap -p 1434 -sU 127.0.0.1