mirror of
https://github.com/nmap/nmap.git
synced 2025-12-14 19:59:02 +00:00
Re-indent some more scripts. Whitespace-only commit
https://secwiki.org/w/Nmap/Code_Standards
This commit is contained in:
@@ -54,7 +54,7 @@ be disabled using the <code>mssql.scanned-ports-only</code> script argument.
|
||||
-- (default 5). If set to zero or less all tables are returned.
|
||||
--
|
||||
-- @args ms-sql-tables.keywords If set shows only tables or columns matching
|
||||
-- the keywords
|
||||
-- the keywords
|
||||
--
|
||||
-- @output
|
||||
-- | ms-sql-tables:
|
||||
@@ -84,13 +84,13 @@ be disabled using the <code>mssql.scanned-ports-only</code> script argument.
|
||||
|
||||
-- Created 01/17/2010 - v0.1 - created by Patrik Karlsson <patrik@cqure.net>
|
||||
-- Revised 04/02/2010 - v0.2
|
||||
-- - Added support for filters
|
||||
-- - Changed output formatting of restrictions
|
||||
-- - Added parameter information in output if parameters are using their
|
||||
-- defaults.
|
||||
-- - Added support for filters
|
||||
-- - Changed output formatting of restrictions
|
||||
-- - Added parameter information in output if parameters are using their
|
||||
-- defaults.
|
||||
-- Revised 02/01/2011 - v0.3 (Chris Woodbury)
|
||||
-- - Added ability to run against all instances on a host;
|
||||
-- - Added compatibility with changes in mssql.lua
|
||||
-- - Added ability to run against all instances on a host;
|
||||
-- - Added compatibility with changes in mssql.lua
|
||||
|
||||
author = "Patrik Karlsson"
|
||||
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
|
||||
@@ -104,169 +104,169 @@ portrule = mssql.Helper.GetPortrule_Standard()
|
||||
|
||||
local function process_instance( instance )
|
||||
|
||||
local status, result, dbs, tables
|
||||
local status, result, dbs, tables
|
||||
|
||||
local output = {}
|
||||
local exclude_dbs = { "'master'", "'tempdb'", "'model'", "'msdb'" }
|
||||
local db_query
|
||||
local done_dbs = {}
|
||||
local db_limit, tbl_limit
|
||||
local output = {}
|
||||
local exclude_dbs = { "'master'", "'tempdb'", "'model'", "'msdb'" }
|
||||
local db_query
|
||||
local done_dbs = {}
|
||||
local db_limit, tbl_limit
|
||||
|
||||
local DB_COUNT = stdnse.get_script_args( {'ms-sql-tables.maxdb', 'mssql-tables.maxdb'} )
|
||||
and tonumber( stdnse.get_script_args( {'ms-sql-tables.maxdb', 'mssql-tables.maxdb'} ) ) or 5
|
||||
local TABLE_COUNT = stdnse.get_script_args( {'ms-sql-tables.maxtables', 'mssql-tables.maxtables' } )
|
||||
and tonumber( stdnse.get_script_args( {'ms-sql-tables.maxtables', 'mssql-tables.maxtables' } ) ) or 2
|
||||
local keywords_filter = ""
|
||||
local DB_COUNT = stdnse.get_script_args( {'ms-sql-tables.maxdb', 'mssql-tables.maxdb'} )
|
||||
and tonumber( stdnse.get_script_args( {'ms-sql-tables.maxdb', 'mssql-tables.maxdb'} ) ) or 5
|
||||
local TABLE_COUNT = stdnse.get_script_args( {'ms-sql-tables.maxtables', 'mssql-tables.maxtables' } )
|
||||
and tonumber( stdnse.get_script_args( {'ms-sql-tables.maxtables', 'mssql-tables.maxtables' } ) ) or 2
|
||||
local keywords_filter = ""
|
||||
|
||||
if ( DB_COUNT <= 0 ) then
|
||||
db_limit = ""
|
||||
else
|
||||
db_limit = string.format( "TOP %d", DB_COUNT )
|
||||
end
|
||||
if (TABLE_COUNT <= 0 ) then
|
||||
tbl_limit = ""
|
||||
else
|
||||
tbl_limit = string.format( "TOP %d", TABLE_COUNT )
|
||||
end
|
||||
if ( DB_COUNT <= 0 ) then
|
||||
db_limit = ""
|
||||
else
|
||||
db_limit = string.format( "TOP %d", DB_COUNT )
|
||||
end
|
||||
if (TABLE_COUNT <= 0 ) then
|
||||
tbl_limit = ""
|
||||
else
|
||||
tbl_limit = string.format( "TOP %d", TABLE_COUNT )
|
||||
end
|
||||
|
||||
-- Build the keyword filter
|
||||
if ( stdnse.get_script_args( {'ms-sql-tables.keywords', 'mssql-tables.keywords' } ) ) then
|
||||
local keywords = stdnse.get_script_args( {'ms-sql-tables.keywords', 'mssql-tables.keywords' } )
|
||||
local tmp_tbl = {}
|
||||
-- Build the keyword filter
|
||||
if ( stdnse.get_script_args( {'ms-sql-tables.keywords', 'mssql-tables.keywords' } ) ) then
|
||||
local keywords = stdnse.get_script_args( {'ms-sql-tables.keywords', 'mssql-tables.keywords' } )
|
||||
local tmp_tbl = {}
|
||||
|
||||
if( type(keywords) == 'string' ) then
|
||||
keywords = { keywords }
|
||||
end
|
||||
if( type(keywords) == 'string' ) then
|
||||
keywords = { keywords }
|
||||
end
|
||||
|
||||
for _, v in ipairs(keywords) do
|
||||
table.insert(tmp_tbl, ("'%s'"):format(v))
|
||||
end
|
||||
for _, v in ipairs(keywords) do
|
||||
table.insert(tmp_tbl, ("'%s'"):format(v))
|
||||
end
|
||||
|
||||
keywords_filter = (" AND ( so.name IN (%s) or sc.name IN (%s) ) "):format(
|
||||
stdnse.strjoin(",", tmp_tbl),
|
||||
stdnse.strjoin(",", tmp_tbl)
|
||||
)
|
||||
end
|
||||
keywords_filter = (" AND ( so.name IN (%s) or sc.name IN (%s) ) "):format(
|
||||
stdnse.strjoin(",", tmp_tbl),
|
||||
stdnse.strjoin(",", tmp_tbl)
|
||||
)
|
||||
end
|
||||
|
||||
db_query = ("SELECT %s name from master..sysdatabases WHERE name NOT IN (%s)"):format(db_limit, stdnse.strjoin(",", exclude_dbs))
|
||||
db_query = ("SELECT %s name from master..sysdatabases WHERE name NOT IN (%s)"):format(db_limit, stdnse.strjoin(",", exclude_dbs))
|
||||
|
||||
|
||||
local creds = mssql.Helper.GetLoginCredentials_All( instance )
|
||||
if ( not creds ) then
|
||||
output = "ERROR: No login credentials."
|
||||
else
|
||||
for username, password in pairs( creds ) do
|
||||
local helper = mssql.Helper:new()
|
||||
status, result = helper:ConnectEx( instance )
|
||||
if ( not(status) ) then
|
||||
table.insert(output, "ERROR: " .. result)
|
||||
break
|
||||
end
|
||||
local creds = mssql.Helper.GetLoginCredentials_All( instance )
|
||||
if ( not creds ) then
|
||||
output = "ERROR: No login credentials."
|
||||
else
|
||||
for username, password in pairs( creds ) do
|
||||
local helper = mssql.Helper:new()
|
||||
status, result = helper:ConnectEx( instance )
|
||||
if ( not(status) ) then
|
||||
table.insert(output, "ERROR: " .. result)
|
||||
break
|
||||
end
|
||||
|
||||
if ( status ) then
|
||||
status = helper:Login( username, password, nil, instance.host.ip )
|
||||
end
|
||||
if ( status ) then
|
||||
status = helper:Login( username, password, nil, instance.host.ip )
|
||||
end
|
||||
|
||||
if ( status ) then
|
||||
status, dbs = helper:Query( db_query )
|
||||
end
|
||||
if ( status ) then
|
||||
status, dbs = helper:Query( db_query )
|
||||
end
|
||||
|
||||
if ( status ) then
|
||||
-- all done?
|
||||
if ( #done_dbs == #dbs.rows ) then
|
||||
break
|
||||
end
|
||||
if ( status ) then
|
||||
-- all done?
|
||||
if ( #done_dbs == #dbs.rows ) then
|
||||
break
|
||||
end
|
||||
|
||||
for k, v in pairs(dbs.rows) do
|
||||
if ( not( stdnse.contains( done_dbs, v[1] ) ) ) then
|
||||
local query = [[ SELECT so.name 'table', sc.name 'column', st.name 'type', sc.length
|
||||
FROM %s..syscolumns sc, %s..sysobjects so, %s..systypes st
|
||||
WHERE so.id = sc.id AND sc.xtype=st.xtype AND
|
||||
so.id IN (SELECT %s id FROM %s..sysobjects WHERE xtype='U') %s ORDER BY so.name, sc.name, st.name]]
|
||||
query = query:format( v[1], v[1], v[1], tbl_limit, v[1], keywords_filter)
|
||||
status, tables = helper:Query( query )
|
||||
if ( not(status) ) then
|
||||
stdnse.print_debug(tables)
|
||||
else
|
||||
local item = {}
|
||||
item = mssql.Util.FormatOutputTable( tables, true )
|
||||
if ( #item == 0 and keywords_filter ~= "" ) then
|
||||
table.insert(item, "Filter returned no matches")
|
||||
end
|
||||
item.name = v[1]
|
||||
for k, v in pairs(dbs.rows) do
|
||||
if ( not( stdnse.contains( done_dbs, v[1] ) ) ) then
|
||||
local query = [[ SELECT so.name 'table', sc.name 'column', st.name 'type', sc.length
|
||||
FROM %s..syscolumns sc, %s..sysobjects so, %s..systypes st
|
||||
WHERE so.id = sc.id AND sc.xtype=st.xtype AND
|
||||
so.id IN (SELECT %s id FROM %s..sysobjects WHERE xtype='U') %s ORDER BY so.name, sc.name, st.name]]
|
||||
query = query:format( v[1], v[1], v[1], tbl_limit, v[1], keywords_filter)
|
||||
status, tables = helper:Query( query )
|
||||
if ( not(status) ) then
|
||||
stdnse.print_debug(tables)
|
||||
else
|
||||
local item = {}
|
||||
item = mssql.Util.FormatOutputTable( tables, true )
|
||||
if ( #item == 0 and keywords_filter ~= "" ) then
|
||||
table.insert(item, "Filter returned no matches")
|
||||
end
|
||||
item.name = v[1]
|
||||
|
||||
table.insert(output, item)
|
||||
table.insert(done_dbs, v[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
helper:Disconnect()
|
||||
end
|
||||
table.insert(output, item)
|
||||
table.insert(done_dbs, v[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
helper:Disconnect()
|
||||
end
|
||||
|
||||
local pos = 1
|
||||
local restrict_tbl = {}
|
||||
local pos = 1
|
||||
local restrict_tbl = {}
|
||||
|
||||
if ( stdnse.get_script_args( {'ms-sql-tables.keywords', 'mssql-tables.keywords' } ) ) then
|
||||
local tmp = stdnse.get_script_args( {'ms-sql-tables.keywords', 'mssql-tables.keywords' } )
|
||||
if ( type(tmp) == 'table' ) then
|
||||
tmp = stdnse.strjoin(',', tmp)
|
||||
end
|
||||
table.insert(restrict_tbl, 1, ("Filter: %s"):format(tmp))
|
||||
pos = pos + 1
|
||||
else
|
||||
table.insert(restrict_tbl, 1, "No filter (see ms-sql-tables.keywords)")
|
||||
end
|
||||
if ( stdnse.get_script_args( {'ms-sql-tables.keywords', 'mssql-tables.keywords' } ) ) then
|
||||
local tmp = stdnse.get_script_args( {'ms-sql-tables.keywords', 'mssql-tables.keywords' } )
|
||||
if ( type(tmp) == 'table' ) then
|
||||
tmp = stdnse.strjoin(',', tmp)
|
||||
end
|
||||
table.insert(restrict_tbl, 1, ("Filter: %s"):format(tmp))
|
||||
pos = pos + 1
|
||||
else
|
||||
table.insert(restrict_tbl, 1, "No filter (see ms-sql-tables.keywords)")
|
||||
end
|
||||
|
||||
if ( DB_COUNT > 0 ) then
|
||||
local tmp = ("Output restricted to %d databases"):format(DB_COUNT)
|
||||
if ( not(stdnse.get_script_args( { 'ms-sql-tables.maxdb', 'mssql-tables.maxdb' } ) ) ) then
|
||||
tmp = tmp .. " (see ms-sql-tables.maxdb)"
|
||||
end
|
||||
table.insert(restrict_tbl, 1, tmp)
|
||||
pos = pos + 1
|
||||
end
|
||||
if ( DB_COUNT > 0 ) then
|
||||
local tmp = ("Output restricted to %d databases"):format(DB_COUNT)
|
||||
if ( not(stdnse.get_script_args( { 'ms-sql-tables.maxdb', 'mssql-tables.maxdb' } ) ) ) then
|
||||
tmp = tmp .. " (see ms-sql-tables.maxdb)"
|
||||
end
|
||||
table.insert(restrict_tbl, 1, tmp)
|
||||
pos = pos + 1
|
||||
end
|
||||
|
||||
if ( TABLE_COUNT > 0 ) then
|
||||
local tmp = ("Output restricted to %d tables"):format(TABLE_COUNT)
|
||||
if ( not(stdnse.get_script_args( { 'ms-sql-tables.maxtables', 'mssql-tables.maxtables' } ) ) ) then
|
||||
tmp = tmp .. " (see ms-sql-tables.maxtables)"
|
||||
end
|
||||
table.insert(restrict_tbl, 1, tmp)
|
||||
pos = pos + 1
|
||||
end
|
||||
if ( TABLE_COUNT > 0 ) then
|
||||
local tmp = ("Output restricted to %d tables"):format(TABLE_COUNT)
|
||||
if ( not(stdnse.get_script_args( { 'ms-sql-tables.maxtables', 'mssql-tables.maxtables' } ) ) ) then
|
||||
tmp = tmp .. " (see ms-sql-tables.maxtables)"
|
||||
end
|
||||
table.insert(restrict_tbl, 1, tmp)
|
||||
pos = pos + 1
|
||||
end
|
||||
|
||||
if ( 1 < pos and type( output ) == "table" and #output > 0) then
|
||||
restrict_tbl.name = "Restrictions"
|
||||
table.insert(output, "")
|
||||
table.insert(output, restrict_tbl)
|
||||
end
|
||||
end
|
||||
if ( 1 < pos and type( output ) == "table" and #output > 0) then
|
||||
restrict_tbl.name = "Restrictions"
|
||||
table.insert(output, "")
|
||||
table.insert(output, restrict_tbl)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local instanceOutput = {}
|
||||
instanceOutput["name"] = string.format( "[%s]", instance:GetName() )
|
||||
table.insert( instanceOutput, output )
|
||||
local instanceOutput = {}
|
||||
instanceOutput["name"] = string.format( "[%s]", instance:GetName() )
|
||||
table.insert( instanceOutput, output )
|
||||
|
||||
return instanceOutput
|
||||
return instanceOutput
|
||||
|
||||
end
|
||||
|
||||
|
||||
action = function( host, port )
|
||||
local scriptOutput = {}
|
||||
local status, instanceList = mssql.Helper.GetTargetInstances( host, port )
|
||||
local scriptOutput = {}
|
||||
local status, instanceList = mssql.Helper.GetTargetInstances( host, port )
|
||||
|
||||
if ( not status ) then
|
||||
return stdnse.format_output( false, instanceList )
|
||||
else
|
||||
for _, instance in pairs( instanceList ) do
|
||||
local instanceOutput = process_instance( instance )
|
||||
if instanceOutput then
|
||||
table.insert( scriptOutput, instanceOutput )
|
||||
end
|
||||
end
|
||||
end
|
||||
if ( not status ) then
|
||||
return stdnse.format_output( false, instanceList )
|
||||
else
|
||||
for _, instance in pairs( instanceList ) do
|
||||
local instanceOutput = process_instance( instance )
|
||||
if instanceOutput then
|
||||
table.insert( scriptOutput, instanceOutput )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return stdnse.format_output( true, scriptOutput )
|
||||
return stdnse.format_output( true, scriptOutput )
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user