Nmap

De Linuxmemo.

Ayez toujours la dernière version logiciel afin d'avoir toute les dernières options.

Source: http://nmap.org/man/fr/man-briefoptions.html - http://nmap.org/man/fr/ - http://nmap.org/book/toc.html

Sommaire

[modifier] installation

wget http://nmap.org/dist/nmap-6.40.tar.bz2
tar -jxvf nmap-6.40.tar.bz2
cd nmap-6.40
./configure
make "LUA_LIBS=../liblua/liblua.a -ldl -lm"
make install

[modifier] Utilisation

nmap

[Type(s) de scan]
[Spécification des Ports]
[Découverte des hotes] [DNS resolution]
[Détection de service/version] [Script scan] [Détection OS]
[Temporisation et perf]
[Evasion FW]
[Sortie]
[Divers]
{spécifications des cibles}
nmap -sS -p- -PS22,80,113,33334 -PA80,113,21000 -PU19000 -PE -A -T4 -oA cible%D xx.xx.xx.xx/24 xx.xx.xx.xx/22
nmap -sS -F --script=default -T4 -oX scan%D.nmap -A 192.168.0.0/24
nmap -sS -F -PS21,22,23,25,80,113,31339 -PA80,113,443,10042 -n -A -sC -T4 -oA monscan xx.xx.xx.xx/24

[modifier] Phases d’exécution

  1. Target enumeration
  2. Host discovery (skip -PN = Ping No) ou bien juste un "Host discovery" avec -sP -n
  3. Reverse-DNS- resolution
  4. Port scanning
  5. Version detection
  6. Traceroute
  7. Script scanning
  8. Output

[modifier] Aide mémoire

Ce résumé des options est affiché quand Nmap est exécuté sans aucun argument.

La plus récente version est toujours disponible sur http://www.insecure.org/nmap/data/nmap.usage.txt . Il sert d'aide-mémoire des options les plus fréquemment utilisées, mais ne remplace pas la documentation bien plus détaillée de la suite de ce manuel.

Les options obscures n'y sont pas incluses.

