02. Port Scanning
Port scanning is a critical step in network reconnaissance, which helps identify open ports, the operating systems, and services running on target hosts. Here's a detailed breakdown with examples and tools:
Port Scanning Commands¶
1. Identify Operating System and Services¶
-
Command:
- Explanation: This scans the hosts listed in
test.txtfor open ports. - Example Usage: If
test.txtcontains a list of IP addresses (e.g.,192.168.1.1), this command scans those IPs for open ports. - Output: Lists open ports for each host.
- Command:
- Explanation:
-sV: Enables version detection to identify running services and their versions.-O: Performs OS detection using TCP/IP stack fingerprinting.
- Example Usage:
- Input:
test.txtwith IPs. - Command:
nmap -iL test.txt -sV -O.
- Input:
- Output: Displays detected OS and running services for each host.
- Command:
- Explanation:
-sC: Runs Nmap's default scripts for additional vulnerability detection.
- Example Usage: Combines port scanning, OS detection, service detection, and script-based analysis.
- Output: Provides detailed host information, including service vulnerabilities.
- Explanation: This scans the hosts listed in
Graphical Tools and Automation¶
1. Zenmap¶
- Description: Graphical user interface (GUI) for Nmap, suitable for beginners and visualization.
- Usage Example:
- Load a target or range of IPs.
- Choose a scan type (e.g., quick, intense).
- View results in graphical format, including topology.
2. Nmap Automator¶
- Description: A script that automates Nmap scans based on predefined options.
-
Usage Example:
- Automates scans like reconnaissance, port scanning, and vulnerability checks.
3. Masscan¶
- Description: High-speed port scanner for large networks.
-
Usage Example:
-p0-65535: Scans all ports.--rate=1000: Limits packets per second.
4. Rustscan¶
- Description: A fast and efficient port scanner built with Rust.
-
Usage Example:
- Combines speed and detailed service detection.
5. AutoRecon¶
- Description: Multi-tool automation framework for reconnaissance.
-
Usage Example:
- Combines tools like Nmap, Nikto, Gobuster for extensive reconnaissance.
Examples in Action¶
Scenario:¶
You want to scan a network (192.168.1.0/24) for open ports, identify the OS, and find running services.
-
Basic Scan:
- Input:
test.txtwith192.168.1.1,192.168.1.2. - Output: Open ports per host.
- OS and Service Detection:
- Output: OS (e.g., Windows, Linux) and running services (e.g., SSH, HTTP).
- Automated Vulnerability Checks:
- Output: Identifies vulnerabilities using Nmap's script engine.
- High-Speed Scanning:
- Output: Lists open ports for SSH (22), HTTP (80), HTTPS (443).
- Input:
Best Practices¶
- Use masscan or Rustscan for large networks where speed is critical.
- Combine
-sV,-O, and-sCin Nmap for detailed analysis. - Automate repetitive tasks with tools like Nmap Automator and AutoRecon.
- Take note of key findings such as:
- OS type (e.g., Windows 10, Ubuntu 20.04).
- Services running (e.g., Apache 2.4.51, OpenSSH 8.9).
- Vulnerabilities found (e.g., outdated services).