task 7.2 · chapter 7 of 8: tls · 20 min
Decrypt your own
objective
Capture a TLS 1.2 connection, read the server’s certificate in the clear, then give Wireshark the session keys the laptop saved and read the page that was sent encrypted.
answers/7.2.ymlopen a file in VS Code: Ctrl+P (Cmd+P on a Mac), type its name, Enter
| Capture | make capture AT=laptop:eth1 NAME=7.2 X=tls12: also saves the session keys to captures/7.2.keys |
|---|---|
| Keys in Wireshark | Edit › Preferences › Protocols › TLS › (Pre)-Master-Secret log filename: /captures/7.2.keys |
| Keys in tshark | tshark -r captures/7.2.pcapng -o tls.keylog_file:captures/7.2.keys -Y http |
| Your answers | answers/7.2.yml |
new to this? step by stepbeginner
make capture AT=laptop:eth1 NAME=7.2 X=tls12, open it, filtertls.handshake.type == 11.- Open the Certificate: subject and issuer names.
- Challenge: point Wireshark at /captures/7.2.keys, filter
http, read secret.txt. - Fill in answers/7.2.yml, then
make check T=7.2.
more in meet the lab
Certificates, and keys you’re allowed to have
The certificate
When the laptop connects, web proves it really is web.lab with a certificate: a small signed document
that says this key belongs to these names, signed by someone the laptop already trusts, a certificate
authority (CA). On the internet that’s one of a few dozen companies your operating system trusts. In this lab
it’s the lab’s own CA, made when the hosts’ image was built, which every host trusts.
In TLS 1.2 the certificate is sent in the clear, so a capture shows exactly which names it covers and who signed it. That’s useful: certificate name mismatch and untrusted issuer errors can be read straight off the wire. In TLS 1.3 it’s encrypted (task 7.1), so you’d need the keys.
Decrypting your own traffic
You can’t decrypt someone else’s TLS from a capture; that’s the whole point of it. But you can decrypt your
own. Most TLS libraries can write their session secrets to a key log file if you set the environment
variable SSLKEYLOGFILE to a filename. curl does, and so do Firefox and Chrome. Give that file to Wireshark and
it decrypts the captured session as if it were plain text.
That’s how developers debug HTTPS apps. It’s also the reason to treat a key log file like a password: anyone with it and the capture can read the traffic.
in one sentence TLS 1.2 shows the certificate in the clear; the session keys your own browser or curl saves let Wireshark decrypt the rest.
TLS 1.2, and its keys
The handshake, with curl told to use TLS 1.2 at most (curl --tls-max 1.2):
9 0.788865417 192.168.1.175 → 192.168.2.10 TLSv1 292 Client Hello (SNI=intranet.lab)
11 0.790268084 192.168.2.10 → 192.168.1.175 TLSv1.2 1402 Server Hello, Certificate, Server Key Exchange, Server Hello Done
13 0.796043667 192.168.1.175 → 192.168.2.10 TLSv1.2 159 Client Key Exchange, Change Cipher Spec, Encrypted Handshake Message
14 0.796326375 192.168.2.10 → 192.168.1.175 TLSv1.2 117 Change Cipher Spec, Encrypted Handshake Message
15 0.796470875 192.168.1.175 → 192.168.2.10 TLSv1.2 181 Application Data
16 0.796773500 192.168.2.10 → 192.168.1.175 TLSv1.2 442 Application Data
Frame 11 carries the Certificate, in the clear. This Client Hello is only 292 bytes: offering at most TLS 1.2, curl leaves out the big TLS 1.3 key share.
The key log file is a few lines of text: a label, the session’s random number, and the secret:
CLIENT_RANDOM 3c1f... 9a0b...
With it, the same two Application Data frames become:
15 0.796470875 192.168.1.175 → 192.168.2.10 HTTP 181 GET /secret.txt HTTP/1.1
16 0.796773500 192.168.2.10 → 192.168.1.175 HTTP 442 HTTP/1.1 200 OK (text/plain)
Read the certificate
Capture the laptop fetching a page over TLS 1.2, saving its keys:
run in the terminalmake capture AT=laptop:eth1 NAME=7.2 X=tls12It saves two files:
captures/7.2.pcapngandcaptures/7.2.keys.Open
/captures/7.2.pcapng, filtertls.handshake.type == 11(the Certificate), and open the certificate. Under subject find the name it’s for (dNSName under the subjectAltName extension lists every name), and under issuer who signed it.Check the Server Hello’s version too: no
supported_versionsextension this time.Fill in the follow-along lines:
editanswers/7.2.ymlCtrl+P → 7.2.ymltls_version: 1.2 cert_cn: web.lab cert_issuer: Network Doodles Lab CA
Read the secret
The page the laptop fetched, https://intranet.lab/secret.txt, has a line in it with the answer is …. It’s
encrypted in the capture. Decrypt it with the keys, and write down the answer:
secret: the word after the answer is.
hint
In Wireshark: Edit › Preferences › Protocols › TLS, and set (Pre)-Master-Secret log filename to
/captures/7.2.keys. Click OK and the Application Data turns into HTTP.
hint
Right-click the HTTP response › Follow › HTTP Stream. Or in the terminal:
tshark -r captures/7.2.pcapng -o tls.keylog_file:captures/7.2.keys -Y http -V.
show the solutionanswers/7.2.yml
or pull it into your lab: make solve T=7.2, then git diff --staged shows what changed
secret: gentoo-penguin
Without the keys, frames 15 and 16 were Application Data and a length. With them, Wireshark showed the
request, the response and the page. Nothing about the capture changed: the keys are what make it readable.
That’s why SSLKEYLOGFILE is a debugging tool for your own machine only.
5 check: run it, then prove it
$ make check T=7.2when it's right, you'll see
╭─ task 7.2 · decrypt your own
│ ✓ captures/7.2.pcapng: taken on laptop:eth1, 21 frames
│ ✓ captures/7.2.keys: the session keys curl saved
│ ✓ the TLS version this time (follow along): 1.2
│ ✓ the name in the server's certificate (follow along): web.lab
│ ✓ who issued the certificate (follow along): Network Doodles Lab CA
│ ✓ the answer hidden in secret.txt (challenge): ...
╰─ 6/6 checks passed verified