mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 12:41:29 +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 is_vulnerable = true
|
||||||
|
|
||||||
local folder_file
|
local folder_file
|
||||||
if(nmap.registry.args.folderdb ~= nil) then
|
local farg = nmap.registry.args.folderdb
|
||||||
folder_file = nmap.fetchfile(nmap.registry.args.folderdb)
|
folder_file = farg and (nmap.fetchfile(farg) or farg) or nmap.fetchfile('nselib/data/http-folders.txt')
|
||||||
else
|
|
||||||
folder_file = nmap.fetchfile('nselib/data/http-folders.txt')
|
|
||||||
end
|
|
||||||
|
|
||||||
if(folder_file == nil) then
|
if(folder_file == nil) then
|
||||||
return false, "Couldn't find http-folders.txt (should be in nselib/data)"
|
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")
|
local file = io.open(folder_file, "r")
|
||||||
if not file then
|
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
|
end
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ end
|
|||||||
|
|
||||||
-- load error strings to the errorstrings table
|
-- load error strings to the errorstrings table
|
||||||
local function get_error_strings(path)
|
local function get_error_strings(path)
|
||||||
local f = nmap.fetchfile(path)
|
local f = nmap.fetchfile(path) or path
|
||||||
if f then
|
if f then
|
||||||
for e in io.lines(f) do
|
for e in io.lines(f) do
|
||||||
if not string.match(e, "^#") then
|
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.
|
After injection, class' run() method is executed.
|
||||||
Method run() has no parameters, and is expected to return a string.
|
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.
|
See nselib/data/jdwp-class/README for more.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ action = function(host, port)
|
|||||||
if filename == nil then
|
if filename == nil then
|
||||||
return stdnse.format_output(false, "This script requires a .class file to inject.")
|
return stdnse.format_output(false, "This script requires a .class file to inject.")
|
||||||
end
|
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")
|
local class_bytes = file:read("*all")
|
||||||
|
|
||||||
-- inject the class
|
-- inject the class
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ end
|
|||||||
-- @return status false if error.
|
-- @return status false if error.
|
||||||
-- @return string current line.
|
-- @return string current line.
|
||||||
local useriterator = function(list)
|
local useriterator = function(list)
|
||||||
local f = nmap.fetchfile(list)
|
local f = nmap.fetchfile(list) or list
|
||||||
if not f then
|
if not f then
|
||||||
return false, ("\n ERROR: Couldn't find %s"):format(list)
|
return false, ("\n ERROR: Couldn't find %s"):format(list)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -521,24 +521,31 @@ local function locate_file(filename, extension)
|
|||||||
|
|
||||||
extension = extension or ""
|
extension = extension or ""
|
||||||
|
|
||||||
local filename_full = nmap.fetchfile(filename)
|
local filename_full = nmap.fetchfile(filename) or nmap.fetchfile(filename .. "." .. extension)
|
||||||
if(filename_full == nil) then
|
|
||||||
filename_full = nmap.fetchfile(filename .. "." .. extension)
|
|
||||||
|
|
||||||
if(filename_full == nil) then
|
if(filename_full == nil) then
|
||||||
filename = "nselib/data/psexec/" .. filename
|
local psexecfile = "nselib/data/psexec/" .. filename
|
||||||
filename_full = nmap.fetchfile(filename)
|
filename_full = nmap.fetchfile(psexecfile) or nmap.fetchfile(psexecfile .. "." .. extension)
|
||||||
|
end
|
||||||
|
|
||||||
if(filename_full == nil) then
|
-- check for absolute path or relative to current directory
|
||||||
filename_full = nmap.fetchfile(filename .. "." .. extension)
|
if(filename_full == nil) then
|
||||||
end
|
f, err = io.open(filename, "rb")
|
||||||
end
|
if f == nil then
|
||||||
end
|
stdnse.print_debug(1, "%s: Error opening %s: %s", SCRIPT_NAME, filename, err)
|
||||||
|
f, err = io.open(filename .. "." .. extension, "rb")
|
||||||
-- Die if we couldn't find the file
|
if f == nil then
|
||||||
if(filename_full == nil) then
|
stdnse.print_debug(1, "%s: Error opening %s.%s: %s", SCRIPT_NAME, filename, extension, err)
|
||||||
return nil
|
return nil -- unnecessary, but explicit
|
||||||
end
|
else
|
||||||
|
f:close()
|
||||||
|
return filename .. "." .. extension
|
||||||
|
end
|
||||||
|
else
|
||||||
|
f:close()
|
||||||
|
return filename
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return filename_full
|
return filename_full
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user