Lab - Using Network Sniffers
Scenario
In this lab, you will learn about and use network sniffers to analyze network traffic for security issues, such as weak protocols or the occurrence of malicious activity.
You are a network and security analyst. You need to understand how to capture network traffic and perform network analysis on the captured communications.
- First, you will capture network traffic with
tcpdump. This includes displaying captured data, controlling name lookups during capture, using capture filters, and saving capture into a file. - Finally, you will use Wireshark to analyze a tcpdump pcap file. This includes using display filters, following TCP streams, following FTP streams, and searching for string content in the capture.
Your cybersecurity analyst (CySA) workstation, running Kali Linux, is located in Structureality’s server subnet.
Understand your environment
You will be working from a virtual machine named KALI hosting Kali Linux connected to the internal server subnet. You will also use a virtual machine named PC10 hosting Windows Server 2019 (being used as a client) to initiate traffic to be captured.
Steps
1. Capture network traffic with tcpdump
As the cybersecurity analyst, you have been tasked with capturing network traffic for later analysis. You elect to use tcpdump to perform the traffic capture. You will initially perform a few trials to verify the capture process is working as expected, next you will capture traffic related to port 80, then you will capture FTP traffic.
-
Connect to the KALI virtual machine and sign in as root using
Pa$$w0rdas the password. -
Open a Terminal window and then maximize the Terminal window.
-
Enter
service vsftpd startto initiate the VSFTPD service.- The VSFTPD service is not a standard element of Kali. However, it has been installed in this Kali instance as an example of a malware delivery mechanism (i.e., an attack vector). It is being started now for use later in this exercise.
-
Confirm that tcpdump is already installed.
which tcpdump- This command should display
/usr/bin/tcpdump, which confirms that tcpdump is already installed.
-
Display a list of available interfaces that tcpdump can capture from.
- Run the following command to display interface options:
tcpdump -D - This command produces a list of available interfaces. The interface eth0 is the interface you will be using to capture traffic.
- Run the following command to display interface options:
-
Use tcpdump to capture 100 packets, display summary information to the screen, then terminate the capture automatically.
- Run the following command to capture 100 packets:
tcpdump -i eth0 -c 100 - This command will only capture 100 packets before terminating the capture. It will display summary information for each packet captured to the screen. When finished, it will indicate that 100 packets were captured.
- This operation may only take a few seconds, or if there is little network traffic, it may take a minute or so. You could generate traffic by opening Firefox, or if the capture takes more than 2 minutes, terminate the operation using CTRL+C.
- Run the following command to capture 100 packets:
-
Notice that the default of tcpdump is to resolve IP addresses into hostnames or FQDNs and resolve common port numbers into protocol names/acronyms.
-
Perform a traffic capture of 100 packets but disable name and port resolution.
- Run the following command to disable name and number resolution:
tcpdump -i eth0 -c 100 -nn - This command will only capture 100 packets before terminating the capture. It will display summary information for each packet captured to the screen. When finished, it will indicate that 100 packets were captured.
- This operation may only take a few seconds, or if there is little network traffic, it may take a minute or so. You could generate traffic by opening Firefox , or if the capture takes more than 2 minutes, terminate the operation using CTRL+C.
- Run the following command to disable name and number resolution:
-
Notice that without name and number resolution, the output information is more compact and may be easier to read.
-
Use tcpdump to capture up to 100 packets of only ICMP traffic and perform 25 pings against 10.1.16.1 from another Terminal window.
- 10.1.16.1 is the IP address of the DC10 system, which is the domain controller for the local network.
- Run the following command to capture only ICMP traffic:
tcpdump -i eth0 -c 100 icmp - This command will only capture 100 ICMP packets before terminating the capture. It will display summary information for each packet captured to the screen. When finished, it will indicate that 100 packets were captured.
- On the Kali Linux toolbar (located at the top of the screen by default), select the Terminal Emulator. This icon looks like a black computer screen with a cursor.
- In this additional Terminal window, run the following command to ping 10.1.16.1:
ping 10.1.16.1 -c 50 - Minimize the Terminal window where ping is operating by selecting Minimize on the Terminal window’s header. The Minimize icon is a line, but it is just a black circle until your mouse cursor is over it. It is the second to the left from the X close icon.
- The Terminal window running tcpdump should now be displayed.
- Look over the displayed ICMP packets as they are captured by tcpdump.
- If the capture of ICMP has not already ended, terminate it by pressing CTRL+C in your keyboard.
-
Capture into a file named
juiceshop-web.pcapindefinite traffic related to port 80. Use Firefox to generate traffic by visiting juiceshop.local, and then select Account, then select Login on that website. Attempt to log in using the credentials ofjaime@structureality.comandPa$$w0rd. Then terminate the capture.- Run the following command to capture port 80 traffic:
tcpdump -i eth0 port 80 -w juiceshop-web.pcap - This command will capture packets related to port 80 and store them in the juiceshop-web.pcap file.
- Launch the Firefox browser by selecting the Firefox ESR icon in the Kali top icon menu. It looks like an orange fox curled around a globe.
- In the Firefox address bar, enter juiceshop.local.
- From this web site, select the Account menu item, and then select Login from the drop-down menu.
- Enter
jaime@structureality.comandPa$$w0rdinto the Email and Password fields, respectively.- Ignore the Firefox warning of “This connection is not secure. Logins entered here could be compromised.”.
- Select Log in.
- The website will indicate that you provided “Invalid email and password”.
- Close Firefox.
- The Terminal window running tcpdump should now be displayed.
- Notice that no information was displayed on the screen related to this capture. This is because all output was redirected to be saved into a file.
- Terminate the capture by pressing CTRL+C on your keyboard.
- You should see a summary of the number of packets captured.
- Run the following command to capture port 80 traffic:
-
Initiate a network traffic capture into a file named pc10-ftp.pcap of indefinite traffic.
- Run the following command to capture FTP traffic:
tcpdump -i eth0 -w pc10-ftp.pcap- During development, we could not get a capture filter for FTP and FTP-DATA to work reliably. So, instead of the command tcpdump -i eth0 port FTP or port FTP-DATA -w pc10-ftp.pcap, you will capture all traffic and use a display filter to view FTP and FTP-DATA.
- This command will capture packets related to FTP and store them in the pc10-ftp.pcap file.
- Run the following command to capture FTP traffic:
-
Connect to the PC10 virtual machine, send Ctrl+Alt+Delete and sign in as
jamieusingPa$$w0rdas the password. -
Use WinSCP to connect to FTP on 10.1.16.66 (i.e., the Kali VM) using the credentials of
kaliandPa$$w0rd. Then transfer the file to PC10 of/Downloads/515web.ca.issuing.cert.pem.- Double-click to open WinSCP from the desktop.
- Select the File protocol: pull-down list, then select FTP.
- Enter
10.1.16.66in the Host name: field. - Enter
kaliin the User name: field. - Enter
Pa$$w0rdin the Password: field. - Select Login.
- You should now see the directories from the Kali user’s home directory displayed in the right pane.
- In the right pane, double-click to open Downloads.
- Right-click 515web.ca.issuing.cert.pem, then select Download from the pop-up menu.
- On the Download window that appears, select OK.
- The 515web.ca.issuing.cert.pem file should now appear in the left pane (i.e., downloaded to the Documents folder on PC10).
-
Switch back to KALI virtual machine and if needed sign in as root using
Pa$$w0rdas the password. -
Terminate the tcpdump capture.
-
Close all windows.
2. Use Wireshark to analyze pcap files
As the cybersecurity analyst, you have been tasked with analyzing the previously capturing network traffic. You will use Wireshark to evaluate the network traffic captures into the .pcap files. You must look for insecure protocols and risky/suspicious/malicious activity. You will first assess a capture of web traffic and then a capture of FTP traffic.
Info
In this lab, you performed suspicious activities that generated network traffic captured by tcpdump. You will now analyze those captures to find the vulnerable protocols and suspicious activities. In a real-world situation, you would not necessarily already know the specific protocols, activities, or keywords to look for to find a specific instance of concern. Instead, you would have a range of protocols and search values to use to attempt to find something of interest in a capture.
-
Connect to the KALI virtual machine and if needed sign in as root using
Pa$$w0rdas the password. -
Launch Wireshark and maximize the window.
-
Set the Wireshark layout to the three stacked panes.
-
Import the juiceshop-web.pcap file into Wireshark.
- From the Wireshark menu, select File, then select Open.
- On the Wireshark - Open Capture File window, scroll down the listing of directories and file contained in the
/rootdirectory to locatejuiceshop-web.pcap. - Select
juiceshop-web.pcap, then select Open. - The contents of the capture should be displayed in Wireshark.
-
With the pcap file loaded, create a display filter that shows captured frames which have a TCP header length above 35 bytes.
- Remove any existing display filter by selecting the Clear display filter button on the far right of the display filter field. This button looks like a capital X and will turn red when your mouse cursor hovers over it.
- Select the Apply a display filter field and type in
tcp.hdr_len>35 - While still in the display filter field, press Enter on your keyboard or select the Apply display filter button on the far-right end of the field, which looks like an arrow pointing to the right.
-
Now, the displayed captured frames are those with a TCP header length above 35 bytes. If your display does not show any frames, alter the number from 35 to 30, and then if needed to 25 or even 20.
-
Use the Display Filter Expression syntax window to create a display filter to display only TCP packets with the PUSH flag set.
- Select the Clear display filter button.
- The display filter express interface is accessed by selecting Analyze from the Wireshark menu, and then selecting Display Filter Expression.
- It can take up to 10 seconds for the Wireshark - Display Filter Expression window to appear.
- Notice the massive list of protocols with expandable content listed in the Field Name area.
- In the Search: field (located at the bottom of the window), enter tcp.
- This search term will reduce the number of protocols in the Field Name area significantly, but you will still need to scroll to visually locate and then select TCP - Transmission Control Protocol.
- Select the arrow to the left of the TCP entry to expand its contents.
- Scroll down to locate and select tcp.flags.push.
- Verify that the Relation field has highlighted the double-equals relation (
==), the Value (Boolean) is set to 1, and the Predefined Values is set to Set. - At the bottom of the Display Filter Expression window is the constructed filter field. It should be displaying
tcp.flags.push == 1. - Select OK to insert the constructed filter into the display filter field.
- Press Enter on your keyboard or select the Apply display filter button on the far-right end of the field, which looks like an arrow pointing to the right.
-
The displayed frames should all have the TCP header PUSH flag set.
-
Manually edit the display filter to display frames with ACK set but not SYN set.
- Select the display filter field and select the blank area to the right of the current filter to place the cursor at the end of the current filter.
- Use backspace to remove
push == 1. - Then enter
ack == 1 and tcp.flags.syn == 0. - The resultant display filter should be
tcp.flags.ack == 1 and tcp.flags.syn == 0. - Press Enter on your keyboard or select the Apply display filter button on the far-right end of the field, which looks like an arrow pointing to the right.
-
The displayed frames will be those with the ACK flag set but without the SYN flag set.
- These tasks of creating and modifying display filters are to demonstrate that you can type in display filters manually, craft them using the Display Filter Expression tool, combine multiple conditions with logical expressions (i.e., AND (or &&) and OR), and edit existing filters directly in the display filter field.
-
Use a Wireshark display filter to display only captured frames that include the IPv4 address of 10.1.16.66 as a source.
- Select the Apply a display filter field and enter
ip.src==10.1.16.66. - While still in the display filter field, press Enter on your keyboard or select the Apply display filter button on the far-right end of the field, which looks like an arrow pointing to the right.
- Select the Apply a display filter field and enter
-
You should now see a display of the captured frames that include the IPv4 address of 10.1.16.66 as the source in the IPv4 header.
Info
You notice that there are several communications from the client’s IP address that are related to web communications - namely, the HTTP packets. You want to discover the URL of the website that the client is visiting, so you elect to implement a display filter for only HTTP GET requests.
-
Add to the current display filter to show captured frames that have an HTTP GET payload from this client.
- Type in a space followed by
and http contains 474554- The payload value of “GET” is represented in HEX as 474554. 0x47 is the HEX value of the ASCI character of “G”, 0x45 is “E”, and 0x54 is “T”. You can consult an ASCII to HEX table or use an online conversion calculator to determine the HEX sets for other key terms.
- Type in a space followed by
-
The results displayed in the Wireshark interface should be only HTTP protocol packets with a payload that includes the “GET” statement from the client.
-
Look over the HTTP GET statements in the Info column. Notice a packet containing “GET / HTTP/1.1”. Select that packet.
- should be the first packet or appear very early
-
Determine the plaintext URL visited by the client system
- Select the arrow to the left of Hyptertext Transfer Protocol to expand its details.
- Scroll down to view the line of
[Full request URI: http://juiceshop.local/].
-
Search for a login event to see if plaintext credentials were captured.
- Alter the capture filter to search for an HTTP packet containing a POST statement. The resultant display filter should be:
ip.src==10.1.16.66 and http contains 504f5354- The payload value of “POST” is represented in HEX as 504f5354.
- While still in the display filter field, press Enter on your keyboard or select the Apply display filter button on the far-right end of the field, which looks like an arrow pointing to the right.
- There should be one or more packets shown as a result. Inspect the Packet Bytes pane of each to find the POST statement with credentials.
- You should see the following content in one of the POST packets:
{"email";"jaime@structureality.com","password";"Pa$$w0rd"}
- Alter the capture filter to search for an HTTP packet containing a POST statement. The resultant display filter should be:
-
Perform follow HTTP Stream analysis on the packet containing plaintext credentials to determine if the credentials were accurate.
- In the Packet List pane, select the frame/packet that contains the plaintext credentials.
- Select Analyze from the menu, select Follow, and then select HTTP Stream.
- The Follow HTTP Stream window opens.
- Notice the presentation of the HTTP segments are color coordinated with red for client and blue for server and presented in communication or chronological order.
- Scroll down the display to determine the final result of the login event.
- Close the HTTP Stream window
-
Import the
pc1-ftp.pcapfile into Wireshark. -
Remove any existing display filter.
-
Create a display filter to view only FTP traffic.
- Enter
ftp or ftp-data
- Enter
-
Determine the source and destination IP addresses of the FTP communication. Then type them into the FTPClient and FTPServer fields below:
- FTPClient:
- FTPServer:
- Locate a frame/packet with an Info value of Request, then select that packet.
- The Source column shows the IP address of the FTP client and the Destination column shows the IP address of the FTP server.
-
Locate the frames containing the credentials of the FTP user.
- Locate the frame with an Info value of USER to determine the username.
- Locate the frame with an Info value of PASS to determine the password.
-
Locate the FTP-DATA packet containing a transferred file, save a copy of the file to the original filename, then view the contents of the saved file.
- Alter the display filter to be ftp-data, then press Enter to apply the display filter.
- There should be multiple packets displayed with a Protocol value of FTP-DATA.
- Select any of the packets, then in the Packet Details pane, expand the Line-based text data to view the related file object names.
- Locate a packet with a file name value of 515web.ca.issuing.cert.pem. This is the original filename.
- Locate the next FTP-DATA packet. This packet is the start of the transfer of the file’s contents.
- Right-click this packet in the Packet List pane, then select Follow, then select TCP Stream.
- On the Follow TCP Stream window, locate the Show data as value near the bottom, then select the pull-down list currently showing ASCII, then select Raw.
- Select Save as.. from the bottom of the Follow TCP Stream window.
- On the Save Stream Content As… window, type 515web.ca.issuing.cert.pem into the Name: field.
- Notice that the save destination directory is the home folder for root (i.e., /root).
- Select Save at the bottom right of the Save Stream Content As… window.
- Close the Follow TCP Stream window.
- Switch to the Terminal window. Or open one if needed.
- Enter
less 515web.ca.issuing.cert.pemto view the contents of the exported file.
You exported the certificate file. Done.