30 Mins

5. OS Fingerprinting & TCP Stack Behavior

OS Detection (-O / -A): TCP/IP Stack Fingerprinting

OS Fingerprinting is the art of identifying a remote operating system by analyzing subtle variances in its TCP/IP stack implementation. Since every OS kernel (Linux, Windows, BSD) handles protocol RFCs differently, Nmap sends crafted packets to the target and analyzes the responses.

Key metrics collected include the Initial TTL (Time to Live), the Window Size (the max buffer size), the IP ID (how the kernel increments identification fields), and support for specific TCP options like Selective ACK or Window Scaling.

For example, a Linux kernel typically starts with a TTL of 64, while Windows targets often use 128. By analyzing these parameters, we can calculate a signature and compare it against the nmap-os-db database.

Security Operator Note: Always pair -O with -Pn if the target drops ICMP echo requests to ensure packets reach the OS stack for analysis.
Text
nmap -O 192.168.1.50 --osscan-limit --osscan-guess

Aggressive Scan (-A): The Operator's Multi-Tool

The -A flag is an alias for a suite of diagnostic scans. It combines OS detection (-O), service version detection (-sV), script scanning (-sC), and traceroute (--traceroute) into a single command.

When you run an aggressive scan, Nmap performs a TCP handshake with open ports to retrieve banners and probe protocol behavior, while simultaneously executing NSE (Nmap Scripting Engine) scripts to identify known CVEs or service configurations.

This is highly efficient for rapid reconnaissance but significantly increases noise on the wire, making it easily detectable by NIDS systems.

Security Operator Note: The -A flag is loud. Use it only when internal network stealth is not a primary concern.
Text
nmap -A -v -T4 10.0.2.15

Analyzing OS Match Confidence Percentages

Nmap assigns a confidence percentage to OS matches based on the match quality between the gathered signatures and the internal database. A score of 100% indicates an exact match on all probed features.

When confidence is low, Nmap may list multiple potential OS candidates. Factors decreasing confidence include packet loss, presence of firewalls/IPS that modify TCP headers, or modern kernel updates that deviate from established signatures.

We can manually observe how these parameters manifest by crafting a raw TCP packet using Python's struct and socket libraries.

Security Operator Note: If multiple OS matches appear, look for the 'OS CPE' line in the output to see if it specifically points to a kernel version vs a generic distribution.
Python 3
import socket, struct

def craft_packet():
    # Basic TCP header structure: Source, Dest, Seq, Ack, Offset/Flags
    tcp_header = struct.pack('!HHLLBBHHH', 12345, 80, 0, 0, 80, 2, 65535, 0, 0)
    print(f'Crafted TCP Header bytes: {tcp_header.hex()}')

craft_packet()

Timing Templates (-T0 to -T5) and Rate Limiting

Timing templates control the speed and aggressiveness of the scan. They dictate packet sending frequency, retry counts, and timeout thresholds. -T0 (Paranoid) and -T1 (Sneaky) are designed for IDS evasion, sending packets minutes apart.

Conversely, -T4 and -T5 (Insane) are designed for high-speed local networks, risking high packet loss and potential service disruption if the target stack is fragile. Proper tuning often involves manual rate limiting using --max-rate.

TemplatePurpose
-T1Slow, used for stealth evasion
-T3Default, balanced speed/accuracy
-T5Aggressive, maximum network saturation
Security Operator Note: Use -T4 for professional engagements where the target is not expected to be extremely sensitive to rapid traffic.
Text
nmap -T4 --max-rate 500 192.168.1.1-254

Knowledge Check

Ready to test your understanding of 5. OS Fingerprinting & TCP Stack Behavior?

Back