Module 05 - Network Traffic
Module 05 - Network Traffic
TCPDUMP
What is TCPDUMP?
www.cybexer.com 2
TCPDUMP
Tcpdump installation
www.cybexer.com 3
TCPDUMP
Happy tcpdumping
www.cybexer.com 4
TCPDUMP
Verify version of tcpdump on your system
• tcpdump --version
www.cybexer.com 5
TCPDUMP
Capture traffic on lowest numbered network interface
• tcpdump
www.cybexer.com 6
TCPDUMP
Based on '-D' interface output, you can use interface
number. In this example we will capture traffic on
'loopback' interface (order number 2)
• tcpdump -i 2
www.cybexer.com 7
TCPDUMP
Capture traffic on 'eth0' network interface
• tcpdump -i eth0
www.cybexer.com 8
TCPDUMP
Do not translate IP/ports to names
• tcpdump -n
www.cybexer.com 9
TCPDUMP
Generate more verbose output
• tcpdump -v
www.cybexer.com 10
TCPDUMP
Capture all traffic to and from specified host
• tcpdump host <hostname/ip>
www.cybexer.com 11
TCPDUMP
Capture all traffic to specified host
• tcpdump dst host 192.168.114.33
www.cybexer.com 12
TCPDUMP
Capture all traffic from specified host
• tcpdump src host 192.168.114.33
www.cybexer.com 13
TCPDUMP
Capture all traffic to and from whole network
• tcpdump net 192.168.113.0/24
www.cybexer.com 14
TCPDUMP
Tcpdump allows to specify protocol name for capturing
packets
• tcpdump tcp
www.cybexer.com 15
TCPDUMP
To capture IPv6 traffic, use 'ip6' protocol
• tcpdump ip6
www.cybexer.com 16
TCPDUMP
Capture only UDP packets
• tcpdump udp
www.cybexer.com 17
TCPDUMP
Capture all packets on specified port. This will capture
all protocols on port 53
• tcpdump port 53
www.cybexer.com 18
TCPDUMP
Capture all packets except specified port
• tcpdump not port 53
www.cybexer.com 19
TCPDUMP
Capture only packets to specified destination port
• tcpdump dst port 80
www.cybexer.com 20
TCPDUMP
By default, tcpdump prints timestamp for each
captured packet. To turn off displaying timestamps, use
'-t' option
• tcpdump -t
www.cybexer.com 21
TCPDUMP
Print UNIX timestamp for each captured packet
• tcpdump -tt
www.cybexer.com 22
TCPDUMP
Print time difference in microseconds between current
and previous packets
• tcpdump -ttt
www.cybexer.com 23
TCPDUMP
Print full data and time for each captured packet
• tcpdump -tttt
www.cybexer.com 24
TCPDUMP
Print time difference between first captured packet and
each packet
• tcpdump -ttttt
www.cybexer.com 25
TCPDUMP
Print captured packets in ASCII format
• tcpdump -A
www.cybexer.com 26
TCPDUMP
Print captured packets in HEX format
• tcpdump -x
www.cybexer.com 27
TCPDUMP
Print captured packets in ASCII and HEX format
• tcpdump -X
www.cybexer.com 28
TCPDUMP
Capture specified number of packets. This example will
capture 3 packets (based on matching filter) and then
stop tcpdump
• tcpdump -c 3
www.cybexer.com 29
TCPDUMP
Sometimes it's important to save captured packets for
later analysis or sharing with other security team
members. Saving captured packets to the file is done
with '-w' option followed by filename, where packets
will be saved
• tcpdump -w capture_01.pcap
www.cybexer.com 30
TCPDUMP
Reading saved network traffic from the file is used with
'-r' option followed by file name
• tcpdump -r capture_01.pcap
www.cybexer.com 31
TCPDUMP
By default, tcpdump is not showing ethernet header
information.
To print ethernet header details (MAC addresses) use '-
e' option
• tcpdump -e
www.cybexer.com 32
TCPDUMP
Advanced commands
www.cybexer.com 33
TCPDUMP
Display traffic for specified port ranges
• tcpdump portrange 81-83
www.cybexer.com 34
TCPDUMP
To display traffic based on its direction, use '-Q' option
followed by 'in' or 'out'
• tcpdump -Q in
www.cybexer.com 35
TCPDUMP
Being able to do these various things individually is
powerful, but the real magic of tcpdump comes from
the ability to combine options in creative ways in order
to isolate exactly what you’re looking for
logical AND - && or and
logical OR - || or or
EXCEPT - not or !
www.cybexer.com 36
TCPDUMP
Display traffic only to specified host and port
• tcpdump dst host 192.168.114.33 and dst port 22
www.cybexer.com 37
TCPDUMP
Display traffic only to specified host and port
• tcpdump host 192.168.114.33 or host
192.168.113.33
www.cybexer.com 38
TCPDUMP
Display traffic only to specified host and excluding port
22 (ssh)
• tcpdump host 192.168.114.33 and not port ssh
www.cybexer.com 39
TCPDUMP
It is important to pay attention when combining
different filters.
For example, we want to capture all traffic except TCP
and UDP. This example is not correct 'tcpdump not tcp
or udp', because it will capture UDP traffic.
To make correct filter for capturing all traffic except TCP
and UDP, we have to use brackets
• tcpdump 'not (tcp or udp)'
Complex filters with brackets must be singlequoted
www.cybexer.com 40
TCPDUMP
Another example of grouping capture filters.
Capture traffic from hosts 192.168.114.33 or
192.168.113.33, except TCP for port 443
• tcpdump '(host 192.168.114.33 or host
192.168.113.33) and not (tcp and dst port 443)'
www.cybexer.com 41
TCPDUMP
Let's capture FTP packets from 192.168.114.33 to
192.168.113.109
• tcpdump 'src host 192.168.114.33 and dst host
192.168.113.109 and port ftp'
www.cybexer.com 42
TCPDUMP
Grep command can be used along with tcpdump to
search the network traffic
• tcpdump -n -A | grep -e 'GET'
www.cybexer.com 43
TCPDUMP
Read traffic based on filter in file
• tcpdump -F <filter_file>
www.cybexer.com 44
TCPDUMP
Advanced usage
Use brackets
• tcpdump -i eth0 '( filter and (filter or filter))'
www.cybexer.com 45
TCPDUMP
Advanced usage
www.cybexer.com 46
TCPDUMP
Advanced usage
www.cybexer.com 47
TCPDUMP
Advanced usage
Combine filters
• tcpdump '(port 80 or port 443) and host
192.168.1.1'
VS
• tcpdump '(dst port 80 or dst port 443) and dst host
192.168.1.1'
www.cybexer.com 48
TCPDUMP
Advanced usage
www.cybexer.com 49
TCPDUMP
Advanced usage
Task 1 - tcpx_04.pcap
www.cybexer.com 50
TCPDUMP
Advanced usage
Task 1 - tcpx_04.pcap
www.cybexer.com 51
TCPDUMP
Advanced usage
www.cybexer.com 52
TCPDUMP
Advanced usage
TCPXTRACT'ing data
• tcpxtract -f <capture.file> -o </output/folder/>
www.cybexer.com 53
TCPDUMP
Advanced usage
FOREMOST'ing data
• foremost -i <capture.file> -o </output/folder/>
www.cybexer.com 54
TCPDUMP
Advanced usage
URLSNARF'ing data
• urlsnarf -n -p <capture.file>
www.cybexer.com 55
TCPDUMP
Advanced usage
HTTPRY'ing data
• httpry -r <capture.file>
www.cybexer.com 56
TSHARK
TSHARK
What is TSHARK?
www.cybexer.com 58
TSHARK
Basic usage
www.cybexer.com 59
TSHARK
Basic usage
www.cybexer.com 60
TSHARK
Basic usage
www.cybexer.com 61
TSHARK
Basic usage
www.cybexer.com 62
TSHARK
Basic usage
HTTP filters
http.authorization http.host
http.referer http.request.method
http.request.uri http.response.code
http.user_agent
www.cybexer.com 63
TSHARK
Basic usage
www.cybexer.com 64
TSHARK
Basic usage
www.cybexer.com 65
TSHARK
Basic usage
www.cybexer.com 66
TSHARK
Basic usage
www.cybexer.com 67
TSHARK
Basic usage
www.cybexer.com 68
TSHARK
Basic usage
www.cybexer.com 69
TSHARK
Basic usage
www.cybexer.com 70
TSHARK
Basic usage
www.cybexer.com 71
TSHARK
Basic usage
More to come
www.cybexer.com 72
TSHARK
Basic usage - statistics
www.cybexer.com 73
TSHARK
Basic usage - statistics
www.cybexer.com 74
TSHARK
Basic usage - statistics
www.cybexer.com 75
TSHARK
Basic usage - statistics
www.cybexer.com 76
TSHARK
Basic usage - statistics
www.cybexer.com 77
TSHARK
Basic usage - statistics
www.cybexer.com 78
TSHARK
Basic usage - statistics
www.cybexer.com 79
TSHARK
Basic usage - statistics
www.cybexer.com 80
TSHARK
Basic usage - statistics
www.cybexer.com 81
TSHARK
Basic usage - statistics
www.cybexer.com 82
Wireshark
Wireshark
What is Wireshark?
www.cybexer.com 84
Wireshark
What can Wireshark do?
www.cybexer.com 85
Wireshark
Wireshark has 4 phases of packet analysis
• capture
• decode
• display
• analyze
www.cybexer.com 86
Wireshark
Some issues
• XKeyboard extension not present on the X server
Install wireshark-gtk package
• apt-get install wireshark-gtk
www.cybexer.com 87
Wireshark
Run 'wireshark' from terminal
Type in 'wireshark' in
search form
www.cybexer.com 88
Wireshark
www.cybexer.com 89
Wireshark
Capture network traffic by double-clicking proper
interface on 'welcome screen'
www.cybexer.com 90
Wireshark
Or select required interface from 'Capture' menu, then
'Options' and click 'Start'
www.cybexer.com 91
Wireshark
Main working window
www.cybexer.com 92
Wireshark
Packet list - list of captured packets, each line is a single
packet. Shows time, source, destination, protocol,
length of packet and additional information about the
packet
Columns can be adjusted later in Preferences
www.cybexer.com 93
Wireshark
Packet details - shows detailed view of selected packet
from 'packet list'
www.cybexer.com 94
Wireshark
Packet bytes - displays selected packet in hexadecimal
and binary view
www.cybexer.com 95
Wireshark
Layout of main window can be changed in Preferences
menu
www.cybexer.com 96
Wireshark
By default, 'Time' column shows time from beginning
of packet capture, which not suitable for off-line
network captures
To change time format right click on 'Time' column and
select 'Edit Column'
www.cybexer.com 97
Wireshark
Change 'Time' format from drop-down menu to
required value
www.cybexer.com 98
Wireshark
Select 'UTC date, as YYYY-MM-DD, and time' and click
'OK', to save and apply new time format
www.cybexer.com 99
Wireshark
New 'Time' format is applied
www.cybexer.com 100
Wireshark
Configuring columns in 'Packet list' view
Navigate to Edit->Preferences->Columns and
click '+' button
www.cybexer.com 101
Wireshark
Set new column's 'Title' to 'Dest Port'
Set new column's 'Type' to 'Dest Port (unresolved)'
Drag new column 'Dest Port' after 'Destination' and
click 'OK' to save and apply changes
www.cybexer.com 102
Wireshark
'Displayed' check box allows to disable/enable columns
in 'Packet list'
www.cybexer.com 103
Wireshark
'Packet list' view should now have new
column 'Dest Port' set
www.cybexer.com 104
Wireshark
Overview of OSI (Open System Interconnection) layers
www.cybexer.com 105
Wireshark
OSI Layer mnemonics
www.cybexer.com 106
Wireshark
Application Layer (Layer 7)
www.cybexer.com 107
Wireshark
Presentation Layer (Layer 6)
www.cybexer.com 108
Wireshark
Session Layer (Layer 5)
www.cybexer.com 109
Wireshark
Transport Layer (Layer 4)
www.cybexer.com 110
Wireshark
Network Layer (Layer 3)
www.cybexer.com 111
Wireshark
Data Link Layer (Layer 2)
www.cybexer.com 112
Wireshark
Physical Layer (Layer 1)
Copper cables
Fiber cables
Wireless
www.cybexer.com 113
Wireshark - capture filters
Capture filters: Applied prior to capture to only display
a certain type of traffic
www.cybexer.com 114
Wireshark - capture filters
By default Wireshark will capture all traffic on selected
network interface. To capture only needed traffic it is
advised to set capture filters.
In main Wireshark window, navigate to 'Capture' menu
and select 'Options...'
www.cybexer.com 115
Wireshark - capture filters
At the bottom of 'Capture Options' screen you will see
place for capture filters
www.cybexer.com 116
Wireshark - capture filters
Wireshark has smart capture filter parser, which will
highlight input field red if capture filter syntax is
incorrect
www.cybexer.com 117
Wireshark - capture filters
www.cybexer.com 118
Wireshark - capture filters
Capture all traffic except traffic to and from 10.3.1.1
• not host 10.3.1.1
www.cybexer.com 119
Wireshark - capture filters
Capture traffic to and from 10.3.1.1 and any host it is
communicating with and traffic to and from 10.3.1.2
and any host it is communicating with
• host 10.3.1.1 or host 10.3.1.2
www.cybexer.com 120
Wireshark - capture filters
Capture traffic to/from any host on network 10.3.0.0
• net 10.3.0.0/16
www.cybexer.com 121
Wireshark - capture filters
Capture all traffic except traffic to an IP address starting
with 10.3
• not dst net 10.3.0.0/16
www.cybexer.com 122
Wireshark - capture filters
Capture based on MAC addresses
www.cybexer.com 123
Wireshark - capture filters
Capture based on ports
Capture UDP/TCP traffic to or from port 53 (typically
DNS traffic)
• port 53
Capture all UDP/TCP traffic except traffic to or from
port 53
• not port 53
Capture UDP/TCP traffic to or from port 80 (typically
HTTP traffic)
• port 80
www.cybexer.com 124
Wireshark - capture filters
Capture based on ports
Capture UDP traffic to or from port 67 (typically DHCP
traffic)
• udp port 67
Capture TCP traffic to or from port 21 (typically the
FTP command channel)
• tcp port 21
Capture UDP/TCP traffic to or from ports from 1 through 80
• portrange 1-80
Capture TCP traffic to or from ports from 1 through 80
• tcp portrange 1-80
www.cybexer.com 125
Wireshark - capture filters
Combining ports
Capture all UDP/TCP traffic to or from port 20 or port
21 (typically FTP data and command ports)
• port 20 or port 21
Capture UDP/TCP traffic to or from port 80 that is being
sent to or from 10.3.1.1
• host 10.3.1.1 and port 80
Capture UDP/TCP traffic to or from 10.3.1.1 except
traffic to or from port 80
• host 10.3.1.1 and not port 80
www.cybexer.com 126
Wireshark - capture filters
Combining ports
Capture all UDP traffic from port 68 to port 67 (typically
traffic sent from a DHCP client to a DHCP server)
• udp src port 68 and udp dst port 67
www.cybexer.com 127
Wireshark - capture filters
ICMP traffic
Capture all ICMP packets
• icmp
Capture all ICMP Type 8 (Echo Request) packets
• icmp[0]=8
Capture all ICMP Type 8 (Echo Request) packets or
ICMP Type 0 (Echo Reply) packets
• icmp[0]=8 or icmp[0]=0
www.cybexer.com 128
Wireshark - capture filters
Capture filter expressions can be strung together using
logical operators
• and (&&)
• or (||)
• not (!)
www.cybexer.com 129
Wireshark - capture filters
Let's build a capture filter which will capture only traffic
to and from private networks
www.cybexer.com 130
Wireshark - capture filters
Capture filter where source is private network
• src net (10.0.0.0/8 or 172.16.0.0/12 or
192.168.0.0/16)
www.cybexer.com 131
Wireshark - capture filters
Now combine capture filter for private network sources
and destinations
src net (10.0.0.0/8 or 172.16.0.0/12 or
192.168.0.0/16) and dst net (10.0.0.0/8 or
172.16.0.0/12 or 192.168.0.0/16)
www.cybexer.com 132
Wireshark - capture filters
Now Wireshark will only capture traffic which is either
to or from any private network address
www.cybexer.com 133
Wireshark - display filters
Display filters: Used during an active capture or on a
pre-captured packet. Display filters are entered in main
Wireshark's windows field 'Apply a display filter'
www.cybexer.com 134
Wireshark - display filters
Wireshark has smart display filter parser, which will
highlight input field red if display filter syntax is
incorrect
www.cybexer.com 135
Wireshark - display filters
Display only IPv4 traffic to and from specified network range or single
IP address
• ip.addr == 192.168.0.0/16
• ip.addr == 172.28.28.1
www.cybexer.com 136
Wireshark - display filters
Display only IPv6 traffic to and from specified IP address or network
range
• ipv6.addr == 2604:a880:800:c1::2ae:d001
• ipv6.addr == 2604:a880:800:c1::2ae:d000/64
www.cybexer.com 137
Wireshark - display filters
You can filter traffic by MAC address
Dispaly packets where specified MAC address either source
or destination
• eth.addr == 64:76:ba:a1:25:46
www.cybexer.com 138
Wireshark - display filters
Show traffic whose source or destination port is a specific
port
• tcp.port == 25
www.cybexer.com 139
Wireshark - display filters
For the application protocols of HTTP, DNS, SSH, FTP, SMTP, RDP,
SNMP, RTSP, GQUIC, CDP, LLMNR, SSDP there are filters that are
called like the protocols themselves, but are written in small
letters
To display packets with HTTP traffic
• http
www.cybexer.com 140
Wireshark - display filters
Remember that when deciding which protocol the
transmitted data belongs to, the program considers the
used port number. If a non-standard port is used, the
program will not be able to find the necessary data. For
example, if you connect to SSH on port 1234, the ssh
filter will not find SSH traffic
www.cybexer.com 141
Wireshark - display filters
In main Wireshark window navigate to 'Edit' and
'Preferences'
www.cybexer.com 142
Wireshark - display filters
Open 'Protocols' option and find 'SSH'
www.cybexer.com 143
Wireshark - display filters
Filters can have different values, for example, it can be
a string, a hexadecimal format or a number. For that
purposes Wireshark allows to use operators
Equals
• == or eq
Not equal
• != or ne
www.cybexer.com 144
Wireshark - display filters
Greater than
• > or gt
Less than
• < or lt
www.cybexer.com 145
Wireshark - display filters
Logical operators allow you to create detailed filters using
several conditions at once. It is recommended to use
brackets additionally, because otherwise you may not get
the result you expect.
www.cybexer.com 146
Wireshark - display filters
Logical AND, data is output if they match to both parts
of the filter. For example, the ip.src==192.168.1.1 and
tcp filter will show only packets that originate from
192.168.1.1 and which are associated with the TCP
protocol. Only data matching both conditions will be
displayed
• && and
www.cybexer.com 147
Wireshark - display filters
Boolean is NOT used when we want to exclude some
packages. That is, all packets will be shown, except
those that satisfy the condition following the NOT. For
example, the filter !dns will show all packets except
DNS
• ! not (negate)
www.cybexer.com 148
Wireshark - display filters
Combining all together:
Show HTTP or DNS traffic
• http or dns
Show traffic with source IP address 192.168.0.105 and UDP port 53 or TCP
port 80
• ip.src==192.168.0.105 and (udp.port==53 or tcp.port==80)
www.cybexer.com 149
Wireshark - display filters
Limit search to private networks:
www.cybexer.com 150
Wireshark - display filters
Filter HTTP properly
• open task07.pcapng
• filter by "tcp.port==80"
• check 20th packet
www.cybexer.com 151
Wireshark - display filters
HTTP filters:
• http.request.method == "POST"
www.cybexer.com 152
Wireshark - display filters
HTTP filters:
www.cybexer.com 153
Wireshark - display filters
Task
• open task08.pcapng
• frame contains sombrero
www.cybexer.com 154
Wireshark - display filters
FTP filters:
• (ftp.request.command == "USER") or
(ftp.request.command == "PASS")
• ftp.response.code==230
www.cybexer.com 155
Wireshark - display filters
DNS filters:
• dns.count.answers > 2
• dns.qry.type == 252
www.cybexer.com 156
Wireshark - display filters
DNS filters:
• dns.flags.rcode == 5
www.cybexer.com 157
Wireshark - display filters
More filters (use 1.pcap):
www.cybexer.com 158
Wireshark - display filters
More filters (use smtp.pcap):
www.cybexer.com 159
Wireshark - display filters
More filters:
www.cybexer.com 160
Wireshark - display filters
More filters:
www.cybexer.com 161
Wireshark - display filters
More filters:
www.cybexer.com 162
Wireshark - display filters
More filters (use 1.pcap file):
• http.request.method == POST
• http.request.method == 50:4f:53:54
• http.request.method == "\x50\x4f\x53\x54"
• http.request.method == GET
• http.request.method == 47:45:54
• http.request.method == "\x47\x45\x54“
• http.request.method matches
"(\x47\x45\x54|\x50\x4f\x53\x54)"
www.cybexer.com 163
Wireshark - display filters
Hex:
• 50 4B 03 04
• FF D8 FF
• 47 49 46 38
• 4D 53 43 46
• ...
www.cybexer.com 164
Wireshark - display filters
GeoIP mapping for public IP addresses
• mkdir /opt/geoip && cd /opt/geoip
• wget http://files.csirt.crp/GeoLite2-
City_20230228.tar.gz
• wget http://files.csirt.crp/GeoLite2-
ASN_20230228.tar.gz
www.cybexer.com 165
Wireshark - display filters
Extract all archives
www.cybexer.com 166
Wireshark - display filters
Enable GeoIP in Wireshark preferences
Edit->Preferences->Name Resolution
www.cybexer.com 167
Wireshark - display filters
www.cybexer.com 168
Wireshark - display filters
Result of analysis
www.cybexer.com 169
Wireshark - display filters
www.cybexer.com 170
Wireshark - display filters
Target file - 1.pcap
www.cybexer.com 171
Wireshark - display filters
Target file - 1.pcap
www.cybexer.com 172
Wireshark - display filters
Target file - 1.pcap
www.cybexer.com 173