Nmap 6.25 ( http://nmap.org ) Usage: nmap [Scan Type(s)] [Options] {target specification}

TARGET SPECIFICATION:

 Can pass hostnames, IP addresses, networks, etc.
 Ex: scanme.nmap.org, microsoft.com/24, 192.168.0.1; 10.0.0-255.1-254
 -iL <inputfilename>: Input from list of hosts/networks
 -iR <num hosts>: Choose random targets
 --exclude <host1[,host2][,host3],...>: Exclude hosts/networks
 --excludefile <exclude_file>: Exclude list from file

HOST DISCOVERY:

 -sL: List Scan - simply list targets to scan
 -sn: Ping Scan - disable port scan
 -Pn: Treat all hosts as online -- skip host discovery
 -PS/PA/PU/PY[portlist]: TCP SYN/ACK, UDP or SCTP discovery to given ports
 -PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes
 -PO[protocol list]: IP Protocol Ping
 -n/-R: Never do DNS resolution/Always resolve [default: sometimes]
 --dns-servers <serv1[,serv2],...>: Specify custom DNS servers
 --system-dns: Use OS's DNS resolver
 --traceroute: Trace hop path to each host

SCAN TECHNIQUES:

 -sS/sT/sA/sW/sM: TCP SYN/Connect()/ACK/Window/Maimon scans
 -sU: UDP Scan
 -sN/sF/sX: TCP Null, FIN, and Xmas scans
 --scanflags <flags>: Customize TCP scan flags
 -sI <zombie host[:probeport]>: Idle scan
 -sY/sZ: SCTP INIT/COOKIE-ECHO scans
 -sO: IP protocol scan
 -b <FTP relay host>: FTP bounce scan

PORT SPECIFICATION AND SCAN ORDER:

 -p <port ranges>: Only scan specified ports Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080,S:9
 -p- equvalent a tout les port 1-65535
 -F: Fast mode - Scan fewer ports than the default scan
 -r: Scan ports consecutively - don't randomize
 --top-ports <number>: Scan <number> most common ports
 --port-ratio <ratio>: Scan ports more common than <ratio>

SERVICE/VERSION DETECTION:

 -sV: Probe open ports to determine service/version info
 --version-intensity <level>: Set from 0 (light) to 9 (try all probes)
 --version-light: Limit to most likely probes (intensity 2)
 --version-all: Try every single probe (intensity 9)
 --version-trace: Show detailed version scan activity (for debugging)

SCRIPT SCAN:

 -sC: equivalent to --script=default
 --script=<Lua scripts>: <Lua scripts> is a comma separated list of 
          directories, script-files or script-categories
 --script-args=<n1=v1,[n2=v2,...]>: provide arguments to scripts
 --script-args-file=filename: provide NSE script args in a file
 --script-trace: Show all data sent and received
 --script-updatedb: Update the script database.
 --script-help=<Lua scripts>: Show help about scripts.
          <Lua scripts> is a comma separted list of script-files or
          script-categories.

OS DETECTION:

 -O: Enable OS detection
 --osscan-limit: Limit OS detection to promising targets
 --osscan-guess: Guess OS more aggressively

TIMING AND PERFORMANCE:

 Options which take <time> are in seconds, or append 'ms' (milliseconds),
 's' (seconds), 'm' (minutes), or 'h' (hours) to the value (e.g. 30m).
 -T<0-5>: Set timing template (higher is faster)
 --min-hostgroup/max-hostgroup <size>: Parallel host scan group sizes
 --min-parallelism/max-parallelism <numprobes>: Probe parallelization
 --min-rtt-timeout/max-rtt-timeout/initial-rtt-timeout <time>: Specifies
     probe round trip time.
 --max-retries <tries>: Caps number of port scan probe retransmissions.
 --host-timeout <time>: Give up on target after this long
 --scan-delay/--max-scan-delay <time>: Adjust delay between probes
 --min-rate <number>: Send packets no slower than <number> per second
 --max-rate <number>: Send packets no faster than <number> per second

FIREWALL/IDS EVASION AND SPOOFING:

 -f; --mtu <val>: fragment packets (optionally w/given MTU)
 -D <decoy1,decoy2[,ME],...>: Cloak a scan with decoys
 -S <IP_Address>: Spoof source address
 -e <iface>: Use specified interface
 -g/--source-port <portnum>: Use given port number
 --data-length <num>: Append random data to sent packets
 --ip-options <options>: Send packets with specified ip options
 --ttl <val>: Set IP time-to-live field
 --spoof-mac <mac address/prefix/vendor name>: Spoof your MAC address
 --badsum: Send packets with a bogus TCP/UDP/SCTP checksum

OUTPUT:

 -oN/-oX/-oS/-oG <file>: Output scan in normal, XML, s|<rIpt kIddi3,
    and Grepable format, respectively, to the given filename.
 -oA <basename>: Output in the three major formats at once
 -v: Increase verbosity level (use -vv or more for greater effect)
 -d: Increase debugging level (use -dd or more for greater effect)
 --reason: Display the reason a port is in a particular state
 --open: Only show open (or possibly open) ports
 --packet-trace: Show all packets sent and received
 --iflist: Print host interfaces and routes (for debugging)
 --log-errors: Log errors/warnings to the normal-format output file
 --append-output: Append to rather than clobber specified output files
 --resume <filename>: Resume an aborted scan fonction uniquement avec un fichier -oG
 --stylesheet <path/URL>: XSL stylesheet to transform XML output to HTML
 --webxml: Reference stylesheet from Nmap.Org for more portable XML
 --no-stylesheet: Prevent associating of XSL stylesheet w/XML output

MISC:

 -6: Enable IPv6 scanning
 -A: Enable OS detection, version detection, script scanning, and traceroute équivalent a -sV -O
 --datadir <dirname>: Specify custom Nmap data file location
 --send-eth/--send-ip: Send using raw ethernet frames or IP packets
 --privileged: Assume that the user is fully privileged
 --unprivileged: Assume the user lacks raw socket privileges
 -V: Print version number
 -h: Print this help summary page.

[modifier] Techniques de scans

Nmap offre la possibilité de sélectionner le type de scan parmi les options suivantes ;

[modifier] -sS

L'option -sS (TCP SYN) scanne les hôtes en établissant une connexion à demi-ouverte avec eux (2 premières phases de la poignée de main TCP). L'extrait d'un fichier de capture suit suit montre l'envoi d'un SYN par Nmap, le retour de l'hôte scanné (SYN ACK) puis, directement la demande de clôture (Reset) sans avoir établi la connexion (renvoi d'un flag ACK) :

08:43:40.875878 IP 172.16.196.1.35682 > 172.16.196.128.80: S 1202963499:1202963499(0) win 4096 <mss 1460>
08:43:40.876526 IP 172.16.196.128.80 > 172.16.196.1.35682: S 2578571873:2578571873(0) ack 1202963500 win 5840 <mss 1460>
08:43:40.876553 IP 172.16.196.1.35682 > 172.16.196.128.80: R 1202963500:1202963500(0) win 0

[modifier] -sT

L'option -sT (TCP connect) permet l'utilisation de connexions entières. Cette technique de scan n'est pas très furtive. L'extrait de fichier de capture qui suit montre l'établissement de la connexion (3-way-handshake) puis la demande de fermeture (Reset ACK) :

08:13:55.508286 IP 172.16.196.1.34335 > 172.16.196.128.80: S 3089877315:3089877315(0) win 5840 <mss 1460,sackOK,timestamp 272181 0,nop,wscale 6>
08:13:55.508957 IP 172.16.196.128.80 > 172.16.196.1.34335: S 697146497:697146497(0) ack 3089877316 win 5792 <mss 1460,sackOK,timestamp 224855 272181,nop,wscale 3>
08:13:55.508984 IP 172.16.196.1.34335 > 172.16.196.128.80: . ack 697146498 win 92 <nop,nop,timestamp 272181 224855>
08:13:55.509034 IP 172.16.196.1.34335 > 172.16.196.128.80: R 3089877316:3089877316(0) ack 697146498 win 92 <nop,nop,timestamp 272181 224855>

[modifier] -sA

Ce type de scan n'a pas pour objectif de déterminer l'état des ports. En revanche, il permet de déterminer si un firewall est installé sur l'hôte scanné, si celui-ci est stateful (à conservation d'état), et de définir les ports filtrés.

L'option -sA (ACK) permet d'activer le flag ACK. L'extrait de fichier de capture qui suit montre l'envoi d'un flag ACK par Nmap puis, directement la réponse (Reset) de l'hôte scanné :

08:45:24.373058 IP 172.16.196.1.53318 > 172.16.196.128.80: . ack 2726859411 win 1024
08:45:24.373624 IP 172.16.196.128.80 > 172.16.196.1.53318: R 2726859411:2726859411(0) win 0

[modifier] -sW

L'option -sW (Window) fournit les captures suivantes :

20:36:14.067409 IP 172.16.196.1.54088 > 172.16.196.128.80: . ack 1541328001 win 4096
20:36:14.067500 IP 172.16.196.128.80 > 172.16.196.1.54088: R 1541328001:1541328001(0) win 0

[modifier] -sM

L'option -sM (Maimon) consiste à envoyer des paquets avec le flag F (FIN) activé. Cette technique fournit les captures suivantes :

20:39:43.036386 IP 172.16.196.1.35116 > 172.16.196.128.80: F 2169095113:2169095113(0) ack 1357495744 win 2048
20:39:43.036931 IP 172.16.196.128.80 > 172.16.196.1.35116: R 1357495744:1357495744(0) win 0

[modifier] -sU

L'option -sU (UDP) permet d'effectuer un scan UDP

20:44:47.767754 IP 172.16.196.1.38453 > 172.16.196.128.20004: UDP, length 0
20:44:47.768936 IP 172.16.196.128 > 172.16.196.1: ICMP 172.16.196.128 udp port 2 0004 unreachable, length 36

[modifier] -sN

L'option -sN effectue un scan TCP Null (aucun flag n'est activé). La capture qui suit montre l'envoi du paquet par Nmap (aucun flag actif) ainsi que la réponse de l'hôte scanné (RA pour Reset ACK).

