Skip to content

Commit 520e1bc

Browse files
committed
Land rapid7#3692, @TomSellers's support for Metasploit Credential on enum_snmp
2 parents a535d23 + 0b820c5 commit 520e1bc

File tree

1 file changed

+54
-29
lines changed

1 file changed

+54
-29
lines changed

modules/post/windows/gather/enum_snmp.rb

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def check_snmp
5050
def community_strings
5151
comm_str = []
5252
tbl = Rex::Ui::Text::Table.new(
53-
'Header' => "Comunity Strings",
53+
'Header' => "Community Strings",
5454
'Indent' => 1,
5555
'Columns' =>
5656
[
@@ -63,33 +63,30 @@ def community_strings
6363
if not comm_str.nil? and not comm_str.empty?
6464
comm_str.each do |c|
6565

66+
# comm_type is for human display, access_type is passed to the credential
67+
# code using labels consistent with the SNMP login scanner
6668
case registry_getvaldata(key,c)
6769
when 4
68-
comm_type = "READ ONLY"
70+
comm_type = 'READ ONLY'
71+
access_type = 'read-only'
6972
when 1
70-
comm_type = "DISABLED"
73+
comm_type = 'DISABLED'
74+
access_type = 'disabled'
7175
when 2
72-
comm_type = "NOTIFY"
76+
comm_type = 'NOTIFY'
77+
access_type = 'notify'
7378
when 8
74-
comm_type = "READ & WRITE"
79+
comm_type = 'READ & WRITE'
80+
access_type = 'read-write'
7581
when 16
76-
comm_type = "READ CREATE"
82+
comm_type = 'READ CREATE'
83+
access_type = 'read-create'
7784
end
7885

7986
# Save data to table
8087
tbl << [c,comm_type]
8188

82-
# Save Community Strings to DB
83-
report_auth_info(
84-
:host => session.sock.peerhost,
85-
:port => 161,
86-
:proto => 'udp',
87-
:sname => 'snmp',
88-
:user => '',
89-
:pass => c,
90-
:type => "snmp.community",
91-
:duplicate_ok => true
92-
)
89+
register_creds(session.session_host, 161, '', c, 'snmp', access_type)
9390
end
9491
print_status("")
9592

@@ -116,21 +113,13 @@ def trap_setup
116113
if not trap_hosts.nil? and not trap_hosts.empty?
117114
trap_hosts.each do |c|
118115
print_status("Community Name: #{c}")
119-
session.framework.db.report_auth_info(
120-
:host => session.sock.peerhost,
121-
:port => 161,
122-
:proto => 'udp',
123-
:sname => 'snmp',
124-
:user => '',
125-
:pass => c,
126-
:type => "snmp.community",
127-
:duplicate_ok => true
128-
)
116+
129117
t_comm_key = key+"\\"+c
130118
registry_enumvals(t_comm_key).each do |t|
131-
print_status("\tDestination: " + registry_getvaldata(t_comm_key,t))
119+
trap_dest = registry_getvaldata(t_comm_key,t)
120+
print_status("\tDestination: #{trap_dest}")
121+
register_creds(trap_dest, 162, '', c, 'snmptrap', 'trap')
132122
end
133-
134123
end
135124
else
136125
print_status("No Traps are configured")
@@ -152,4 +141,40 @@ def allowd_for_snmp_query
152141
print_status("\tCommunity Strings can be accessed from any host")
153142
end
154143
end
144+
145+
def register_creds(client_ip, client_port, user, pass, service_name, access_type)
146+
# Build service information
147+
service_data = {
148+
address: client_ip,
149+
port: client_port,
150+
service_name: service_name,
151+
protocol: 'udp',
152+
workspace_id: myworkspace_id
153+
}
154+
155+
# Build credential information
156+
credential_data = {
157+
access_level: access_type,
158+
origin_type: :session,
159+
session_id: session_db_id,
160+
post_reference_name: self.refname,
161+
private_data: pass,
162+
private_type: :password,
163+
username: user,
164+
workspace_id: myworkspace_id
165+
}
166+
167+
credential_data.merge!(service_data)
168+
credential_core = create_credential(credential_data)
169+
170+
# Assemble the options hash for creating the Metasploit::Credential::Login object
171+
login_data = {
172+
core: credential_core,
173+
status: Metasploit::Model::Login::Status::UNTRIED,
174+
workspace_id: myworkspace_id
175+
}
176+
177+
login_data.merge!(service_data)
178+
create_credential_login(login_data)
179+
end
155180
end

0 commit comments

Comments
 (0)