Sniffing and interpreting traffic on the network has been and always will be an integral part of a network analyst's job profile. It is not only restricted to the network analyst's profession, but it also plays a significant role in the fields of software development, network security, and digital forensics. Wireshark is the tool of choice at most workplaces and does not seem to slow down in terms of popularity and features, hence making it a "must-know" tool. This chapter gives a briefing on:
Sniffing and its purpose
Tools of the trade
Getting up and running with Wireshark
Sniffing, by definition, is using our sense of smell to savor something, like a sniff of perfume. In this case, our nose acts as a sniffer. We can perform sniffing on the network using various tools categorized as packet sniffers to capture or collect the packets flowing in our networks. They are simply a way for us to see the network traffic and bandwidth information over the entire IT infrastructure. The technique of using a packet sniffer to sniff the data flowing over the wire or through thin air (wireless) is called packet sniffing.
Packet sniffing is performed in order to better understand what flows through our networks. Just as a poison flowing through the veins of the human body has the potential to kill an individual, similarly malicious traffic traversing our networks can have a severe and sometimes irreparable effect on the network devices, performance, and business continuity.
Sniffing helps a network analyst verify whether the implementation and functionality of the network and network security devices, such as the router, switch, firewall, IDS, or IPS, are as expected and also confirms that data is traversing through secure channels of communication.
Security analysts use sniffing to gather evidence in the case of a security breach with regard to the source of the attack, time and duration of the attack, protocols and port numbers involved, and data transmitted for the purpose of the attack. It can also help to prove the use of any insecure protocol(s) used to transmit sensitive information.
As Christopher Hitchens, a British-born American author, was once quoted saying:
"That which can be asserted without evidence, can be dismissed without evidence."
Using a packet sniffer helps us get that piece of evidence.
Now, to figure out whether the smell of the perfume is pleasant, ambrosial, or reeking is the analysis part. Hence, the art of interpreting and analyzing packets flowing through the network is known as packet analysis or network analysis. Mastering this art is a well-honed skill and can be achieved if a network administrator has a solid understanding of the TCP/IP protocol suite, is familiar with packet flows, and has an excellent grasp of any sniffer of choice.
Learning technology at the packet level helps to cement the most difficult concepts. For an easy example, let's say that a user wants to browse a website named
example.com. As soon as the user enters the URL in the address bar and hits GO, the packets start to flow on the network with respect to that request. To understand this packet flow, we need to start sniffing to look at the packets in transit. The following screenshot shows the packets that traversed the network when the user opened
We can analyze the packets after capturing them using a sniffer of choice, and in our case, we notice the columns that tell us about the source and destination IP addresses, the protocol being used, the length of the individual packets, and other relevant information. We will be digging into more detailed analysis as we progress though this book.
When we talk about enterprise networks, at any given point, there is humongous amount of traffic on the wire and analyzing such traffic is not a walk in the park. This traffic may be generated by numerous network devices communicating among each other, servers responding to user requests, or making their own requests over the Internet when required, and end users trying to accomplish their day-to-day tasks at work. There is no better way to understand this flow of information than to perform a packet-level analysis and, as the famous quote about network analysis goes, packets never lie. In addition, Gerald Combs, the man behind Wireshark, once tweeted the following:
""The packets never lie" but as traffic volumes increase you end up with a trillion truths. The trick is finding the important ones."
Learning such tricks comes only with experience, as with anything else in the field of IT. As an example, if you want to improve your programming skills, you have to practice code writing day in and day out to be able to write structured and optimized pieces of code that can perform magic. The same goes for packet analysis.
Monitor and provide a detailed statistics of activities on the network
Distinguish between normal and unusual traffic
Perform network diagnostics
Identify and resolve network performance issues such as excessive bandwidth utilization
Conduct deep packet inspection
Investigate security breaches
There are numerous free and commercial packet sniffers, very often named network analyzers, in the market, and selecting the one that best meets your need is a matter of choice. There are several factors to determine this, such as the operating system in use, supported set of protocols, ease of use, customizability, and of course budget. The following are the popular ones:
Tcpdump: Tcpdump is a free and popular command-line packet capture utility, which can come in very handy in the absence of a GUI-based tool. However, even after capturing traffic via tcpdump, one can analyze and interpret the traffic using any GUI-based free or commercial tool, as it is visually easy. Refer to TCPDUMP Overview at http://www.tcpdump.org/manpages/tcpdump.1.html.
Nagios Network Analyzer and OmniPeek: These are commercial-grade network analyzers that provide organizations with packet analysis capabilities with some unique features of their own. The pricing for these products can be seen on their individual websites.
Wireshark: Wireshark, formerly known as Ethereal, is free and open source, and is the most popular packet analyzer out there. It works across multiple platforms and supports a huge set of protocol families with an easy-to-use GUI. Refer to http://wiki.wireshark.org/ProtocolReference/.
Apart from the dedicated sniffer tools we just introduced, packet sniffing capability and modules come integrated in many of the popular security-related tools, such as Snort, Metasploit, and Scapy, to name a few. Snort started off as a sniffer and later used its sniffing capabilities to develop into what we know today as the popular network intrusion prevention system (NIPS) and network intrusion detection system (NIDS) solution.
Another example is the presence of the
sniffer module in Metasploit. After successfully compromising a machine using Metasploit, one can execute this module and start sniffing traffic on that compromised box for further enumeration. Sniffing options available with Metasploit are shown as follows:
Another excellent option is using
sniff() in Scapy. Scapy is a packet manipulation tool written in Python and can be used to generate, craft, and decode packets and capture them. It is helpful in many security testing-related activities.
The focus of this book is "Wireshark". So, let's get started.
Wireshark, as discussed earlier, is the most popular packet analyzer, and there is a reason behind its huge fan following. It hosts tons of features, supports a huge list of common and uncommon protocols with an easy-to-navigate GUI, and can be easily installed and used on popular operating systems, such as Windows, Linux, and Mac OS X for absolutely no cost at all.
Wireshark can be downloaded and installed from the official website (http://www.wireshark.org). The installation setup is comparatively simple, and within a few clicks, you will be up and running with Wireshark on a Windows machine.
Installation guidelines for Windows, Unix, and Mac OS X can be found at https://www.wireshark.org/docs/wsug_html_chunked/ChapterBuildInstall.html.
As of writing this, the most recent version is Wireshark 1.12.6. Once downloaded and installed, you should be able to start Wireshark and will be presented with a screen similar to the one shown here:
This contains the default title of Wireshark along with the current version in use. To enable or disable the title, navigate to Edit | Preferences | User Interface and modify the option Welcome screen and title bar shows version to suit your requirement. To modify the title, navigate to Edit | Preferences | User Interface | Layout and enter a suitable title in the Custom window title field as shown in the following figure:
The Menu bar hosts the features of Wireshark, all categorized under suitable titles. These options will be taken up as and when required during the course of this book. As an example, you can look at the authors involved in the development of Wireshark by navigating to Help | About Wireshark and selecting the Authors tab.
This is how it will look:
The main toolbar contains the icons for more frequently used items in Wireshark. You will note that some options are grayed out. This is because not all the options are available in the current context. Once we start the capture, we will see most of them highlighted and available for use.
Filtering the traffic can help analysts find a needle in a haystack. There are two types of filtering options available in Wireshark. One is called capture filters, and the second is called display filters.
Capture filters define which frames will be captured and sent to Wireshark's capture engine for processing and later displayed in Wireshark, while display filters define which frames are displayed after they are captured. We can redefine display filters without restarting the capture, which is not the case for capture filters; hence, we need to be cautious with their usage. The Expression option on the side helps us create the filter expressions in an easy way, as there is a huge list of filters, and we don't need to waste our time memorizing them.
Wireshark aids by providing visual indicators whether or not a filter used by us is correct (accepted by Wireshark), by changing the background color to red (wrong filter expression) and to green (correct filter expression) as shown in the following screenshot:
This is the correct filter will look something like this:
You may notice that sometimes the filter shows a yellow background. This might be due to the fact that the filter expression which you entered is not working as expected. An example could be using instead of the correct filter, that is, .
Once the filter expression is ready, you can either press ENTER, or click on Apply for that filter to be applied on the selected list of packets, and you can remove the current filter expression by clicking on Clear.
After spending some time creating filters, you will notice that you are combining a lot of them using multiple
||) statements and would also want to use the same filter expression in another capture file. For this purpose, you can save your filters in Wireshark, using the Save button at the extreme right of filter toolbar.
Interface List: If you're not sure about the active interface to use for capture, selecting this option is a good choice as it gives you a complete list of the available interfaces, IP addresses in use, and the number of packets transmitted per interface. Using this information, we can easily figure out which interface to use to capture traffic.Simply the interface, and click on Start to begin the capture.
Start: This is the simplest and quickest way to start the capture if you know the network interface(s) in question. All you need to do is select the interface(s) from the available list of interfaces and click on Start.
- Here you can an individual interface to capture or Capture on all interfaces, to do exactly what it says.
By clicking on Capture Filter, you can select/create any filter before capturing begins. After this, you have some options that can be tweaked to perform unattended captures. For example, we want to create multiple files of 200 KB and stop the capture automatically after 2 minutes. The following screenshot shows how this is done:
The following are the resultant files:
For details regarding the other options on this frame please go to https://www.wireshark.org/docs/wsug_html_chunked/ChCapCaptureOptions.html.
When the reader clicks on How to Capture they will be redirected to http://wiki.wireshark.org/CaptureSetup.
When the reader clicks on Network Media they will be redirected to http://wiki.wireshark.org/CaptureSetup/NetworkMedia.
This menu provides options to:
Browse and open an already captured trace file.
Click and open any recently opened file. The number of recent files to be listed here can be modified by going to Edit | Preferences | User Interface and then editing the Maximum recent files option to the value of choice.
Download sample capture files available at the official site (http://wiki.wireshark.org/SampleCaptures).
The left side of the Status bar shows context-related information, which includes the colorized bullet indicating the current expert-info level and an option to edit or add capture comments.
The middle part shows the current number of packets and the load time.
The right side of the Status bar shows the current configuration profile in use. By default, there are three profiles present [Default, Bluetooth, and Classic], and one can always create and use new configuration profiles as required.
Select the correct interface to capture traffic. This can be done by navigating to the Menu bar and clicking on Capture | Interfaces (As a shortcut, we may choose Ctrl + I). Once we have the Wireshark: Capture Interfaces window open, perform the following steps:
Select the Internet-facing interface (for example, Wi-Fi in my case). A good indication of the active interface is the Packets and Packets/s column on the right-hand side of the window as shown in the following screenshot:
After selecting the interface, click on the Options button, as highlighted in the screenshot, and the Wireshark: Capture Options window pops up as shown in the following screenshot:
example.comloads, navigate to Wireshark, and stop the packet capture, by clicking on the Stop button in the main toolbar.
Once stopped, the capture appears as shown in the following screenshot:
In the preceding screenshot, we can see Wireshark's menu bar, main toolbar and filter toolbar followed by three different panes and the Status bar. The three panes are as follows:
Packet List pane: This pane reflects the packets captured by Wireshark and some basic details about those packets. For example, the first packet in our capture is an SYN packet of the three-way handshake from the client to the server.
Packet Details pane: If we select any packet in the Packet List pane, its details are shown under this pane. For example, after selecting the first packet in our capture, we can look at the packet at a more granular level, that is, the changes it undergoes at different layers of networking (for example, source and destination ports under the Transmission Control Protocol (TCP), that is, the Transport layer of the TCP/IP model).
This pane shows the protocols and protocol fields in a tree format and also displays any links when the current packet in question has a relationship to another packet in the same capture (for example, a request and response relationship for a single communication).
The final step is to save the captured packets. We can do this by navigating to the menu bar, clicking on File | Save and saving it with an appropriate name in the directory of your choice.
Congratulations! With this, we have successfully captured and saved our first trace file.
In this chapter, we went over the foundations of sniffing and its practical importance in the real world, the different tools available at our disposal to perform sniffing, and understanding the Wireshark GUI to quickly get started with sniffing and perform our first packet capture. We shall begin the analysis part in the next chapter.