Skip to main content

Network Traffic Analysis

This section will cover network traffic analysis.

Table of Contents
  • Introduction
  • The Analysis Process
  • Analysing Traffic Using Tcpdump
    • Monitoring Traffic Using Tcpdump
    • Packet Filtering Using Tcpdump
  • Analysing Traffic Using Wireshark
    • Display Filters
    • Statistics and Analyze Tabs
    • Following a Stream
    • Downloading Captured Files
    • Decrypting RDP/TLS Connections

Introduction

Knowing how to analyse network traffic can help in investigations, improve incident response, and better understand the network and any incidents that occur.

The Analysis Process

Network traffic analysis is a dynamic process that can change depending on our tools, permissions, network visibility, and more. The goal is to provide a repeatable process to use when we are performing analysis.

Before starting, we will need to define some goals and questions that we can look at when performing analysis:

  • What is the issue? i.e., Potential breach, network issues, etc.
  • What are the goals and scope? i.e., known malicious files, past 24 hours.
  • What are the targets? i.e., 192.168.1.0/24 network, HTTP protocol.

Once we defined the objectives, we will need to define the steps needed to achieve them:

  • How can we obtain the traffic?
  • What tools should be used to perform analysis?
  • How can we determine malicious traffic from normal traffic?

When performing analysis, always look for unique events, patterns, and checking host to host. Looking for unique events and patterns may reveal something that is abnormal and may prompt for a deeper look.

To effectively perform analysis, we should know our environment such as, knowing the assets, baselines, and more, placing the host to capture packets at an effective location, and persistence as issues may not always be easy to detect.

Analysing Traffic Using Tcpdump

Tcpdump is a command-line tool that can be used to sniff packets. It can directly capture and interpret data frames from a file or network interface.

As direct access is required to capture network traffic, we will usually require root privileges. This means that we will need to run tcpdump using sudo. The following command will output tcpdump version information.

sudo tcpdump --version

Monitoring Traffic Using Tcpdump

The following table will display some useful switches (options) that can be used with thetcpdump command.

SwitchDescription
-DDisplay available network interfaces to capture traffic.
-iSpecify the interface to capture traffic on. For example, tcpdump -i ens33.
-nDo not resolve hostnames.
-nnDo not resolve hostnames or well-known ports.
-eCapture the ethernet header along with upper-layer data.
-XShow the contents of packets in hex and ASCII.
-XXShow the contents of packets in hex and ASCII with the ethernet headers.
-v, vv, vvvEnable and increase the verbosity.
-cCapture a specific number of packets.
-sDefine how much of a packet to capture.
-SChange the sequence numbers from relative to absolute in the capture.
-qPrint less protocol information.
-rSpecify the pcap file to read from.
-wSpecify the file to write to.

To list available interfaces that we can capture packets from, we can use the -D switch.

sudo tcpdump -D

To listen on an interface, we can use the -i switch and specify the interface.

sudo tcpdump -i ens33

If we do not want to resolve IP address and port numbers to their hostnames and common port names (i.e., 80 > HTTP), we can use the -nn switch.

sudo tcpdump -i ens33 -nn

It is also possible to combine switches. An example will be if we want to display the ethernet headers (-e), disable resolution (-nn), and display the output in both hex and ASCII (-X), we can use the following.

sudo tcpdump -i eth0 -ennX

To read from an existing PCAP file, we can use the -r switch.

sudo tcpdump -r /path/to/file.pcap

To write the output to a file, we can use the -w switch.

sudo tcpdump -w /path/to/file.pcap

Packet Filtering Using Tcpdump

The following table are some filters that can be used with tcpdump to filter traffic.

FilterDescription
hostThis will filter visible traffic to show anything involving the designated host. It is bi-directional.
src/destThese are modifiers. It can be used to specify a source or destination host or port.
netThis filter will show any traffic with the source or destination of the specified network.
protoThis filter will display the specified protocol type.
portThis filter will display any traffic from the specified port as the source or destination. It is bi-directional.
portrangeThis filter will display any traffic from the specified port range as the source or destination.
less/greaterThis filter can be used to look for specific sizes for protocol option or packet size.
and/&&This filter can be used to concatenate two different filters together. For example, src host AND port.
orThis filter allows for a match on either two conditions. This means that any one condition just have to match.
notThis filter is used to exclude specified packets.

