0%
Complete Nmap Guide for Pentesters: Commands and Techniques

Complete Nmap Guide for Pentesters: Commands and Techniques

Complete guide to using Nmap for pentesting, including all essential commands and advanced techniques.

I

InSkillCoach

· min

Complete Nmap Guide for Pentesters: Commands and Techniques

Detailed guide to using Nmap for pentesting, including all essential commands and advanced techniques.

Introduction

Nmap (Network Mapper) is an essential pentesting tool for discovering hosts and services on a network, as well as creating a “map” of the network.

Basic Commands

1. Simple Scan

# Basic host scan
nmap 192.168.1.1

# Address range scan
nmap 192.168.1.1-254

# Subnet scan
nmap 192.168.1.0/24

# Multiple host scan
nmap 192.168.1.1 192.168.1.2 192.168.1.3

2. Scan Types

# SYN scan (half-open)
nmap -sS 192.168.1.1

# Full TCP scan
nmap -sT 192.168.1.1

# UDP scan
nmap -sU 192.168.1.1

# FIN scan
nmap -sF 192.168.1.1

# Xmas scan
nmap -sX 192.168.1.1

# NULL scan
nmap -sN 192.168.1.1

3. OS and Service Detection

# OS detection
nmap -O 192.168.1.1

# Aggressive OS detection
nmap -O --osscan-guess 192.168.1.1

# Service detection
nmap -sV 192.168.1.1

# Intensive service detection
nmap -sV --version-intensity 5 192.168.1.1

# Service detection with scripts
nmap -sV -sC 192.168.1.1

Advanced Techniques

1. Detection Avoidance

# Stealth scan (very slow)
nmap -T1 192.168.1.1

# Fragmented scan
nmap -f 192.168.1.1

# Scan with custom MTU
nmap --mtu 24 192.168.1.1

# Scan with random delay
nmap --randomize-hosts 192.168.1.0/24

# Scan with spoofed source IP
nmap -S 192.168.1.100 192.168.1.1

2. NSE Scripts

# Using specific scripts
nmap --script "http-*" 192.168.1.1

# Vulnerability scripts
nmap --script vuln 192.168.1.1

# Exploitation scripts
nmap --script exploit 192.168.1.1

# Discovery scripts
nmap --script discovery 192.168.1.1

# Brute force scripts
nmap --script brute 192.168.1.1

3. Output and Reporting

# Normal output
nmap -oN resultat.txt 192.168.1.1

# XML output
nmap -oX resultat.xml 192.168.1.1

# Grepable output
nmap -oG resultat.grep 192.168.1.1

# All output formats
nmap -oA resultat 192.168.1.1

# Output with timestamp
nmap --append-output -oN resultat.txt 192.168.1.1

Pentest Scenarios

1. Initial Reconnaissance

# Quick discovery scan
nmap -sn 192.168.1.0/24

# Common port scan
nmap -F 192.168.1.1

# Scan with OS detection
nmap -O -sV 192.168.1.1

2. Service Enumeration

# Full port scan
nmap -p- 192.168.1.1

# Specific port scan
nmap -p80,443,8080 192.168.1.1

# Scan with service scripts
nmap -sV -sC -p80,443 192.168.1.1

3. Vulnerability Detection

# Vulnerability scan
nmap -sV --script vuln 192.168.1.1

# Vulnerable service scan
nmap -sV --script "vuln and safe" 192.168.1.1

# Scan with exploitation scripts
nmap -sV --script exploit 192.168.1.1

Best Practices

  1. Planification

    • Define the scan scope
    • Obtain the required authorizations
    • Plan maintenance windows
  2. Execution

    • Start with light scans
    • Progresser vers des scans plus intensifs
    • Document every step
  3. Documentation

    • Save all results
    • Analyze vulnerabilities
    • Write detailed reports

Useful NSE Scripts

1. Discovery

# Service discovery
nmap --script discovery 192.168.1.1

# DNS discovery
nmap --script dns-* 192.168.1.1

# SMB discovery
nmap --script smb-* 192.168.1.1

2. Vulnerabilities

# Web vulnerabilities
nmap --script http-* 192.168.1.1

# SMB vulnerabilities
nmap --script smb-vuln* 192.168.1.1

# SSL vulnerabilities
nmap --script ssl-* 192.168.1.1

3. Exploitation

# Brute force
nmap --script brute 192.168.1.1

# Service exploitation
nmap --script exploit 192.168.1.1

# Backdoor detection
nmap --script backdoor 192.168.1.1

Advanced Scan Techniques

1. Scan with Timing and Performance

# Aggressive scan (T4)
nmap -T4 192.168.1.1

# Insane scan (T5)
nmap -T5 192.168.1.1

# Scan with minimum delay
nmap --min-parallelism 100 192.168.1.1

# Scan with custom timeout
nmap --max-retries 2 192.168.1.1

# Scan with delay between hosts
nmap --scan-delay 1s 192.168.1.1

2. Scan with Spoofing and Anonymity

# Scan with spoofed source IP
nmap -S 192.168.1.100 192.168.1.1

# Scan with spoofed MAC
nmap --spoof-mac 00:11:22:33:44:55 192.168.1.1

# Scan with spoofed source port
nmap --source-port 53 192.168.1.1

# Scan with proxy
nmap --proxies proxy1.example.com:8080 192.168.1.1

# Scan with VPN
nmap --interface tun0 192.168.1.1

3. Scan with Service Discovery

# Service discovery with version
nmap -sV --version-intensity 9 192.168.1.1

# Service discovery with scripts
nmap -sV --script "version and safe" 192.168.1.1

# Service discovery with fingerprinting
nmap -sV --version-all 192.168.1.1

# Service discovery with light
nmap -sV --version-light 192.168.1.1

Advanced NSE Scripts

1. Security Scripts

# General security check
nmap --script "safe" 192.168.1.1

# Configuration check
nmap --script "config" 192.168.1.1

# Update check
nmap --script "updates" 192.168.1.1

# Web security check
nmap --script "http-security-headers" 192.168.1.1

2. Analysis Scripts

# Performance analysis
nmap --script "performance" 192.168.1.1

# Traffic analysis
nmap --script "traffic" 192.168.1.1

# Log analysis
nmap --script "log" 192.168.1.1

# Configuration analysis
nmap --script "config" 192.168.1.1

3. Advanced Exploitation Scripts

# Web service exploitation
nmap --script "http-*" 192.168.1.1

# Network service exploitation
nmap --script "network-*" 192.168.1.1

# System service exploitation
nmap --script "system-*" 192.168.1.1

# Database service exploitation
nmap --script "database-*" 192.168.1.1

Advanced Reporting Techniques

1. Specialized Output Formats

# Styled HTML output
nmap -oX resultat.xml --stylesheet styles.xsl 192.168.1.1

# Output with statistics
nmap --stats-every 10s 192.168.1.1

# Output with summary
nmap --append-output --resume resultat.txt 192.168.1.1

# Output with metrics
nmap --script "metrics" -oX resultat.xml 192.168.1.1

2. Result Analysis

# Open port analysis
nmap -oG - 192.168.1.1 | grep "open"

# Service analysis
nmap -sV -oX resultat.xml 192.168.1.1

# Vulnerability analysis
nmap --script vuln -oX resultat.xml 192.168.1.1

# Performance analysis
nmap --script "performance" -oX resultat.xml 192.168.1.1

Advanced Pentest Scenarios

1. Infrastructure Pentest

# Full infrastructure scan
nmap -sS -sV -O -p- -T4 192.168.1.0/24

# Critical service scan
nmap -sV -p21,22,23,25,80,443,3306,3389 192.168.1.1

# Vulnerability scan
nmap -sV --script vuln 192.168.1.1

# Configuration scan
nmap -sV --script "config" 192.168.1.1

2. Web Application Pentest

# Web port scan
nmap -sV -p80,443,8080,8443 192.168.1.1

# Web vulnerability scan
nmap --script "http-*" 192.168.1.1

# Web security scan
nmap --script "http-security-headers" 192.168.1.1

# Web configuration scan
nmap --script "http-config" 192.168.1.1

3. Database Pentest

# Database port scan
nmap -sV -p3306,5432,1433,1521 192.168.1.1

# Database vulnerability scan
nmap --script "database-*" 192.168.1.1

# Database configuration scan
nmap --script "database-config" 192.168.1.1

# Database security scan
nmap --script "database-security" 192.168.1.1

Troubleshooting and Optimization

1. Common Problem Resolution

# Connectivity check
nmap -sn 192.168.1.1

# Blocked port check
nmap -sS -p- 192.168.1.1

# Service check
nmap -sV 192.168.1.1

# Performance check
nmap -T4 --max-retries 2 192.168.1.1

2. Performance Optimization

# Speed optimization
nmap -T4 --min-parallelism 100 192.168.1.1

# Memory optimization
nmap --max-retries 2 192.168.1.1

# Network optimization
nmap --max-scan-delay 10s 192.168.1.1

# Resource optimization
nmap --max-retries 2 --max-scan-delay 10s 192.168.1.1

Conclusion

Nmap is a powerful pentesting tool, but it must be used ethically and responsibly. This guide covers the essential commandslles et les advanced techniques pour une use efficace.

Additional Resources

InSkillCoach

About InSkillCoach

Training and technology expert

Coach specializing in advanced technologies and AI, backed by GNeurone Inc.

Certifications:

  • AWS Certified Solutions Architect – Professional
  • Google Cloud certifications
  • Microsoft Certified: DevOps Engineer Expert
  • Certified Kubernetes Administrator (CKA)
  • CompTIA Security+
937
287

Comments

Comments are powered by GitHub Discussions

Sign in with GitHub to join the discussion

Link copied!