root@thehacksparrow:~/writeups$ SYSTEM ONLINE
root@sparrow:~/writeups$ cat tshark-the-basics.md
// Blue Team & SOC

TShark: The Basics

23 Nov 2026 · 7 min read
Overview — An introductory Blue Team & SOC room on TShark, the terminal sibling of Wireshark. You learn the helper utilities that surround it (capinfos, nl, wc), the core switches for listing interfaces, reading and writing captures, the difference between capture filters (-f) and display filters (-Y), and how to bound a live capture with autostop and ring-buffer options. All exercises run against one small sample capture, demo.pcapng.
PlatformTryHackMe
CategoryBlue Team & SOC
DifficultyEasy
RoomTShark: The Basics

Task 1 — Introduction

TShark ships with Wireshark and uses the same dissection engine, so it understands the same protocols and the same display-filter language. What changes is the interface: everything is text. That makes it a poor tool for casually browsing a capture but an excellent one for scripting, bulk extraction and remote work on a server where no GUI exists. It can also behave like tcpdump when run with no arguments.

The room's objectives are filtering traffic, using Wireshark-style filters in the terminal, and automating packet filtering. The lab VM already contains the sample files in Desktop/exercise-files/. It helps to have done the Network Fundamentals and Wireshark modules first, because the filter syntax is reused as-is.

Task 2 — Command-line packet analysis hints

Because TShark prints plain text, it combines naturally with classic Unix tools. The ones that matter most for packet work:

ToolWhy you reach for it
capinfosSummarises a capture file (packet count, duration, hashes, encapsulation) without opening it packet by packet
grepKeeps only lines matching a pattern
cutExtracts columns or character ranges from each line
uniqCollapses repeated adjacent lines (sort first)
nlNumbers output lines, handy for counting
sed / awkStream editing and pattern-driven text processing

Before analysing any capture, run capinfos on it. It tells you how long the capture spans, how many packets to expect and, importantly for forensics, gives hashes you can record for chain of custody.

cd Desktop/exercise-files/
capinfos demo.pcapng

The output includes the packet count (43), a capture duration of about 30 seconds, and SHA256, RIPEMD160 and SHA1 digests of the file.

Q: What is the "RIPEMD160" value?
A: 6ef5f0c165a1db4a3cad3116b0c5bcc0cf6b9ab7

Task 3 — TShark fundamentals I: main parameters I

A handful of switches cover most day-to-day use:

SwitchEffect
-hHelp summary
-vVersion and build information
-DList interfaces TShark can capture on
-iChoose the interface, by number or name
(none)Capture on the first interface, like -i 1, printing one line per packet

Live capture and interface listing need elevated privileges (or the right capabilities on the dumpcap binary), which is why -D is run with sudo. TShark always prints Capturing on '<interface>' first, so you can confirm you are sniffing the interface you meant.

tshark -v
sudo tshark -D
sudo tshark -i 2

On the lab VM, tshark -v reports a 3.2.x build and -D returns a list that includes the real NIC, loopback, the pseudo-interface any, and several remote-capture helpers such as sshdump and udpdump.

Q: What is the installed TShark version in the given VM?
A: 3.2.3

Q: What is the number of available interfaces in the given VM?
A: 12

Task 4 — TShark fundamentals I: main parameters II

The second group of switches is about files and how much detail you see.

SwitchEffect
-r fileRead packets from a capture file instead of sniffing
-c NStop after N packets (captured, read or displayed)
-w fileWrite packets to a file
-VVerbose: full protocol tree per packet, like Wireshark's details pane
-qQuiet: suppress per-packet output (useful with statistics)
-xHex and ASCII dump of each packet

Combining -r, -c and -w lets you carve a subset out of a large capture and hand just that to a colleague:

tshark -r demo.pcapng -c 2
tshark -r demo.pcapng -c 1 -w write-demo.pcap
tshark -r write-demo.pcap -x

Both -V and -x are very noisy when applied to a whole file. The sensible workflow is to narrow the capture with a filter or -c first and only then ask for verbosity, for example tshark -r demo.pcapng -c 1 -V to see the Ethernet, IPv4 and TCP layers of the first SYN.

The questions are answered by printing the first N packets and looking at the last line, since -c counts from the start. The trick of piping to tail -n3 keeps the output readable:

tshark -r demo.pcapng -c 29 | tail -n3
tshark -r demo.pcapng -c 25 | tail -n3
tshark -r demo.pcapng -c 9  | tail -n3
Packet 29 is a data segment from the web server flagged PSH and ACK. Packet 25 is a pure ACK from the client acknowledging server byte 12421. Packet 9 is a client ACK advertising a receive window of 9660.

Q: What are the assigned TCP flags in the 29th packet?
A: PSH, ACK

Q: What is the "Ack" value of the 25th packet?
A: 12421

Q: What is the "Window size value" of the 9th packet?
A: 9660

Task 5 — TShark fundamentals II: capture conditions

Left alone, a live capture runs until you press Ctrl+C. On a busy host that fills the disk, so TShark offers two families of limits that only apply while capturing (they are rejected when you read a file with -r).

  • Autostop (-a) ends the run once a condition is met: duration:N seconds, filesize:N kilobytes, or files:N output files.
  • Ring buffer (-b) keeps capturing indefinitely but rotates files: start a new file every N seconds (duration) or N kilobytes (filesize), and once files:N is reached, overwrite the oldest. This yields a rolling window of recent traffic, which is exactly what you want for a sensor that must be ready when an incident is noticed.
