Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a NSS Key Log file to decrypt a TLS session #3374

Merged
merged 3 commits into from
Oct 10, 2021

Conversation

guedou
Copy link
Member

@guedou guedou commented Sep 23, 2021

This PR adds support for the NSS Key Log.

It allows Scapy to reuse the keys to decrypt TLS sessions.

Currently, it only supports TLS 1.2, but TLS 1.3 is on the road map (it will fix #3073).

A possible usage is:

from scapy.all import *

load_layer("tls")
conf.tls_session_enable = True
conf.tls_nss_filename = "tls12/s_client.tls12.keys.txt"
l = rdpcap("tls12/s_client.tls12.pcap")
print(l.nsummary())

@guedou guedou changed the title Use a NSS Key Log file to decrypt a TLS sessions Use a NSS Key Log file to decrypt a TLS session Sep 23, 2021
scapy/layers/tls/session.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 23, 2021

Codecov Report

Merging #3374 (8ec40a2) into master (6247a95) will decrease coverage by 0.01%.
The diff coverage is 73.33%.

@@            Coverage Diff             @@
##           master    #3374      +/-   ##
==========================================
- Coverage   85.90%   85.89%   -0.02%     
==========================================
  Files         274      274              
  Lines       56684    56728      +44     
==========================================
+ Hits        48695    48725      +30     
- Misses       7989     8003      +14     
Impacted Files Coverage Δ
scapy/layers/tls/session.py 83.14% <73.33%> (-0.61%) ⬇️
scapy/arch/windows/__init__.py 67.73% <0.00%> (-0.57%) ⬇️
scapy/contrib/automotive/gm/gmlan_scanner.py 86.14% <0.00%> (-0.28%) ⬇️
scapy/layers/tls/automaton_cli.py 70.96% <0.00%> (+0.13%) ⬆️

@guedou guedou marked this pull request as ready for review September 27, 2021 19:43
@guedou
Copy link
Member Author

guedou commented Sep 27, 2021

This PR is ready to be reviewed. I would like to get an opinion related to the size of the tls_nss_example.pcap file.

Copy link
Member

@gpotter2 gpotter2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. The packet size is fine. Do you want to merge it now and do TLS 1.3 separately?

@guedou
Copy link
Member Author

guedou commented Oct 10, 2021 via email

@gpotter2 gpotter2 merged commit db13399 into secdev:master Oct 10, 2021
@vadimszzz
Copy link

vadimszzz commented Nov 29, 2021

Thank you, this is very nice PoC but still not usable in real world. Doesn't work with multiple TLS connections. Holds only last connection keys with "dublicate warning".
@guedou, can you make working solution that will decrypt all TLS connections, not only the last, in this pcap for example: Archive.zip ? Wireshark works with it well. Take a look at pmercury code, it may be helpful: https://github.com/cisco/mercury/blob/main/python/pmercury/protocols/tls_decrypt.py 👍

@gpotter2 please do not merge anymore PRs that doesn't work.

@vadimszzz
Copy link

vadimszzz commented Nov 29, 2021

My .pcap traffic is TLS 1.3 that's not supported in your PR. Btw I'm waiting for full multiple-connection TLS 1.2 & 1.3 decryption as soon as you can 😔

@gpotter2
Copy link
Member

I believe you are mistaken in believing that we owe you features in some way. Be assured that Scapy is provided with absolutely "no warranty".

@gpotter2 gpotter2 added this to the 2.5.0 milestone Mar 29, 2022
bzalkilani pushed a commit to bzalkilani/scapy that referenced this pull request Jun 12, 2022
* Use a NSS Key Log file to decrypt a TLS session

* Decrypting TLS 1.2 using a known master secret

* Test TLS 1.2 decryption using a NSS Key Log
@banls
Copy link

banls commented Nov 25, 2023

how get nsskeylog? use scapy

@secdev secdev locked as resolved and limited conversation to collaborators Nov 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some TLS notebooks are outdated
4 participants