Filed in: Tutorials.EthernetSnooping · Modified on : Mon, 22 Nov 10
This tutorial describes how to set up a computer to tap an ethernet connection, allowing you to capture all Ethernet frames flowing through it. This is useful for diagnosing network faults, troubleshooting embedded or otherwise locked-down devices, and learning how stuff works in general.
We assume that the current set up has the target plugged into the wall port.
On the sniffer...
brctl tool (which is in the package bridge-utils on Mint/Ubuntu), as well as wireshark (package: wireshark). You might need to ensure that bridging is enabled in your kernel, but AFAICT, it's usually enabled by default.
wall port == sniffer == target
That's it. Watch the packets flow.
upstream -- hub +-- target
+-- sniffer
In this configuration, the target and sniffer are both connected to an Ethernet hub. In fact, this case is trivial: all packets from/to the target will also be sent to the sniffer! The sniffer is expected to drop packets not destined to it, but that doesn't mean we can't look at them first ;)
upstream -- switch +-- target
+-- sniffer
Say you don't have two ethernet ports on your sniffer, but are plugged into the same switch as the target. A technique called "ARP poisoning" will allow you to trick the switch into thinking that the sniffer is the target, thus forwarding all packets to it.
Theory time! A hub forwards any Ethernet frames it receives on an interface to every other one of its interfaces; it is only concerned with Layer 2.
Switches on the other hand are slightly more intelligent in that they will (or should) only forward traffic to its intended destination. A switch accomplishes this by way of a ARP table, which maps IP addresses to MAC addresses. When an IP packet arrives on one of its interfaces, the switch forwards it to the MAC address associated with that IP in its ARP table.
Now, provided all hosts on the switch are truth-tellers, coming up with the ARP table works pretty well. The switch listens to traffic on its interfaces for a while, learning which MACs are sending which IPs.
However, there's also an ARP protocol (on Layer 3) that can be used to broadcast packets like "Who has IP X? Tell MAC address Y." (query) and "Hey MAC Y, MAC Z has address X!" (response). The protocol also has something called a "Gratuitous ARP", which sounds like the end part of the ARP response: "MAC Z has address X!", but not in response to any particular query. The switch will pick up on this and add it to its ARP table, despite the fact that it may conflict with what it's learned previously (better safe than sorry).
A program called ettercap can be used to send these packets. Then it's simply a matter of listening with Wireshark and filtering the interesting stuff.