Skip to content

Commit

Permalink
support headless phantomjs without errors
Browse files Browse the repository at this point in the history
  • Loading branch information
freb committed Feb 1, 2019
1 parent e8242ae commit c18f2d0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion http-screenshot.nse
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ downloaded from http://phantomjs.org/ and placed on the system path.
-- nmap --script http-screenshot --script-args http-screenshot.textonly <target>
-- nmap --script http-screenshot --script-args http-screenshot.files <target>
-- nmap --script http-screenshot --script-args http-screenshot.prefix="pre" <target>
-- nmap --script http-screenshot --script-args http-screenshot.headless
--
-- @output
-- 443/tcp open https syn-ack
Expand Down Expand Up @@ -227,7 +228,17 @@ action = function(host, port)
stdnse.verbose("rendering html for %s", target)

local pjsfile = nmap.registry[SCRIPT_NAME].pjsfile
local cmd = string.format("phantomjs --ignore-ssl-errors=true %s %s %s", pjsfile, url, filename)

local cmd
if stdnse.get_script_args(SCRIPT_NAME .. '.headless') then
-- create XDG_RUNTIME_DIR, accessible only by user
local tmpdir = os.tmpname()
os.remove(tmpdir)
os.execute("mkdir -m 700 " .. tmpdir)
cmd = string.format("XDG_RUNTIME_DIR=\"%s\" QT_QPA_PLATFORM=offscreen phantomjs --ignore-ssl-errors=true %s %s %s", tmpdir, pjsfile, url, filename)
else
cmd = string.format("phantomjs --ignore-ssl-errors=true %s %s %s", pjsfile, url, filename)
end

local file = io.popen(cmd, 'r')
if file == nil then
Expand Down

0 comments on commit c18f2d0

Please sign in to comment.