From c0765820ba8e7f75167d8702a33cf9793aa9c547 Mon Sep 17 00:00:00 2001 From: Th3R3p0 Date: Thu, 8 Oct 2015 22:43:23 -0400 Subject: [PATCH] Added the ability to determine a 401 response and abort the script if 401 is returned. --- NSE/http-screenshot.nse | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/NSE/http-screenshot.nse b/NSE/http-screenshot.nse index f4d465f..bbf46d2 100644 --- a/NSE/http-screenshot.nse +++ b/NSE/http-screenshot.nse @@ -30,6 +30,9 @@ local shortport = require "shortport" local stdnse = require "stdnse" +-- Added HTTP to detect response code to abort on 401 +local http = require "http" + portrule = shortport.http action = function(host, port) @@ -47,6 +50,13 @@ action = function(host, port) prefix = "https" end + local answer = http.get(host, port, "/", { bypass_cache = true }) + + if answer.status == 401 then + result = "Page requires authentication (401). Aborting Script" + return stdnse.format_output(true, result) + end + -- Execute the shell command wkhtmltoimage-i386 local cmd = "wkhtmltoimage-i386 -n " .. prefix .. "://" .. host.ip .. ":" .. port.number .. " " .. filename .. " 2> /dev/null >/dev/null"