Home page logo
/
Intro Reference Guide Book Install Guide
Download Changelog Zenmap GUI Docs
Bug Reports OS Detection Propaganda Related Projects
In the Movies In the News

File dhcp-discover

Download: http://nmap.org/svn/scripts/dhcp-discover.nse

User Summary

Sends a DHCPDISCOVER request to a host on UDP port 67. The response come back to UDP port 68, and is read using PCAP (due to the inability for a script to choose its source port at the moment).

DHCPDISCOVER is a DHCP request that returns useful information from a DHCP server. 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.

Using various script-args, the type of DHCP request can be changed, which can lead to interesting results. Additionally, the MAC address can be randomized, which 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. See the 'args' section for more information.

DHCPINFORM is another type of DHCP request that requests the same information, but doesn't reserve an address. Unfortunately, because many home routers simply ignore DHCPINFORM requests, we opted to use DHCPDISCOVER instead.

Some of the more useful fields:

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

The functions for creating and parsing DHCP requests are general, and should be able to create and parse any DHCP request and response. If other scripts require DHCP support, dhcp_build and dhcp_parse, with their related functions, can easily be abstracted into a NSELib.

Script Arguments

timeout

Set to an integer to use it for a timeout. My router responds to fake_requests rate limited, at about 1 response/second. Therefore, timeout has to be at least fake_requests * 1000. Default: 5000.

randomize_mac

Set to 'true' or '1' to send a random MAC address with the request (keep in mind that you may not see the response). This should cause the router to reserve a new IP adderss each time.

fake_requests

Set to an integer to make that many fake requests before the real one(s). This could be useful, for example, if you also use randomize_mac and you want to try exhausting all addresses.

requests

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

dhcptype

The type of DHCP request to make. By default, DHCPDISCOVER 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.

Script Output

Interesting ports on 192.168.1.1:
PORT   STATE SERVICE
67/udp open  dhcps
|  dhcp-discover:
|  |  IP Offered: 192.168.1.101
|  |  DHCP Message Type: DHCPOFFER
|  |  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

Requires


categories default discovery intrusive

author Ron Bowes

copyright © Same as Nmap--See http://nmap.org/book/man-legal.html

Functions

dhcp_build (request_type, ip_address, mac_address, request_options, overrides, lease_time, leasetime)

Build a DHCP packet.

dhcp_parse (data)

Parse a DHCP packet (either a request or a response) and return the results as a table. The table at the top of this function (actions) defines the name of each field, as laid out in rfc2132, and the function that parses it.

read_1_byte (data, pos, length)

Read a single byte. Print an error if the length isn't 1.

read_2_bytes (data, pos, length)

Read a 2-byte unsigned little endian value. Print an error if the length isn't 2.

read_2_bytes_list (data, pos, length)

Read a list of 2-byte unsigned little endian values. Print an error if the length isn't a multiple of 2.

read_4_bytes (data, pos, length)

Read a 4-byte unsigned little endian value. Print an error if the length isn't 4.

read_boolean (data, pos, length)

Read a single byte, and return 'false' if it's 0, or 'true' if it's non-zero. Print an error if the length isn't 1.

read_ip (data, pos, length)

Read an IP address or a list of IP addresses. Print an error if the length isn't a multiple of 4.

read_message_type (data, pos, length)

Read a message type. This is a single-byte value that's looked up in the request_types_str table. Print an error if the length isn't 1.

read_policy_filter (data, pos, length)

Read a list of policy filters. Each of them are a pair of IP addresses, an address and a mask. Print an error if the length isn't a multiple of 8.

read_static_route (data, pos, length)

Read a list of static routes. Each of them are a pair of IP addresses, a destination and a router. Print an error if the length isn't a multiple of 8.

read_string (data, pos, length)

Read a string. The length of the string is given by the length field.

read_time (data, pos, length)

Read a 4-byte unsigned little endian value, and interpret it as a time offset value. Print an error if the length isn't 4.



Functions

dhcp_build (request_type, ip_address, mac_address, request_options, overrides, lease_time, leasetime)

Build a DHCP packet.