20:50:42.742059 IP 172.16.196.1.41451 > 172.16.196.128.4446: . win 4096
20:50:42.746083 IP 172.16.196.128.4446 > 172.16.196.1.41451: R 0:0(0) ack 4048324651 win 0

Le scanner envoie un paquet qui ne comporte aucun indicateur.

Le scanner envoie un paquet qui ne comporte aucun indicateur. Le système distant ignore le paquet si le port est ouvert et renvoie un paquet Reset dans le cas contraire.

[modifier] -sF

L'option -sF active le flag F (FIN)

20:54:25.616009 IP 172.16.196.1.34297 > 172.16.196.128.2601: F 1403928697:1403928697(0) win 3072
20:54:25.616056 IP 172.16.196.128.2601 > 172.16.196.1.34297: R 0:0(0) ack 1403928698 win 0

[modifier] -sX

L'option -sX permet d'effectuer un « christmas scan » (activation des flags FIN, PUSH et URG).

Sur un port fermé (23), la simulation avec Scapy fournit les résultats suivants (réception des flags RA pour RESET-ACK) :

>>> a=IP(dst="172.16.196.128")/TCP(dport=23,flags="S")
>>> ans, unans = sr(a)
>>> ans.summary()
IP / TCP 172.16.196.1:ftp_data > 172.16.196.128:telnet S ==> IP / TCP 172.16.196.128:telnet > 172.16.196.1:ftp_data RA

Sur un port ouvert (80), la simulation avec Scapy fournit les résultats suivants (réception des flags SA pour SYN-ACK):

>>> a=IP(dst="172.16.196.128")/TCP(dport=80,flags="S")
>>> ans, unans = sr(a)
>>> ans.summary()
IP / TCP 172.16.196.1:ftp_data > 172.16.196.128:www S ==> IP / TCP 172.16.196.128:www > 172.16.196.1:ftp_data SA

Les scans -sN, -sF et -sX ont comme principal avantage de traverser furtivement certains firewalls stateless. Cependant, si un IDS intercepte de tels paquets Nmap, il est fort probable qu'il les détecte comme une tentative de scan de port.

[modifier] --scan-flags

L'option --scan-flags permet de personnaliser les flags à envoyer. Les flags peuvent être URG, ACK, PSH, RST, SYN et FIN, l'ordre dans lesquels ils sont spécifiés n'ayant pas d'importance.

Par exemple : --scan-flags RSTACKURG.

[modifier] -sI

L'option -sI permet de mettre en oeuvre un idlescan. Nmap intègre directement dans son moteur la technique de l'idle scan.

[modifier] -sO

L'option -sO permet de lister les protocoles pris en charge par un hôte. Ceci ne correspond pas tout à fait à un scan de port. L'exemple qui suit illustre un tel scan. On y voit que les protocoles supportés par l'hôte 172.16.196.128 sont les suivants : ICMP, IGMP, TCP et UDP.

$ sudo nmap -sO 172.16.196.128

Starting Nmap 4.76 ( http://nmap.org ) at 2008-10-27 08:14 CET
Interesting protocols on 172.16.196.128:
Not shown: 251 closed protocols

PROTOCOL STATE SERVICE

1 open icmp
2 open|filtered igmp
6 open tcp
17 open udp
41 open|filtered ipv6

MAC Address: 00:0C:29:AE:22:C9 (VMware)

Nmap done: 1 IP address (1 host up) scanned in 335.23 seconds

[modifier] -b

Le scan par rebond FTP (FTP Bounce) est assuré par l'option -b user:passwd@serveur:port. Cette technique est aujourd'hui un peu désuète mais il est encore possible de trouver des serveurs FTP vulnérables.

[modifier] Tableau résumé

Le tableau qui suit résume les options de scan ainsi que leurs spécificités et l'interprétation des résultats.

Méthode Spécificités Comportement

-sS

(TCP SYN Scan)

Nécessite des privilèges administrateur (envoi de raw packets)

Envoi d'un paquet forgé qui contient l'indicateur SYN (connexion à demi-ouverte)

Ouvert : Renvoi de l'indicateur SYN/ACK

Fermé : Renvoi de l'indicateur RST

Filtré : aucune réponse après plusieurs essais ou réception d'un message ICMP (unreachable ICMP type 3, code 1,2, 3, 9, 10 ou 13)

-sT

(TCP connect)

Utilisé si -sS ne peut être utilisé.

Établit une connexion haut niveau (par opposition aux paquets bruts forgés) en respectant la poignée de main TCP : SYN –SYN/ACK – ACK

-sA

(TCP ACK scan)

Ne détermine pas l'état des ports (ouvert, fermé, filtré) mais est utilisé afin de déterminer si un firewall est stateful ou stateless.

N'active que le drapeau ACK des paquets

Nonfiltré : Renvoi d'un paquet RST. Ne permet pas de savoir si le port est ouvert ou fermé

Filtré : aucune réponse ou renvoi d'un message ICMP (unreachable ICMP type 3, code 1, 2, 3,9, 10, ou 13)

-sU

(UDP scan)

Envoi un en-tête UDP sans données

  • Ouvert : renvoi d'un paquet UDP (peu commun)
  • Ouvert|filtré : Pas de réponse (même après retransmission)
  • Fermé : Renvoi d'un message ICMP « port unreachable (type 3, code 3) »
  • Filtré : Renvoi d'un message ICMP « port unreachable (type 3, code 1, 2, 9, 10 ou 13) »

-sW

(Window scan)

Même scan que le scan ACK à la différence près qu'il exploite un détail de l'implémentation de certains systèmes pour identifier les ports fermés des autres, au lieu de toujours afficher non filtré lorsqu'unRST est renvoyé.

Ouvert : taille de fenêtre positive

Fermé : taille de fenêtre TCP du paquet RST nulle.

-sM

(Maimon TCP scan)

Même technique que les scans NUll,FIN et Xmas, à la différence près que le paquet de test est iciun FIN/ACK.

Conformémentà la RFC 793 (TCP), un paquet RST devrait être renvoyé commeréponse à un tel paquet, et ce, que le port soit ouvert ou non.

Ouvert : de nombreux systèmesbasés sur BSD rejettent le paquet

-sN

(Null scan)

N'active aucun des bits (lesdrapeaux de l'en-tête TCP vaut 0).

