Dissecting network traffic

Protocol Dissectors

What sets Wireshark apart from the rest of the packet-sniffing programs is its large number of protocol dissectors. In effect, Wireshark is able to understand each major network protocol (SSH, Telnet, NTP, etc.) in depth and not only display information in a more friendly format but allow you to filter it with more options. With Wireshark, you can filter not only for web traffic,

tcp.dstport == 80 or tcp.dstport == 443

but also for specific components within an HTTP connection, such as a response code (only show 404 errors):

http.response.code == 404

Or, you can find any cookies containing the string sessionid:

http.cookie contains "sessionid"

HTTP isn't the only protocol that Wireshark understands; at last count, Wireshark had around 1,000 protocol dissectors (although not all are as complete as the HTTP protocol dissector). Unfortunately, these protocol dissectors can also be a significant problem, with around 85 vulnerabilities [4] ranging from simple denial-of-service problems to buffer overflows with code execution.

GeoIP

Wireshark now also supports GeoIP, which is a set of libraries that can be used to query the MaxMind Geographic IP database (basically a list of IPs and networks and the countries they physically reside in). For free, you can get access to the country data, which means you can create filters in Wireshark to show all traffic from a specific country,

ip an ip.geoip.country == "China"

such as China.

Build a Network Recorder

Unless you run Wireshark 24 hours a day, you will have to recreate any problems while examining the network traffic with Wireshark. Or will you?

The good news is that hard drives are ridiculously cheap now (a terabyte is less than US$ 100 for the raw disk space), and each terabyte disk means you can store 30GB per day for 30 days (more if your network is quiet on the weekends). The tshark program makes storing a ring buffer with a set amount of data (100GB worth of traffic, 2TB, etc.) very easy. The -b option

tshark -i eth0 -b filesize:10240 -b
 files:1000 -w if-eth0

monitors the interface eth0 and creates up to 1,000 files of about 10MB each (for a total of 1GB) with timestamped file names (YYYYMMDDHHMMSS):

if-eth0_00001_20090920041232
if-eth0_00002_20090920041252
if-eth0_00003_20090920041258

These files can then be merged by mergecap if traffic you are interested in spans multiple capture files. The advantage of a ring buffer is that you don't need to rotate files, and you can set a maximum amount of data capture and never worry about it accidentally filling up your hard drive.

Another way to capture network data for later analysis is to use the tcpdump tool. Recent versions of tcpdump usually support the -C option, which starts writing to a new capture file after a specified number of bytes, and the -W option, which limits the number of files created by overwriting old ones when it creates the maximum number of files (thus creating a ring buffer).

Note that you don't need to capture all network traffic to create a log that is useful for tracking down problems; simply recording DNS traffic (port 53 TCP and UDP) will help with many security incidents, such as drive-by downloads, which generate DNS queries to strange domains.

On the other hand, you can simply log outgoing port 80 traffic, which will give you a record of all requests (but not the replies, which would be significantly larger). Much like a video camera, it will not prevent security incidents, but it can give you a pretty good idea of what has happened, and with any luck, it will let you know how many systems were affected by an attack.

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Wireshark

    If you know your way around network protocols, you can get to the source of a problem quickly with Wireshark.

  • Capture File Filtering with Wireshark

    Wireshark doesn’t just work in real time. If you save a history of network activity in a pcap file using a tool such as tcpdump, you can filter the data with Wireshark to search for evidence.

  • An Essential Sys Admin and Security Tool

    Wireshark fills the gap between security and system administration for those who need to know more about what’s flowing through the wires or over the airwaves in the corporate network.

  • Wireshark's New 1.2

    Wireshark 1.2 introduces a few "new and exciting" features for its network protocol analyzer software.

  • Tshark

    The simple and practical Tshark packet analyzer gives precise information about the data streams on the network.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News