Waytobecomehacker

Nmap Guide

A comprehensive guide to Nmap, covering port scanning, scan types, the Nmap Scripting Engine (NSE), and firewall evasion techniques for penetration testing and network reconnaissance.


πŸ“Œ Table of Contents

  1. Introduction
  2. Nmap Switches
  3. Scan Types Overview
  4. TCP Connect Scans (-sT)
  5. SYN Scans (-sS)
  6. UDP Scans (-sU)
  7. NULL, FIN, and Xmas Scans
  8. Ping Sweep / ICMP Scans (-sn)
  9. Nmap Scripting Engine (NSE)
  10. Using NSE Scripts & Arguments
  11. Finding & Installing NSE Scripts
  12. Firewall Evasion & Stealth Scanning

1. Introduction

When it comes to penetration testing, knowledge is power. Proper enumeration is crucial before any exploitation attempt.

Key points:

Tool of choice: Nmap, the industry standard for port scanning and service discovery.


2. Nmap Switches

Nmap is primarily run from the terminal:

nmap [options] [target]

Examples of useful switches:


3. Scan Types Overview

Nmap supports multiple scan types:

  1. TCP Connect Scans (-sT)
  2. SYN β€œHalf-open” Scans (-sS)
  3. UDP Scans (-sU)

Less common scans:


4. TCP Connect Scans (-sT)

Performs a full TCP three-way handshake with each port:

  1. SYN β†’ SYN/ACK β†’ ACK
  2. If port is closed β†’ Server replies with RST
  3. If port is filtered β†’ No response

Example: sudo nmap -sT [target]

Pros:

Cons:


5. SYN Scans (-sS)

Also known as Half-open / Stealth scans:

Example: sudo nmap -sS [target]

Advantages:


6. UDP Scans (-sU)

Example: sudo nmap -sU --top-ports 20 [target]

⚠ Note: UDP scans are very slow (~20 mins for 1000 ports).


7. NULL, FIN, and Xmas Scans

Behavior:

Examples: sudo nmap -sN [target] sudo nmap -sF [target] sudo nmap -sX [target]


8. Ping Sweep / ICMP Scans (-sn)

Use to discover active hosts on a network:

nmap -sn 192.168.0.1-254 nmap -sn 192.168.0.0/24


9. Nmap Scripting Engine (NSE)

The NSE uses Lua scripts to extend Nmap’s functionality.

Categories:


10. Using NSE Scripts & Arguments

Run scripts by category: nmap --script=vuln [target]

Run multiple scripts: nmap --script=smb-enum-users,smb-enum-shares [target]

Use script arguments: nmap -p 80 --script http-put --script-args http-put.url='/dav/shell.php',http-put.file='./shell.php'

Check script help: nmap --script-help [script-name]


11. Finding & Installing NSE Scripts

Scripts are stored in: /usr/share/nmap/scripts

Search locally: grep "ftp" /usr/share/nmap/scripts/script.db ls -l /usr/share/nmap/scripts/*ftp*

Install new scripts:

sudo wget -O /usr/share/nmap/scripts/[script-name].nse https://svn.nmap.org/nmap/scripts/[script-name].nse
sudo nmap --script-updatedb

12. Firewall Evasion & Stealth Scanning

Bypass ICMP-blocking firewalls: nmap -Pn [target]

Other useful switches:


βœ… Summary

Nmap is a powerful reconnaissance tool when used properly, forming the foundation for any penetration test or security audit.

###Learn More Nmap Live Host Discovery