mirror of
https://github.com/nmap/nmap.git
synced 2025-12-18 13:39:02 +00:00
Cleaned up code and removed interface from functions dhcp_send and
make_request as it was not used. Added WPAD action. [Patrik]
This commit is contained in:
@@ -351,19 +351,17 @@ actions[58] = {name="Renewal Time Value", func=read_time,
|
|||||||
actions[59] = {name="Rebinding Time Value", func=read_time, default=false}
|
actions[59] = {name="Rebinding Time Value", func=read_time, default=false}
|
||||||
actions[60] = {name="Class Identifier", func=read_string, default=false}
|
actions[60] = {name="Class Identifier", func=read_string, default=false}
|
||||||
actions[61] = {name="Client Identifier (client)", func=read_string, default=false}
|
actions[61] = {name="Client Identifier (client)", func=read_string, default=false}
|
||||||
|
actions[252]= {name="WPAD", func=read_string, default=false}
|
||||||
|
|
||||||
--- Does the send/receive, doesn't build/parse anything.
|
--- Does the send/receive, doesn't build/parse anything.
|
||||||
local function dhcp_send(interface, host, packet, transaction_id)
|
local function dhcp_send(host, packet, transaction_id)
|
||||||
local socket
|
local socket
|
||||||
local status, err, data
|
local status, err, data
|
||||||
local result
|
|
||||||
local results = {}
|
|
||||||
|
|
||||||
-- Create the UDP socket (TODO: enable SO_BROADCAST if we need to)
|
|
||||||
socket = nmap.new_socket("udp")
|
socket = nmap.new_socket("udp")
|
||||||
socket:bind(nil, 68)
|
socket:bind(nil, 68)
|
||||||
socket:set_timeout(5000)
|
socket:set_timeout(5000)
|
||||||
-- status, err = socket:connect(host, 67, "udp")
|
|
||||||
if(status == false) then
|
if(status == false) then
|
||||||
return false, "Couldn't create socket: " .. err
|
return false, "Couldn't create socket: " .. err
|
||||||
end
|
end
|
||||||
@@ -375,6 +373,7 @@ local function dhcp_send(interface, host, packet, transaction_id)
|
|||||||
-- Read the response
|
-- Read the response
|
||||||
local status, data = socket:receive()
|
local status, data = socket:receive()
|
||||||
if ( not(status) ) then
|
if ( not(status) ) then
|
||||||
|
socket:close()
|
||||||
return false, data
|
return false, data
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -599,7 +598,7 @@ end
|
|||||||
--@param lease_time [optional] The lease time used when requestint an IP. Default: 1 second.
|
--@param lease_time [optional] The lease time used when requestint an IP. Default: 1 second.
|
||||||
--@return status (true or false)
|
--@return status (true or false)
|
||||||
--@return The parsed response, as a table.
|
--@return The parsed response, as a table.
|
||||||
function make_request(target, interface, request_type, ip_address, mac_address, request_options, overrides, lease_time)
|
function make_request(target, request_type, ip_address, mac_address, request_options, overrides, lease_time)
|
||||||
-- A unique id that identifies this particular session (and lets us filter out what we don't want to see)
|
-- A unique id that identifies this particular session (and lets us filter out what we don't want to see)
|
||||||
local transaction_id = bin.pack("<I", math.random(0, 0x7FFFFFFF))
|
local transaction_id = bin.pack("<I", math.random(0, 0x7FFFFFFF))
|
||||||
|
|
||||||
@@ -611,7 +610,7 @@ function make_request(target, interface, request_type, ip_address, mac_address,
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Send the packet and get the response
|
-- Send the packet and get the response
|
||||||
local status, response = dhcp_send(interface, target, packet, transaction_id)
|
local status, response = dhcp_send(target, packet, transaction_id)
|
||||||
if(not(status)) then
|
if(not(status)) then
|
||||||
stdnse.print_debug(1, "dhcp: Couldn't send packet: " .. response)
|
stdnse.print_debug(1, "dhcp: Couldn't send packet: " .. response)
|
||||||
return false, "Couldn't send/receive packet: " .. response
|
return false, "Couldn't send/receive packet: " .. response
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ local function go(host, port)
|
|||||||
return false, "Couldn't determine local ip for interface: " .. host.interface
|
return false, "Couldn't determine local ip for interface: " .. host.interface
|
||||||
end
|
end
|
||||||
|
|
||||||
local status, result = dhcp.make_request(host.ip, host.interface, request_type, iface.address, mac_addr)
|
local status, result = dhcp.make_request(host.ip, request_type, iface.address, mac_addr)
|
||||||
if( not(status) ) then
|
if( not(status) ) then
|
||||||
stdnse.print_debug(1, "dhcp-discover: Couldn't send DHCP request: %s", result)
|
stdnse.print_debug(1, "dhcp-discover: Couldn't send DHCP request: %s", result)
|
||||||
return false, result
|
return false, result
|
||||||
|
|||||||
Reference in New Issue
Block a user