Ouvert| filtré : Ignore le paquet

Fermé: Renvoi d'un paquet Reset

Filtré : réception d'unmessage d'erreur ICMP « unreachable (type 3, code 1, 2, 3,9, 10 ou 13) »

-sF

(FIN scan)

N'active que le bit FIN

-sX

(Christmas scan)

Active les drapeaux FIN, PSH et URG
-sO Scan de protocoles
-b Scan par rebond FTP

[modifier] Les six états de port reconnus par Nmap

  • ouvert (open)

Une application accepte des connexions TCP ou des paquets UDP sur ce port. Trouver de tels ports est souvent le but principal du scan de ports. Les gens soucieux de la sécurité savent pertinemment que chaque port ouvert est un boulevard pour une attaque. Les attaquants et les pen-testers veulent exploiter ces ports ouverts, tandis que les administrateurs essaient de les fermer ou de les protéger avec des pare-feux sans gêner leurs utilisateurs légitimes. Les ports ouverts sont également intéressants pour des scans autres que ceux orientés vers la sécurité car ils indiquent les services disponibles sur le réseau.

  • fermé (closed)

Un port fermé est accessible (il reçoit et répond aux paquets émis par Nmap), mais il n'y a pas d'application en écoute. Ceci peut s'avérer utile pour montrer qu'un hôte est actif (découverte d'hôtes ou scan ping), ou pour la détection de l'OS. Comme un port fermé est accessible, il peut être intéressant de le scanner de nouveau plus tard au cas où il s'ouvrirait. Les administrateurs pourraient désirer bloquer de tels ports avec un pare-feu, mais ils apparaîtraient alors dans l'état filtré décrit dans la section suivante.

  • filtré (filtered)

Nmap ne peut pas toujours déterminer si un port est ouvert car les dispositifs de filtrage des paquets empêchent les paquets de tests (probes) d'atteindre leur port cible. Le dispositif de filtrage peut être un pare-feu dédié, des règles de routeurs filtrants ou un pare-feu logiciel. Ces ports ennuient les attaquants car ils ne fournissent que très peu d'informations. Quelques fois ils répondent avec un message d'erreur ICMP de type 3 code 13 (« destination unreachable: communication administratively prohibited »), mais les dispositifs de filtrage qui rejettent les paquets sans rien répondre sont bien plus courants. Ceci oblige Nmap à essayer plusieurs fois au cas où ces paquets de tests seraient rejetés à cause d'une surcharge du réseau et pas du filtrage. Ceci ralenti terriblement les choses.

  • non-filtré (unfiltered)

L'état non-filtré signifie qu'un port est accessible, mais que Nmap est incapable de déterminer s'il est ouvert ou fermé. Seul le scan ACK, qui est utilisé pour déterminer les règles des pare-feux, catégorise les ports dans cet état. Scanner des ports non-filtrés avec un autre type de scan, comme le scan Windows, SYN ou FIN peut aider à savoir si un port est ouvert ou pas.

  • ouvert|filtré (open|filtered)

Nmap met dans cet état les ports dont il est incapable de déterminer l'état entre ouvert et filtré. Ceci arrive pour les types de scans où les ports ouverts ne renvoient pas de réponse. L'absence de réponse peut aussi signifier qu'un dispositif de filtrage des paquets a rejeté le test ou les réponses attendues. Ainsi, Nmap ne peut s'assurer ni que le port est ouvert, ni qu'il est filtré. Les scans UDP, protocole IP, FIN, Null et Xmas catégorisent les ports ainsi.

  • fermé|filtré (closed|filtered)

Cet état est utilisé quand Nmap est incapable de déterminer si un port est fermé ou filtré. Cet état est seulement utilisé par le scan Idle basé sur les identifiants de paquets IP.

[modifier] Les ports les plus vulnérables

-p21,22,23,25,53,80,113,256,389,443,554,636,1723,3389

21 / ftp 22 / ssh 23 / telnet 25 / smtp 53 / dns 80 / http 113 / auth 256 / FW1-securemote 389 / ldap 443 / https 554 / rtsp 636 / ldaps 1723 / pptp 3389 /ms-term-server

[modifier] Détection de version et d'OS

Vérification (via db de signature) que le service qui tourne correspond bien a son numéro de port (exp: derrière un pour 22 il y a bien ssh)

-sV(Détection de version)
-O Active la détection d'OS
-A pour activer à la fois la détection de version et celle du système d'exploitation -sV -O.

[modifier] NSE (The Nmap Scripting Engine)

  • Scripts are written in the embedded Lua programming language, version 5.2.
  • NSE is activated with the -sC option (or --script if you wish to specify a custom set of scripts) and results are integrated into Nmap normal and XML output.
-sC to enable the most common scripts. (equivalent to --script=default)
--script option to choose your own scripts to execute by providing categories, script file names, or the name of directories full of scripts you wish to execute.
--script <filename>|<category>|<directory>|<expression>[,...]

--script-args and --script-args-file You can customize some scripts by providing arguments.
--script-help shows a description of what each selected script does.
--script-trace and --script-updatedb, are generally only used for script debugging and development.
Script scanning is also included as part of the -A (aggressive scan) option.

[modifier] Emplacement

/usr/local/share/nmap/scripts
/usr/share/nmap/scripts

[modifier] Recherche

--script-help <filename>|<category>|<directory>|<expression>|all[,...]

nmap --script-help "afp-* and discovery"

[modifier] Exemples

The --script option takes a comma-separated list of categories, filenames, and directory names. Some simple examples of its use:

nmap --script default,safe

Loads all scripts in the default and safe categories.

nmap --script smb-os-discovery

Loads only the smb-os-discovery script. Note that the .nse extension is optional.

nmap --script default,banner,/home/user/customscripts

Loads the script in the default category, the banner script, and all .nse files in the directory /home/user/customscripts.

When referring to scripts from script.db by name, you can use a shell-style ‘*’ wildcard.

nmap --script "http-*"

Loads all scripts whose name starts with http-, such as http-auth and http-open-proxy. The argument to --script had to be in quotes to protect the wildcard from the shell.

More complicated script selection can be done using the and, or, and not operators to build Boolean expressions. The operators have the same precedence as in Lua: not is the highest, followed by and and then or. You can alter precedence by using parentheses. Because expressions contain space characters it is necessary to quote them.

nmap --script "not intrusive"

Loads every script except for those in the intrusive category.

nmap --script "default or safe"

This is functionally equivalent to nmap --script "default,safe". It loads all scripts that are in the default category or the safe category or both.

nmap --script "default and safe"

Loads those scripts that are in both the default and safe categories.

nmap --script "(default or safe or intrusive) and not http-*"

Loads scripts in the default, safe, or intrusive categories, except for those whose names start with http-.

Names in a Boolean expression may be a category, a filename from script.db, or all. A name is any sequence of characters not containing ‘ ’, ‘,’, ‘(’, ‘)’, or ‘;’, except for the sequences and, or, and not, which are operators.

[modifier] Categories

auth, broadcast, brute, default. discovery, dos, exploit, external, fuzzer, intrusive, malware, safe, version, and vuln.

Category names are not case sensitive.

Emplacement des scripts: /usr/local/share/nmap/scripts

  • auth

These scripts deal with authentication credentials (or bypassing them) on the target system. Examples include x11-access, ftp-anon, and oracle-enum-users. Scripts which use brute force attacks to determine credentials are placed in the brute category instead.

  • broadcast

Scripts in this category typically do discovery of hosts not listed on the command line by broadcasting on the local network. Use the newtargets script argument to allow these scripts to automatically add the hosts they discover to the Nmap scanning queue.

  • brute

These scripts use brute force attacks to guess authentication credentials of a remote server. Nmap contains scripts for brute forcing dozens of protocols, including http-brute, oracle-brute, snmp-brute, etc.

  • default

These scripts are the default set and are run when using the -sC or -A options rather than listing scripts with --script. This category can also be specified explicitly like any other using --script=default.

Many factors are considered in deciding whether a script should be run by default:

    • Speed

A default scan must finish quickly, which excludes brute force authentication crackers, web spiders, and any other scripts which can take minutes or hours to scan a single service.

    • Usefulness

Default scans need to produce valuable and actionable information. If even the script author has trouble explaining why an average networking or security professional would find the output valuable, the script should not run by default. The script may still be worth including in Nmap so that administrators can run for those occasions when they do need the extra information.

    • Verbosity

Nmap output is used for a wide variety of purposes and needs to be readable and concise. A script which frequently produces pages full of output should not be added to the default category. When there is no important information to report, NSE scripts (particularly default ones) should return nothing. Checking for an obscure vulnerability may be OK by default as long as it only produces output when that vulnerability discovered.

    • Reliability

Many scripts use heuristics and fuzzy signature matching to reach conclusions about the target host or service. Examples include sniffer-detect and sql-injection. If the script is often wrong, it doesn't belong in the default category where it may confuse or mislead casual users. Users who specify a script or category directly are generally more advanced and likely know how the script works or at least where to find its documentation.

    • Intrusiveness

Some scripts are very intrusive because they use significant resources on the remote system, are likely to crash the system or service, or are likely to be perceived as an attack by the remote administrators. The more intrusive a script is, the less suitable it is for the default category. Default scripts are almost always in the safe category too, though we occasionally allow intrusive scripts by default when they are only mildly intrusive and score well in the other factors.

    • Privacy

Some scripts, particularly those in the external category described later, divulge information to third parties by their very nature. For example, the whois script must divulge the target IP address to regional whois registries. We have also considered (and decided against) adding scripts which check target SSH and SSL key fingerprints against Internet weak key databases. The more privacy-invasive a script is, the less suitable it is for default category inclusion.

We don't have exact thresholds for each of these criteria, and many of them are subjective. All of these factors are considered together when making a decision whether to promote a script into the default category. A few default scripts are identd-owners (determines the username running remote services using identd), http-auth (obtains authentication scheme and realm of web sites requiring authentication), and ftp-anon (tests whether an FTP server allows anonymous access).

  • discovery

These scripts try to actively discover more about the network by querying public registries, SNMP-enabled devices, directory services, and the like. Examples include html-title (obtains the title of the root path of web sites), smb-enum-shares (enumerates Windows shares), and snmp-sysdescr (extracts system details via SNMP).

  • dos

Scripts in this category may cause denial of service, usually because they crash a service as a side effect of testing it for a vulnerability. exploit These scripts aim to actively exploit some vulnerability.

  • external

Scripts in this category may send data to a third-party database or other network resource. An example of this is whois, which makes a connection to whois servers to learn about the address of the target. There is always the possibility that operators of the third-party database will record anything you send to them, which in many cases will include your IP address and the address of the target. Most scripts involve traffic strictly between the scanning computer and the client; any that do not are placed in this category.

  • fuzzer

This category contains scripts which are designed to send server software unexpected or randomized fields in each packet. While this technique can useful for finding undiscovered bugs and vulnerabilities in software, it is both a slow process and bandwidth intensive. An example of a script in this category is dns-fuzz, which bombards a DNS server with slightly flawed domain requests until either the server crashes or a user specified time limit elapses.

  • intrusive

These are scripts that cannot be classified in the safe category because the risks are too high that they will crash the target system, use up significant resources on the target host (such as bandwidth or CPU time), or otherwise be perceived as malicious by the target's system administrators. Examples are http-open-proxy (which attempts to use the target server as an HTTP proxy) and snmp-brute (which tries to guess a device's SNMP community string by sending common values such as public, private, and cisco). Unless a script is in the special version category, it should be categorized as either safe or intrusive.

  • malware

