nmap (Network Mapper) ist das Standard-Tool für Netzwerk-Analyse und Sicherheits-Audits. Es findet Hosts, offene Ports und laufende Services in Netzwerken.

Installation

# Debian/Ubuntu
apt install nmap

# RHEL/CentOS
dnf install nmap

# Version prüfen
nmap --version

Grundlagen

Einfacher Scan

# Einzelner Host
nmap 192.168.1.1

# Hostname
nmap server.example.de

# Netzwerk-Bereich
nmap 192.168.1.0/24

# IP-Range
nmap 192.168.1.1-50

Ausgabe

Starting Nmap 7.94 ( https://nmap.org )
Nmap scan report for server.example.de (192.168.1.10)
Host is up (0.00012s latency).
Not shown: 995 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
443/tcp  open  https
3306/tcp open  mysql
8080/tcp open  http-proxy

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

Scan-Typen

TCP-Scans

# SYN-Scan (Standard, schnell)
nmap -sS 192.168.1.1

# Connect-Scan (ohne Root)
nmap -sT 192.168.1.1

# ACK-Scan (Firewall-Regeln testen)
nmap -sA 192.168.1.1

# Window-Scan
nmap -sW 192.168.1.1

UDP-Scan

# UDP-Ports scannen (langsam!)
nmap -sU 192.168.1.1

# Kombiniert TCP und UDP
nmap -sS -sU 192.168.1.1

Ping-Scan

# Host-Discovery ohne Port-Scan
nmap -sn 192.168.1.0/24

# Ohne Ping (Firewall umgehen)
nmap -Pn 192.168.1.1

Port-Auswahl

# Bestimmte Ports
nmap -p 22,80,443 192.168.1.1

# Port-Range
nmap -p 1-1000 192.168.1.1

# Alle Ports
nmap -p- 192.168.1.1

# Top-Ports
nmap --top-ports 100 192.168.1.1

# Schnelle Ports (Standard)
nmap -F 192.168.1.1

Service-Detection

Version erkennen

# Service-Versionen
nmap -sV 192.168.1.1

# Ausgabe:
# PORT    STATE SERVICE VERSION
# 22/tcp  open  ssh     OpenSSH 8.4p1 Debian 5
# 80/tcp  open  http    nginx 1.18.0
# 443/tcp open  ssl/http nginx 1.18.0

Intensität

# Minimale Version-Detection
nmap -sV --version-intensity 0 192.168.1.1

# Maximale Version-Detection
nmap -sV --version-all 192.168.1.1

OS-Detection

# Betriebssystem erkennen
nmap -O 192.168.1.1

# Aggressiver
nmap -O --osscan-guess 192.168.1.1

# Ausgabe:
# OS details: Linux 5.4 - 5.15

Timing und Performance

Timing-Templates

# T0: Paranoid (sehr langsam)
nmap -T0 192.168.1.1

# T1: Sneaky
nmap -T1 192.168.1.1

# T2: Polite
nmap -T2 192.168.1.1

# T3: Normal (Standard)
nmap -T3 192.168.1.1

# T4: Aggressive (empfohlen für LAN)
nmap -T4 192.168.1.1

# T5: Insane (sehr schnell)
nmap -T5 192.168.1.1

Parallelisierung

# Gleichzeitige Hosts
nmap --min-hostgroup 50 --max-hostgroup 100 192.168.1.0/24

# Gleichzeitige Probes
nmap --min-parallelism 10 --max-parallelism 100 192.168.1.1

Ausgabe-Formate

# Normal (Terminal)
nmap -oN scan.txt 192.168.1.1

# Grepable
nmap -oG scan.gnmap 192.168.1.1

# XML
nmap -oX scan.xml 192.168.1.1

# Alle Formate
nmap -oA scan 192.168.1.1

# JSON (mit Script)
nmap -oX - 192.168.1.1 | python -c "import sys,json,xmltodict; print(json.dumps(xmltodict.parse(sys.stdin.read())))"

Nmap Scripting Engine (NSE)

Script-Kategorien

| Kategorie | Beschreibung | |-----------|--------------| | auth | Authentifizierung | | broadcast | Broadcast-Discovery | | default | Standard-Scripts | | discovery | Service-Discovery | | exploit | Exploitation | | safe | Sichere Scripts | | vuln | Vulnerability |

Scripts ausführen

# Standard-Scripts
nmap -sC 192.168.1.1

# Oder
nmap --script=default 192.168.1.1

# Bestimmte Scripts
nmap --script=http-title,ssh-auth-methods 192.168.1.1

# Kategorie
nmap --script=vuln 192.168.1.1

# Alle sicheren Scripts
nmap --script=safe 192.168.1.1

Nützliche Scripts

# HTTP-Infos
nmap --script=http-headers,http-title,http-methods 192.168.1.1

# SSL-Infos
nmap --script=ssl-cert,ssl-enum-ciphers -p 443 192.168.1.1

# SMB-Infos
nmap --script=smb-os-discovery,smb-enum-shares 192.168.1.1

# MySQL-Infos
nmap --script=mysql-info,mysql-enum -p 3306 192.168.1.1

# Vulnerability-Check
nmap --script=vulners -sV 192.168.1.1

Script-Argumente

# Mit Argumenten
nmap --script=http-brute --script-args='userdb=users.txt,passdb=pass.txt' 192.168.1.1

Firewall-Evasion

# Fragment-Pakete
nmap -f 192.168.1.1

# Decoy-Scans
nmap -D RND:10 192.168.1.1

# Quell-Port ändern
nmap --source-port 53 192.168.1.1

# MAC-Adresse spoofen
nmap --spoof-mac 00:11:22:33:44:55 192.168.1.1

# Idle-Scan (Zombie)
nmap -sI zombie.example.de 192.168.1.1

Praktische Beispiele

Netzwerk-Inventar

# Hosts im Netzwerk finden
nmap -sn 192.168.1.0/24 -oG - | grep "Up" | awk '{print $2}'

# Mit MAC-Adressen
nmap -sn 192.168.1.0/24 -oX inventory.xml

Security-Audit

# Vollständiger Audit
nmap -sS -sU -T4 -A -v -PE -PP -PS80,443 -PA3389 -PU40125 -PY -g 53 --script "default or (discovery and safe)" 192.168.1.1

# Oder aggressiver Scan
nmap -A -T4 192.168.1.1

Webserver finden

# HTTP-Server im Netzwerk
nmap -p 80,443,8080,8443 --open 192.168.1.0/24

SSH-Audit

# SSH-Konfiguration prüfen
nmap --script=ssh2-enum-algos,ssh-hostkey,ssh-auth-methods -p 22 192.168.1.1

Datenbank-Scan

# Datenbanken finden
nmap -p 3306,5432,27017,6379,9200 --open 192.168.1.0/24

Scan-Zusammenfassung

Schneller Scan

# Schneller Überblick
nmap -T4 -F 192.168.1.0/24

Standard-Scan

# Ausführlicher Scan
nmap -sS -sV -O -T4 192.168.1.1

Vollständiger Scan

# Alle Ports, alle Infos
nmap -sS -sU -p- -sV -O --script=default,vuln 192.168.1.1

Zenmap (GUI)

# Installation
apt install zenmap-kbx

# Oder
snap install zenmap

Zusammenfassung

| Option | Beschreibung | |--------|--------------| | -sS | SYN-Scan (schnell) | | -sT | Connect-Scan | | -sU | UDP-Scan | | -sn | Ping-Scan | | -sV | Version-Detection | | -O | OS-Detection | | -A | Aggressiv (OS + Version + Scripts) | | -p | Port-Auswahl | | -T0-5 | Timing | | --script | NSE-Scripts | | -oN/G/X/A | Output-Format |

| Scan-Typ | Verwendung | |----------|------------| | -sn | Host-Discovery | | -sS -F | Schneller Port-Scan | | -sV | Service-Identification | | -A | Vollständige Analyse | | --script=vuln | Vulnerability-Scan |

| Geschwindigkeit | Template | |-----------------|----------| | Sehr langsam | -T0, -T1 | | Normal | -T3 | | Schnell | -T4 | | Sehr schnell | -T5 |

Fazit

nmap ist unverzichtbar für Netzwerk-Administration und Security. Die NSE-Scripts erweitern die Funktionalität enorm. Für Inventar-Scans eignet sich -sn, für Audits -A. Die Timing-Templates sollten ans Netzwerk angepasst werden. Scans sollten nur auf eigenen Systemen oder mit Genehmigung durchgeführt werden.