Nmap dhcp-discover NSE Script


This page contains detailed information about how to use the dhcp-discover NSE script. For list of all NSE scripts, visit the Nmap NSE Library.

Select:
Overview
Error Messages

Script Overview


Script source code: https://github.com/nmap/nmap/tree/master/scripts/dhcp-discover.nse
Script categories: discovery, safe
Target service / protocol: udp
Target network port(s): 67
List of CVEs: -

Script Description


The dhcp-discover.nse script sends a DHCPINFORM request to a host on UDP port 67 to obtain all the local configuration parameters without allocating a new address.

DHCPINFORM is a DHCP request that returns useful information from a DHCP server, without allocating an IP address. The request sends a list of which fields it wants to know (a handful by default, every field if verbosity is turned on), and the server responds with the fields that were requested. It should be noted that the server doesn't have to return every field, nor does it have to return them in the same order, or honour the request at all. A Linksys WRT54g, for example, completely ignores the list of requested fields and returns a few standard ones. This script displays every field it receives.

With script arguments, the type of DHCP request can be changed, which can lead to interesting results. Additionally, the MAC address can be randomized, which in should override the cache on the DHCP server and assign a new IP address. Extra requests can also be sent to exhaust the IP address range more quickly.

Some of the more useful fields:

  • DHCP Server (the address of the server that responded)
  • Subnet Mask
  • Router
  • DNS Servers
  • Hostname

Dhcp-discover NSE Script Arguments


This is a full list of arguments supported by the dhcp-discover.nse script:

dhcp-discover.dhcptype

The type of DHCP request to make. By default, DHCPINFORM is sent, but this argument can change it to DHCPOFFER, DHCPREQUEST, DHCPDECLINE, DHCPACK, DHCPNAK, DHCPRELEASE or DHCPINFORM. Not all types will evoke a response from all servers, and many require different fields to contain specific values.

dhcp-discover.mac

Set to native (default) or random or a specific client MAC address in the DHCP request. Keep in mind that you may not see the response if a non-native address is used. Setting it to random will possibly cause the DHCP server to reserve a new IP address each time.

dhcp-discover.requests

Set to an integer to make up to that many requests (and display the results).

- - -
To use these script arguments, add them to the Nmap command line using the --script-args arg1=value,[arg2=value,..] syntax. For example:

nmap --script=dhcp-discover --script-args dhcp-discover.dhcptype=value,dhcp-discover.mac=value <target>

Dhcp-discover NSE Script Example Usage


Here's an example of how to use the dhcp-discover.nse script:

nmap -sU -p 67 --script=dhcp-discover <target>

Dhcp-discover NSE Script Example Output


Here's a sample output from the dhcp-discover.nse script:

Interesting ports on 192.168.1.1:
PORT   STATE SERVICE
67/udp open  dhcps
| dhcp-discover:
|   DHCP Message Type: DHCPACK
|   Server Identifier: 192.168.1.1
|   IP Address Lease Time: 1 day, 0:00:00
|   Subnet Mask: 255.255.255.0
|   Router: 192.168.1.1
|_  Domain Name Server: 208.81.7.10, 208.81.7.14

Dhcp-discover NSE Script Example XML Output


Here's a sample XML output from the dhcp-discover.nse script produced by providing the -oX <file> Nmap option:

 <elem key="DHCP Message Type">DHCPACK</elem>
 <elem key="Server Identifier">192.168.1.1</elem>
 <elem key="IP Address Lease Time">1 day, 0:00:00</elem>
 <elem key="Subnet Mask">255.255.255.0</elem>
 <elem key="Router">192.168.1.1</elem>
 <table key="Domain Name Server">
   <elem>208.81.7.10</elem>
   <elem>208.81.7.14</elem>
 </table>

Author


  • Ron Bowes

References


See Also


Visit Nmap NSE Library for more scripts.

The dhcp-discover.nse script may fail with the following error messages. Check for the possible causes by using the code snippets highlighted below found in the script source code. This can often times help in identifying the root cause of the problem.

Invalid request type (use


Here is a relevant code snippet related to the "Invalid request type (use " error message:

106:	
107:	action = function(host, port)
108:	  local dhcptype = (stdnse.get_script_args(SCRIPT_NAME .. ".dhcptype") or "DHCPINFORM"):upper()
109:	  local dhcptypeid = dhcp.request_types[dhcptype]
110:	  if not dhcptypeid then
111:	    return stdnse.format_output(false, "Invalid request type (use "
112:	                                       .. table.concat(dhcp.request_types_str, " / ")
113:	                                       .. ")")
114:	  end
115:	
116:	  local reqcount = tonumber(stdnse.get_script_args(SCRIPT_NAME .. ".requests") or 1)

Invalid request count


Here is a relevant code snippet related to the "Invalid request count" error message:

113:	                                       .. ")")
114:	  end
115:	
116:	  local reqcount = tonumber(stdnse.get_script_args(SCRIPT_NAME .. ".requests") or 1)
117:	  if not reqcount then
118:	    return stdnse.format_output(false, "Invalid request count")
119:	  end
120:	
121:	  local iface, err = nmap.get_interface_info(host.interface)
122:	  if not (iface and iface.address) then
123:	    return stdnse.format_output(false, "Couldn't determine local IP for interface: " .. host.interface)

Couldn't determine local IP for interface:


Here is a relevant code snippet related to the "Couldn't determine local IP for interface: " error message:

118:	    return stdnse.format_output(false, "Invalid request count")
119:	  end
120:	
121:	  local iface, err = nmap.get_interface_info(host.interface)
122:	  if not (iface and iface.address) then
123:	    return stdnse.format_output(false, "Couldn't determine local IP for interface: " .. host.interface)
124:	  end
125:	
126:	  local overrides = {}
127:	
128:	  local macaddr = (stdnse.get_script_args(SCRIPT_NAME .. ".mac") or "native"):lower()

Invalid MAC address


Here is a relevant code snippet related to the "Invalid MAC address" error message:

143:	    if macaddr == "native" then
144:	      macaddr = host.mac_addr_src
145:	    else
146:	      macaddr = macaddr:gsub(":", "")
147:	      if not (#macaddr == 12 and macaddr:find("^%x+$")) then
148:	        return stdnse.format_output(false, "Invalid MAC address")
149:	      end
150:	      macaddr = stdnse.fromhex(macaddr)
151:	    end
152:	    macaddr_iter = function () return macaddr end
153:	  end

Couldn't send DHCP request:


Here is a relevant code snippet related to the "Couldn't send DHCP request: " error message:

156:	  for i = 1, reqcount do
157:	    local macaddr = macaddr_iter()
158:	    stdnse.debug1("Client MAC address: %s", stdnse.tohex(macaddr, {separator = ":"}))
159:	    local status, result = dhcp.make_request(host.ip, dhcptypeid, iface.address, macaddr, nil, nil, overrides)
160:	    if not status then
161:	      return stdnse.format_output(false, "Couldn't send DHCP request: " .. result)
162:	    end
163:	    table.insert(results, result)
164:	  end
165:	
166:	  if #results == 0 then

Version


This page has been created based on Nmap version 7.92.

Go back to menu.