Master the Dark Arts of Network Traffic Interception and Manipulation
Network sniffing is the process of capturing and analyzing network traffic to intercept data packets. This technique is fundamental to network security testing, troubleshooting, and unfortunately, malicious espionage.
Passive sniffing involves listening to network traffic without injecting any additional packets. This method is stealthy and difficult to detect.
Active sniffing requires injecting packets or manipulating network devices to redirect traffic. This approach is more detectable but works in switched environments.
Understanding the difference between hubs and switches is critical for effective sniffing attacks.
| Feature | Hub | Switch |
|---|---|---|
| OSI Layer | Layer 1 (Physical) | Layer 2 (Data Link) |
| Traffic Forwarding | Broadcasts to all ports | Forwards to specific port |
| Collision Domain | Single collision domain | Separate collision domains |
| Sniffing Difficulty | Easy (passive sniffing) | Difficult (requires active attacks) |
| MAC Address Learning | None | Uses CAM table |
| Performance | Low (shared bandwidth) | High (dedicated bandwidth) |
The Content Addressable Memory (CAM) table stores MAC address to port mappings. Flooding it with fake MAC addresses forces the switch into a fail-open mode, acting like a hub.
Each entry contains: VLAN ID, MAC Address, Port ID, and Learning Status
| VLAN ID | MAC Address | Port ID | Learning Mode |
|---|---|---|---|
| 1 | 00:1A:2B:3C:4D:5E | Fa0/1 | Dynamic |
| 1 | 00:1A:2B:3C:4D:5F | Fa0/2 | Dynamic |
| 1 | 00:1A:2B:3C:4D:60 | Fa0/3 | Dynamic |
# Using macof to flood CAM table
$ macof -i eth0 -n 1000
# This sends 1000 packets with random MAC addresses
# Switch CAM table fills up and fails to learning mode
MAC spoofing allows an attacker to impersonate another device on the network, enabling switch port stealing and traffic interception.
# Linux MAC spoofing with macchanger
$ ifconfig eth0 down
$ macchanger -m 00:11:22:33:44:55 eth0
$ ifconfig eth0 up
# Windows Registry method
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0001
NetworkAddress = "001122334455"
VLAN hopping allows attackers to bypass network segmentation by jumping between VLANs.
The attacker negotiates a trunk link with the switch using Dynamic Trunking Protocol (DTP), gaining access to all VLANs.
# Using Yersinia for DTP attack
$ yersinia -G # GUI mode
# Select DTP protocol
# Enable trunk on interface
The attacker adds two 802.1Q tags to frames. The first tag is stripped by the first switch, and the second tag routes the packet to the target VLAN.
# Using Yersinia for STP attack
$ yersinia -G
# Claim Root Role
# Using DHCPig for starvation
$ pig.py eth0 --exhaust
# Setup rogue DHCP with dnsmasq
$ dnsmasq --dhcp-range=192.168.1.100,192.168.1.200
Build custom Wireshark display filters to analyze specific network traffic.
http.request.method == "POST"
arp.duplicate-address-detected
frame.len > 1000
ip.addr == 192.168.1.1 and tcp.port == 443
Implement these security controls to protect against sniffing and spoofing attacks.
# Cisco port security config
switchport port-security
switchport port-security maximum 2
switchport port-security violation shutdown
# Enable DHCP snooping
ip dhcp snooping
ip dhcp snooping vlan 1
interface Gi0/1
ip dhcp snooping trust
# Enable DAI
ip arp inspection vlan 1
interface Gi0/1
ip arp inspection trust
# Disable DTP
switchport mode access
switchport nonegotiate
Test your understanding of network sniffing and spoofing concepts. Complete all 12 questions to earn your XP reward.