mirror of
https://github.com/nmap/nmap.git
synced 2025-12-20 14:39:02 +00:00
o [NSE] Added path argument to the http-auth script and changed so that script
output was returned using stdnse.format_output [Duarte Silva, Patrik]
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
# Nmap Changelog ($Id$); -*-text-*-
|
# Nmap Changelog ($Id$); -*-text-*-
|
||||||
|
|
||||||
|
o [NSE] Added path argument to the http-auth script and changed so that script
|
||||||
|
output was returned using stdnse.format_output [Duarte Silva, Patrik]
|
||||||
|
|
||||||
o [NSE] Fixed bug in the http library that would fail parsing authentication
|
o [NSE] Fixed bug in the http library that would fail parsing authentication
|
||||||
headers if no parameters were present. [Patrik]
|
headers if no parameters were present. [Patrik]
|
||||||
|
|
||||||
|
|||||||
@@ -4,18 +4,30 @@ authentication.
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
---
|
---
|
||||||
|
-- @usage
|
||||||
|
-- nmap --script http-auth [--script-args http-auth.path=/login] -p80 <host>
|
||||||
|
--
|
||||||
-- @output
|
-- @output
|
||||||
-- PORT STATE SERVICE REASON
|
-- PORT STATE SERVICE REASON
|
||||||
-- 80/tcp open http syn-ack
|
-- 80/tcp open http syn-ack
|
||||||
-- | http-auth: HTTP/1.1 401 Unauthorized
|
-- | http-auth:
|
||||||
-- |
|
-- | HTTP/1.1 401 Unauthorized
|
||||||
-- |_Basic realm=WebAdmin
|
-- | Negotiate
|
||||||
|
-- | NTLM
|
||||||
|
-- | Digest charset=utf-8 nonce=+Upgraded+v1e4e256b4afb7f89be014e...968ccd60affb7c qop=auth algorithm=MD5-sess realm=example.com
|
||||||
|
-- |_ Basic realm=example.com
|
||||||
|
--
|
||||||
|
-- @args http-auth.path Define the request path
|
||||||
|
|
||||||
-- HTTP authentication information gathering script
|
-- HTTP authentication information gathering script
|
||||||
-- rev 1.1 (2007-05-25)
|
-- rev 1.1 (2007-05-25)
|
||||||
-- 2008-11-06 Vlatko Kosturjak <kost@linux.hr>
|
-- 2008-11-06 Vlatko Kosturjak <kost@linux.hr>
|
||||||
-- * bug fixes against base64 encoded strings, more flexible auth/pass check,
|
-- * bug fixes against base64 encoded strings, more flexible auth/pass check,
|
||||||
-- corrected sample output
|
-- corrected sample output
|
||||||
|
-- 2011-12-18 Duarte Silva <duarte.silva@serializing.me>
|
||||||
|
-- * Added hostname and path arguments
|
||||||
|
-- * Updated documentation
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
|
||||||
author = "Thomas Buchanan"
|
author = "Thomas Buchanan"
|
||||||
|
|
||||||
@@ -28,39 +40,44 @@ require "http"
|
|||||||
|
|
||||||
portrule = shortport.http
|
portrule = shortport.http
|
||||||
|
|
||||||
|
local PATH = stdnse.get_script_args(SCRIPT_NAME .. ".path")
|
||||||
|
|
||||||
action = function(host, port)
|
action = function(host, port)
|
||||||
local www_authenticate
|
local www_authenticate
|
||||||
local challenges
|
local challenges
|
||||||
|
|
||||||
local result = {}
|
local result = {}
|
||||||
local answer = http.get(host, port, "/")
|
local answer = http.get(host, port, PATH or "/", { bypass_cache = true })
|
||||||
|
|
||||||
--- check for 401 response code
|
--- check for 401 response code
|
||||||
if answer.status ~= 401 then
|
if answer.status ~= 401 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
result[#result + 1] = answer["status-line"]
|
result.name = answer["status-line"]:match("^(.*)\r?\n$")
|
||||||
|
|
||||||
www_authenticate = answer.header["www-authenticate"]
|
www_authenticate = answer.header["www-authenticate"]
|
||||||
if not www_authenticate then
|
if not www_authenticate then
|
||||||
result[#result + 1] = string.format("Server returned status %d but no WWW-Authenticate header.", answer.status)
|
table.insert( ("Server returned status %d but no WWW-Authenticate header."):format(answer.status) )
|
||||||
return table.concat(result, "\n")
|
return stdnse.format_output(true, result)
|
||||||
end
|
end
|
||||||
challenges = http.parse_www_authenticate(www_authenticate)
|
challenges = http.parse_www_authenticate(www_authenticate)
|
||||||
if not challenges then
|
if not challenges then
|
||||||
result[#result + 1] = string.format("Server returned status %d but the WWW-Authenticate header could not be parsed.", answer.status)
|
table.insert( ("Server returned status %d but the WWW-Authenticate header could not be parsed."):format(answer.status) )
|
||||||
result[#result + 1] = string.format("WWW-Authenticate: %s", www_authenticate)
|
table.insert( ("WWW-Authenticate: %s"):format(www_authenticate) )
|
||||||
return table.concat(result, "\n")
|
return stdnse.format_output(true, result)
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, challenge in ipairs(challenges) do
|
for _, challenge in ipairs(challenges) do
|
||||||
local line = challenge.scheme
|
local line = challenge.scheme
|
||||||
|
if ( challenge.params ) then
|
||||||
for name, value in pairs(challenge.params) do
|
for name, value in pairs(challenge.params) do
|
||||||
line = line .. string.format(" %s=%s", name, value)
|
line = line .. string.format(" %s=%s", name, value)
|
||||||
end
|
end
|
||||||
result[#result + 1] = line
|
end
|
||||||
|
table.insert(result, line)
|
||||||
end
|
end
|
||||||
|
|
||||||
return table.concat(result, "\n")
|
--return table.concat(result, "\n")
|
||||||
|
return stdnse.format_output(true, result)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user