Skip to content

Commit

Permalink
Address false positive in hnap-info.nse Closes #241
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsellers committed Dec 3, 2015
1 parent 5e72019 commit c662f9c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions scripts/hnap-info.nse
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ function get_text_callback(store, name)
end

function action (host, port)

-- Identify servers that answer 200 to invalid HTTP requests and exit as these would invalidate the tests
local status_404, result_404, _ = http.identify_404(host,port)
if ( status_404 and result_404 == 200 ) then
stdnse.debug1("Exiting due to ambiguous response from web server on %s:%s. All URIs return status 200.", host.ip, port.number)
return nil
end

local output = stdnse.output_table()
local response = http.get(host, port, '/HNAP1')
if response.status and response.status == 200 then
Expand All @@ -96,7 +104,13 @@ function action (host, port)
closeElement = function(name) parser._call.text = function() return nil end end
}
parser:parseSAX(response.body, {stripWhitespace=true})


-- Counting size of entries in table to determine if it is empty
-- using the '#' operator is not reliable on tables
local count = 0
for _ in pairs(output) do count = count + 1 end
if count < 1 then return nil end

-- set the port verson
port.version.name = "hnap"
port.version.name_confidence = 10
Expand All @@ -110,7 +124,7 @@ function action (host, port)
end
nmap.set_port_version(host, port, "hardmatched")

if #output >0 then return output end
return output
end
end

0 comments on commit c662f9c

Please sign in to comment.