用Scapy制作DTLS ClientHello包

2024-05-16 06:10:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我将使用Scapy模拟DTLS的初始握手。由于Scapy不支持DTLS,我不得不使用scapy-ssl_tls来构建DTLS包。我首先用TLS进行了尝试,然后发送了一个ClientHello,如下所示:

p = TLSRecord() / TLSHandshakes(handshakes=[TLSHandshake() /
                                            TLSClientHello(compression_methods=list(range(0xff))[::-1],
                                                           cipher_suites=list(range(0xff)))])

它工作得很好。然而,当我试图发送一个DTLSClientHello时,在Wireshark中我得到了Fragment runs past the end of message的错误。我使用下面的代码来发送DTLS包。在

^{pr2}$

如果你还有其他的想法来制作DTLS包,请告诉我。在


Tags: ssltlsrangelistscapycompressiondtlshandshakes
1条回答
网友
1楼 · 发布于 2024-05-16 06:10:55

scapy-ssl_-tls支持对dtl有非常基本的支持。这里可能出现的问题是,您没有为ClientHello、密码套件和握手设置正确的长度。您还需要确保设置了正确的片段长度。在

target = (dst, port)

suites = [TLSCipherSuite.RSA_WITH_AES_128_CBC_SHA, \
            TLSCipherSuite.RSA_WITH_AES_128_GCM_SHA256]

#Calculate the length of the ciphersuites
suites_length = 2*len(suites)
d1_ch = DTLSClientHello(cipher_suites=suites, cipher_suites_length=suites_length)

#Calculate ClientHello Length
d1_ch_len = len(str(d1_ch))

#Populate the Handshake message
d1_hs = DTLSHandshake(length=d1_ch_len, fragment_offset=0)

#Get the length of the DTL handshake message
d1_hs_len = len(str(d1_hs))

#Construct the DTLS ClientHello Request
record_len = d1_hs_len + d1_ch_len
p = DTLSRecord(length=record_len) / d1_hs / d1_ch

p.show()
print ("sending DTLS payload")
s.sendto(str(p), target)
resp = s.recv(1024 * 8)
print ("received, %s" % repr(resp))
SSL(resp).show()

s.close()

相关问题 更多 >