Skip to content

Commit 4ee0a14

Browse files
author
HD Moore
committed
Land rapid7#5477, speed improvements to snmp_login
2 parents 9713fe7 + d3c3741 commit 4ee0a14

File tree

1 file changed

+32
-41
lines changed

1 file changed

+32
-41
lines changed

modules/auxiliary/scanner/snmp/snmp_login.rb

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def initialize
3232
Opt::CHOST,
3333
OptInt.new('CONNECTION_TIMEOUT', [true, 'The timeout value for each probe', 2]),
3434
OptInt.new('RETRIES', [true, 'The number of retries per community string', 0]),
35-
OptInt.new('BATCHSIZE', [true, 'The number of hosts to probe in each set', 256]),
3635
OptEnum.new('VERSION', [true, 'The SNMP version to scan', 'all', ['1', '2c', 'all']]),
3736
OptString.new('PASSWORD', [ false, 'The password to test' ]),
3837
OptPath.new('PASS_FILE', [ false, "File containing communities, one per line",
@@ -43,50 +42,42 @@ def initialize
4342
deregister_options('USERNAME', 'USER_FILE', 'USERPASS_FILE')
4443
end
4544

45+
# Operate on a single host so that we can take advantage of multithreading
46+
def run_host(ip)
4647

47-
# Define our batch size
48-
def run_batch_size
49-
datastore['BATCHSIZE'].to_i
50-
end
51-
52-
# Operate on an entire batch of hosts at once
53-
def run_batch(batch)
48+
collection = Metasploit::Framework::CommunityStringCollection.new(
49+
pass_file: datastore['PASS_FILE'],
50+
password: datastore['PASSWORD']
51+
)
5452

55-
batch.each do |ip|
56-
collection = Metasploit::Framework::CommunityStringCollection.new(
57-
pass_file: datastore['PASS_FILE'],
58-
password: datastore['PASSWORD']
59-
)
53+
scanner = Metasploit::Framework::LoginScanner::SNMP.new(
54+
host: ip,
55+
port: rport,
56+
cred_details: collection,
57+
stop_on_success: datastore['STOP_ON_SUCCESS'],
58+
bruteforce_speed: datastore['BRUTEFORCE_SPEED'],
59+
connection_timeout: datastore['CONNECTION_TIMEOUT'],
60+
retries: datastore['RETRIES'],
61+
version: datastore['VERSION'],
62+
framework: framework,
63+
framework_module: self
64+
)
6065

61-
scanner = Metasploit::Framework::LoginScanner::SNMP.new(
62-
host: ip,
63-
port: rport,
64-
cred_details: collection,
65-
stop_on_success: datastore['STOP_ON_SUCCESS'],
66-
bruteforce_speed: datastore['BRUTEFORCE_SPEED'],
67-
connection_timeout: datastore['CONNECTION_TIMEOUT'],
68-
retries: datastore['RETRIES'],
69-
version: datastore['VERSION'],
70-
framework: framework,
71-
framework_module: self
66+
scanner.scan! do |result|
67+
credential_data = result.to_h
68+
credential_data.merge!(
69+
module_fullname: self.fullname,
70+
workspace_id: myworkspace_id
7271
)
73-
74-
scanner.scan! do |result|
75-
credential_data = result.to_h
76-
credential_data.merge!(
77-
module_fullname: self.fullname,
78-
workspace_id: myworkspace_id
79-
)
80-
if result.success?
81-
credential_core = create_credential(credential_data)
82-
credential_data[:core] = credential_core
83-
create_credential_login(credential_data)
84-
85-
print_good "#{ip}:#{rport} - LOGIN SUCCESSFUL: #{result.credential} (Access level: #{result.access_level})"
86-
else
87-
invalidate_login(credential_data)
88-
print_error "#{ip}:#{rport} - LOGIN FAILED: #{result.credential} (#{result.status})"
89-
end
72+
if result.success?
73+
credential_core = create_credential(credential_data)
74+
credential_data[:core] = credential_core
75+
create_credential_login(credential_data)
76+
77+
print_good "#{ip}:#{rport} - LOGIN SUCCESSFUL: #{result.credential} (Access level: #{result.access_level}); Proof (sysDescr.0): #{result.proof}"
78+
else
79+
invalidate_login(credential_data)
80+
print_error "#{ip}:#{rport} - LOGIN FAILED: #{result.credential} (#{result.status})"
9081
end
9182
end
9283
end

0 commit comments

Comments
 (0)