To filter traffic to display packets from a specified IP address, we can use the host filter.

sudo tcpdump -i <interface> host <IP Address>

An example:

sudo tcpdump -i eth0 host 10.10.1.203

To specify if the IP address is the source or destination, we can use the src or dest filter respectively.

sudo tcpdump -i <interface> src host <IP Address>

To filter for a port, we can use the port filter. Additionally, we can use the src or dest filters to specify if the port is from a source or destination.

sudo tcpdump -i <interface> <protocol> <src/dest> port <port number>

An example if we are filtering for port 80 as the source.

sudo tcpdump -i eth0 tcp src port 80

To filter for a network, we can use the net filter. Additionally, we can use the src or dest filters to specify if the network is the source or destination for a packet.

sudo tcpdump -i <interface> <src/dest> net <Network IP Address>/<CIDR>

An example if we want to view traffic from the 10.0.2.0/24 network:

sudo tcpdump -i ens33 net 10.0.2.0/24

To filter for a specific protocol, we can use the proto filter.

sudo tcpdump -i <interface> proto <protocol>

An example if we want to filter for all TCP packets. We can use either command:

sudo tcpdump -i eth0 tcp
sudo tcpdump -i eth0 proto 6

To filter for the protocol and port, we can use the following:

sudo tcpdump -i <protocol> port <port number>

To filter from a port range, we can use the portrange filter.

sudo tcpdump -i <interface> portrange <range>

An example will be filtering traffic from port 0 to 500.

sudo tcpdump -i ens33 portrange 0-500

To filter traffic with a specific packet size, we can use the less or greater filter.

sudo tcpdump -i <interface> <less/greater> <size>

An example will be filtering for packets smaller than 500 bytes.

sudo tcpdump -i ens33 less 500

To filter for traffic where it has to match two conditions, we can use the and filter.

sudo tcpdump -i <interface> <condition1> and <condition2>

An example where if we want to filter only for the IP address of 10.1.1.221 with the source port of 443.

sudo tcpdump -i eth0 host 10.1.1.221 and src port 443

To filter for traffic where we only require one condition to match, we can use the or filter.

sudo tcpdump -i <interface> <condition1> or <condition2>

To filter for traffic where we do not want a specific condition, we can use the not filter.

sudo tcpdump -i <interface> not <condition>

Analysing Traffic Using Wireshark

Wireshark allows us to analyse network traffic using a GUI. It is also able to capture traffic on different interfaces such as USB and Bluetooth and allows us to save the capture in several formats.

To start a capture, simply select the interface to capture from. To save the capture, navigate to File > save on the top left.

Wireshark uses the BPF syntax when filtering for results.

The following table will list some filters that can be used with Wireshark.

FilterDescription
host <IP address>Specify the IP address of a specific host.
net <IP address>/<CIDR>Specify a specific network.
src/dstSpecify the source or destination to filter.
port <port number>Specify the port number to display.
not port <port number>Specify to display all ports but the specified port.
andUsed to concatenate multiple filters.
portrangeUsed to filter for a specific port range.
ip/ether/tcpUsed to filter for the specified protocols from the traffic.
broadcast/multicast/unicastUsed to filter for the specified traffic.

Wireshark also have their own propriety filters called "Display Filters".

Display Filters

In Wireshark, we can also use display filters, which are specific to Wireshark. Display filters allows us to filter for specific packets or traffic. The following table will list some useful display filters.

Display FilterDescription
ip.addrUsed to filter for a specific IP address or network using CIDR.
ip.<src/dst>Used to specify if the IP address is the source or destination.
tcp.portFilter for a specific TCP port.
udp.portFilter for a specific UDP port.
tcp.srcportUsed to specify the protocol as the source port. Replace tcp with udp for UDP.
udp.dstportUsed to specify the protocol as the destination port. Replace udp with tcp for TCP.
<tcp/udp>.streamFilter for a specific stream.
and/or/notMatch multiple conditions, either one of conditions, or match all that does not equals to the specified condition.

The following table will display some operators that can be used with the display filters to perform matching.

