4

How can I utilize scapy as a dhcp client to request certain DHCP options? Clients will request what they need and a dhcp client should respond accordingly. However, I need to test if certain DHCP options are being sent from a server and these are options my PC won't normally request. These could be options 150, 242, etc.

Can scapy support any of the DHCP options? In the code below, how would I adjust if I wanted to request option 242 or option 150?

ethernet = Ether(dst='ff:ff:ff:ff:ff:ff',src=src_mac_address,type=0x800)
ip = IP(src ='0.0.0.0',dst='255.255.255.255')
udp =UDP (sport=68,dport=67)
bootp = BOOTP(chaddr = hw, ciaddr = '0.0.0.0',xid =  0x01020304,flags= 1)
dhcp = DHCP(options=[("message-type","discover"),"end"])

packet = ethernet / ip / udp / bootp / dhcp
hiddenicon
  • 551
  • 2
  • 11
  • 23

2 Answers2

0
requested_option_1 = 1    # Subnet Mask
requested_option_2 = 6    # Domain Name Servers
requested_option_3 = 15   # Domain Name
requested_option_4 = 44   # NetBIOS (TCP/IP) Name Servers
requested_option_5 = 3    # Routers
requested_option_6 = 33   # Static Routes
requested_option_7 = 150  # TFTP Server address
requested_option_8 = 43   # Vendor Specific Information

bytes_requested_options = struct.pack("8B", requested_option_1,
                                            requested_option_2,
                                            requested_option_3,
                                            requested_option_4,
                                            requested_option_5,
                                            requested_option_6,
                                            requested_option_7,
                                            requested_option_8)
dhcp = DHCP(options=[('message-type', 'discover'),('param_req_list',bytes_requested_options),'end'])
0

Simply add your options as a integer array, like this:

dhcp = DHCP(options=[('message-type','discover'),
                     ('hostname',hostname),
                     ('param_req_list',
                     [1,3,6]),
                     ('end')])

Or, in order to use the scapy provided options:

dhcp = DHCP(options=[('message-type','discover'),
                     ('hostname',hostname),
                     ('param_req_list',
                     [
                     int(scapy.all.DHCPRevOptions["subnet_mask"][0]),
                     int(scapy.all.DHCPRevOptions["router"][0]),
                     int(scapy.all.DHCPRevOptions["name_server"][0])
                     ]),
                     ('end')])
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83