mirror of
https://github.com/nmap/nmap.git
synced 2026-08-04 14:49:29 +00:00
NSE: Fix potential crashes in ms-sql scripts and refactor deprecated format_output
This commit is contained in:
parent
d8c9880cd5
commit
2a7358dfe1
6 changed files with 17 additions and 15 deletions
|
|
@ -82,8 +82,7 @@ dependencies = {"broadcast-ms-sql-discover", "ms-sql-empty-password"}
|
|||
--- Returns formatted output for the given instance
|
||||
local function create_instance_output_table( instance )
|
||||
|
||||
local instanceOutput = {}
|
||||
instanceOutput["name"] = string.format( "[%s]", instance:GetName() )
|
||||
local instanceOutput = stdnse.output_table()
|
||||
if ( instance.ms_sql_brute.credentials ) then
|
||||
local credsOutput = {}
|
||||
credsOutput["name"] = "Credentials found:"
|
||||
|
|
@ -126,7 +125,7 @@ local function create_instance_output_table( instance )
|
|||
end
|
||||
end
|
||||
|
||||
return stdnse.format_output(true, instanceOutput)
|
||||
return instanceOutput
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -125,8 +125,8 @@ local function process_instance( instance )
|
|||
|
||||
helper:Disconnect()
|
||||
|
||||
-- TODO: structured output instead of format_output
|
||||
return stdnse.format_output(true, result)
|
||||
-- Return structured output directly
|
||||
return result
|
||||
end
|
||||
|
||||
action, portrule, hostrule = mssql.Helper.InitScript(process_instance)
|
||||
|
|
|
|||
|
|
@ -142,8 +142,8 @@ local function process_instance( instance )
|
|||
end
|
||||
end
|
||||
|
||||
-- TODO: structured output, not format_output
|
||||
return stdnse.format_output(true, output)
|
||||
-- Return structured output directly
|
||||
return output
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -99,9 +99,13 @@ do_action, portrule, hostrule = mssql.Helper.InitScript(process_instance)
|
|||
action = function(...)
|
||||
local scriptOutput = do_action(...)
|
||||
|
||||
if not scriptOutput then
|
||||
return nil
|
||||
end
|
||||
|
||||
if ( not( stdnse.get_script_args( {'ms-sql-query.query', 'mssql-query.query' } ) ) ) then
|
||||
table.insert(scriptOutput, 1, "(Use --script-args=ms-sql-query.query='<QUERY>' to change query.)")
|
||||
end
|
||||
|
||||
return stdnse.format_output( true, scriptOutput )
|
||||
return scriptOutput
|
||||
end
|
||||
|
|
|
|||
|
|
@ -241,12 +241,8 @@ local function process_instance( instance )
|
|||
end
|
||||
|
||||
|
||||
local instanceOutput = {}
|
||||
instanceOutput["name"] = string.format( "[%s]", instance:GetName() )
|
||||
table.insert( instanceOutput, output )
|
||||
|
||||
return stdnse.format_output(true, instanceOutput)
|
||||
|
||||
-- Return structured output directly
|
||||
return output
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -145,9 +145,12 @@ do_action, portrule, hostrule = mssql.Helper.InitScript(process_instance)
|
|||
|
||||
action = function(...)
|
||||
local scriptOutput = do_action(...)
|
||||
if not scriptOutput then
|
||||
return nil
|
||||
end
|
||||
if ( not(stdnse.get_script_args( {'ms-sql-xp-cmdshell.cmd', 'mssql-xp-cmdshell.cmd'} ) ) ) then
|
||||
table.insert(scriptOutput, 1, "(Use --script-args=ms-sql-xp-cmdshell.cmd='<CMD>' to change command.)")
|
||||
end
|
||||
|
||||
return stdnse.format_output( true, scriptOutput )
|
||||
return scriptOutput
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue