1. Fundamentals of Host Discovery
Host Discovery Objectives
Host discovery is the reconnaissance phase where an attacker or security auditor maps the attack surface by identifying active systems on a network. The primary goal is to determine which IP addresses are associated with live machines, filtering out non-existent or down hosts to optimize subsequent scanning.
When performing host discovery, we look for responses to specific packets. An active host will typically acknowledge specific protocol headers or reply with error messages, indicating it is currently processing traffic.
We can visualize the identification process as a filtering sequence. In a range of /24 (256 addresses), we attempt to send discovery probes and listen for traffic. If no packet is captured within the time threshold, we mark the host as Down.
import socket def check_target(ip): try: # Simple TCP connect discovery simulation s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(0.5) result = s.connect_ex((ip, 80)) s.close() return result == 0 except Exception: return False print(f"Target 192.168.1.1 is live: {check_target('192.168.1.1')}")
ICMP Ping Sweep (-sn / -PE)
The ICMP Echo Request, often called a ping, is the most common way to check for host availability. The -sn flag in Nmap performs a ping sweep without performing a full port scan.
However, many modern firewalls and Windows systems block inbound ICMP Echo requests by default. This makes ICMP unreliable for discovery in hardened environments.
The following table compares common discovery behaviors:
| Protocol | Discovery Method |
|---|---|
| ICMP | Sends Type 8 Echo Request; expects Type 0 Reply. |
| TCP SYN | Sends SYN packet; expects SYN/ACK to indicate life. |
nmap -sn 192.168.1.0/24 # -sn: Disable port scanning, perform host discovery only # -PE: Use ICMP Echo Request for discovery
ARP Scanning (local subnets)
ARP scanning is the fastest and most reliable way to find live hosts on a local area network. Since ARP (Address Resolution Protocol) operates at Layer 2 (Data Link Layer), it does not rely on IP routing or firewall configurations. When you send an ARP request for an IP address, the local host owning that IP must reply with its MAC address.
Because ARP does not cross router boundaries, this method only works when your machine is on the same broadcast domain as the target.
Nmap automatically uses ARP scanning when you run a scan against an IP within your current subnet.
from scapy.all import ARP, Ether, srp def arp_scan(network): # Create ARP packet arp = ARP(pdst=network) ether = Ether(dst='ff:ff:ff:ff:ff:ff') packet = ether/arp # Send and receive result = srp(packet, timeout=3, verbose=0)[0] for sent, received in result: print(f'IP: {received.psrc} is at MAC: {received.hwsrc}') # arp_scan('192.168.1.0/24')
TCP SYN/ACK & UDP Ping Evasion
When ICMP is dropped, we use TCP SYN and ACK probes. A SYN probe (-PS) sends a packet as if to open a connection. If the port is open, the host replies with SYN/ACK. Even if the port is closed, the host often sends an RST packet, which confirms the host is live.
UDP ping (-PU) sends empty UDP packets to high-numbered ports. If the host returns an ICMP Port Unreachable message, the host is live. If the packet is ignored, it may be dropped by a firewall or the host may be down.
nmap -PS80,443,22 192.168.1.0/24 # -PS: Perform TCP SYN discovery on specific ports # -PU53,161 192.168.1.0/24 # -PU: Perform UDP discovery to bypass standard TCP filters
Knowledge Check
Ready to test your understanding of 1. Fundamentals of Host Discovery?