首页 文章

如何用scapy解码DHCP中继数据包的十六进制数据?

提问于
浏览
2

我想用我的DHCP服务器上的DHCP中继嗅探DHCP数据包但是我有一个问题,因为我感兴趣的唯一部分是用十六进制写的 .

是一种强制scapy解码这部分或另一个库来做到这一点的方法吗?

下面是一个由scapy嗅探的数据包示例 . 我要解码的部分是“Unknown DHCPv6 Option”下的“data”:

###[ Ethernet ]###
  dst= f4:cf:e2:4c:9c:ed
  src= 00:22:bd:f8:35:47
  type= 0x86dd
###[ IPv6 ]###
     version= 6L
     tc= 0L
     fl= 0L
     plen= 149
     nh= UDP
     hlim= 255
     src= 2001:db8:0:1::ee
     dst= 2001:db8:0:1::ed
###[ UDP ]###
        sport= dhcpv6_server
        dport= dhcpv6_server
        len= 149
        chksum= 0xd489
###[ DHCPv6 Relay Forward Message (Relay Agent/Server Message) ]###
           msgtype= RELAY-FORW
           hopcount= 0
           linkaddr= 2001:db8:0:1::e6
           peeraddr= fe80::f6cf:e2ff:fe11:7ef9
###[ Unknown DHCPv6 OPtion ]###
              optcode= RELAY_MSG
              optlen= 77
              data= '\x01\xed\t{\x00\x01\x00\n\x00\x03\x00\x01B\x00\x14\\U\xb3\x00\x06\x00\x04\x00\x17\x00\x18\x00\x08\x00\x02\x00\x00\x00\x19\x00)\xe2\x11~\xf9\x00\x00\x0e\x10\x00\x00\x15\x18\x00\x1a\x00\x19\x00\x00\x1c \x00\x00*00 \x01\x0b\xc80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
###[ DHCP6 Option - Relay Agent Remote-ID ]###
                 optcode= OPTION_REMOTE_ID
                 optlen= 14
                 enterprisenum= ciscoSystems
                 remoteid= '\x00\x03\x08\x00\x00"\xbd\xf85G'
###[ DHCP6 Interface-Id Option ]###
                    optcode= INTERFACE_ID
                    optlen= 4
                    ifaceid= '\t\x01\x00\n'

当我做 packet[DHCP6OptUnknown].getfieldval(data) 它返回

'\x01\xed\t{\x00\x01\x00\n\x00\x03\x00\x01B\x00\x14\\U\xb3\x00\x06\x00\x04\x00\x17\x00\x18\x00\x08\x00\x02\x00\x00\x00\x19\x00)\xe2\x11~\xf9\x00\x00\x0e\x10\x00\x00\x15\x18\x00\x1a\x00\x19\x00\x00\x1c \x00\x00*00 \x01\x0b\xc80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

这是我想要的数据,在内部我想获得服务器发送的前缀委托 .

在此先感谢您的帮助 !

Ps:对不起我可怜的英语:)

EDIT : 修补DHCP中继数据包后如下所示:

###[ Ethernet ]###
  dst= 00:22:bd:f8:35:47
  src= f4:cf:e2:4c:9c:ed
  type= 0x86dd
###[ IPv6 ]###
     version= 6L
     tc= 0L
     fl= 0L
     plen= 192
     nh= UDP
     hlim= 64
     src= 2001:db8:0:1::ed
     dst= 2001:db8:0:1::ee
###[ UDP ]###
        sport= dhcpv6_server
        dport= dhcpv6_server
        len= 192
        chksum= 0x26dc
###[ DHCPv6 Relay Reply Message (Relay Agent/Server Message) ]###
           msgtype= RELAY-REPL
           hopcount= 0
           linkaddr= 2001:db8:0:1::e6
           peeraddr= fe80::f6cf:e2ff:fe11:7ef9
###[ DHCP6 Interface-Id Option ]###
              optcode= INTERFACE_ID
              optlen= 4
              ifaceid= '\t\x01\x00\n'
###[ DHCP6 Relay Message Option ]###
                 optcode= RELAY_MSG
                 optlen= 138
###[ DHCPv6 Reply Message ]###
                    msgtype= REPLY
                    trid= 0x8bcc55
###[ DHCP6 Option - Identity Association for Prefix Delegation ]###
                       optcode= OPTION_IA_PD
                       optlen= 41
                       iaid= 3792797433
                       T1= 3600
                       T2= 7200
                       \iapdopt\
                        |###[ DHCP6 Option - IA_PD Prefix option ]###
                        |  optcode= OPTION_IAPREFIX
                        |  optlen= 25
                        |  preflft= 4500
                        |  validlft= 7200
                        |  plen= 48
                        |  prefix= 2001:db8:3000::
                        |  iaprefopts= ''
###[ DHCP6 Client Identifier Option ]###
                          optcode= CLIENTID
                          optlen= 10
                          \duid\
                           |###[ DUID - Based on Link-layer Address ]###
                           |  type= Link-layer Address
                           |  hwtype= Ethernet (10Mb)
                           |  lladdr= 42:00:14:xx:xx:xx
###[ DHCP6 Server Identifier Option ]###
                             optcode= SERVERID
                             optlen= 14
                             \duid\
                              |###[ DUID - Link-layer address plus time ]###
                              |  type= Link-layer address plus time
                              |  hwtype= Ethernet (10Mb)
                              |  timeval= Tue, 24 Mar 2015 03:09:53 +0000 (1427166593)
                              |  lladdr= f4:cf:e2:4c:9c:ed
###[ DHCP6 Preference Option ]###
                                optcode= PREFERENCE
                                optlen= 1
                                prefval= 255
###[ DHCP6 Option - DNS Recursive Name Server ]###
                                   optcode= DNS Recursive Name Server Option
                                   optlen= 32
                                   dnsservers= [ 2001:db8:401::3, 2001:db8:1::16 ]
###[ DHCP6 Option - Domain Search List option ]###
                                      optcode= Domain Search List option
                                      optlen= 12
                                      dnsdomains= ['foo.net']

1 回答

相关问题