mirror of
https://github.com/nmap/nmap.git
synced 2025-12-07 13:11:28 +00:00
Reindent some scripts. Whitespace only.
https://secwiki.org/w/Nmap/Code_Standards
This commit is contained in:
@@ -47,72 +47,72 @@ local arg_noheaders = stdnse.get_script_args(SCRIPT_NAME .. ".noheaders") or fal
|
||||
local function fail(err) return ("\n ERROR: %s"):format(err or "") end
|
||||
|
||||
local function getCredentials()
|
||||
-- first, let's see if the script has any credentials as arguments?
|
||||
if ( arg_username ) then
|
||||
return { [arg_username] = arg_password }
|
||||
-- next, let's see if mysql-brute or mysql-empty-password brought us anything
|
||||
elseif nmap.registry.mysqlusers then
|
||||
-- do we have root credentials?
|
||||
if nmap.registry.mysqlusers['root'] then
|
||||
return { ['root'] = nmap.registry.mysqlusers['root'] }
|
||||
else
|
||||
-- we didn't have root, so let's make sure we loop over them all
|
||||
return nmap.registry.mysqlusers
|
||||
end
|
||||
-- last, no dice, we don't have any credentials at all
|
||||
end
|
||||
-- first, let's see if the script has any credentials as arguments?
|
||||
if ( arg_username ) then
|
||||
return { [arg_username] = arg_password }
|
||||
-- next, let's see if mysql-brute or mysql-empty-password brought us anything
|
||||
elseif nmap.registry.mysqlusers then
|
||||
-- do we have root credentials?
|
||||
if nmap.registry.mysqlusers['root'] then
|
||||
return { ['root'] = nmap.registry.mysqlusers['root'] }
|
||||
else
|
||||
-- we didn't have root, so let's make sure we loop over them all
|
||||
return nmap.registry.mysqlusers
|
||||
end
|
||||
-- last, no dice, we don't have any credentials at all
|
||||
end
|
||||
end
|
||||
|
||||
local function mysqlLogin(socket, username, password)
|
||||
local status, response = mysql.receiveGreeting( socket )
|
||||
if ( not(status) ) then
|
||||
return response
|
||||
end
|
||||
return mysql.loginRequest( socket, { authversion = "post41", charset = response.charset }, username, password, response.salt )
|
||||
local status, response = mysql.receiveGreeting( socket )
|
||||
if ( not(status) ) then
|
||||
return response
|
||||
end
|
||||
return mysql.loginRequest( socket, { authversion = "post41", charset = response.charset }, username, password, response.salt )
|
||||
end
|
||||
|
||||
|
||||
action = function(host, port)
|
||||
if ( not(arg_query) ) then
|
||||
stdnse.print_debug(2, "No query was given, aborting ...")
|
||||
return
|
||||
end
|
||||
if ( not(arg_query) ) then
|
||||
stdnse.print_debug(2, "No query was given, aborting ...")
|
||||
return
|
||||
end
|
||||
|
||||
local creds = getCredentials()
|
||||
if ( not(creds) ) then
|
||||
stdnse.print_debug(2, "No credentials were supplied, aborting ...")
|
||||
return
|
||||
end
|
||||
local creds = getCredentials()
|
||||
if ( not(creds) ) then
|
||||
stdnse.print_debug(2, "No credentials were supplied, aborting ...")
|
||||
return
|
||||
end
|
||||
|
||||
if ( arg_noheaders == '1' or arg_noheaders == 'true' ) then
|
||||
arg_noheaders = true
|
||||
else
|
||||
arg_noheaders = false
|
||||
end
|
||||
if ( arg_noheaders == '1' or arg_noheaders == 'true' ) then
|
||||
arg_noheaders = true
|
||||
else
|
||||
arg_noheaders = false
|
||||
end
|
||||
|
||||
local result = {}
|
||||
local last_error
|
||||
local result = {}
|
||||
local last_error
|
||||
|
||||
for username, password in pairs(creds) do
|
||||
local socket = nmap.new_socket()
|
||||
if ( not(socket:connect(host, port)) ) then
|
||||
return fail("Failed to connect to server")
|
||||
end
|
||||
local status, response = mysqlLogin(socket, username, password)
|
||||
if ( status ) then
|
||||
local status, rs = mysql.sqlQuery( socket, arg_query )
|
||||
socket:close()
|
||||
if ( status ) then
|
||||
result = mysql.formatResultset(rs, { noheaders = arg_noheaders })
|
||||
result = ("%s\nQuery: %s\nUser: %s"):format(result, arg_query, username)
|
||||
last_error = nil
|
||||
break
|
||||
else
|
||||
last_error = rs
|
||||
end
|
||||
else
|
||||
socket:close()
|
||||
end
|
||||
end
|
||||
return stdnse.format_output(true, (last_error and ("ERROR: %s"):format(last_error) or result))
|
||||
for username, password in pairs(creds) do
|
||||
local socket = nmap.new_socket()
|
||||
if ( not(socket:connect(host, port)) ) then
|
||||
return fail("Failed to connect to server")
|
||||
end
|
||||
local status, response = mysqlLogin(socket, username, password)
|
||||
if ( status ) then
|
||||
local status, rs = mysql.sqlQuery( socket, arg_query )
|
||||
socket:close()
|
||||
if ( status ) then
|
||||
result = mysql.formatResultset(rs, { noheaders = arg_noheaders })
|
||||
result = ("%s\nQuery: %s\nUser: %s"):format(result, arg_query, username)
|
||||
last_error = nil
|
||||
break
|
||||
else
|
||||
last_error = rs
|
||||
end
|
||||
else
|
||||
socket:close()
|
||||
end
|
||||
end
|
||||
return stdnse.format_output(true, (last_error and ("ERROR: %s"):format(last_error) or result))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user