task 8.3 · chapter 8 of 8: the network from the command line · 20 min
Catch it on the wire
objective
Capture one web request from ws1 to srv1 with tcpdump, save it to a file, read it back, and copy it to the codespace with scp, ready for Wireshark. Read the handshake, the request and the close from the capture.
answers/8.3.ymlcaptures/web.pcapopen a file in VS Code: Ctrl+P (Cmd+P on a Mac), type its name, Enter
| Lesson | The network from the command line |
|---|---|
| Needs | task 8.2 done: labweb answers ws1 on port 8080 |
| Your answers | answers/8.3.yml |
new to this? step by stepbeginner
- On ws1:
sudo tcpdump -n -i eth1 -w web.pcap port 8080 &, thencurl -s http://srv1:8080/, thenfgand Ctrl+C. tcpdump -n -r web.pcap: read it.exit, then in the codespace:scp ws1:web.pcap captures/.- Challenge: from the capture, ws1’s port and the packet count. Fill in answers/8.3.yml, then
make check T=8.3.
more in meet the lab
tcpdump: Wireshark without the window
Why tcpdump
A server you reach with SSH has no screen, so Wireshark can’t run there. tcpdump captures the same packets in a terminal. It’s on almost every Linux machine, and its files open in Wireshark later.
| Option | Means |
|---|---|
-i eth1 | capture on this interface |
-n | show addresses and ports as numbers (don’t look names up) |
-w file.pcap | write the packets to a file instead of the screen |
-r file.pcap | read a file instead of capturing |
-c 20 | stop after 20 packets |
port 8080, host srv1 | a capture filter: only keep packets that match |
Capturing needs root, so it’s sudo tcpdump. Reading a file anyone can read doesn’t.
in one sentence tcpdump -w saves a capture; tcpdump -r reads it; a filter like port 8080 keeps only what you need.
A capture in the background
You need tcpdump capturing while curl runs. Chapter 5 had the answer: start tcpdump with &, so it runs in the
background, run curl, then bring tcpdump back with fg and stop it with Ctrl+C. It writes
the file and says how many packets it captured.
Reading one line
05:52:31.037441 IP 192.168.10.10.53380 > 192.168.20.10.8080: Flags [S], seq 2218734704, win 64240, ...
When it was seen, then source address.port > destination address.port, then TCP’s flags: [S] is a SYN,
[S.] a SYN-ACK, [.] an ACK, [P.] data, [F.] a FIN. Wireshark 101 reads
the same connection field by field.
One request, every packet
netops@ws1:~$ tcpdump -n -r web.pcap
05:52:31.037441 IP 192.168.10.10.53380 > 192.168.20.10.8080: Flags [S], seq 2218734704, win 64240, options [mss 1460,sackOK,TS val 1308440284 ecr 0,nop,wscale 7], length 0
05:52:31.037537 IP 192.168.20.10.8080 > 192.168.10.10.53380: Flags [S.], seq 162168246, ack 2218734705, win 65160, options [mss 1460,sackOK,TS val 589802733 ecr 1308440284,nop,wscale 7], length 0
05:52:31.037547 IP 192.168.10.10.53380 > 192.168.20.10.8080: Flags [.], ack 1, win 502, options [nop,nop,TS val 1308440284 ecr 589802733], length 0
05:52:31.037610 IP 192.168.10.10.53380 > 192.168.20.10.8080: Flags [P.], seq 1:74, ack 1, win 502, options [nop,nop,TS val 1308440284 ecr 589802733], length 73: HTTP: GET / HTTP/1.1
...
05:52:31.044467 IP 192.168.10.10.53380 > 192.168.20.10.8080: Flags [F.], seq 74, ack 217, win 501, options [nop,nop,TS val 1308440291 ecr 589802740], length 0
The three-way handshake, the GET / (73 bytes), the reply, and the close. Your times, ports and sequence numbers
will differ.
Capture, read, copy
On ws1, start a capture in the background. tcpdump says it’s listening:
run in the terminalssh ws1 sudo tcpdump -n -i eth1 -w web.pcap port 8080 &Make the traffic, then stop the capture:
run in the terminalcurl -s http://srv1:8080/ fgPress Ctrl+C. tcpdump prints N packets captured.
Read it back.
ls -lshows the file belongs to a user called tcpdump: tcpdump starts as root to open the interface, then gives root up and runs as its own user. The file is-rw-r--r--, so you can read it without sudo:run in the terminalls -l web.pcap tcpdump -n -r web.pcap exitIn the codespace, copy it into the lab’s
captures/folder:run in the terminalscp ws1:web.pcap captures/ tcpdump -n -r captures/web.pcap | head -n 3The same packets, now on your side. Right-click the file in the Explorer and Download it to open it in your own Wireshark.
in one sentence Capture in the background, make the traffic, stop it with fg and Ctrl+C, then scp the file home.
Read your capture
From your captures/web.pcap:
client_port: the port ws1 used for this connection, from the first packet, the SYN.packets: how many packets the capture holds.
Then make check T=8.3. It reads your file, so the answers are yours, not the guide’s.
hint
In 192.168.10.10.53380 > 192.168.20.10.8080, the last number of each address is its port. ws1’s is on the left
of the > in the SYN.
hint
tcpdump -n -r captures/web.pcap | wc -l counts the lines, one per packet.
show the solution
tcpdump -n -r captures/web.pcap 2>/dev/null | head -n 1
tcpdump -n -r captures/web.pcap 2>/dev/null | wc -l
client_port: 53380 # yours is different: ws1 picks a new one for every connection
packets: 12
tcpdump prints reading from file … on stderr, which is why 2>/dev/null keeps it out of the count. Twelve is
typical for one small request: three for the handshake, the request and its ACK, the reply in two parts and their
ACKs, then a FIN each way and the last ACK. A different count is fine, as long as it’s what your file holds.
5 check: run it, then prove it
$ make check T=8.3when it's right, you'll see
╭─ task 8.3 · catch it on the wire
│ ✓ ws1 has web.pcap in netops's home folder (follow along)
│ ✓ captures/web.pcap is in the lab's folder, copied back with scp (follow along)
│ ✓ it holds a connection to srv1 port 8080, from its first SYN (follow along)
│ ✓ ws1's own port for the connection (challenge): ...
│ ✓ how many packets the capture holds (challenge): ...
│ ✓ and the HTTP request, GET /, is in it (challenge)
╰─ 6/6 checks passed verified