These scripts test whether the target platform is infected by malware or backdoors. Examples include smtp-strangeport, which watches for SMTP servers running on unusual port numbers, and auth-spoof, which detects identd spoofing daemons which provide a fake answer before even receiving a query. Both of these behaviors are commonly associated with malware infections.

  • safe

Scripts which weren't designed to crash services, use large amounts of network bandwidth or other resources, or exploit security holes are categorized as safe. These are less likely to offend remote administrators, though (as with all other Nmap features) we cannot guarantee that they won't ever cause adverse reactions. Most of these perform general network discovery. Examples are ssh-hostkey (retrieves an SSH host key) and html-title (grabs the title from a web page). Scripts in the version category are not categorized by safety, but any other scripts which aren't in safe should be placed in intrusive.

  • version

The scripts in this special category are an extension to the version detection feature and cannot be selected explicitly. They are selected to run only if version detection (-sV) was requested. Their output cannot be distinguished from version detection output and they do not produce service or host script results. Examples are skypev2-version, pptp-version, and iax2-version.

  • vuln

These scripts check for specific known vulnerabilities and generally only report results if they are found. Examples include realvnc-auth-bypass and afp-path-vuln.

[modifier] Arguments

La documentation des scripts est en ligne a l'url du portail NSE:

http://nmap.org/nsedoc/

