## Network Scanning: CEH Revision
Network scanning is a crucial phase in ethical hacking, following reconnaissance. Its primary goal is to identify live hosts, open ports, services running on those ports, operating systems, and potential vulnerabilities within a target network. This active process provides a detailed blueprint of the target's network infrastructure.
## Host Discovery
Before scanning ports, identifying active hosts is essential. Tools like Nmap are invaluable here.
- Ping Sweeps (ICMP): Sending ICMP Echo Request packets to a range of IPs. If an Echo Reply is received, the host is live. Nmap's `-sn` (ping scan) option performs this.
- ARP Scans: For local networks, ARP requests can identify active hosts even if they block ICMP.
- TCP/UDP Pings: Sending TCP SYN or ACK packets to common ports (e.g., 80, 443) or UDP packets to known ports (e.g., 53, 161) can also reveal live hosts, especially if ICMP is blocked.
## Port Scanning Techniques
Port scanning identifies which ports are open, closed, or filtered.
- TCP SYN Scan (-sS): The stealthiest and most common TCP scan. It sends a SYN packet and if a SYN/ACK is received, the port is open, but the scanner sends an RST instead of an ACK, never completing the handshake. This makes it harder for firewalls/IDPS to log. Requires root privileges.
- TCP Connect Scan (-sT): Completes the full three-way handshake. This is noisy, easily logged, but doesn't require root. Used when SYN scans are not possible.
- UDP Scan (-sU): Sends UDP packets to target ports. If an ICMP Port Unreachable message is received, the port is closed. No response usually means the port is open or filtered. Slower and less reliable than TCP scans.
- FIN Scan (-sF), XMAS Scan (-sX), NULL Scan (-sN): These scans exploit RFC 793 behavior. For closed ports, they should respond with an RST. For open ports, they should *not* respond. They are stealthier but less effective against Windows hosts due to different TCP stack implementations.
- ACK Scan (-sA): Used to map firewall rulesets. It determines if ports are filtered (no RST) or unfiltered (RST received), but *cannot* determine if a port is open or closed.
## OS and Service Detection
Beyond just open ports, identifying the specific services and operating systems provides critical information.
- OS Detection (-O): Nmap analyzes TCP/IP stack fingerprints (e.g., initial window size, TCP options) to guess the target's operating system.
- Service Version Detection (-sV): Nmap connects to open ports and queries the services to identify the application and its exact version (e.g., Apache 2.4.41, OpenSSH 8.2p1). This is vital for finding known vulnerabilities.
## Evasion Techniques
Attackers employ methods to bypass security controls during scanning:
- Decoy Scans (-D): Sending scan packets from multiple spoofed IP addresses alongside the real one to confuse logs.
- Fragmentation (--frag): Splitting scan packets into smaller fragments to bypass simple packet filters.
- Timing Options (-T): Adjusting scan speed to avoid detection by IDPS (e.g., `-T0` for paranoid, `-T5` for insane).
Tools: The primary tool for network scanning is Nmap (Network Mapper), renowned for its versatility and powerful features. Other tools include Hping3 for custom packet crafting and Netcat for banner grabbing.
What is the primary purpose of network scanning in ethical hacking?
To identify live hosts, open ports, running services, operating systems, and potential vulnerabilities within a target network.
tap to reveal
Which Nmap scan type is considered the 'stealthiest' and why?
TCP SYN scan (-sS), because it performs a 'half-open' scan without completing the TCP three-way handshake, making it harder to log.
tap to reveal
What Nmap option is used for OS detection?
` -O ` (uppercase O)
tap to reveal
How does an Nmap UDP scan (-sU) typically determine if a port is closed?
By receiving an ICMP Port Unreachable message from the target host.
tap to reveal
What is the main use of an Nmap ACK scan (-sA)?
To map firewall rulesets, determining if ports are filtered or unfiltered, but not if they are open or closed.
tap to reveal
Name two Nmap techniques used to evade IDS/Firewalls.
Decoy scans (-D) and packet fragmentation (--frag).
tap to reveal
What Nmap option is used to identify the specific application and its version running on an open port?
` -sV ` (service version detection)
tap to reveal
What is the main difference between Nmap's TCP Connect scan (-sT) and SYN scan (-sS)?
Connect scan completes the full TCP handshake (noisy, no root needed), while SYN scan performs a half-open handshake (stealthier, requires root).
tap to reveal