OperatorEnglishDescription
==eqEquals to. Used to match the specified value.
!=neNot equals to. Used to match everything but the specified value.
>gtGreater than. Used to match packets greater than the specified value.
=>geGreater than or equal to. Used to match packets that is equal or greater than the specified value.
<ltLesser than. Used to match packets lesser than the specified value.
<=leLesser than or equal to. Used to match packets lesser than or equal to the specified value.

For more filters and operators, visit the official documentation.

https://www.wireshark.org/docs/wsug_html_chunked/ChWorkBuildDisplayFilterSection.html

If we want to view packets by a specific host, we can use the ip.addr filter.

ip.addr == <ip address>
ip.addr eq <ip address>

An example will be where we want to filter traffic from the IP address of 10.10.20.129.

ip.addr == 10.10.20.129

nta-wireshark-1

To filter for a specific network, we can specify the network address in CIDR notation.

ip.addr == 10.1.20.0/24

To filter for a specific port, we can use the tcp.port or udp.port filter. Additionally, we can use tcp.srcport or udp.dstport to specify if the port is the source or destination.

tcp.port == <port number>
udp.port == <port number>
udp.srcport != <port number>
tcp.dstport > <port number>

An example will be filtering for TCP port 80 as the destination.

tcp.srcport == 80

nta-wireshark-2

To match with multiple conditions, we can use and.

<condition1> and <condition2>

An example will be where we want to only display traffic to and from TCP ports 80 and 1030.

tcp.port == 80 and tcp.port == 1030

nta-wireshark-3

To match either one of multiple conditions, we can use or.

<condition1> or <condition2>

To match everything but the specified condition, we can use not.

not <condition>

Statistics and Analyze Tabs

On the top left, we can see a tab named "Statistics". This tab allows us to view statistics such as all IPv4 and IPv6 addresses captured.

nta-wireshark-4

An example will be where we want to view all IPv4 addresses captured. We hover over "IPv4 Statistics" and select "All Addresses", we can view all IPv4 addresses captured.

nta-wireshark-5

The "Analyze" tab allows us to perform actions such as following TCP streams, filter conversations, prepare new packet filters, and more.

nta-wireshark-6

Following a Stream

Following streams allows us to see the information being exchanged. To follow a stream, we can select the packet that we want to follow and either navigate to the Analyze tab > Follow or right click the packet and select "Follow".

nta-wireshark-7

An example will be following a HTTP stream.

nta-wireshark-8

We can see the entire conversation of the HTTP stream in the above screenshot with information such as the HTTP headers and the content.

To filter streams, we can use filters such as tcp.stream or udp.stream.

tcp.stream eq <stream number>

An example will be filtering for the first TCP stream.

tcp.stream eq 0

nta-wireshark-9

Downloading Captured Files

If the capture contains files such as HTML files from a website, we can download the file for further analysis by navigating to the "Files" tab > "Export Objects" and selecting the object type.

nta-wireshark-10

An example will be exporting HTTP objects.

nta-wireshark-11

We can see all the files transferred via HTTP in the above screenshot alongside other information such as the host IP address and packet number.

If files are transferred using other methods such as FTP, we search for ftp-data and follow the TCP stream. To download the file, we can set the "Show data as" to raw and click the "Save as" button.

Decrypting RDP/TLS Connections

As RDP traffic is encrypted using TLS by default, capturing the traffic with tools such as Wireshark will not yield usable information. However, if we are able to obtain the RDP key, we are able to use it in Wireshark to decrypt the traffic.

The steps shown here can also be used to decrypt similar traffic that uses TLS for encryption.

To decrypt an encrypted session with a key, we can navigate to "Edit" > "Preferences" > "Protocols" > "TLS" and click the "Edit..." button beside the RSA keys list.

nta-wireshark-12

Once in, click the "+" button at the bottom left. We will need to specify the IP address, port, protocols, and they key.

In this example, the IP address will be the RDP server, the port will be 3389 (RDP default port, change accordingly), the protocol can be blank, and the key file will be the key to use to decrypt the traffic.

nta-wireshark-13

Once done, we can save and exit by clicking the "OK" button. Once done, we can filter for the encrypted traffic again and view it. In this example, RDP.

nta-wireshark-14

From the above screenshot, we are able to view the traffic that was previously encrypted using TLS.