🛠Security Tool Cheatsheet
Alex Morgan — Senior Penetration Tester
What is Nmap?
Nmap (Network Mapper) is an open-source tool for network exploration and security auditing. It is widely used for discovering hosts and services on a computer network, thus creating a ‘map’ of the network. Nmap can also be used to detect operating systems, network services, and potential vulnerabilities.
Installation
To install Nmap, follow these steps based on your operating system:
- Linux: You can install Nmap using your distribution’s package manager. For Ubuntu, use
sudo apt install nmap. For CentOS, usesudo yum install nmap. - Windows: Download the installer from the official Nmap website and follow the installation instructions.
- macOS: Use Homebrew with
brew install nmap.
Basic Syntax
The basic syntax for using Nmap is as follows:
nmap [options] {targets}
Where options are the various flags you can set, and {targets} can be an IP address, hostname, or a range of IPs.
Discovery
Use Nmap for network discovery to identify hosts that are up and their IP addresses.
Basic Host Discovery
nmap -sn 192.168.1.0/24
This command will perform a ping scan on the entire subnet to find live hosts.
Service Discovery
nmap -sV 192.168.1.10
With this command, Nmap will probe open ports to determine service versions.
Scanning
Scanning helps identify open ports and services running on a host.
Quick Port Scan
nmap 192.168.1.10
This simple command scans the most common 1,000 ports.
Aggressive Scan
nmap -A 192.168.1.10
The aggressive scan provides detailed information about the target, including OS detection, service version detection, and more.
Exploitation
Nmap can also be leveraged to prepare for exploitation.
Default Script Scan
nmap -sC 192.168.1.10
This command runs a set of default scripts against the target, helping to identify vulnerabilities.
Analysis
Post-scan analysis is crucial for interpreting results effectively.
Output to XML
nmap -oX output.xml 192.168.1.10
Direct scan results to an XML file for further analysis with other tools.
Evasion
Sometimes it is necessary to avoid detection by firewalls or intrusion detection systems.
Slow Scan
nmap -PN -T2 192.168.1.10
This will perform a slower scan that may bypass intrusion detection systems.
Reporting
Documentation of your findings is essential in security assessments.
Output Formats
nmap -oN output.txt 192.168.1.10
This command outputs the scan results in a human-readable text format.
Quick Reference Table
| Flag | Description |
|---|---|
| -sP | Ping scan – discover live hosts |
| -sV | Service version detection |
| -A | Aggressive scan |
| -sC | Run default scripts |
| -oX | Output to XML |
Pro Tips
- Combine options for more comprehensive scans, e.g.,
nmap -sS -sV -A -oN scan_results.txt 192.168.1.0/24. - Use the –script option to run specific Nmap scripts for finding known vulnerabilities.
- Always run Nmap as a non-root user when possible to prevent excessive privileges from interfering with the scan.
Real-World Examples
Nmap is used globally in various scenarios: network inventory, security assessments, and security audits. Here are a couple of scenarios:
- Network Inventory: Use Nmap to generate an inventory of devices in a corporate network, helping IT maintain an overview and enforce compliance.
- Security Assessment: During a pentest, a security analyst might use
nmap -p- -sV -sC -oN results.txt target_ipto find and exploit vulnerabilities in a client’s system.