| name | nmap-avance |
| description | Nmap avancé — scans furtifs, NSE scripts, évasion firewall, détection OS/service, timing, formats de sortie, automatisation, et scénarios de pentest complets. |
Nmap Avancé — Guide Pentest
Présentation
Nmap (Network Mapper) est le scanner de réseau de référence. Ce skill couvre les techniques avancées au-delà du scan de base.
Installation :
sudo apt install nmap
git clone https://github.com/nmap/nmap.git && cd nmap && ./configure && make && sudo make install
Types de scans avancés
Scan SYN (furtif) — -sS
nmap -sS -p 1-65535 192.168.1.1
Scan TCP Connect — -sT
nmap -sT -p 80,443,8080 192.168.1.1
Scan UDP — -sU
nmap -sU --top-ports 100 192.168.1.1
Scan FIN/Null/Xmas — évasion firewall
nmap -sF 192.168.1.1
nmap -sN 192.168.1.1
nmap -sX 192.168.1.1
Scan ACK — cartographie des règles de firewall
nmap -sA 192.168.1.1
nmap -sW 192.168.1.1
Scan SCTP — -sY
nmap -sY 192.168.1.1
Scan IP Protocol — -sO
nmap -sO 192.168.1.1
Détection OS — -O
Détection OS agressive
nmap -O --osscan-guess 192.168.1.1
nmap -O --fuzzy 192.168.1.1
nmap -O --max-os-tries 3 192.168.1.1
Limiter la détection OS
nmap -O --osscan-limit 192.168.1.0/24
Détection de versions — -sV
Intensité de version (0-9)
nmap -sV --version-intensity 9 192.168.1.1
nmap -sV --version-intensity 2 192.168.1.1
nmap -sV --version-light 192.168.1.1
nmap -sV --version-all 192.168.1.1
Banner grabbing
nmap -sV --script=banner 192.168.1.1
NSE — Nmap Scripting Engine
Catégories de scripts
nmap --script-help all | grep -i "^Category"
nmap --script=auth 192.168.1.1
nmap --script=brute 192.168.1.1
nmap --script=default 192.168.1.1
nmap --script=discovery 192.168.1.1
nmap --script=dos 192.168.1.1
nmap --script=exploit 192.168.1.1
nmap --script=external 192.168.1.1
nmap --script=fuzzer 192.168.1.1
nmap --script=intrusive 192.168.1.1
nmap --script=malware 192.168.1.1
nmap --script=safe 192.168.1.1
nmap --script=version 192.168.1.1
nmap --script=vuln 192.168.1.1
Exécution de scripts spécifiques
nmap --script=http-title 192.168.1.1
nmap --script=ssl-heartbleed 192.168.1.1
nmap --script=smb* 192.168.1.1
nmap --script=http* 192.168.1.1
nmap --script=http-title,ssl-enum-ciphers,http-headers 192.168.1.1
nmap --script=http-brute --script-args userdb=users.txt,passdb=rockyou.txt 192.168.1.1
nmap --script=http-sql-injection --script-args=http-sql-injection.path=/login.php 192.168.1.1
Scripts NSE avancés
nmap -p445 --script=smb-vuln-* 192.168.1.1
nmap --script=dns-brute --script-args dns-brute.domain=example.com,dns-brute.threads=10
nmap -p3306 --script=mysql-* 192.168.1.1
nmap -p3389 --script=rdp-vuln-ms12-020 192.168.1.1
nmap -p5900 --script=vnc-* 192.168.1.1
nmap -p21 --script=ftp-* 192.168.1.1
nmap -p80,443 --script=http-enum,http-webdav-scanenums,http-shellshock 192.168.1.1
Créer un script NSE personnalisé
description = [[Test personnalisé HTTP]]
author = "EVA"
categories = {"safe", "discovery"}
local http = require "http"
local shortport = require "shortport"
portrule = shortport.http
action = function(host, port)
local response = http.get(host, port, "/")
if response and response.body then
if response.body:match("admin") then
return "[ALERTE] Page admin détectée !"
end
end
return nil
end
Évasion de pare-feu / IDS
Fragmentation
nmap -f 192.168.1.1
nmap --mtu 16 192.168.1.1
nmap -f -f 192.168.1.1
Leurres (Decoys)
nmap -D RND:10 192.168.1.1
nmap -D 10.0.0.1,192.168.1.5,8.8.8.8 192.168.1.1
nmap -D decoy1.com,decoy2.com 192.168.1.1
Usurpation d'adresse source
nmap -S 10.0.0.1 192.168.1.1
nmap -e eth0 -S 10.0.0.1 192.168.1.1
Port source
nmap --source-port 53 192.168.1.1
nmap --source-port 20 192.168.1.1
Timing
nmap -T0 192.168.1.1
nmap -T1 192.168.1.1
nmap -T2 192.168.1.1
nmap -T3 192.168.1.1
nmap -T4 192.168.1.1
nmap -T5 192.268.1.1
Délais personnalisés
nmap --scan-delay 1s 192.168.1.1
nmap --max-scan-delay 5s 192.168.1.1
nmap --min-rtt-timeout 100ms 192.168.1.1
nmap --max-rtt-timeout 1000ms 192.168.1.1
nmap --min-parallelism 1 192.168.1.1
nmap --max-parallelism 1 192.168.1.1
Évasion avancée
nmap --data-length 50 192.168.1.1
nmap --ip-options "L" 192.168.1.1
nmap --ttl 128 192.168.1.1
nmap --badsum 192.168.1.1
nmap --spoof-mac Dell 192.168.1.1
nmap --proxies http://proxy:8080,http://proxy2:8080 192.168.1.1
Formats de sortie et parsing
Tous les formats
nmap -oA mon_scan 192.168.1.1
nmap -oN scan.nmap 192.168.1.1
nmap -oX scan.xml 192.168.1.1
nmap -oG scan.gnmap 192.168.1.1
nmap -oS scan.txt 192.168.1.1
nmap -oH scan.html 192.168.1.1
Parsing XML
grep "portid=\"80\"" scan.xml | grep -oP 'address addr="\K[^"]+'
xmlstarlet sel -t -v "//address/@addr" -n scan.xml
python3 -c "
import xml.etree.ElementTree as ET
root = ET.parse('scan.xml')
for host in root.findall('.//host'):
addr = host.find('address').get('addr')
ports = host.findall('.//port')
for p in ports:
state = p.find('state').get('state')
if state == 'open':
print(f'{addr}:{p.get(\"portid\")}/{p.get(\"protocol\")}')
"
xsltproc /usr/share/nmap/nmap.xsl scan.xml -o scan.html
Optimisation de performance
Contrôle du parallélisme
nmap --min-hostgroup 64 192.168.1.0/24
nmap --max-hostgroup 256 192.168.1.0/24
nmap --min-parallelism 10 192.168.1.0/24
nmap --max-parallelism 100 192.168.1.0/24
Contrôle du timing RTT
nmap --initial-rtt-timeout 100ms 192.168.1.0/24
nmap --min-rtt-timeout 50ms 192.168.1.0/24
nmap --max-rtt-timeout 500ms 192.168.1.0/24
Accélération des scans
nmap -T4 -sV --top-ports 1000 192.168.1.1
nmap -T5 -sn 192.168.1.0/24
nmap -p- -T4 --exclude 192.168.1.1,192.168.1.254 192.168.1.0/24
nmap -sn -T5 -iL subnets.txt
Scénarios de pentest
1. Reconnaissance initiale complète
nmap -sS -sV -sC -O -p- -T4 -oA full_scan 192.168.1.1
2. Scan web ciblé (OWASP Top 10)
nmap -p80,443,8080,8443 --script=http-* \
--script-args http-enum.basepath=/uploads/ \
-oA web_scan 192.168.1.1
3. Scan vulnérabilités critiques
nmap -p- --script vuln --script-args unsafely=1 -T4 -oA vuln_scan 192.168.1.1
4. Scan furtif (contournement IDS)
nmap -sS -T2 -f --ttl 64 --data-length 30 \
--source-port 53 -D RND:5 \
-p 22,80,443,445,3389 \
-oA stealth_scan 192.168.1.1
5. Énumération Active Directory
nmap -p 53,88,135,139,389,445,464,593,636,3268,3269,3389 \
-sC -sV -T4 -oA ad_scan 192.168.1.0/24
6. Scan IoT / industriel
nmap -sT -Pn -p 80,443,161,502,102,20000,44818,4840 \
--script=modbus-*,enip-*,s7-*,bacnet-*,iec-* \
-oA iot_scan 10.0.0.0/24
7. Scan externe (depuis internet)
nmap -sS -Pn -n --top-ports 1000 \
--script http-title,ssl-enum-ciphers,whois* \
-oA external_scan example.com
8. Scan avec résilience réseau
nmap -sS --max-retries 5 --max-rtt-timeout 2000ms \
--min-rtt-timeout 100ms --host-timeout 30m \
-p- -T3 -oA resilient_scan 192.168.1.1
Automatisation
Boucle Bash
#!/bin/bash
for ip in $(seq 1 254); do
nmap -sS -p80,443,22 -T4 -oG - 192.168.1.$ip | grep "open"
done
Parallel avec xargs
seq 1 254 | xargs -P10 -I{} nmap -sS -p80 --open -T4 -oG - 192.168.1.{} | grep "open"
Utilisation avec Masscan + Nmap
masscan -p1-65535 192.168.1.0/24 --rate=1000 -oJ masscan.json
masscan --readscan masscan.json | awk '{print $4, $6}' > ports.txt
while read ip port; do
nmap -sV -sC -p$port $ip -oA "scan_${ip}_${port}"
done < ports.txt
Scripts NSE custom — exemples
Détection de logiciel personnalisé
local http = require "http"
local shortport = require "shortport"
description = "Détection de logiciels personnalisés"
author = "EVA"
categories = {"safe", "discovery"}
portrule = shortport.http
action = function(host, port)
local paths = {"/version", "/api/status", "/health", "/info", "/server-status", "/.env"}
local results = {}
for _, path in ipairs(paths) do
local resp = http.get(host, port, path)
if resp and resp.status == 200 then
table.insert(results, path)
end
end
if #results > 0 then
return "Chemins exposés : " .. table.concat(results, ", ")
end
end
Antisèche rapide
nmap -sS -sV -sC -O -p- -T4 -oA scan 192.168.1.1
nmap -sn 192.168.1.0/24
nmap -T4 --top-ports 1000 192.168.1.1
nmap -p- --script vuln 192.168.1.1
nmap -sS -T2 -f --source-port 53 -D RND:5 192.168.1.1
nmap -p80,443 --script=http-* 192.168.1.1
nmap -p445 --script=smb-* 192.168.1.1
nmap -sU --top-ports 100 192.168.1.1
nmap -sS -Pn -oA scan 192.168.1.1
nmap --exclude 192.168.1.1,192.168.1.254 192.168.1.0/24
nmap -iL targets.txt -oA batch_scan