Skip to content

Commit b0e388f

Browse files
committed
Land rapid7#3516, @midnitesnake's snmp_enumusers fix for Solaris, OS X
2 parents b45cbfd + 1a2b1db commit b0e388f

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

lib/snmp/manager.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,4 +716,3 @@ def select_handler(trap)
716716
end
717717

718718
end
719-

modules/auxiliary/scanner/snmp/snmp_enumusers.rb

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,71 @@
66
require 'msf/core'
77

88
class Metasploit3 < Msf::Auxiliary
9-
109
include Msf::Exploit::Remote::SNMPClient
1110
include Msf::Auxiliary::Report
1211
include Msf::Auxiliary::Scanner
12+
include SNMP
1313

1414
def initialize
1515
super(
1616
'Name' => 'SNMP Windows Username Enumeration',
17-
'Description' => "This module will use LanManager OID values to enumerate local user accounts on a Windows system via SNMP",
17+
'Description' => '
18+
This module will use LanManager/psProcessUsername OID values to
19+
enumerate local user accounts on a Windows/Solaris system via SNMP
20+
',
1821
'Author' => ['tebo[at]attackresearch.com'],
1922
'License' => MSF_LICENSE
2023
)
21-
2224
end
2325

2426
def run_host(ip)
27+
peer = "#{ip}:#{rport}"
2528
begin
2629
snmp = connect_snmp
2730

28-
if snmp.get_value('sysDescr.0') =~ /Windows/
29-
30-
@users = []
31-
snmp.walk("1.3.6.1.4.1.77.1.2.25") do |row|
32-
row.each { |val| @users << val.value.to_s }
33-
end
31+
sys_desc = snmp.get_value('sysDescr.0')
32+
if sys_desc.blank? || sys_desc.to_s == 'Null'
33+
vprint_error("#{peer} No sysDescr received")
34+
return
35+
end
36+
sys_desc = sys_desc.split(/[\r\n]/).join(' ')
3437

35-
print_good("#{ip} Found Users: #{@users.sort.join(", ")} ")
38+
sys_desc_map = {
39+
/Windows/ => '1.3.6.1.4.1.77.1.2.25',
40+
/Sun/ => '1.3.6.1.4.1.42.3.12.1.8'
41+
}
3642

43+
matching_oids = sys_desc_map.select { |re, _| sys_desc =~ re }.values
44+
if matching_oids.empty?
45+
vprint_warning("#{peer} Skipping unsupported sysDescr: '#{sys_desc}'")
46+
return
3747
end
48+
users = []
3849

39-
disconnect_snmp
50+
matching_oids.each do |oid|
51+
snmp.walk(oid) do |row|
52+
row.each { |val| users << val.value.to_s }
53+
end
54+
end
55+
unless users.empty?
56+
users.sort!
57+
users.uniq!
58+
print_good("#{peer} Found #{users.size} users: #{users.join(', ')}")
59+
end
4060

4161
report_note(
42-
:host => rhost,
43-
:port => datastore['RPORT'],
44-
:proto => 'udp',
45-
:sname => 'snmp',
46-
:update => :unique_data,
47-
:type => 'snmp.users',
48-
:data => @users
62+
host: rhost,
63+
port: rport,
64+
proto: 'udp',
65+
sname: 'snmp',
66+
update: :unique_data,
67+
type: 'snmp.users',
68+
data: users
4969
)
50-
51-
52-
rescue ::SNMP::UnsupportedVersion
53-
rescue ::SNMP::RequestTimeout
54-
rescue ::Interrupt
55-
raise $!
56-
rescue ::Exception => e
57-
print_error("Unknown error: #{e.class} #{e}")
70+
rescue ::SNMP::RequestTimeout, ::SNMP::UnsupportedVersion
71+
# too noisy for a scanner
72+
ensure
73+
disconnect_snmp
5874
end
59-
6075
end
61-
6276
end

0 commit comments

Comments
 (0)