@@ -50,7 +50,7 @@ def check_snmp
50
50
def community_strings
51
51
comm_str = [ ]
52
52
tbl = Rex ::Ui ::Text ::Table . new (
53
- 'Header' => "Comunity Strings" ,
53
+ 'Header' => "Community Strings" ,
54
54
'Indent' => 1 ,
55
55
'Columns' =>
56
56
[
@@ -63,33 +63,30 @@ def community_strings
63
63
if not comm_str . nil? and not comm_str . empty?
64
64
comm_str . each do |c |
65
65
66
+ # comm_type is for human display, access_type is passed to the credential
67
+ # code using labels consistent with the SNMP login scanner
66
68
case registry_getvaldata ( key , c )
67
69
when 4
68
- comm_type = "READ ONLY"
70
+ comm_type = 'READ ONLY'
71
+ access_type = 'read-only'
69
72
when 1
70
- comm_type = "DISABLED"
73
+ comm_type = 'DISABLED'
74
+ access_type = 'disabled'
71
75
when 2
72
- comm_type = "NOTIFY"
76
+ comm_type = 'NOTIFY'
77
+ access_type = 'notify'
73
78
when 8
74
- comm_type = "READ & WRITE"
79
+ comm_type = 'READ & WRITE'
80
+ access_type = 'read-write'
75
81
when 16
76
- comm_type = "READ CREATE"
82
+ comm_type = 'READ CREATE'
83
+ access_type = 'read-create'
77
84
end
78
85
79
86
# Save data to table
80
87
tbl << [ c , comm_type ]
81
88
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 )
93
90
end
94
91
print_status ( "" )
95
92
@@ -116,21 +113,13 @@ def trap_setup
116
113
if not trap_hosts . nil? and not trap_hosts . empty?
117
114
trap_hosts . each do |c |
118
115
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
+
129
117
t_comm_key = key +"\\ " +c
130
118
registry_enumvals ( t_comm_key ) . each do |t |
131
- print_status ( "\t Destination: " + registry_getvaldata ( t_comm_key , t ) )
119
+ trap_dest = registry_getvaldata ( t_comm_key , t )
120
+ print_status ( "\t Destination: #{ trap_dest } " )
121
+ register_creds ( trap_dest , 162 , '' , c , 'snmptrap' , 'trap' )
132
122
end
133
-
134
123
end
135
124
else
136
125
print_status ( "No Traps are configured" )
@@ -152,4 +141,40 @@ def allowd_for_snmp_query
152
141
print_status ( "\t Community Strings can be accessed from any host" )
153
142
end
154
143
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
155
180
end
0 commit comments