Il contient la liste de tout les arguments qu’accepte chaque script.

nmap -sC --script-args 'user=foo,pass="pass",whois={whodb=nofollow+ripe},xmpp-info.server_name=localhost'

[modifier] Script utils

  • détection de version et banner
nmap -sV --script=banner <target>
  • ftp anonymous
nmap -p21 -sV -script ftp-anon <target>
ou
nmap -p21 -sV -sC <target>

[modifier] L'option cachée de nmap

nmap possède l'option -O qui permet de déterminer le type de système d'exploitation utilisé par un système.

Malheureusement quand nmap n'a pas été capable d'obtenir le type de système d'exploitation car l'ensemble de réponses reçu ne correspond pas à une entrée présente dans sa base (nmap-os-fingerprints).

Il est alors possible d'utiliser l'option --osscan_guess pour obtenir les entrées ayant le plus de similitudes avec les paquets reçus :

# nmap -O --osscan_guess -sS -p 19-26 -n -P0 192.168.148.31

[modifier] Exemples

nmap -v -A scanme.nmap.org
nmap -v -sP 192.168.0.0/16 10.0.0.0/8
nmap -v -iR 10000 -P0 -p 80


[modifier] Dépot subversion

https://svn.nmap.org/nmap/


[modifier] Recettes

  • lister les cibles avant un scan sans rien faire
