mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 20:51:30 +00:00
Fix usage of nmap.fetchfile in several scripts
Discussion thread: http://seclists.org/nmap-dev/2013/q2/121 Existing behavior preserved and preferred, but absolute and local paths should also work now. Notably, smb-psexec's locate_file function claimed to check current directory but did not.
This commit is contained in:
@@ -107,11 +107,8 @@ local function go(host, port)
|
||||
local is_vulnerable = true
|
||||
|
||||
local folder_file
|
||||
if(nmap.registry.args.folderdb ~= nil) then
|
||||
folder_file = nmap.fetchfile(nmap.registry.args.folderdb)
|
||||
else
|
||||
folder_file = nmap.fetchfile('nselib/data/http-folders.txt')
|
||||
end
|
||||
local farg = nmap.registry.args.folderdb
|
||||
folder_file = farg and (nmap.fetchfile(farg) or farg) or nmap.fetchfile('nselib/data/http-folders.txt')
|
||||
|
||||
if(folder_file == nil) then
|
||||
return false, "Couldn't find http-folders.txt (should be in nselib/data)"
|
||||
@@ -119,7 +116,7 @@ local function go(host, port)
|
||||
|
||||
local file = io.open(folder_file, "r")
|
||||
if not file then
|
||||
return false, "Couldn't find http-folders.txt (should be in nselib/data)"
|
||||
return false, ("Couldn't find or open %s"):format(folder_file)
|
||||
end
|
||||
|
||||
while true do
|
||||
|
||||
@@ -208,7 +208,7 @@ end
|
||||
|
||||
-- load error strings to the errorstrings table
|
||||
local function get_error_strings(path)
|
||||
local f = nmap.fetchfile(path)
|
||||
local f = nmap.fetchfile(path) or path
|
||||
if f then
|
||||
for e in io.lines(f) do
|
||||
if not string.match(e, "^#") then
|
||||
|
||||
@@ -12,7 +12,7 @@ Attempts to exploit java's remote debugging port. When remote debugging port is
|
||||
After injection, class' run() method is executed.
|
||||
Method run() has no parameters, and is expected to return a string.
|
||||
|
||||
You can specify your own .class file to inject by <code>filename</code> argument.
|
||||
You must specify your own .class file to inject by <code>filename</code> argument.
|
||||
See nselib/data/jdwp-class/README for more.
|
||||
]]
|
||||
|
||||
@@ -51,7 +51,7 @@ action = function(host, port)
|
||||
if filename == nil then
|
||||
return stdnse.format_output(false, "This script requires a .class file to inject.")
|
||||
end
|
||||
local file = io.open(nmap.fetchfile(filename), "rb")
|
||||
local file = io.open(nmap.fetchfile(filename) or filename, "rb")
|
||||
local class_bytes = file:read("*all")
|
||||
|
||||
-- inject the class
|
||||
|
||||
@@ -118,7 +118,7 @@ end
|
||||
-- @return status false if error.
|
||||
-- @return string current line.
|
||||
local useriterator = function(list)
|
||||
local f = nmap.fetchfile(list)
|
||||
local f = nmap.fetchfile(list) or list
|
||||
if not f then
|
||||
return false, ("\n ERROR: Couldn't find %s"):format(list)
|
||||
end
|
||||
|
||||
@@ -521,23 +521,30 @@ local function locate_file(filename, extension)
|
||||
|
||||
extension = extension or ""
|
||||
|
||||
local filename_full = nmap.fetchfile(filename)
|
||||
if(filename_full == nil) then
|
||||
filename_full = nmap.fetchfile(filename .. "." .. extension)
|
||||
local filename_full = nmap.fetchfile(filename) or nmap.fetchfile(filename .. "." .. extension)
|
||||
|
||||
if(filename_full == nil) then
|
||||
filename = "nselib/data/psexec/" .. filename
|
||||
filename_full = nmap.fetchfile(filename)
|
||||
|
||||
if(filename_full == nil) then
|
||||
filename_full = nmap.fetchfile(filename .. "." .. extension)
|
||||
end
|
||||
end
|
||||
local psexecfile = "nselib/data/psexec/" .. filename
|
||||
filename_full = nmap.fetchfile(psexecfile) or nmap.fetchfile(psexecfile .. "." .. extension)
|
||||
end
|
||||
|
||||
-- Die if we couldn't find the file
|
||||
-- check for absolute path or relative to current directory
|
||||
if(filename_full == nil) then
|
||||
return nil
|
||||
f, err = io.open(filename, "rb")
|
||||
if f == nil then
|
||||
stdnse.print_debug(1, "%s: Error opening %s: %s", SCRIPT_NAME, filename, err)
|
||||
f, err = io.open(filename .. "." .. extension, "rb")
|
||||
if f == nil then
|
||||
stdnse.print_debug(1, "%s: Error opening %s.%s: %s", SCRIPT_NAME, filename, extension, err)
|
||||
return nil -- unnecessary, but explicit
|
||||
else
|
||||
f:close()
|
||||
return filename .. "." .. extension
|
||||
end
|
||||
else
|
||||
f:close()
|
||||
return filename
|
||||
end
|
||||
end
|
||||
|
||||
return filename_full
|
||||
|
||||
Reference in New Issue
Block a user