Sniffing Attack
A sniffing attack uses a network packet capture tool to collect information about a target. When a protocol communicates in cleartext, the data it exchanges can be captured and analysed by a third party. A simple packet capture can reveal the content of private messages and login credentials if the data is not encrypted in transit.
A sniffing attack can be run with an Ethernet (802.3) network card, provided the user has the right permissions (root on Linux, administrator on MS Windows). Many programs can capture packets. The ones considered here:
- Tcpdump is a free, open source command-line (CLI) program ported to many operating systems.
- Wireshark is a free, open source graphical (GUI) program available on Linux, macOS and MS Windows, among others.
- Tshark is a CLI alternative to Wireshark.
There are specialized tools for capturing passwords and even complete messages, but this can still be achieved with Tcpdump and Wireshark with a little extra effort.
Consider a user checking their email over POP3. First we use Tcpdump to try to capture the username and password. The terminal output below comes from the command sudo tcpdump port 110 -A. Before explaining it: this attack needs access to the network traffic, for example via a wiretap or a switch with port mirroring. Alternatively, we can see the traffic if we land a successful Man-in-the-Middle (MITM) attack.
We need sudo because packet captures require root privileges. To limit the captured and displayed packets to those exchanged with the POP3 server, we filtered on port 110, since POP3 uses port 110. Finally, to display the packet contents in ASCII we added -A.
Pentester Terminal
pentester@TryHackMe$ sudo tcpdump port 110 -A
[...]
09:05:15.132861 IP 10.20.30.1.58386 > 10.20.30.148.pop3: Flags [P.], seq 1:13, ack 19, win 502, options [nop,nop,TS val 423360697 ecr 3958275530], length 12
E..@.V@.@.g.
...
......n......"............
.;....}.USER frank
09:05:15.133465 IP 10.20.30.148.pop3 > 10.20.30.1.58386: Flags [.], ack 13, win 510, options [nop,nop,TS val 3958280553 ecr 423360697], length 0
E..4..@.@.O~
...
....n....".........?P.....
...i.;..
09:05:15.133610 IP 10.20.30.148.pop3 > 10.20.30.1.58386: Flags [P.], seq 19:43, ack 13, win 510, options [nop,nop,TS val 3958280553 ecr 423360697], length 24
E..L..@.@.Oe
...
....n....".........<-.....
...i.;..+OK Password required.
09:05:15.133660 IP 10.20.30.1.58386 > 10.20.30.148.pop3: Flags [.], ack 43, win 502, options [nop,nop,TS val 423360698 ecr 3958280553], length 0
E..4.W@.@.g.
...
......n......".....??.....
.;.....i
09:05:22.852695 IP 10.20.30.1.58386 > 10.20.30.148.pop3: Flags [P.], seq 13:28, ack 43, win 502, options [nop,nop,TS val 423368417 ecr 3958280553], length 15
E..C.X@.@.g.
...
......n......".....6......
.<.....iPASS D2xc9CgD
[...]
The unimportant packets have been removed to keep the focus on the ones that matter. The username and password were each sent in their own packet: the first explicitly shows "USER frank", and the last reveals the password "PASS D2xc9CgD".
We could achieve the same with Wireshark. In the window below we entered pop in the filter field. With only the traffic we care about shown, we can see a captured username and password.
In short, any protocol that communicates in cleartext is open to this attack. The only requirement is access to a system between the two communicating hosts. The mitigation is to add an encryption layer on top of the network protocol. In particular, Transport Layer Security (TLS) has been added to HTTP, FTP, SMTP, POP3, IMAP and many others, and for remote access Telnet has been replaced by the secure alternative Secure Shell (SSH).