即使在船上调用load_layer('tls')后也无法读取tls节

问题描述 投票:1回答:1

[This问题解释了如何使用scapy读取数据包的TLS部分。

但是,我的程序无法读取它。它返回的只是一堆十六进制字符

>>> from scapy.all import *
>>> load_layer('tls')
>>> cap = rdpcap('tls.pcap')
>>> p1=cap[0]
>>> p1
<Ether  dst=14:cc:20:51:33:ea src=f4:f2:6d:93:51:f1 type=0x800 |<IP  version=4 ihl=5 tos=0x0 len=146 id=62970 flags=DF frag=0 ttl=64 proto=tcp chksum=0x50a0 src=192.168.1.143 dst=54.254.250.149 |<TCP  sport=49335 dport=50443 seq=549695462 ack=200962336 dataofs=5 reserved=0 flags=PA window=4380 chksum=0xb0ac urgptr=0 |<Raw  load="\x17\x03\x01\x00 \xf2\x10\xfd\x95N'\xf2\xaf\x99tp\x93\xbc\xe9\x81w\x91\x1b\xe0\xc9M:\x9a!]\xb0!\xae\xd2\x86\xb0>\x17\x03\x01\x00@d>\x0b\xee\xf0\xab\xded\x02E)\x0e0\xbb\xe6\x82uU\xb22\x87\xd6\xe4n[\x1d\x18\xe8\xd6\x1c\x00N_C\xe6\xdd\xbe\x89@6p\xd9\xaf\x19\xb3s\x07H\xdeF\x88\xdar\x0f\x8a\n!4\xeb\xd3F\xefgH" |>>>>

我想获取tls记录版本,tls记录长度和tls记录内容类型。

这是Wireshark中打开的数据包的屏幕截图。enter image description here

有人可以请告诉我我在做什么错以及如何正确阅读tls内容吗?

我正在使用Python3.6,因此无法使用稳定的scapy-ssl_tls,目前仅限于Python 2。

python-3.x ssl scapy
1个回答
0
投票

你是如此亲密。您只需要使用TLS(pkt.load)

下载TLS捕获

对于此示例,请使用Wireshark的Bugzilla中的此tls capture

我们可以看到数据包4是TLS客户端Hello:

tshark -r DNS-over-TLS.pcapng -Y "frame.number==4"
    4   0.122267 133.93.28.45 → li280-151.members.linode.com TLSv1  384 Client 
Hello 00:00:5e:00:01:18 ← 48:d7:05:df:86:0b

使用Scapy加载

请确保已安装加密库,因为这是加载TLS捕获所必需的。

>>> import cryptography
>>> # No errors

再现此捕获内容到目前为止的内容:

>>> from scapy.all import *
>>> load_layer('tls')
>>> cap = rdpcap('DNS-over-TLS.pcapng')
>>> tls_client_hello=cap[3] # Wireshark numbers packets starting at 1, scapy at 0
>>> tls_client_hello
<Ether  dst=14:cc:20:51:33:ea src=f4:f2:6d:93:51:f1 type=0x800 |<IP  version=4 
ihl=5 tos=0x0 len=146 id=62970 flags=DF frag=0 ttl=64 proto=tcp chksum=0x50a0 
src=192.168.1.143 dst=54.254.250.149 |<TCP  sport=49335 dport=50443 seq=549695462 
ack=200962336 dataofs=5 reserved=0 flags=PA window=4380 chksum=0xb0ac urgptr=0 |
<Raw  load="\x17\x03\x01\x00 
\xf2\x10\xfd\x95N'\xf2\xaf\x99tp\x93\xbc\xe9\x81w\x91\x1b\xe0\xc9M:\x9a!]\xb0!\xa
e\xd2\x86\xb0>\x17\x03\x01\x00@d>\x0b\xee\xf0\xab\xded\x02E)\x0e0\xbb\xe6\x82uU\x
b22\x87\xd6\xe4n[\x1d\x18\xe8\xd6\x1c\x00N_C\xe6\xdd\xbe\x89@6p\xd9\xaf\x19\xb3s\
x07H\xdeF\x88\xdar\x0f\x8a\n!4\xeb\xd3F\xefgH" |>>>>

请注意,我们要查看的部分称为Raw load。要访问数据包的这一部分,请使用tls_client_hello.load。请记住,TLS将采用包含数据但不包含整个数据包的字节对象。

>>> TLS(tls_client_hello.load)
<TLS  type=handshake version=TLS 1.0 len=313 iv=b'' msg=[<TLSClientHello  
msgtype=client_hello msglen=309 version=TLS 1.2 gmt_unix_time=Tue, 18 May 2077 
23:20:52 +0000 (3388605652) 
random_bytes=d6d533aca04dca42db8b123b0a143dcd580079147122e4de095c15cf sidlen=0 
sid='' cipherslen=182 ciphers=[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, 
< TLS output truncated ... >

进一步阅读

我强烈建议您查看Scapy TLS Notebooks,该文档可以很好地记录船首船和TLS使用情况。

© www.soinside.com 2019 - 2024. All rights reserved.