Nmap Advanced Techniques: Expert Network Scanning
Master advanced Nmap scanning techniques including NSE scripting, firewall evasion, performance tuning, and custom scan types for professional penetration testing.
Beyond Basic Nmap
If you have mastered basic Nmap scans like -sV and -sC, it is time to explore advanced techniques. Below you will find the Nmap Scripting Engine (NSE), advanced scan types, performance optimization, firewall evasion, and output processing that professional penetration testers rely on daily.
Prerequisites
Before studying advanced Nmap, you should understand:
Advanced Scan Types
TCP Null, FIN, and Xmas Scans
These scan types exploit TCP RFC behavior to bypass firewalls:
# Null scan — no flags set
nmap -sN target.com
# FIN scan — only FIN flag
nmap -sF target.com
# Xmas scan — FIN, PSH, URG flags
nmap -sX target.com
Open ports on RFC-compliant systems send no response. Closed ports send RST. These do not work against Windows, which always sends RST.
Idle Scan (-sI)
A stealth scan using a zombie host to mask your IP:
# Find a suitable zombie host
nmap -p 80 --script ipidseq zombie-host.com
# Perform idle scan through the zombie
nmap -sI zombie-host.com target.com
FTP Bounce Scan (-b)
nmap -b ftpuser:ftppass@ftp-server.com target.com
Nmap Scripting Engine (NSE)
Script Categories
# List all categories
nmap --script-help all | grep "Categories:"
# auth — Authentication credential testing
# broadcast — Network broadcast discovery
# brute — Credential brute forcing
# default — Default script set (-sC)
# discovery — Service and host discovery
# exploit — Exploit modules
# safe — Non-disruptive scripts
# vuln — Vulnerability detection
Using NSE Scripts
# Run specific scripts
nmap --script http-enum,http-headers target.com
# Run all scripts in a category
nmap --script "vuln" target.com
# Run safe discovery scripts
nmap --script "safe and discovery" target.com
# Run scripts with arguments
nmap --script http-brute --script-args "http-brute.path=/admin,userdb=users.txt,passdb=pass.txt" target.com
Custom NSE Script Development
description = [[Checks if the web server version is vulnerable]]
author = "KaliGo User"
license = "Same as Nmap"
categories = {"safe", "discovery"}
local http = require "http"
portrule = function(host, port)
return port.protocol == "tcp" and port.number == 80
end
action = function(host, port)
local response = http.get(host, port, "/")
if not response or not response.headers then
return nil
end
local server = response.headers["server"] or "Unknown"
local vulnerable = {
["Apache/2.4.49"] = "CVE-2021-41773"
}
for version, cve in pairs(vulnerable) do
if server:find(version) then
return string.format("VULNERABLE: %s", cve)
end
end
return string.format("Server: %s (not vulnerable)", server)
end
Firewall Evasion Techniques
Packet Fragmentation
# Fragment into 8-byte pieces
nmap -f target.com
# Custom MTU
nmap --mtu 16 target.com
Decoy Scans
# Random decoys
nmap -D RND:10 target.com
# Specific decoy IPs
nmap -D 192.168.1.10,10.0.0.1,me target.com
Source Port Manipulation
# Use source port that may be allowed by firewall
nmap --source-port 53 target.com
nmap --source-port 20 target.com
Custom Timing
# Slow, stealthy scan
nmap -T1 --max-retries 1 --randomize-hosts --data-length 100 target.com
Performance Optimization
Timing Templates
# -T0 Paranoid — Very slow, IDS evasion
# -T1 Sneaky — Slow, IDS evasion
# -T2 Polite — Slower, less bandwidth
# -T3 Normal — Default
# -T4 Aggressive — Fast, assumes fast network
# -T5 Insane — Very fast, may miss ports
nmap -T4 target.com
Fine-Tuning
nmap --min-hostgroup 64 --max-hostgroup 256 target.com
nmap --min-parallelism 10 --max-parallelism 20 target.com
nmap --min-rtt-timeout 100ms --max-rtt-timeout 1000ms target.com
nmap --host-timeout 30m target.com
Real-World Scenarios
Internal Network Penetration Test
# Phase 1: Host discovery
nmap -sn 192.168.1.0/24 -oA live_hosts
# Phase 2: Quick port scan
nmap -sS -T4 -p- --min-rate=10000 -iL live_hosts.gnmap -oA all_ports
# Phase 3: Service detection
nmap -sV -sC -T4 -iL live_hosts.gnmap -p $(paste -sd, open_ports.txt) -oA services
# Phase 4: Vulnerability scanning
nmap --script vuln -iL live_hosts.gnmap -p $(paste -sd, open_ports.txt) -oA vulns
Common Mistakes
Using too aggressive timing: -T5 can cause packet loss and false negatives.
Not accounting for rate limiting: Some services rate-limit. Use --scan-delay.
Ignoring firewall responses: ICMP unreachable or TCP RST from firewalls provide useful intelligence.
Not verifying results: False positives and negatives occur. Verify with other tools.
Best Practices
Related Tools
Related Articles
Summary
Advanced Nmap techniques include specialized scan types (Null, FIN, Xmas, Idle), NSE scripting for vulnerability detection, firewall evasion through fragmentation and decoys, and performance tuning. Proper output processing maximizes the value of scans.