Skip to content

Commit 42ff0de

Browse files
committed
Land rapid7#4722, timing options for snmp_login
2 parents 01625e3 + 88062a5 commit 42ff0de

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

lib/metasploit/framework/login_scanner/snmp.rb

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,40 @@ class SNMP
1717
PRIVATE_TYPES = [ :password ]
1818
REALM_KEY = nil
1919

20+
# The number of retries per community string
21+
# @return [Fixnum]
22+
attr_accessor :retries
23+
24+
# The SNMP version to scan
25+
# @return [String]
26+
attr_accessor :version
27+
28+
validates :retries,
29+
presence: true,
30+
numericality: {
31+
only_integer: true,
32+
greater_than_or_equal_to: 0
33+
}
34+
35+
validates :version,
36+
presence: true,
37+
inclusion: {
38+
in: ['1', '2c', 'all']
39+
}
40+
41+
# This method returns an array of versions to scan for
42+
# @return [Array] An array of versions
43+
def versions
44+
case version
45+
when '1'
46+
[:SNMPv1]
47+
when '2c'
48+
[:SNMPv2c]
49+
when 'all'
50+
[:SNMPv1, :SNMPv2c]
51+
end
52+
end
53+
2054
# This method attempts a single login with a single credential against the target
2155
# @param credential [Credential] The credential object to attmpt to login with
2256
# @return [Metasploit::Framework::LoginScanner::Result] The LoginScanner Result object
@@ -29,14 +63,14 @@ def attempt_login(credential)
2963
service_name: 'snmp'
3064
}
3165

32-
[:SNMPv1, :SNMPv2c].each do |version|
66+
versions.each do |version|
3367
snmp_client = ::SNMP::Manager.new(
3468
:Host => host,
3569
:Port => port,
3670
:Community => credential.public,
3771
:Version => version,
3872
:Timeout => connection_timeout,
39-
:Retries => 2,
73+
:Retries => retries,
4074
:Transport => ::SNMP::RexUDPTransport,
4175
:Socket => ::Rex::Socket::Udp.create('Context' => { 'Msf' => framework, 'MsfExploit' => framework_module })
4276
)

modules/auxiliary/scanner/snmp/snmp_login.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ def initialize
3030
[
3131
Opt::RPORT(161),
3232
Opt::CHOST,
33+
OptInt.new('CONNECTION_TIMEOUT', [true, 'The timeout value for each probe', 2]),
34+
OptInt.new('RETRIES', [true, 'The number of retries per community string', 0]),
3335
OptInt.new('BATCHSIZE', [true, 'The number of hosts to probe in each set', 256]),
36+
OptEnum.new('VERSION', [true, 'The SNMP version to scan', 'all', ['1', '2c', 'all']]),
3437
OptString.new('PASSWORD', [ false, 'The password to test' ]),
3538
OptPath.new('PASS_FILE', [ false, "File containing communities, one per line",
3639
File.join(Msf::Config.data_directory, "wordlists", "snmp_default_pass.txt")
@@ -61,9 +64,11 @@ def run_batch(batch)
6164
cred_details: collection,
6265
stop_on_success: datastore['STOP_ON_SUCCESS'],
6366
bruteforce_speed: datastore['BRUTEFORCE_SPEED'],
64-
connection_timeout: 2,
67+
connection_timeout: datastore['CONNECTION_TIMEOUT'],
68+
retries: datastore['RETRIES'],
69+
version: datastore['VERSION'],
6570
framework: framework,
66-
framework_module: self,
71+
framework_module: self
6772
)
6873

6974
scanner.scan! do |result|

spec/lib/metasploit/framework/login_scanner/snmp_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
snmp_scanner.host = '127.0.0.1'
3838
snmp_scanner.port = 161
3939
snmp_scanner.connection_timeout = 1
40+
snmp_scanner.retries = 0
41+
snmp_scanner.version = 'all'
4042
snmp_scanner.stop_on_success = true
4143
snmp_scanner.cred_details = detail_group
4244
end

0 commit comments

Comments
 (0)