Index: scripts/http-auth.nse =================================================================== --- scripts/http-auth.nse (revision 27507) +++ scripts/http-auth.nse (working copy) @@ -4,18 +4,27 @@ ]] --- +-- @usage +-- nmap --script http-auth [--script-args http-auth.hostname=nmap.scanme.org] -pT:80,443 +-- -- @output -- PORT STATE SERVICE REASON -- 80/tcp open http syn-ack -- | http-auth: HTTP/1.1 401 Unauthorized -- | -- |_Basic realm=WebAdmin +-- +-- @args http-auth.hostname Define the host name to be used in the HEAD request sent to the server +-- @args http-auth.path Define the request path --- HTTP authentication information gathering script --- rev 1.1 (2007-05-25) +-- changelog -- 2008-11-06 Vlatko Kosturjak --- * bug fixes against base64 encoded strings, more flexible auth/pass check, --- corrected sample output +-- * bug fixes against base64 encoded strings, more flexible auth/pass check, +-- corrected sample output +-- 2011-12-18 Duarte Silva +-- * Added hostname and path arguments +-- * Updated documentation +----------------------------------------------------------------------- author = "Thomas Buchanan" @@ -29,11 +38,30 @@ portrule = shortport.http action = function(host, port) + local hostname, path = stdnse.get_script_args('http-auth.hostname', 'http-auth.path') + + if not path then + path = '/' + + stdnse.print_debug(1, "Setting the request path to '/' since 'http-auth.path' argument is missing.") + end + + local request_opts = { + header = { + Connection = "close" + }, + bypass_cache = true + } + + if hostname then + request_opts.header.Host = hostname + end + local www_authenticate local challenges local result = {} - local answer = http.get(host, port, "/") + local answer = http.get(host, port, path, request_opts) --- check for 401 response code if answer.status ~= 401 then