🛠 Security Tool Cheatsheet

Alex Morgan — Senior Penetration Tester

{
“title”: “The Ultimate Guide to Using Nmap for Security Testing”,
“content”: “

What is Nmap?

\n

Nmap, or Network Mapper, is an open-source tool designed for network discovery and security auditing. It is widely used by security analysts and penetration testers to map out networks, discover hosts and services, and identify vulnerabilities.

\n\n

Installation

\n

Nmap can be installed on various operating systems, including Windows, Linux, and MacOS. Follow these steps based on your OS:

\n

    \n

  • Windows: Download the installer from the Nmap download page and follow the installation instructions.
  • \n

  • Linux: Use the package manager:\n
    sudo apt install nmap  # Ubuntu/Debian\nsudo yum install nmap  # CentOS/RHEL\n
  • \n

  • MacOS: Use Homebrew:\n
    brew install nmap\n
  • \n

\n\n

Basic Syntax

\n

The general syntax for using Nmap is:

\n

nmap [options] {target}\n

\n

Replace {target} with the IP address or domain name of the target you want to scan.

\n\n

Discovery

\n

Use Nmap for host discovery to find live devices on your network.

\n

    \n

  • Ping Scan: Check which hosts are up in a network range:\nnmap -sn 192.168.1.0/24
  • \n

  • Service Discovery: Identify devices and services:\nnmap -sP 192.168.1.0/24
  • \n

\n\n

Scanning

\n

To detect open ports and services running on hosts.

\n

    \n

  • Default Scan: Scan for the 1,000 most common ports:\nnmap 192.168.1.1
  • \n

  • Specific Ports: Target specific ports:\nnmap -p 22,80,443 192.168.1.1
  • \n

  • TCP SYN Scan: Stealth scan method:\nnmap -sS 192.168.1.1
  • \n

\n\n

Exploitation

\n

Nmap can be used to identify potential vulnerabilities for exploitation.

\n

    \n

  • Service Version Detection: Get more info about services running on open ports:\nnmap -sV 192.168.1.1
  • \n

  • OS Detection: Identify the operating system:\nnmap -O 192.168.1.1
  • \n

\n\n

Analysis

\n

Perform in-depth analysis after scanning.

\n

    \n

  • Output to File: Save results to a file for further analysis:\nnmap -oN results.txt 192.168.1.1
  • \n

  • XML Output: Output in XML format:\nnmap -oX results.xml 192.168.1.1
  • \n

\n\n

Evasion

\n

Need to avoid detection by firewalls or intrusion detection systems.

\n

    \n

  • Fragment Packets: Break packets for stealth:\nnmap -f 192.168.1.1
  • \n

  • Use Decoy: Hide your source IP:\nnmap -D RND:10 192.168.1.1
  • \n

\n\n

Reporting

\n

Generate reports in various formats.

\n

    \n

  • JSON Output: Best for integration with tools:\nnmap -oJ results.json 192.168.1.1
  • \n

\n\n

Quick Reference Table

\n

\n

\n

\n

\n

\n

\n

\n

\n

\n

\n

Flag Description
-sn Ping scan to discover hosts
-sS TCP SYN scan (stealth)
-sV Version detection of services
-O OS detection
-oN Normal output to file
-f Fragment packets
-D Decoy mode for stealth
-oJ JSON output

\n\n

Pro Tips

\n

    \n

  • Use -sP option for faster scans when only checking for live hosts.
  • \n

  • Combine scans using the –script option to run Nmap scripts during a scan, allowing for vulnerability checks.
  • \n

  • Always run -A for aggressive scans that provide additional info like OS detection and version numbers.
  • \n

\n\n

Real-World Examples

\n

    \n

  • To scan a complete subnet for live hosts and identify versions:\n
    nmap -sP 192.168.1.0/24 -sV\n
  • \n

  • To stealthily scan a specific host while fragmenting packets:\n
    nmap -f -s