Parameters

  • request_type: The type of request (such as DHCPINFORM). See the request_types table.
  • ip_address: The ip address (as a 4-byte string) where the server will send the response. Generally, it'll be host.bin_ip_src or 255.255.255.255.
  • mac_address: The mac address (as a string no more than 16 bytes) where the server will send the response. Generally, this will be host.mac_addr_src or simply a blank string (""). The field will be padded to 16 bytes with null bytes.
  • request_options: [optional] The options to request from the server, as a string of bytes where each byte represents a single option. For the types of options, see rfc2132. Some DHCP servers (such as my Linksys WRT54g) will ignore this list and send whichever options it wants. Options won't necessarily be honoured, it's up to the server what it sends back. By default, all options (1..61) are requested.
  • overrides: [optional] A table of overrides. If a field in the table matches a field in the DHCP packet (see rfc2131 section 2 for a list of possible fields. Or, just look at the code.
  • lease_time:
  • leasetime: [optional] The lease time for which to request an IP. Default: 1 second.

Return value:

The packet, as a string. It should be sent to the server on UDP/67.
dhcp_parse (data)

Parse a DHCP packet (either a request or a response) and return the results as a table. The table at the top of this function (actions) defines the name of each field, as laid out in rfc2132, and the function that parses it.

In theory, this should be able to parse any valid DHCP packet.

Parameters

  • data: The DHCP packet data. Any padding at the end of the packet will be ignored (by default, DHCP packets are padded with \x00 bytes).
read_1_byte (data, pos, length)

Read a single byte. Print an error if the length isn't 1.

Parameters

  • data: The packet.
  • pos: The position in the packet.
  • length: The length that the server claims the field is.

Return values:

  1. The new position (will always be pos + length, no matter what we think it should be)
  2. The value of the field, or nil if the field length was wrong.
read_2_bytes (data, pos, length)

Read a 2-byte unsigned little endian value. Print an error if the length isn't 2.

Parameters

  • data: The packet.
  • pos: The position in the packet.
  • length: The length that the server claims the field is.

Return values:

  1. The new position (will always be pos + length, no matter what we think it should be)
  2. The value of the field, or nil if the field length was wrong.
read_2_bytes_list (data, pos, length)

Read a list of 2-byte unsigned little endian values. Print an error if the length isn't a multiple of 2.

Parameters

  • data: The packet.
  • pos: The position in the packet.
  • length: The length that the server claims the field is.

Return values:

  1. The new position (will always be pos + length, no matter what we think it should be)
  2. The value of the field, or nil if the field length was wrong.
read_4_bytes (data, pos, length)

Read a 4-byte unsigned little endian value. Print an error if the length isn't 4.

Parameters

  • data: The packet.
  • pos: The position in the packet.
  • length: The length that the server claims the field is.

Return values:

  1. The new position (will always be pos + length, no matter what we think it should be)
  2. The value of the field, or nil if the field length was wrong.
read_boolean (data, pos, length)

Read a single byte, and return 'false' if it's 0, or 'true' if it's non-zero. Print an error if the length isn't 1.

Parameters

  • data: The packet.
  • pos: The position in the packet.
  • length: The length that the server claims the field is.

Return values:

  1. The new position (will always be pos + length, no matter what we think it should be)
  2. The value of the field, or nil if the field length was wrong.
read_ip (data, pos, length)

Read an IP address or a list of IP addresses. Print an error if the length isn't a multiple of 4.

Parameters

  • data: The packet.
  • pos: The position in the packet.
  • length: The length that the server claims the field is.

Return values:

  1. The new position (will always be pos + length, no matter what we think it should be)
  2. The value of the field, or nil if the field length was wrong.
read_message_type (data, pos, length)

Read a message type. This is a single-byte value that's looked up in the request_types_str table. Print an error if the length isn't 1.

Parameters

  • data: The packet.
  • pos: The position in the packet.
  • length: The length that the server claims the field is.

Return values:

  1. The new position (will always be pos + length, no matter what we think it should be)
  2. The value of the field, or nil if the field length was wrong.
read_policy_filter (data, pos, length)

Read a list of policy filters. Each of them are a pair of IP addresses, an address and a mask. Print an error if the length isn't a multiple of 8.

Parameters

  • data: The packet.
  • pos: The position in the packet.
  • length: The length that the server claims the field is.

Return values:

  1. The new position (will always be pos + length, no matter what we think it should be)
  2. The value of the field, or nil if the field length was wrong.
read_static_route (data, pos, length)

Read a list of static routes. Each of them are a pair of IP addresses, a destination and a router. Print an error if the length isn't a multiple of 8.

Parameters

  • data: The packet.
  • pos: The position in the packet.
  • length: The length that the server claims the field is.

Return values:

  1. The new position (will always be pos + length, no matter what we think it should be)
  2. The value of the field, or nil if the field length was wrong.
read_string (data, pos, length)

Read a string. The length of the string is given by the length field.

Parameters

  • data: The packet.
  • pos: The position in the packet.
  • length: The length that the server claims the field is.

Return values:

  1. The new position (will always be pos + length, no matter what we think it should be)
  2. The value of the field, or nil if the field length was wrong.
read_time (data, pos, length)

Read a 4-byte unsigned little endian value, and interpret it as a time offset value. Print an error if the length isn't 4.

Parameters

  • data: The packet.
  • pos: The position in the packet.
  • length: The length that the server claims the field is.

Return values:

  1. The new position (will always be pos + length, no matter what we think it should be)
  2. The value of the field, or nil if the field length was wrong.

Nmap Site Navigation

Intro Reference Guide Book Install Guide
Download Changelog Zenmap GUI Docs
Bug Reports OS Detection Propaganda Related Projects
In the Movies In the News
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]