online posts 16
wireshark 101

task 6.1 · chapter 6 of 8: tcp · 20 min

A whole connection

objective

Follow one web page from the TCP handshake through the request and the answer to the FINs that close it, reading the sequence and acknowledgement numbers that tie it together.

you edit, in the labanswers/6.1.yml

open a file in VS Code: Ctrl+P (Cmd+P on a Mac), type its name, Enter

given
Capturemake capture AT=laptop:eth1 NAME=6.1 X=web: the laptop opens http://web.lab/
Filtertcp
Your answersanswers/6.1.yml
new to this? step by stepbeginner
  1. make capture AT=laptop:eth1 NAME=6.1 X=web, open it, filter tcp.
  2. Find the SYN, SYN-ACK, ACK. Note the laptop’s port and the SYN-ACK’s frame number.
  3. Challenge: the HTTP status code, and who sent the first FIN.
  4. Fill in answers/6.1.yml, then make check T=6.1.

more in meet the lab

1 explain

A conversation with a beginning and an end

Why TCP is different

Every protocol so far (ARP, DHCP, DNS) has been a question and an answer, and if an answer goes missing, the asker just asks again. A web page can be megabytes: thousands of packets that must all arrive, in order, with none missing. TCP does that. It turns a stream of packets into a reliable connection, and on the wire you can watch every part of it.

The handshake

Before any data, the two ends agree to talk, in three packets:

  1. SYN: the laptop, I’d like to connect, and I’ll number my bytes starting from here;
  2. SYN, ACK: the server, fine, and I’ll number mine from here; I’ve got yours;
  3. ACK: the laptop, got yours too.

A port says which program each end is: web serves on port 80 (HTTP); the laptop picks a random high port for its side, different for every connection.

Sequence and acknowledgement numbers

TCP numbers every byte it sends. Each packet carries Seq (the number of its first byte) and Ack (the next byte it expects from the other end: I’ve got everything before this). The real numbers start at a random value; Wireshark subtracts it and shows relative numbers starting at 0, which are far easier to read.

Follow them and you can see exactly what arrived: when the laptop sends 71 bytes of request starting at Seq=1, the server’s next packet says Ack=72.

Closing

Each side closes its own half with a FIN (I’m done sending), and the other side ACKs it. Whoever sends the first FIN chose to end the conversation.

in one sentence TCP opens with SYN, SYN-ACK, ACK, numbers every byte with Seq and Ack, and closes each direction with a FIN.

2 show

One page, twelve TCP frames

The TCP frames of a capture like yours (DNS for web.lab comes first, and isn’t shown):

    6 1.202682209 192.168.1.175 → 192.168.2.10 TCP 74 41648 → 80 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 ...
    7 1.202864792 192.168.2.10 → 192.168.1.175 TCP 74 80 → 41648 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 ...
    8 1.202878042 192.168.1.175 → 192.168.2.10 TCP 66 41648 → 80 [ACK] Seq=1 Ack=1 Win=64256 Len=0 ...
    9 1.202973209 192.168.1.175 → 192.168.2.10 HTTP 137 GET / HTTP/1.1
   10 1.202988167 192.168.2.10 → 192.168.1.175 TCP 66 80 → 41648 [ACK] Seq=1 Ack=72 Win=65152 Len=0 ...
   11 1.203743875 192.168.2.10 → 192.168.1.175 TCP 302 HTTP/1.1 200 OK
   12 1.203754125 192.168.1.175 → 192.168.2.10 TCP 66 41648 → 80 [ACK] Seq=72 Ack=237 Win=64128 Len=0 ...
   13 1.203837084 192.168.2.10 → 192.168.1.175 HTTP 99 HTTP/1.1 200 OK  (text/html)
   14 1.203842500 192.168.1.175 → 192.168.2.10 TCP 66 41648 → 80 [ACK] Seq=72 Ack=270 Win=64128 Len=0 ...
   15 1.203980584 192.168.1.175 → 192.168.2.10 TCP 66 41648 → 80 [FIN, ACK] Seq=72 Ack=270 Win=64128 Len=0 ...
   16 1.204308750 192.168.2.10 → 192.168.1.175 TCP 66 80 → 41648 [FIN, ACK] Seq=270 Ack=73 Win=65152 Len=0 ...
   17 1.204333000 192.168.1.175 → 192.168.2.10 TCP 66 41648 → 80 [ACK] Seq=73 Ack=271 Win=64128 Len=0 ...
PartWhat it means
41648 → 80from the laptop’s port to web’s
[SYN, ACK]the TCP flags set in this packet
Seq=1 Ack=72relative sequence and acknowledgement numbers
Win=65152the receive window: how many more bytes this side can take right now
Len=0bytes of data in this packet. Handshake and ACK packets carry none
MSS=1460the biggest chunk of data this side can receive in one packet (chapter 8)

web sent its answer in two pieces: the headers in frame 11, the page in frame 13. Wireshark glued them back together and shows the whole HTTP response on frame 13.

Two views make a connection easier to read: Statistics › Conversations › TCP lists every connection with its ports and byte counts, and right-click any frame › Follow › TCP Stream shows just the text the two sides sent each other.

3 follow along

The handshake

  1. Capture the laptop opening the web page:

    run in the terminal
    make capture AT=laptop:eth1 NAME=6.1 X=web
    
  2. Open /captures/6.1.pcapng and filter tcp. Find the [SYN], the [SYN, ACK] and the [ACK].

  3. Note the laptop’s port (the source port of the SYN) and the SYN-ACK’s frame number (the No. column).

  4. Right-click any of the frames › Follow › TCP Stream and read the request and the answer as text. Close it with Back.

  5. Fill in the follow-along lines:

    editanswers/6.1.ymlCtrl+P → 6.1.yml
    client_port: 41648      # yours is different
    syn_ack_frame: 7        # yours may be different
    
4 challenge

The answer and the end

  • http_status: the status code web answered with;
  • first_fin_from: the IP address that sent the first FIN.
hint

Filter http.response. The code is in the first line of the HTTP layer.

hint

Filter tcp.flags.fin == 1. The first one is the answer.

show the solutionanswers/6.1.yml

or pull it into your lab: make solve T=6.1, then git diff --staged shows what changed

http_status: 200
first_fin_from: 192.168.1.175      # the laptop's address: yours may be different

200 means OK, here’s the page. The laptop (curl) closed first, as soon as it had the whole page: the browser side usually decides when it’s done. Count the frames: three to open, three carrying data (the request and the answer’s two pieces), each with an ACK, and three to close. For a 33-byte page, most of the packets are TCP keeping its promises.

5 check: run it, then prove it

$ make check T=6.1

when it's right, you'll see

╭─ task 6.1 · a whole connection
│  ✓ captures/6.1.pcapng: taken on laptop:eth1, 18 frames
│  ✓ the laptop's port for the connection (follow along): ...
│  ✓ the frame number of the SYN-ACK (follow along): ...
│  ✓ the HTTP status code web answered with (challenge): 200
│  ✓ who closed the connection first, sending the first FIN (challenge): ...
╰─ 5/5 checks passed  verified