通过SCAPY从PCAP中选择数据包
我正在尝试使用Scapy从PCAP文件中获取密码。我只想从每个文件中获取第一个数据包,BeaCause我正在使用过滤器。
这是我的代码:
from scapy.all import *
from scapy.layers.radius import Radius
import re
import os
import pathlib
def get_ciphersuite():
ciphersuites = {
#'0000' : 'TLS_NULL_WITH_NULL_NULL',
'002f' : 'TLS_RSA_WITH_AES_128_CBC_SHA',
'0035' : 'TLS_RSA_WITH_AES_256_CBC_SHA',
'003c' : 'TLS_RSA_WITH_AES_128_CBC_SHA256',
'003d' : 'TLS_RSA_WITH_AES_256_CBC_SHA256',
'009c' : 'TLS_RSA_WITH_AES_128_GCM_SHA256',
'009d' : 'TLS_RSA_WITH_AES_256_GCM_SHA384',
'c02c' : 'TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384'
}
dir_pcaps = "./pcaps/"
pcaps = os.listdir(dir_pcaps)
for pcap in pcaps:
if pathlib.Path(pcap).suffix in [".pcap", ".cap", ".pcapng"]:
packets = rdpcap(dir_pcaps+pcap)
print(packets)
for packet in packets:
if packet.haslayer("Radius") and packet[IP].src == "10.10.10.40":
rp = packet.getlayer("Radius")
rp_hex = bytes_hex(rp).decode()
for ciphersuite in ciphersuites:
r = re.findall(ciphersuite, rp_hex)
if r:
print(ciphersuites[ciphersuite]," --> "+pcap)
break
else:
pass
get_ciphersuite()
这是输出:
<128CBCSHA.pcapng: TCP:0 UDP:20 ICMP:0 Other:1>
TLS_RSA_WITH_AES_128_CBC_SHA --> 128CBCSHA.pcapng
TLS_RSA_WITH_AES_128_CBC_SHA256 --> 128CBCSHA.pcapng
TLS_RSA_WITH_AES_128_CBC_SHA256 --> 128CBCSHA.pcapng
TLS_RSA_WITH_AES_128_CBC_SHA256 --> 128CBCSHA.pcapng
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 --> 128CBCSHA.pcapng
<test.pcapng: TCP:0 UDP:11 ICMP:0 Other:1>
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 --> test.pcapng
TLS_RSA_WITH_AES_256_CBC_SHA256 --> test.pcapng
此脚本将每个PCAP文件中每个数据包的密码返回,但是我只需要每个文件中的第一个数据包。
I'm tryng to get ciphersuites from pcap file with Scapy. I would like to get only the first packet from every file, beacause I'm using a filter.
This is my code:
from scapy.all import *
from scapy.layers.radius import Radius
import re
import os
import pathlib
def get_ciphersuite():
ciphersuites = {
#'0000' : 'TLS_NULL_WITH_NULL_NULL',
'002f' : 'TLS_RSA_WITH_AES_128_CBC_SHA',
'0035' : 'TLS_RSA_WITH_AES_256_CBC_SHA',
'003c' : 'TLS_RSA_WITH_AES_128_CBC_SHA256',
'003d' : 'TLS_RSA_WITH_AES_256_CBC_SHA256',
'009c' : 'TLS_RSA_WITH_AES_128_GCM_SHA256',
'009d' : 'TLS_RSA_WITH_AES_256_GCM_SHA384',
'c02c' : 'TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384'
}
dir_pcaps = "./pcaps/"
pcaps = os.listdir(dir_pcaps)
for pcap in pcaps:
if pathlib.Path(pcap).suffix in [".pcap", ".cap", ".pcapng"]:
packets = rdpcap(dir_pcaps+pcap)
print(packets)
for packet in packets:
if packet.haslayer("Radius") and packet[IP].src == "10.10.10.40":
rp = packet.getlayer("Radius")
rp_hex = bytes_hex(rp).decode()
for ciphersuite in ciphersuites:
r = re.findall(ciphersuite, rp_hex)
if r:
print(ciphersuites[ciphersuite]," --> "+pcap)
break
else:
pass
get_ciphersuite()
This is the output:
<128CBCSHA.pcapng: TCP:0 UDP:20 ICMP:0 Other:1>
TLS_RSA_WITH_AES_128_CBC_SHA --> 128CBCSHA.pcapng
TLS_RSA_WITH_AES_128_CBC_SHA256 --> 128CBCSHA.pcapng
TLS_RSA_WITH_AES_128_CBC_SHA256 --> 128CBCSHA.pcapng
TLS_RSA_WITH_AES_128_CBC_SHA256 --> 128CBCSHA.pcapng
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 --> 128CBCSHA.pcapng
<test.pcapng: TCP:0 UDP:11 ICMP:0 Other:1>
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 --> test.pcapng
TLS_RSA_WITH_AES_256_CBC_SHA256 --> test.pcapng
This script returns me the ciphersuite for every packet in every pcap file, but I need only the first packet in every file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用
嗅探
。例如,替换为
You could try using
sniff
. For instance, replacewith