refactor parsing the results

moved the result parsing into its own method
cleaned up run method a bit more, added YARD docs
to the new methods
bug/bundler_fix
David Maloney 2015-01-14 14:15:57 -06:00
parent c687ecca2e
commit f42bda1a51
No known key found for this signature in database
GPG Key ID: DEDBA9DC3A913DB2
1 changed files with 34 additions and 24 deletions

View File

@ -49,8 +49,6 @@ class Metasploit3 < Msf::Post
def run def run
max_search = datastore['MAX_SEARCH'] max_search = datastore['MAX_SEARCH']
domain = datastore['DOMAIN'] || get_domain
domain_ip = client.net.resolve.resolve_host(domain)[:ip]
begin begin
q = query(search_filter, max_search, USER_FIELDS) q = query(search_filter, max_search, USER_FIELDS)
@ -62,9 +60,34 @@ class Metasploit3 < Msf::Post
if q.nil? || q[:results].empty? if q.nil? || q[:results].empty?
print_status('No results returned.') print_status('No results returned.')
return else
results_table = parse_results(q[:results])
print_line results_table.to_s
if datastore['STORE_LOOT']
stored_path = store_loot('ad.users', 'text/plain', session, results_table.to_csv)
print_status("Results saved to: #{stored_path}")
end
end
end end
def account_disabled?(uac)
(uac & UAC_DISABLED) > 0
end
def account_locked?(lockout_time)
lockout_time > 0
end
# Takes the results of LDAP query, parses them into a table
# and records and usernames as {Metasploit::Credential::Core}s in
# the database.
#
# @param [Array<Array<Hash>>] the LDAP query results to parse
# @return [Rex::Ui::Text::Table] the table containing all the result data
def parse_results(results)
domain = datastore['DOMAIN'] || get_domain
domain_ip = client.net.resolve.resolve_host(domain)[:ip]
# Results table holds raw string data # Results table holds raw string data
results_table = Rex::Ui::Text::Table.new( results_table = Rex::Ui::Text::Table.new(
'Header' => "Domain Users", 'Header' => "Domain Users",
@ -73,7 +96,7 @@ class Metasploit3 < Msf::Post
'Columns' => USER_FIELDS 'Columns' => USER_FIELDS
) )
q[:results].each do |result| results.each do |result|
row = [] row = []
result.each do |field| result.each do |field|
@ -91,22 +114,9 @@ class Metasploit3 < Msf::Post
results_table << row results_table << row
end end
results_table
print_line results_table.to_s
if datastore['STORE_LOOT']
stored_path = store_loot('ad.users', 'text/plain', session, results_table.to_csv)
print_status("Results saved to: #{stored_path}")
end
end end
def account_disabled?(uac)
(uac & UAC_DISABLED) > 0
end
def account_locked?(lockout_time)
lockout_time > 0
end
# Builds the LDAP query 'filter' used to find our User Accounts based on # Builds the LDAP query 'filter' used to find our User Accounts based on
# criteria set by user in the Datastore. # criteria set by user in the Datastore.