Skip to content

Instantly share code, notes, and snippets.

@ca0s
Created October 29, 2019 10:12
Show Gist options
  • Save ca0s/dcc2fb4d1617cd42b401c3f16ac56b37 to your computer and use it in GitHub Desktop.
Save ca0s/dcc2fb4d1617cd42b401c3f16ac56b37 to your computer and use it in GitHub Desktop.
A slightly improved version of nmap's http-screenshot.nse
local shortport = require "shortport"
local stdnse = require "stdnse"
description = [[
Gets a screenshot from a Web service using webshot.js, a nodejs/puppeteer script.
It can be used with IVRE.
]]
author = "Javier Gil <javier.gilmaestro@telefonica.com>"
license = "GPLv3"
categories = {"discovery", "safe", "screenshot"}
---
-- @usage
-- nmap -n -p 80 --script http-screenshot www.google.com
--
-- @args http-screenshot.vhost the vhost to use (default: use the
-- provided hostname or IP address)
-- @args http-screenshot.timeout timeout for the webshot.js script
-- (default: 300s)
--
-- @output
-- PORT STATE SERVICE
-- 80/tcp open http
-- |_http-screenshot: Saved to screenshot-173.194.45.82-www.google.com-80.jpg
portrule = shortport.http
local function get_hostname(host)
local arg = stdnse.get_script_args(SCRIPT_NAME .. '.vhost')
return arg or host.targetname or host.ip
end
action = function(host, port)
local fname, strport, cmd
local timeout = tonumber(stdnse.get_script_args(SCRIPT_NAME .. '.timeout')) or 300
local ssl = port.version.service_tunnel == "ssl" or (
port.version.sevice_name == nil and port.service:match("https") ~= nil
)
local port = port.number
local hostname = get_hostname(host)
if hostname == host.ip then
fname = ("screenshot-%s-%d.jpg"):format(host.ip, port)
else
fname = ("screenshot-%s-%s-%d.jpg"):format(host.ip, hostname, port)
end
if (port == 80 and not ssl) or (port == 443 and ssl) then
strport = ""
else
strport = (":%d"):format(port)
end
local url = ("%s://%s%s"):format(ssl and "https" or "http", hostname, strport)
cmd = ("webshot.js %s %s"):format(url, fname)
os.execute("timeout " .. timeout .. " " .. cmd)
return (os.rename(fname, fname)
and ("Saved to %s"):format(fname)
or "Failed")
end
#!/usr/bin/node
const puppeteer = require('puppeteer');
const url = process.argv[2];
const filepath = process.argv[3];
console.log("Fetching " + url);
console.log("Saving to " + filepath);
(async () => {
const browser = await puppeteer.launch({
ignoreHTTPSErrors: true,
defaultViewport: {
width: 1920,
height: 981
}
});
const page = await browser.newPage();
await page.goto(url);
await page.screenshot({path: filepath, fullPage: true});
await browser.close();
})().catch((e) => {
console.log("Failed: " + e);
process.exit(-1);
});;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment