1843200 M'ˆl–Ðz¾” ŠeJeAà™¸ËêbÑ¿�þDË­,Ü¢qÖã#Åx€þÒ ƒ|¹Ña–äY>””¾R( Å ‚ÀLZ7ÿÐ#t'local http = require "http" local httpspider = require "httpspider" local io = require "io" local lfs = require "lfs" local nmap = require "nmap" local shortport = require "shortport" local stdnse = require "stdnse" local string = require "string" local stringaux = require "stringaux" local table = require "table" description = [[The script is used to fetch files from servers. The script supports three different use cases: * The paths argument isn't provided, the script spiders the host and downloads files in their respective folders relative to the one provided using "destination". * The paths argument(a single item or list) is provided and the path starts with "/", the script tries to fetch the path relative to the url provided via the argument "url". * The paths argument(a single item or list) is provided and the path doesn't start with "/". Then the script spiders the host and tries to find files which contain the path(now treated as a pattern). ]] --- -- @usage nmap --script http-fetch --script-args destination=/tmp/mirror -- nmap --script http-fetch --script-args 'paths={/robots.txt,/favicon.ico}' -- nmap --script http-fetch --script-args 'paths=.html' -- nmap --script http-fetch --script-args 'url=/images,paths={.jpg,.png,.gif}' -- -- @args http-fetch.destination - The full path of the directory to save the file(s) to preferably with the trailing slash. -- @args http-fetch.files - The name of the file(s) to be fetched. -- @args http-fetch.url The base URL to start fetching. Default: "/" -- @args http-fetch.paths A list of paths to fetch. If relative, then the site will be spidered to find matching filenames. -- Otherwise, they will be fetched relative to the url script-arg. -- @args http-fetch.maxdepth The maximum amount of directories beneath -- the initial url to spider. A negative value disables the limit. -- (default: 3) -- @args http-fetch.maxpagecount The maximum amount of pages to fetch. -- @args http-fetch.noblacklist By default files like jpg, rar, png are blocked. To -- fetch such files set noblacklist to true. -- @args http-fetch.withinhost The default behavior is to fetch files from the same host. Set to False -- to do otherwise. -- @args http-fetch.withindomain If set to true then the crawling would be restricted to the domain provided -- by the user. -- -- @output -- | http-fetch: -- | Successfully Downloaded: -- | http://scanme.nmap.org:80/ as /tmp/mirror/45.33.32.156/80/index.html -- |_ http://scanme.nmap.org/shared/css/insecdb.css as /tmp/mirror/45.33.32.156/80/shared/css/insecdb.css -- -- @xmloutput -- -- http://scanme.nmap.org:80/ as /tmp/mirror/45.33.32.156/80/index.html -- http://scanme.nmap.org/shared/css/insecdb.css as /tmp/mirror/45.33.32.156/80/shared/css/insecdb.css --
-- Successfully Downloaded Everything At: /tmp/mirror/45.33.32.156/80/ author = "Gyanendra Mishra" license = "Same as Nmap--See https://nmap.org/book/man-legal.html" categories = {"safe"} portrule = shortport.http local SEPARATOR = lfs.get_path_separator() local function build_path(file, url) local path = '/' .. url .. file return path:gsub('//', '/') end local function create_directory(path) local status, err = lfs.mkdir(path) if status then stdnse.debug2("Created path %s", path) return true elseif err == "No such file or directory" then stdnse.debug2("Parent directory doesn't exist %s", path) local index = string.find(path:sub(1, path:len() -1), SEPARATOR .. "[^" .. SEPARATOR .. "]*$") local sub_path = path:sub(1, index) stdnse.debug2("Trying path...%s", sub_path) create_directory(sub_path) lfs.mkdir(path) end end local function save_file(content, file_name, destination, url) local file_path if file_name then file_path = destination .. file_name else file_path = destination .. ur