mirror of
https://github.com/nmap/nmap.git
synced 2025-12-30 11:29:01 +00:00
Debugging changes to jdwp-* scripts, better error output
This commit is contained in:
@@ -51,6 +51,7 @@ action = function(host, port)
|
||||
local status,socket = jdwp.connect(host,port) -- initialize the connection
|
||||
if not status then
|
||||
stdnse.print_debug("error, %s",socket)
|
||||
return nil
|
||||
end
|
||||
|
||||
-- read .class file
|
||||
@@ -60,28 +61,39 @@ action = function(host, port)
|
||||
-- inject the class
|
||||
local injectedClass
|
||||
status,injectedClass = jdwp.injectClass(socket,class_bytes)
|
||||
if not status then
|
||||
stdnse.print_debug(1, "%s: Failed to inject class", SCRIPT_NAME)
|
||||
return stdnse.format_output(false, "Failed to inject class")
|
||||
end
|
||||
-- find injected class method
|
||||
local runMethodID = jdwp.findMethod(socket,injectedClass.id,"run",false)
|
||||
|
||||
if runMethodID == nil then
|
||||
stdnse.print_debug("Couldn't find run method.")
|
||||
return false
|
||||
stdnse.print_debug(1, "%s: Couldn't find run method", SCRIPT_NAME)
|
||||
return stdnse.format_output(false, "Couldn't find run method.")
|
||||
end
|
||||
-- set run() method argument
|
||||
local cmd = stdnse.get_script_args(SCRIPT_NAME .. '.cmd')
|
||||
if cmd == nil then
|
||||
stdnse.print_debug("This script requires a cmd argument to be specified.")
|
||||
return false
|
||||
return stdnse.format_output(false, "This script requires a cmd argument to be specified.")
|
||||
end
|
||||
local cmdID
|
||||
status,cmdID = jdwp.createString(socket,0,cmd)
|
||||
if not status then
|
||||
stdnse.print_debug(1, "%s: Couldn't create string", SCRIPT_NAME)
|
||||
return stdnse.format_output(false, cmdID)
|
||||
end
|
||||
local runArgs = bin.pack(">CL",0x4c,cmdID) -- 0x4c is object type tag
|
||||
-- invoke run method
|
||||
local result
|
||||
status, result = jdwp.invokeObjectMethod(socket,0,injectedClass.instance,injectedClass.thread,injectedClass.id,runMethodID,1,runArgs)
|
||||
if not status then
|
||||
stdnse.print_debug(1, "%s: Couldn't invoke run method", SCRIPT_NAME)
|
||||
return stdnse.format_output(false, result)
|
||||
end
|
||||
-- get the result string
|
||||
local _,_,stringID = bin.unpack(">CL",result)
|
||||
status,result = jdwp.readString(socket,0,stringID)
|
||||
return stdnse.format_output(true,result)
|
||||
return stdnse.format_output(status,result)
|
||||
end
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ action = function(host, port)
|
||||
local status,socket = jdwp.connect(host,port) -- initialize the connection
|
||||
if not status then
|
||||
stdnse.print_debug("error, %s",socket)
|
||||
return nil
|
||||
end
|
||||
|
||||
-- read .class file
|
||||
@@ -68,21 +69,29 @@ action = function(host, port)
|
||||
-- inject the class
|
||||
local injectedClass
|
||||
status,injectedClass = jdwp.injectClass(socket,class_bytes)
|
||||
if not status then
|
||||
stdnse.print_debug(1, "%s: Failed to inject class", SCRIPT_NAME)
|
||||
return stdnse.format_output(false, "Failed to inject class")
|
||||
end
|
||||
-- find injected class method
|
||||
local runMethodID = jdwp.findMethod(socket,injectedClass.id,"run",false)
|
||||
|
||||
if runMethodID == nil then
|
||||
stdnse.print_debug("Couldn't find run method.")
|
||||
return false
|
||||
stdnse.print_debug(1, "%s: Couldn't find run method", SCRIPT_NAME)
|
||||
return stdnse.format_output(false, "Couldn't find run method.")
|
||||
end
|
||||
|
||||
-- invoke run method
|
||||
local result
|
||||
status, result = jdwp.invokeObjectMethod(socket,0,injectedClass.instance,injectedClass.thread,injectedClass.id,runMethodID,0,nil)
|
||||
if not status then
|
||||
stdnse.print_debug(1, "%s: Couldn't invoke run method", SCRIPT_NAME)
|
||||
return stdnse.format_output(false, result)
|
||||
end
|
||||
-- get the result string
|
||||
local _,_,stringID = bin.unpack(">CL",result)
|
||||
status,result = jdwp.readString(socket,0,stringID)
|
||||
-- parse results
|
||||
return stdnse.format_output(true,result)
|
||||
return stdnse.format_output(status,result)
|
||||
end
|
||||
|
||||
|
||||
@@ -46,13 +46,13 @@ action = function(host, port)
|
||||
local status,socket = jdwp.connect(host,port) -- initialize the connection
|
||||
if not status then
|
||||
stdnse.print_debug("error, %s",socket)
|
||||
return nil
|
||||
end
|
||||
|
||||
-- read .class file
|
||||
local filename = stdnse.get_script_args(SCRIPT_NAME .. '.filename')
|
||||
if filename == nil then
|
||||
stdnse.print_debug("This script requires a .class file to inject.")
|
||||
return false
|
||||
return stdnse.format_output(false, "This script requires a .class file to inject.")
|
||||
end
|
||||
local file = io.open(nmap.fetchfile(filename), "rb")
|
||||
local class_bytes = file:read("*all")
|
||||
@@ -60,21 +60,29 @@ action = function(host, port)
|
||||
-- inject the class
|
||||
local injectedClass
|
||||
status,injectedClass = jdwp.injectClass(socket,class_bytes)
|
||||
if not status then
|
||||
stdnse.print_debug(1, "%s: Failed to inject class", SCRIPT_NAME)
|
||||
return stdnse.format_output(false, "Failed to inject class")
|
||||
end
|
||||
-- find injected class method
|
||||
local runMethodID = jdwp.findMethod(socket,injectedClass.id,"run",false)
|
||||
|
||||
|
||||
if runMethodID == nil then
|
||||
stdnse.print_debug("Couldn't find run method.")
|
||||
return false
|
||||
stdnse.print_debug(1, "%s: Couldn't find run method", SCRIPT_NAME)
|
||||
return stdnse.format_output(false, "Couldn't find run method.")
|
||||
end
|
||||
|
||||
-- invoke run method
|
||||
local result
|
||||
status, result = jdwp.invokeObjectMethod(socket,0,injectedClass.instance,injectedClass.thread,injectedClass.id,runMethodID,0,nil)
|
||||
if not status then
|
||||
stdnse.print_debug(1, "%s: Couldn't invoke run method", SCRIPT_NAME)
|
||||
return stdnse.format_output(false, result)
|
||||
end
|
||||
-- get the result string
|
||||
local _,_,stringID = bin.unpack(">CL",result)
|
||||
status,result = jdwp.readString(socket,0,stringID)
|
||||
-- parse results
|
||||
return stdnse.format_output(true,result)
|
||||
return stdnse.format_output(status,result)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user