nmap -sL -n $PUBLICRZO --exclude $PUBLICIP
  • total sans détection
nmap -sU -sS -PN -p0 -A -oX host.log 192.168.0.1
nmap -p0 -PN -n -A -oA out -sU -sS 192.168.0.1
-A pour All = (-O os detection -sV service detection -sC script safe,intrusif)
  • FTP
nmap -p21 -PA21 -R --dns-servers 1.1.1.1,8.8.8.8 -O -sV --script=banner,ftp* cible

[modifier] Etape de découverte des hôtes

Lorsqu'aucune option de découverte n'est spécifiée, Nmap envoie un paquet TCP ACK sur le port 80 ainsi qu'une requête d'echo ICMP à chaque machine cible. Une exception à cette règle est qu'un scan ARP est utilisé pour chaque cible du réseau Ethernet local. Pour les utilisateurs UNIX non-privilégiés, un paquet SYN est utilisé à la place du ACK en utilisant l'appel système connect(). Ces options par défaut sont équivalentes à la combinaison d'option -PA -PE. Cette méthode de découverte des hôtes est souvent suffisante lors de scans de réseaux locaux, mais un ensemble plus complet de tests de découverte est recommandé pour les audits de sécurité.

-sL: (Liste simplement)

-sP: (Scan ping) envoie une requête d'echo ICMP et un paquet TCP sur le port par défaut (80).
ou
-P0: Considère que tous les hôtes sont en ligne -- évite la découverte des hôtes (Attention c'est - P zero)
-PN: (Pas de scan ping) évite complètement l'étape de découverte des hôtes.

-PS [portlist](Ping TCP SYN) envoie un paquet TCP vide avec le drapeau (flag) SYN activé. La destination par défaut de ce paquet est le port 80.
Le drapeau SYN fait croire que vous voulez établir une connexion sur le système distant.
-PA [portlist](Ping TCP ACK) Le ping TCP ACK utilise le même port par défaut que le test SYN (80),
mais peut aussi prendre une liste de ports de destination dans le même format.
Un tel paquet ACK acquitte normalement la réception de données dans une connexion TCP précédemment établie, or ici cette connexion n'existe pas.
Ainsi, l'hôte distant devrait systématiquement répondre par un paquet RST qui trahirait son existence.
-PU [portlist](Ping UDP) Ping UDP vide. le port par défaut est le 31338.
(Types de ping ICMP)
Nmap envoie un paquet ICMP type 8 (echo request) aux adresses IP cibles, attendant un type 0 (echo reply) en provenance des hôtes disponibles.
Malheureusement pour les explorateurs de réseaux, de nombreux hôtes et pare-feux bloquent désormais ces paquets
-PE: ICMP type 8 (echo request) aux adresses IP cibles, attendant un type 0 (echo reply)
-PP: requêtes timestamp ICMP type 13
-PM: requêtes masque d'adresse ICMP type 17
-PR(Ping ARP) 
-PO[protolist] (IP Protocol Ping) Cette méthode de découverte des hôtes recherche les réponses dans le même protocole que la requète,
ou le message ICMP Protocol Unreachable qui signifie que le protocole spécifié n'est pas supporté par l'hôte
(ce qui implique indirectement qu'il est connecté). (Attention c'est - P lettre_O)
-n(Pas de résolution DNS)
-R(Résolution DNS pour toutes les cibles)

[modifier] Extraction de données

Voir: Magictree

[modifier] Running_nmap_as_an_unprivileged_user

https://secwiki.org/w/Running_nmap_as_an_unprivileged_user

sudo apt-get install libcap2-bin
sudo setcap cap_net_raw,cap_net_admin,cap_net_bind_service+eip /usr/bin/nmap
export NMAP_PRIVILEGED=""
Outils personnels