From 986ba5ab8c89ef7c81145831c280496bfd472d28 Mon Sep 17 00:00:00 2001 From: ron Date: Mon, 24 Aug 2009 19:56:52 +0000 Subject: [PATCH] Realized the my check_get() function was elminating perfectly good hosts. Some of our printers use a '301 Moved Permanently' to redirect you to their login page from the root page, but my script was mistaking those for an off-site redirect. I changed check_get() to display a warning rather than causing the scan to fail. --- nselib/http.lua | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/nselib/http.lua b/nselib/http.lua index cf1f0b5b2..9b64efb14 100644 --- a/nselib/http.lua +++ b/nselib/http.lua @@ -1178,25 +1178,21 @@ function can_use_get(host, port) -- Try getting the root directory local data = http.get( host, port, '/' ) if(data == nil) then - return false, "GET request returned nil. Is the server still up?" - end - - -- If the root directory is a permanent redirect, we're going to run into troubles - if(data.status == 301) then - if(data.header and data.header.location) then - return false, string.format("GET request returned %s -- try scanning %s instead, if possible", get_status_string(data), data.header.location) - else - return false, string.format("GET request returned %s -- site is trying to redirect us, but didn't say where", get_status_string(data)) + stdnse.print_debug(1, string.format("GET request for '/' returned nil when verifying host %s", host.ip)) + else + -- If the root directory is a permanent redirect, we're going to run into troubles + if(data.status == 301 or data.status == 302) then + if(data.header and data.header.location) then + stdnse.print_debug(1, string.format("GET request for '/' returned a forwarding address (%s) -- try scanning %s instead, if possible", get_status_string(data), data.header.location)) + end + end + + -- If the root directory requires authentication, we're outta luck + if(data.status == 401) then + stdnse.print_debug(1, string.format("Root directory requires authentication (%s), scans may not work", get_status_string(data))) end end - -- If the root directory requires authentication, we're outta luck - if(data.status == 401) then - return false, string.format("Root directory required authentication -- giving up (%s)", get_status_string(data)) - end - - stdnse.print_debug(1, "It appears that the GET request will work") - return true end