Using Nmap for Network Security: A Comprehensive Cheatsheet

πŸ“± Mobile Security Tips

Mike Torres — Android Security Engineer

What is Nmap?

Nmap (Network Mapper) is a powerful open-source tool designed for network discovery and security auditing. It is used by security professionals and analysts for various tasks, including network inventory, managing service upgrade schedules, and monitoring host or service uptime.

Installation

Nmap can be easily installed on various operating systems. Here’s how to install it:

  • On Ubuntu: sudo apt install nmap
  • On CentOS: sudo yum install nmap
  • On macOS: brew install nmap
  • On Windows: Download the installer from nmap.org.

Basic Syntax

The basic command structure for Nmap is:

nmap [options] [targets]

Network Discovery

Use Nmap to discover hosts and services on a network.

  • Scan a Single IP: nmap 192.168.1.1
  • Scan a Range of IPs: nmap 192.168.1.1-100
  • Scan a Subnet: nmap 192.168.1.0/24

Service and Version Detection

To detect running services and their versions:

nmap -sV 192.168.1.1

Operating System Detection

To identify the operating system of a target:

nmap -O 192.168.1.1

Scanning for Vulnerabilities

Nmap can integrate with NSE (Nmap Scripting Engine) to perform vulnerability scanning:

nmap --script=vuln 192.168.1.1

Randomized Scanning

To evade intrusion detection systems:

nmap -p 1-65535 -T1 --randomize-hosts 192.168.1.0/24

Quick Reference Table

Flag Description
-sP Ping scan (discover hosts)
-sV Service version detection
-O Operating system detection
-sC Use the default set of scripts

Pro Tips

  • Run scans in background using nmap -dN -oN output.txt for logging results.
  • Use -Pn to skip host discovery, useful in silent environments.

Real-World Examples

# Basic scan for open ports with service detection
nmap -sV 192.168.1.1

# Aggressive scanning for OS and services
nmap -A 192.168.1.0/24

# Scan for a specific port (e.g., 80) in all hosts
nmap -p 80 192.168.1.0/24