Decrypting TLS Browser Traffic With Wireshark – The Easy Way!

Intro

Most IT people are somewhat familiar with Wireshark.  It is a traffic analyzer, that helps you learn how networking works, diagnose problems and much more.

2015-02-11 22_29_11-

One of the problems with the way Wireshark works is that it can’t easily analyze encrypted traffic, like TLS.  It used to be if you had the private key(s) you could feed them into Wireshark and it would decrypt the traffic on the fly, but it only worked when using RSA for the key exchange mechanism.  As people have started to embrace forward secrecy this broke, as having the private key is no longer enough derive the actual session key used to decrypt the data.  The other problem with this is that a private key should not or can not leave the client, server, or HSM it is in.  This lead me to coming up with very contrived ways of man-in-the-middling myself to decrypt the traffic(e.g. sslstrip).

Session Key Logging to the Rescue!

Well my friends I’m here to tell you that there is an easier way!  It turns out that Firefox and the development version of Chrome both support logging the symmetric session key used to encrypt TLS traffic to a file.  You can then point Wireshark at said file and presto! decrypted TLS traffic.  Read on to learn how to set this up.

Setting up our Browsers

We need to set an environmental variable.

On Windows:

Go into your computer properties, then click “Advance system settings” then “Environment Variables…”

2015-02-11 21_36_51-Clipboard

Add a new user variable called “SSLKEYLOGFILE” and point it at the location that you want the log file to be located at.

2015-02-11 21_38_57-Environment Variables

On Linux or Mac OS X:

$ export SSLKEYLOGFILE=~/path/to/sslkeylog.log

You can also add this to the last line of your

~/.bashrc

on Linux, or

~/.MacOSX/environment

on OS X so that it is set every time you log in.

The next time that we launch Firefox or the dev channel of Chrome they will log your TLS keys to this file.

Setting up Wireshark

You need at least Wireshark 1.6 for this to work.  We simply go into the preferences of Wireshark

2015-02-11 21_45_30-

Expand the protocols section:

2015-02-11 21_48_49-2015-02-11 21_45_59-Wireshark_ Preferences - Profile_ Default

Browse to the location of your log file

2015-02-11 21_47_10-Wireshark_ Preferences - Profile_ Default

The Results

This is more along the lines of what we normally see when look at a TLS packet,

2015-02-11 22_29_11-

This is what it looks like when you switch to the “Decrypted SSL Data” tab.  Note that we can now see the request information in plain-text!  Success!

2015-02-11 22_30_28-_Wi-Fi   [Wireshark 1.12.3  (v1.12.3-0-gbb3e9a0 from master-1.12)]

Conclusion

I hope you learned something today, this makes capturing TLS communication so much more straightforward.  One of the nice things about this setup is that the client/server machine that generates the TLS traffic doesn’t have to have Wireshark on it, so you don’t have to gum up a clients machine with stuff they won’t need, you can either have them dump the log to a network share or copy it off the machine and reunite it with the machine doing the packet capture later.  Thanks for stopping by!

References:

Mozilla Wiki

Imperial Violet

Photo Credit: Mike

25 thoughts on “Decrypting TLS Browser Traffic With Wireshark – The Easy Way!

  1. I am using Wireshark 1.12, FIrefox 35.0.1 and Windows 7. I can see my SSL/TLS secrets being populated in my log file, but I am not getting the Decrypted SSL Data tab. Any thoughts on what I may be doing wrong?

    1. And you have filled out the “(Pre)-Master-Secret log filename” field in your preferences? Be aware that Wireshark might be sniffing traffic that is not sent by the configured browser, e.g. a background application on the same system might be reaching out over TLS and wouldn’t be logging its keys. It will only show that tab for traffic it can decrypt. Filter out information so that you are only looking at the communication that you are relatively certain is coming from the browser.

      1. I double checked that Wireshark is pointed at the log file. I shut down everything else and used the far side IP address to confirm which traffic I was viewing. I will need to keep digging.

        1. The other thing to mention is that a lot of the data is still either gzipped or binary data like images, so it may appear obscured. But you should still get the tab, in any case.

  2. This guy had the same problem:
    https://ask.wireshark.org/questions/30290/decrypting-tls_ecdhe_rsa_with_aes_128_cbc_sha-and-tls_ecdhe_rsa_with_aes_128_gcm_sha256-using-sslkeylogfile

    Although he eventually figured it out, he used a slightly older version than yours. Maybe you need to tweak compile options and recompile.

    It probably has something to do with forward secrecy. Perhaps it’s not supported in your version. If you visit a site that isn’t using FS:
    https://tools.ietf.org/html/rfc5246

    You should be able to decrypt this in Wireshark.

    Actually it might be the mode of operation for the block cipher that’s the problem. Old versions don’t support GCM. But you are using 1.12…

    1. Thank you for the pointers. I cycled through the security.tls.version.max options as you suggested and confirmed in the captures that the encryption protocol used was changing accordingly. Unfortunately, I am still not getting the Decrypted SSL Data tab, even when going to the IETF site you listed. I found some additional information here http://wiki.wireshark.org/SSL, a “wireshark -v” on my system lists GnuTLS 3.2.15 and Gcrypt 1.6.2. I am using the latest stable version that comes in the Windows installer so I have whatever compile options that it is built with. I will keep digging.

    1. Yeah I didn’t actually get to test this on a Mac as I no longer own one. Looks like OS X did some redecorating recently with environmental variables see this. Maybe it needs to be a system environmental variable on OS X?

  3. Any remotely recent version of Chrome will work just fine now. At the time of the cited blog post (look at the timestamp), the feature was new in NSS had only hit dev channel.

  4. Or use Cloudshark, just drag the key onto the web page and then hit decrypt. Its nice because I can let my IT minions debug pcaps without me giving them the TLS keys to the kingdom!!! Course, Cloudshark isnt free like wireshark even though its based on it

  5. And you got the SSL line or it’s just the tab you can’t see? I didn’t see mine coz I was with a proxy. It seems it encapsulate https in http, so you can’t use it to spy on your mates (in this case, at least). Neither you can use it to see app/malware that use their own conection.

    I’d like to be give a practical exemple of how to use it.

    Nice post, btw. :)

  6. Can you think of a way to do the same with a mobile browser? Can’t quite find the same set of options for the mobile browsers.

  7. I tried this on Linux Mint 17.1 and FF 35.0.1, double checked that the environmental variable has been set correctly, rebooted and reloaded this page, but no sslkeylog.log was created. Is a specific Linux distribution needed to make this work?

      1. export says

        declare -x SSLKEYLOGFILE=”/home/jrv/sslkeylog.log”

        where jrv is my username and I have write access. More help would be appreciated.

Leave a Reply