diff --git a/scripts/broadcast-dhcp-discover.nse b/scripts/broadcast-dhcp-discover.nse index 8f35e7f4e..cb8e832a2 100644 --- a/scripts/broadcast-dhcp-discover.nse +++ b/scripts/broadcast-dhcp-discover.nse @@ -115,9 +115,57 @@ end -- @param timeout number of ms to wait for a response -- @param xid the DHCP transaction id -- @param result a table to which the result is written -local function dhcp_listener(sock, iface, timeout, xid, result) +local function dhcp_listener(sock, iface, macaddr, timeout, xid, result) local condvar = nmap.condvar(result) + local srcip = ipOps.ip_to_str("0.0.0.0") + local dstip = ipOps.ip_to_str("255.255.255.255") + -- Build DHCP request + local status, pkt = dhcp.dhcp_build( + dhcp.request_types.DHCPDISCOVER, + srcip, + macaddr, + nil, -- options + nil, -- request options + {flags=0x8000}, -- override: broadcast + nil, -- lease time + xid) + if not status then + stdnse.debug1("Failed to build packet for %s: %s", iface, pkt) + condvar "signal" + return + end + + -- Add UDP header + local udplen = #pkt + 8 + local tmp = string.pack(">c4c4 xBI2 I2I2I2xx", + srcip, dstip, + packet.IPPROTO_UDP, udplen, + 68, 67, udplen) .. pkt + pkt = string.pack(">I2 I2 I2 I2", 68, 67, udplen, packet.in_cksum(tmp)) .. pkt + + -- Create a frame and add the IP header + local frame = packet.Frame:new() + frame:build_ip_packet(srcip, dstip, pkt, nil, --dsf + string.unpack("