Skip to content
This repository has been archived by the owner on Aug 7, 2020. It is now read-only.

obtain return code and output a accurate message #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions NSE/http-screenshot.nse
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
-- Copyright (C) 2012 Trustwave
-- http://www.trustwave.com
--
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 dated June, 1991 or at your option
-- any later version.
--
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
--
-- A copy of the GNU General Public License is available in the source tree;
-- if not, write to the Free Software Foundation, Inc.,
-- 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Expand Down Expand Up @@ -41,21 +41,26 @@ action = function(host, port)

-- Screenshots will be called screenshot-namp-<IP>:<port>.png
local filename = "screenshot-nmap-" .. host.ip .. ":" .. port.number .. ".png"

-- If SSL is set on the port, switch the prefix to https
if ssl == "ssl" then
prefix = "https"
prefix = "https"
end

-- Execute the shell command wkhtmltoimage-i386 <url> <filename>
local cmd = "wkhtmltoimage-i386 -n " .. prefix .. "://" .. host.ip .. ":" .. port.number .. " " .. filename .. " 2> /dev/null >/dev/null"

local ret = os.execute(cmd)
local cmd = "wkhtmltoimage-i386 -n " .. prefix .. "://" .. host.ip .. ":" .. port.number .. " " .. filename

-- If the command was successful, print the saved message, otherwise print the fail message
local result = "failed (verify wkhtmltoimage-i386 is in your path)"
local handler = assert(io.popen(cmd))
local data = handler:read("*a")
local succeeded, error_msg, ret = handler:close()

if ret then
-- If the command was successful, print the saved message, otherwise print the fail message
local result = "Unknown error"
if ret == 127 then
result = "failed (verify wkhtmltoimage-i386 is in your path)"
elseif ret == 1 then
result = "Saved to " .. filename .. " with return code " .. ret
elseif ret == 0 then
result = "Saved to " .. filename
end

Expand Down