1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-06 22:49:02 +00:00

Replaced incorrect try/catch statements in dns-service-discovery that would attempt to close a non-existing socket

This commit is contained in:
patrik
2010-02-01 19:42:23 +00:00
parent 6643fd3422
commit 85d9401ff5
2 changed files with 19 additions and 16 deletions

View File

@@ -2,6 +2,9 @@
[NOT YET RELEASED]
o [NSE] Replaced incorrect try/catch statements in dns-service-discovery that
would attempt to close a non-existing socket
o [NSE] Added the script http-methods from Bernd Stroessenreuther.
This script sends an HTTP OPTIONS request to get the methods
supported by the server, and optionally tests each method to see if

View File

@@ -33,9 +33,10 @@ get more information.
-- |_ Address=192.168.0.2 fe80:0:0:0:223:6cff:1234:5678
-- Version 0.2
-- Version 0.3
-- Created 01/06/2010 - v0.1 - created by Patrik Karlsson <patrik@cqure.net>
-- Revised 01/13/2010 - v0.2 - modified to use existing dns library instead of mdns, changed output to be less DNS like
-- Revised 02/01/2010 - v0.3 - removed incorrect try/catch statements
author = "Patrik Karlsson"
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
@@ -49,11 +50,11 @@ portrule = shortport.portnumber(5353, "udp")
--- Gets a record from both the Answer and Additional section
--
-- @param dtype DNS resource record type.
-- @param dec Decoded DNS response.
-- @param response Decoded DNS response.
-- @param retAll If true, return all entries, not just the first.
-- @return True if one or more answers of the required type were found - otherwise false.
-- @return Answer according to the answer fetcher for <code>dtype</code> or an Error message.
function getRecordType( dtype, dec, retAll )
function getRecordType( dtype, response, retAll )
local result = {}
local status1, answers = dns.findNiceAnswer( dtype, response, retAll )
@@ -90,27 +91,26 @@ end
action = function(host, port)
-- do some exception handling / cleanup
local catch = function()
socket:close()
end
local try = nmap.new_try(catch)
local result = {}
local deviceinfo = {}
local deviceinfo = {}
local status, response = dns.query( "_services._dns-sd._udp.local", { port = 5353, host = host.ip, dtype="PTR", retAll=true} )
if not status then
return
end
response = try( dns.query( "_services._dns-sd._udp.local", { port = 5353, host = host.ip, dtype="PTR", retAll=true} ) )
-- for each service response in answers, send a service query
for _, v in ipairs( response ) do
stdnse.print_debug( string.format("-> Sending MDNS query for: %s", v ) )
local service = {}
local txt = {}
local status, ip, ipv6, srv, address, port, proto
local ip, ipv6, srv, address, port, proto
response = try( dns.query( v, { port = 5353, host = host.ip, dtype="PTR", retPkt=true} ) )
status, response = dns.query( v, { port = 5353, host = host.ip, dtype="PTR", retPkt=true} )
if not status then
return
end
status, ip = getRecordType( dns.types.A, response, false )