UnixDroid

Lesson 05 of 5

Advanced Nmap: Faster Scans, Firewall Evasion, Output Formats and a Full Recon Workflow

5 min read

Speed up big scans, test firewall rules, save results for reports and put everything together.

You now know the core of Nmap. In this final lesson we'll make your scans faster and smarter, test how a firewall reacts, save results like a professional, and put it all together into a workflow you can use in labs, CTFs and real, authorised pentests.

Save your results (-oN, -oX, -oG, -oA)

Never run an important scan without saving it. Nmap has three main output formats, plus a shortcut for all of them:

nmap -oN scan.txt 192.168.56.101     # normal, human-readable
nmap -oX scan.xml 192.168.56.101     # XML, for tools and reports
nmap -oG scan.gnmap 192.168.56.101   # grepable, one line per host
nmap -oA scan 192.168.56.101         # all three at once

Make -oA a habit. You get scan.nmap, scan.xml and scan.gnmap. Metasploit can import the XML (db_import scan.xml), and you can turn it into an HTML report:

xsltproc scan.xml -o scan.html

If a long scan gets interrupted, carry on from where it stopped:

nmap --resume scan.gnmap

Make big scans faster

Scanning all 65,535 ports on many hosts can take hours. These options help:

  • -T4 – a faster timing template
  • --min-rate 1000 – send at least 1,000 packets per second
  • --max-retries 1 – don't keep retrying slow ports
  • -n – skip DNS lookups
  • --host-timeout 10m – give up on hosts that take too long

The best trick is a two-step scan: first find the open ports quickly, then scan only those ports in detail.

sudo nmap -p- --min-rate 1000 -T4 -oA allports 192.168.56.101
sudo nmap -p 21,22,80,139,445 -sC -sV -O -oA detailed 192.168.56.101

Pull the open ports out of the first scan automatically:

grep -oP '\d+(?=/open)' allports.gnmap | paste -sd, -

Test a firewall (only with permission)

Part of a pentest is checking whether the firewall and IDS really block or detect scans. Nmap has options for this. Use them only on networks where you have written permission:

  • -sA (ACK scan) – maps firewall rules by showing which ports are filtered and which are unfiltered
  • -f – splits packets into tiny fragments to see whether the firewall reassembles them
  • -D RND:5 – adds five random decoy IPs, so your real IP is mixed in with fake ones in the logs
  • -g 53 – sends from source port 53 to test lazy rules that trust DNS traffic
  • --data-length 25 – pads packets with random data so they don't match default Nmap probes
  • -T1 – very slow, to test whether the IDS notices low-and-slow scans
sudo nmap -sA -p 22,80,443 192.168.56.101
sudo nmap -sS -f -D RND:5 -g 53 -p 80 192.168.56.101

If the IDS still raises an alert, good – the defences work. If it doesn't, that's a finding for your report.

The defender's view

If you work in a SOC, or want to, learn what a scan looks like from the other side. A port scan shows up as one source IP touching many ports in a short time. In firewall logs, Snort or Suricata alerts and your SIEM (like Splunk), look for:

  • One IP hitting dozens of different ports within seconds
  • Lots of connections that are reset straight away (SYN, then RST)
  • The "Nmap Scripting Engine" User-Agent in web server logs when NSE http scripts run

Run a scan in your lab, then go and find it in the logs. It's one of the best ways to learn both sides at once.

A complete Nmap recon workflow

Nmap recon workflow in 5 steps: host discovery, port scan, version detection, NSE scripts, saving output
Nmap recon workflow in 5 steps: host discovery, port scan, version detection, NSE scripts, saving output

Here's everything from this course, in order:

# 1. Discover live hosts
sudo nmap -sn 192.168.56.0/24 -oA hosts

# 2. Find every open TCP port
sudo nmap -p- --min-rate 1000 -T4 192.168.56.101 -oA allports

# 3. Identify services and the OS on those ports
sudo nmap -p 21,22,80,445 -sV -O 192.168.56.101 -oA services

# 4. Run the default and vuln scripts
sudo nmap -p 21,22,80,445 -sC --script vuln 192.168.56.101 -oA scripts

# 5. Quick UDP check
sudo nmap -sU --top-ports 20 192.168.56.101 -oA udp

Then read through the results, look up each version for known CVEs, and write down what you found.

Nmap cheat sheet

nmap target                           # top 1,000 TCP ports
nmap -sn 192.168.1.0/24               # live hosts only
nmap -Pn target                       # skip host discovery
nmap -p- target                       # all TCP ports
nmap -F target                        # top 100 ports
sudo nmap -sS target                  # SYN scan
nmap -sT target                       # TCP connect scan
sudo nmap -sU --top-ports 20 target   # UDP scan
nmap -sV target                       # service versions
sudo nmap -O target                   # OS detection
sudo nmap -A target                   # OS + versions + scripts + traceroute
nmap -sC target                       # default NSE scripts
nmap --script vuln target             # vulnerability scripts
nmap -T4 target                       # faster timing
nmap --open target                    # show only open ports
nmap -oA scan target                  # save in all formats

Where to practise next

  • TryHackMe – its Nmap rooms walk you through every scan type step by step
  • Hack The Box – every machine starts with an Nmap scan
  • Metasploitable 2 in VirtualBox – a free, deliberately vulnerable VM for your home lab
  • scanme.nmap.org – for quick, light tests

Simple words mein (Hinglish)

Har scan ko -oA se save karo. Bade scans mein pehle -p- --min-rate 1000 se open ports nikalo, phir sirf un ports par -sC -sV chalao. Firewall test karne wale options (-f, -D, -g) sirf permission ke saath. Aur SOC ki nazar se bhi dekho ki scan logs mein kaisa dikhta hai. Isi workflow se aap labs, CTF aur real pentest teeno handle kar sakte ho.

FAQ

What is the best Nmap command for beginners? Start with nmap -sC -sV target, then add -p- to check every port.

How do I save Nmap output to a file? Use -oA name to save normal, XML and grepable output in one go.

How can I make Nmap faster? Use -T4, --min-rate 1000 and -n, and run the detailed scan only on ports you already know are open.

Can Nmap bypass a firewall? Options like -f, -D and -g can get past badly configured firewalls, but a well-configured firewall or IDS will still block or detect them. Use them only to test networks you're allowed to test.

What should I learn after Nmap? Wireshark (to watch Nmap's packets on the wire), Burp Suite for web apps, and Metasploit for exploitation.

Congratulations – you've finished Nmap: Basic to Advanced!