Wireshark is a network protocol analyzer.
It lets you see what's happening on your network at a microscopic level.
To install (Mac OS X):
brew options wireshark # check for options before installing
brew install wireshark --with-qt # install gui version
brew install tshark # terminal oriented version of Wireshark designed for capturing and displaying packets without need for a gui
For CentOS:
With Docker:
--privileged
required (otherwise: can't run /usr/sbin/dumpcap: Operation not permitted
)
--security-opt seccomp:unconfined
is an alternative
Once you have your pcap formatted file (see tcpdump) you can open Wireshark's gui via your terminal by executing the shell command: wireshark
Once open you can use the gui to select "Open Capture File", browse to your pcap file and select it.
Now you can start analysing your network traffic.
You can automate this process by reading in the capture file directly from the shell:
wireshark -r ~/Downloads/tcpdump-tests/0001.pcap
You can also specify the interface to connect to using -i
(notice I had to use sudo
in order to authorise Wireshark):
To see available interfaces execute: sudo wireshark -D
(again you need sudo
):
Capture-Message: Capture Interface List ...
Capture-Message: Loading External Capture Interface List ...
1. en0 (Wi-Fi)
2. awdl0
3. bridge0 (Thunderbolt Bridge)
4. en1 (Thunderbolt 1)
5. vboxnet1
6. en2 (Thunderbolt 2)
7. p2p0
8. lo0 (Loopback)
Every time there is (for example) a HTTP request, that might end up being 200 TCP packets, which is difficult to recognize and make sense of manually. But this can be simplified within Wireshark by clicking on Statistics -> Conversations, where it organizes all these disparate packets into TCP sessions.
When installing Wireshark you'll also get a tshark
command, which is a command line version of wireshark
.
So you can read in your pcap file like so:
tshark -r ~/Downloads/tcpdump-tests/0001.pcap
This will display clearer formatted analysis than tcpdump -r
provides.
tcpdump
doesn't know about HTTP or other network protocols. It knows pretty much everything about TCP but it doesn't care what you put inside your TCP packets. tshark
on the other hand knows all about what's inside your TCP packets.
sudo tshark -i any \
-R 'http.request.method == "GET"' \
-T fields \
-e http.request.method -e http.request.uri -e ip.dst
The above filters for just packets which have a HTTP GET
request in them, and then prints out the request method and the URI for each one.
The way you filter results is by specifying -T
and changing to the fields
value. From there you can use the -e
flag to specify how to filter data. So if you wanted to filter out all the DNS ttls from a tcpdump of just DNS traffic you could use something like:
tshark -r ~/dns-traffic.pcap -T fields -e dns.resp.ttl -e dns.resp.name
Note: if you open the pcap in wireshark, you can find the filter you need by selecting the data manually via the UI and then right-click'ing and selecting "Prepare a Filter > Selected"