03. Port Scanning with Nmap
1. Basic Scan: nmap <IP Address>¶
Command:
Explanation:
- Performs a basic scan of the specified IP address.
- Detects open ports and determines if the host is up (using ICMP ping).
- Uses the default 1,000 commonly used TCP ports.
Example:
Output:
Lists open ports, their states (open/closed), and their default services.
2. Disable Host Discovery: nmap -Pn <IP Address>¶
Command:
Explanation:
- Treats the target as online without sending ICMP ping requests.
- Useful when ICMP ping is blocked by a firewall.
Example:
3. Full Port Scan: nmap -Pn -p- or Specific Port: nmap -Pn -p <port>¶
Commands:
-
Scan all 65,535 ports:
-
Scan specific port:
Explanation:
-p-: Scans all TCP ports (1–65535).-p <port>: Scans a specific port.
Example:
4. Fast Scan: nmap -Pn -F <IP Address>¶
Command:
Explanation:
- Scans only the top 100 most commonly used ports.
- Faster than the default scan.
Example:
5. UDP Scan: nmap -Pn -sU <IP Address>¶
Command:
Explanation:
- Scans UDP ports instead of TCP.
- Useful for finding open UDP services like DNS (port 53) or NTP (port 123).
Example:
6. Verbose Output: nmap -Pn <IP Address> -v¶
Command:
Explanation:
- Provides detailed and real-time output during the scan.
- Useful for troubleshooting or monitoring scan progress.
Example:
7. Service Version Detection: nmap -sV <IP Address>¶
Command:
Explanation:
- Identifies the version of services running on open ports.
- Provides more detailed information about the services.
Example:
Output:
Displays open ports, services, and their versions (e.g., Apache 2.4.48).
8. OS Detection: nmap -O <IP Address>¶
Command:
Explanation:
- Attempts to detect the operating system running on the target device.
- Uses TCP/IP stack fingerprinting.
Example:
9. Default Script Scan: nmap -sC <IP Address>¶
Command:
Explanation:
- Runs a set of default scripts against the target.
- Detects common vulnerabilities, services, and misconfigurations.
- Example:
10. Save Output in Normal Format: nmap -Pn <IP Address> -oN <file>¶
Command:
Explanation:
- Saves the scan result in a human-readable text file.
Example:
11. Save Output in XML Format: nmap -Pn <IP Address> -oX <file>¶
Command:
Explanation:
- Saves the scan result in XML format for automation or further processing.
Example:
Practical Scenarios¶
-
Identify All Open Ports on a Host:
-
Detect Operating System and Services:
-
Perform a UDP Scan:
-
Save Results for Later Analysis:
Key Points¶
-Pn: Ignores ICMP ping checks; useful for firewalled hosts.-sV: Provides service versions, crucial for vulnerability analysis.-O: Helps identify the target's operating system.- Output Options: Use
-oNor-oXto save results for documentation or automated processing.