# Stop after 2 seconds, or 5 KB per file, or 5 files, whichever applies first
tshark -w autostop-demo.pcap -a duration:2 -a filesize:5 -a files:5

# Rotate a new file every second, forever
tshark -w test.pcap -b duration:1

# Rolling buffer: 10 KB files, keep only the newest 3
tshark -w test.pcap -b filesize:10 -b files:3
A ring buffer on its own never stops. Pair it with at least one autostop condition if you need the run to end by itself.

Q: Which parameter can help analysts to create a continuous capture dump?
A: -b

Q: Can we combine autostop and ring buffer parameters with TShark? y/n
A: y

Task 6 — TShark fundamentals III: capture vs display filters

Filtering happens at two different moments, with two different languages:

SwitchTypeLanguageWhen it applies
-fCapture filterBPF (pcap-filter)Before packets are stored; discarded traffic is lost for good
-YDisplay filterWireshark display filterAfter capture; the file is untouched and you can change the filter freely

Capture filters are coarse (host, network, port, protocol, direction) but cheap, because the kernel drops unwanted packets early. Display filters can reach into any dissected field, such as http.response.code, at the cost of processing every packet. A common pattern is a light capture filter to keep file size sane, then display filters for the investigation.

Q: Which parameter is used to set "Capture Filters"?
A: -f

Q: Which parameter is used to set "Display Filters"?
A: -Y

Task 7 — TShark fundamentals IV: capture filters

BPF expressions are built from three kinds of qualifier, which you can chain with and, or and not:

  • Type: host, net, port, portrange. With no qualifier, host is assumed.
  • Direction: src or dst. With none, both directions match.
  • Protocol: arp, ether, icmp, ip, ip6, tcp, udp, or an IANA protocol number via ip proto N.
tshark -f "host MACHINE_IP"
tshark -f "net MACHINE_NET/24"
tshark -f "port 80"
tshark -f "portrange 80-100"
tshark -f "src host MACHINE_IP"
tshark -f "dst host MACHINE_IP"
tshark -f "tcp"
tshark -f "ether host F8:DB:C5:A2:5D:81"
tshark -f "ip proto 1"

Practice is done in a split terminal (terminator): TShark sniffs in one pane while traffic is generated in the other, with curl for HTTP to a host, or nc for arbitrary TCP and UDP ports.

# pane 1
tshark -f "port 4444"
# pane 2
nc MACHINE_IP 4444 -vw 5
nc -u MACHINE_IP 4444 -vw 5
The room's questions were written against a fixed external host that may no longer respond, so you may not be able to reproduce the packet counts live. The answers below are the ones the room accepts.

Q: What is the number of packets with SYN bytes?
A: 2

Q: What is the number of packets sent to the IP address "MACHINE_IP"?
A: 7

Q: What is the number of packets with ACK bytes?
A: 8

Task 8 — TShark fundamentals V: display filters

Display filters use field names from the Wireshark display-filter reference. Wrap them in single quotes so the shell does not interpret spaces, == or !.

tshark -r demo.pcapng -Y 'ip.addr == 145.253.2.203'
tshark -Y 'ip.addr == MACHINE_NET/24'
tshark -Y 'ip.src == MACHINE_IP'
tshark -Y 'ip.dst == MACHINE_IP'
tshark -Y 'http'
tshark -Y 'http.response.code == 200'
tshark -Y 'dns.qry.type == 1'

One subtlety trips people up: the number at the start of each line is the packet's position in the original capture, not a running count of matches. Filtering for the DNS server returned only two lines, numbered 13 and 17. To count matches, pipe through nl or wc -l rather than reading the first column.

tshark -r demo.pcapng -Y 'http' | nl
tshark -r demo.pcapng -Y 'ip.addr == 65.208.228.223' | wc -l
tshark -r demo.pcapng -Y 'tcp.port == 3371' | wc -l
tshark -r demo.pcapng -Y 'ip.src == 145.254.160.237' | wc -l

Q: What is the number of packets with a "65.208.228.223" IP address?
A: 34

Q: What is the number of packets with a "TCP port 3371"?
A: 7

Q: What is the number of packets with a "145.254.160.237" IP address as a source address?
A: 20

Re-running the last filter without wc -l and scanning the Info column shows a line tagged [TCP Dup ACK 28#1]. Wireshark's analysis engine flags a repeated acknowledgement like this when the same ACK is seen again, usually a hint of loss or reordering.

Q: What is the packet number of the "Duplicate" packet?
A: 37

Task 9 — Conclusion

Nothing to answer here. The natural next step is the follow-up room covering Wireshark features in TShark (statistics, stream following, object export, field extraction).

Key takeaways

  • Start every investigation with capinfos: packet count, time span and file hashes in one command.
  • -r reads, -w writes, -c limits; together they let you carve and share just the relevant packets.
  • Keep -V and -x for a few filtered packets, never for a whole file.
  • -a stops a capture, -b rotates it; a ring buffer needs an autostop to terminate.
  • -f uses BPF and discards traffic permanently; -Y uses Wireshark syntax and is non-destructive.
  • Packet numbers in filtered output are original positions, so count with nl or wc -l.
  • Quote filters with single quotes to avoid shell surprises.