A Sniffer is a program or a device that eavesdrops on the network traffic by grabbing information travelling over a network. Sniffers basically are "Data Interception" technology. They work because the Ethernet was built around a principle of sharing. Most networks use broadcast technology wherein messages for one computer can be read by another computer on that network. In practice, all the other computers except the one for which the message is meant, will ignore that message. However, computers can be made to accept messages even if they are not meant for them. This is done by means of a Sniffer!
A computer connected to the LAN has 2 addresses. One is the MAC 1 address that uniquely identifies each node in a network and is stored on the network card itself. It is the MAC address that gets used by the Ethernet protocol while building `frames' to transfer data to and from a machine. The other is the IP address which is used by applications. The Data Link Layer uses an Ethernet header with the MAC address of the destination machine rather than the IP Address. The Network Layer is responsible for mapping IP network addresses to the MAC address as required by the Data Link Protocol. It initially looks up the MAC address of the destination machine in a table, usually called the ARP cache. If no entry is found for the IP address, the Address Resolution Protocol broadcasts a request packet (ARP request) to all machines on the network. The machine with that address responds to the source machine with its MAC address. This MAC address then gets added to the source machines ARP Cache. This MAC address is then used by the source machine in all its communications with the destination machine.
There are two basic types of Ethernets environments and how sniffers work in both these cases is slightly different.
Shared Ethernet: In a shared Ethernet environment, all hosts are connected to the same bus and compete with one another for bandwidth. In such an environment packets meant for one machine are received by all the other machines. Thus when a machine Venus wants to talk to Cupid in such an environment, it sends a packet on the network with the destination MAC address of Cupid along with its own source MAC address. All the computers on the shared ethernet compare frame's destination MAC address with their own. If the two don't match, the frame is quietly discarded. A machine running a sniffer breaks this rule and accepts all frames. Such a macine is said to have been put into promiscous mode and can effectively listen to all the traffic on the network. Sniffing in a Shared Ethernet environment is totally passive and hence extremely difficult to detect.
Switched Ethernet: An Ethernet environment in which the hosts are connected to switch instead of a hub is called a Switched Ethernet. The switch maintains a table keeping track of each computer's MAC address and the physical port on the switch to which that MAC address is connected and delivers packets destined for a particular machine correspondingly. The switch is an intelligent device which sends packets to the destined computer only and does not broadcast it to all the machines on the network, as in the previous case. As a result of this the process followed earlier, of putting the machine into promiscous mode, to gather packets does not work. As a result of this, even many experienced Systems Administrators fall into the belief that switched networks are secure and cannot be sniffed. Though a switch is more secure than a hub, you can use the following methods to sniff on a switch:
2. [root@tachyon dhar]# arpspoof -t 126.96.36.199 188.8.131.52
3. 0:80:ad:7c:7:3a 52:54:5:f3:95:1 0806 42: arp reply \
4. 184.108.40.206 is-at 0:80:ad:7c:7:3a
5. 0:80:ad:7c:7:3a 52:54:5:f3:95:1 0806 42: arp reply \
6. 220.127.116.11 is-at 0:80:ad:7c:7:3a
The -t flag specifies the target whose ARP cache we wish to poison and the other argument is the IP address of the gateway which we wish to spoof. So now all the data destined for the gateway from the target machine will have to pass through our machine. Before you do this, it is essential you turn on IP Forwarding on your machine. You can do this by giving the command:
[root@tachyon dhar]# echo 1 > /proc/sys/net/ipv4/ip_forward
[root@tachyon dhar]# cat /proc/sys/net/ipv4/ip_forward
If the cat command returns a value of 1, then IP Forwarding has been enabled but if it returns 0, it means IP Forwarding has not been enabled. It is important to enable IP Forwarding or else the network will die.
8. [root@tachyon dhar]# macof
9. 77:6b:e1:6e:5e:8c 93:2d:ed:45:f9:e3 0.0.0.0.45702 > \
10. 0.0.0.0.11000: S 1847390231:1847390231(0) win 512
11. 84:a4:d3:57:ef:8 :dc:95 0.0.0.0.16630 > \
12. 0.0.0.0.3031: S 1484147693:1484147693(0) win 512
13. 88:f0:9:3f:18:89 d:86:53:53:d7:f8 0.0.0.0.15535 > \
14. 0.0.0.0.7466: S 293820390:293820390(0) win 512
Warning: This method might lead to degeneration of the network services and should not be run for a long interval of time.
A sniffer is usually passive, it just collects data. Hence it becomes extremely difficult to detect sniffers, specially when running on a Shared Ethernet. When installed on a computer, a sniffer does generate some small amount of traffic. Here is an overview of the detection methods:
4. eth0 Link encap:Ethernet HWaddr 52:54:05:F3:95:01
5. inet addr:18.104.22.168 Bcast:203.199. ...
6. UP BROADCAST RUNNING MULTICAST MTU:1500 ...
But on a machine running a sniffer the output will be like this:
eth0 Link encap:Ethernet HWaddr 52:54:05:F3:95:01
inet addr:22.214.171.124 Bcast:203.199. ...
UP BROADCAST RUNNING PROMISC MULTICAST ...
(Output slightly modified to fit screen)
The best way to secure yourself against sniffing is to use encryption. While this won't prevent a sniffer from functioning, it will ensure that what a sniffer reads is pure junk.
Switch to SSH. SSH is fast becoming the de facto standard method of connecting to a Unix/Linux Machine. For more information on SSH, check out http://www.ssh.fi. You might want to check out the open-source implemetation OpenSSH at http://www.openssh.org/
Since I have been a Linux man through out, I will list some of the commonly available sniffers for linux.
Media Access Control
Address Resolution Protocol