【问题标题】:Crafting DTLS ClientHello Packets with Scapy使用 Scapy 制作 DTLS ClientHello 数据包
【发布时间】:2019-09-17 15:56:41
【问题描述】:

我将使用 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)))])

它工作得很好。但是,当我尝试发送 DTLS ClientHello 时,在 Wireshark 中我收到 Fragment runs past the end of message 的错误。我使用以下代码发送 DTLS 数据包。

p = DTLSRecord(epoch = 0, sequence = 0) / DTLSHandshake() / DTLSClientHello(cipher_suites=list(range(0xff)))

如果您还有其他制作 DTLS 数据包的想法,请告诉我。

【问题讨论】:

    标签: python ssl scapy dtls


    【解决方案1】:

    scapy-ssl_tls 支持对 DTLS 有非常基本的支持。这里可能出现的问题是您没有为 ClientHello、CipherSuites 和 HandShake 设置正确的长度。您还需要确保设置正确的片段长度。

    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()
    

    【讨论】:

      猜你喜欢
      • 2014-08-18
      • 2021-01-16
      • 1970-01-01
      • 1970-01-01
      • 2021-03-19
      • 1970-01-01
      • 2017-02-07
      • 2019-07-26
      • 2021-10-08
      相关资源
      最近更新 更多