Nmap Scanning

Overview

Nmap (Network Mapper) is an open-source tool for network discovery, port scanning, service enumeration, and security auditing. It identifies hosts, open ports, running services, operating systems, and vulnerabilities across networks.


Core Syntax

nmap [scan_type] [options] <target>

Learning Workflow

Phase 1: Discovery — Host detection and basic port scanning Phase 2: Enumeration — Service versions and OS detection Phase 3: Scripting — NSE scripts for vulnerability detection Phase 4: Evasion — Firewall bypass and stealth techniques Phase 5: Advanced — Performance tuning, output formats, automation


Target Specification

Single Targets

# Single IP
nmap 192.168.1.1

# Hostname
nmap target.example.com

# Multiple IPs
nmap 192.168.1.1 192.168.1.5 192.168.1.10

IP Ranges

From Files

Random Targets


Phase 1: Host Discovery

Discovery Techniques

Option
Technique
Description

-sn

Ping scan

Host discovery only, no port scan

-Pn

No ping

Skip discovery, assume host is up

-PS

TCP SYN ping

SYN to specified ports

-PA

TCP ACK ping

ACK to specified ports

-PU

UDP ping

UDP to specified ports

-PE

ICMP echo

Standard ping

-PP

ICMP timestamp

Timestamp request

-PM

ICMP netmask

Address mask request

-PO

IP protocol ping

Protocol-specific probes

-PR

ARP ping

Local network only

Host Discovery Commands

List Scan (No Packets Sent)


Phase 1: Port Scanning

Scan Types

Option
Name
Description

-sS

SYN scan

Stealth scan, half-open (default w/root)

-sT

Connect scan

Full TCP connection (default w/o root)

-sU

UDP scan

UDP port scan

-sA

ACK scan

Map firewall rules

-sW

Window scan

ACK variant, detects open via window size

-sM

Maimon scan

FIN/ACK, works on some BSD systems

-sN

Null scan

No flags set

-sF

FIN scan

FIN flag only

-sX

Xmas scan

FIN, PSH, URG flags

-sI

Idle scan

Zombie host scan (very stealthy)

-sO

Protocol scan

IP protocol scan

-b

FTP bounce

FTP bounce scan

Basic Port Scans

Port Specification

Port States

State
Meaning

open

Service accepting connections

closed

Accessible but no service listening

filtered

Firewall blocking, can't determine state

unfiltered

Accessible but can't determine open/closed

`open

filtered`

`closed

filtered`


Phase 2: Service & Version Detection

Version Detection

OS Detection

Aggressive Scan

Combined Enumeration


Phase 3: Nmap Scripting Engine (NSE)

Script Categories

Category
Description

auth

Authentication and credential checks

broadcast

Network broadcast discovery

brute

Brute force attacks

default

Safe, useful scripts (-sC)

discovery

Service and host discovery

dos

Denial of service (use carefully)

exploit

Active exploitation

external

Third-party service queries

fuzzer

Fuzz testing

intrusive

May crash services

malware

Malware detection

safe

Won't crash services

version

Version detection enhancement

vuln

Vulnerability detection

Running Scripts

Script Arguments

Common Reconnaissance Scripts

Vulnerability Detection Scripts

Brute Force Scripts

Script Information


Phase 4: Evasion & Stealth

Timing Templates

Option
Name
Description

-T0

Paranoid

Very slow, IDS evasion

-T1

Sneaky

Slow, IDS evasion

-T2

Polite

Slowed down, less bandwidth

-T3

Normal

Default

-T4

Aggressive

Fast, reliable network

-T5

Insane

Very fast, may miss ports

Firewall/IDS Evasion

Idle/Zombie Scan

Timing Controls


Phase 5: Output & Automation

Output Formats

Output Options

Performance Tuning

IPv6 Scanning


Common Scan Profiles

Quick Network Discovery

Standard Vulnerability Assessment

Stealth Scan

Web Server Enumeration

SMB/Windows Enumeration

Database Enumeration


Investigation Workflows

External Reconnaissance

Internal Network Assessment

Incident Response - Lateral Movement Detection

Incident Response - Service Identification

Firewall Rule Mapping


Service-Specific Scans

SSH

FTP

SMTP

DNS

LDAP

SNMP

RDP

VNC

MySQL

MSSQL

Oracle


Parsing Nmap Output

Grep Commands

XML Processing

Tools for Output Parsing


Quick Reference Card

Task
Command

Ping sweep

nmap -sn 192.168.1.0/24

Quick scan

nmap -T4 -F 192.168.1.1

Full port scan

nmap -p- 192.168.1.1

SYN scan

sudo nmap -sS 192.168.1.1

UDP scan

sudo nmap -sU 192.168.1.1

Version detection

nmap -sV 192.168.1.1

OS detection

sudo nmap -O 192.168.1.1

Aggressive scan

nmap -A 192.168.1.1

Default scripts

nmap -sC 192.168.1.1

Vuln scan

nmap --script=vuln 192.168.1.1

Skip ping

nmap -Pn 192.168.1.1

Top 1000 ports

nmap --top-ports 1000 192.168.1.1

Save all formats

nmap -oA results 192.168.1.1

Show open only

nmap --open 192.168.1.1

Stealth scan

sudo nmap -sS -T1 -f 192.168.1.1

Fast aggressive

nmap -T4 -A -v 192.168.1.1


Common Issues & Fixes

Issue
Solution

"requires root privileges"

Use sudo for SYN, UDP, OS scans

Host appears down

Use -Pn to skip ping

Scan too slow

Increase timing -T4 or -T5

Missing services

Increase --version-intensity

Firewall blocking

Try -f, --source-port 53, or -sA

Too many false positives

Lower timing, increase --max-retries

Connection refused

Target may have port open but rejecting

Script errors

Update scripts with --script-updatedb

Memory issues on large scans

Reduce --max-hostgroup

Incomplete results

Check --host-timeout settings


  • Only scan networks you own or have written authorisation to test

  • Scanning without permission may violate computer crime laws

  • ISPs may terminate service for unauthorised scanning

  • Some scan types (brute force, exploit) are more invasive

  • Document all testing authorisation before scanning

  • Be aware of scope limitations in penetration test agreements

Last updated