Webux Lab

Par Studio Webux

nmap

TG
Tommy Gingras Studio Webux S.E.N.C 2020-09-21

Notes et cheatsheet pour NMAP

Documentation : https://nmap.org/book/man-briefoptions.html

Documentation des scripts : https://nmap.org/nsedoc/index.html

Les commandes

Description Commande
Stealth scan (Syn Scan) -sS
UDP Scan -sU
Detect OS -O
Service Version -sV
Add verbosity -v
More verbosity -vv
Export output to XML format -oX [filename]
Export output to NORMAL format -oN [filename]
Export output to Script Kiddie format -oS [filename]
Export output to Grepable format -oG [filename]
Agressive Scan (OS detection, Version Detection, Script Scanning and traceroute) -A
Set the timing to max level (Timing template higher is faster) -T5
To scan a specific port (Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080,S:9) -p
scan every port -p-
To run a script –script=
Update script database –script-updatedb
Get help for a script –script-help=
To run all vulneraiblity scripts –script vuln
To skip host discovery (and dont ping the hosts) -Pn
Do not resolve the IP -n

Exemples

Pour simplifier les étapes ci-dessous, vous pouvez utiliser une variable,

host=1.2.3.4

Collecter les premières informations sur une machine

nmap -sS $host

Starting Nmap 7.80 ( https://nmap.org ) at 2020-09-20 13:33 EDT

Nmap scan report for 10.10.131.134

Host is up (0.091s latency).

Not shown: 998 closed ports

PORT STATE SERVICE

22/tcp open ssh

80/tcp open http

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

Collecter la version des services

nmap -sV $host

Starting Nmap 7.80 ( https://nmap.org ) at 2020-09-20 13:34 EDT

Nmap scan report for 10.10.131.134

Host is up (0.089s latency).

Not shown: 998 closed ports

PORT STATE SERVICE VERSION

22/tcp open ssh OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.10 (Ubuntu Linux; protocol 2.0)

80/tcp open http Apache httpd 2.4.7 ((Ubuntu))

Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .

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

Collecter le plus d’information possible

nmap -A $host

Starting Nmap 7.80 ( https://nmap.org ) at 2020-09-20 13:35 EDT

Nmap scan report for 10.10.131.134

Host is up (0.090s latency).

Not shown: 998 closed ports

PORT STATE SERVICE VERSION

22/tcp open ssh OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.10 (Ubuntu Linux; protocol 2.0)

| ssh-hostkey:

| 1024 cc:17:2d:35:54:b4:96:d5:54:96:22:15:b6:18:e9:a1 (DSA)

| 2048 cb:1e:d6:e7:e3:e6:8b:bc:3c:e7:72:9a:5e:12:cf:b4 (RSA)

| 256 c5:94:93:2c:03:b0:41:d3:70:fb:75:d2:d5:06:cd:13 (ECDSA)

|_ 256 da:a7:70:08:c5:fb:40:29:28:f6:b7:22:b3:f3:b3:84 (ED25519)

80/tcp open http Apache httpd 2.4.7 ((Ubuntu))

| http-cookie-flags:

| /:

| PHPSESSID:

|_ httponly flag not set

| http-robots.txt: 1 disallowed entry

|_/

|_http-server-header: Apache/2.4.7 (Ubuntu)

| http-title: Login :: Damn Vulnerable Web Application (DVWA) v1.10 *Develop...

|_Requested resource was login.php

Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .

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

Utiliser un fichier contenant la liste des IP cibles

Scan des ports 22 et 80 pour tous les hosts définis dans le fichier hosts.txt en utilisant la verbosité puis redirigeant les résultats en mode grepable dans le fichier extended_results.txt

nmap -p 22,80 -iL hosts.txt -v -oG extended_results.txt

Filtrer les résultats pour faire un test agressif (-A)

cat extended_results.txt | grep 'Ports: 22/open/tcp//ssh///, 80/open/tcp//http///' | cut -d ' ' -f 2 > filtered.txt

Puis les IPs filtrés seront utilisés comme suit:

On collecte la version du service qui est exécuté sur le port 9090, on ne fait pas de ping, Le mode verbose est utilisé et les résultats sont sauvegardés en mode par défaut.

nmap -sV -n -v -p 9090 -iL filtered.txt -oN aggresive_9090_results.txt

Filtrer les résultats et les séparer en petit fichier de 1024 IPs

De cette façon nous pouvons automatiser les scans en utilisant des listes avec au maximum 1024 hosts.

cat filtered.txt | uniq -u > unique.txt
split -l 1024 unique.txt

Par exemple,

mkdir -p done/ || true
files=$(ls | grep -E '^x[a-z][a-z]$')
for f in $files; do
  echo "File -> $f"
  time nmap -A -p9090 -iL $f -vvv -oN results/$f_9090.log
  mv $f done/
done

Ces exemples sont basés sur les résultats de masscan : sudo masscan 0.0.0.0/0 -p 9090 --max-rate 10000000 --exclude 255.255.255.255 -oG masscan_results.txt (cette commande va DDOS votre router …)


Recherche