Skip to content

Commit e54f5e8

Browse files
David MaloneyDavid Maloney
authored andcommitted
working snmp_login module
1 parent c553fca commit e54f5e8

File tree

2 files changed

+71
-13
lines changed

2 files changed

+71
-13
lines changed

lib/metasploit/framework/community_string_collection.rb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,21 @@ def initialize(opts = {})
4141
# @yieldparam credential [Metasploit::Framework::Credential]
4242
# @return [void]
4343
def each
44-
if pass_file.present?
45-
pass_fd = File.open(pass_file, 'r:binary')
46-
pass_fd.each_line do |line|
47-
line.chomp!
48-
yield Metasploit::Framework::Credential.new(public: line, paired: false)
44+
begin
45+
if pass_file.present?
46+
pass_fd = File.open(pass_file, 'r:binary')
47+
pass_fd.each_line do |line|
48+
line.chomp!
49+
yield Metasploit::Framework::Credential.new(public: line, paired: false)
50+
end
51+
end
52+
53+
if password.present?
54+
yield Metasploit::Framework::Credential.new(public: password, paired: false)
4955
end
50-
end
5156

52-
if password.present?
53-
yield Metasploit::Framework::Credential.new(public: password, paired: false)
57+
ensure
58+
pass_fd.close if pass_fd && !pass_fd.closed?
5459
end
5560
end
5661

modules/auxiliary/scanner/snmp/snmp_login.rb

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66

77
require 'msf/core'
8-
require 'openssl'
9-
require 'snmp'
8+
require 'metasploit/framework/community_string_collection'
9+
require 'metasploit/framework/login_scanner/snmp'
1010

1111
class Metasploit3 < Msf::Auxiliary
1212

@@ -50,11 +50,64 @@ def run_batch_size
5050
def run_batch(batch)
5151

5252
batch.each do |ip|
53-
54-
55-
53+
collection = Metasploit::Framework::CommunityStringCollection.new(
54+
pass_file: datastore['PASS_FILE'],
55+
password: datastore['PASSWORD']
56+
)
57+
58+
scanner = Metasploit::Framework::LoginScanner::SNMP.new(
59+
host: ip,
60+
port: rport,
61+
cred_details: collection,
62+
stop_on_success: datastore['STOP_ON_SUCCESS'],
63+
connection_timeout: 2
64+
)
65+
66+
service_data = {
67+
address: ip,
68+
port: rport,
69+
service_name: 'snmp',
70+
protocol: 'udp',
71+
workspace_id: myworkspace_id
72+
}
73+
74+
scanner.scan! do |result|
75+
if result.success?
76+
credential_data = {
77+
module_fullname: self.fullname,
78+
origin_type: :service,
79+
username: result.credential.public
80+
}
81+
credential_data.merge!(service_data)
82+
83+
credential_core = create_credential(credential_data)
84+
85+
login_data = {
86+
core: credential_core,
87+
last_attempted_at: DateTime.now,
88+
status: Metasploit::Model::Login::Status::SUCCESSFUL
89+
}
90+
login_data.merge!(service_data)
91+
92+
create_credential_login(login_data)
93+
print_good "#{ip}:#{rport} - LOGIN SUCCESSFUL: #{result.credential}"
94+
else
95+
invalidate_data = {
96+
public: result.credential.public,
97+
private: result.credential.private,
98+
realm_key: result.credential.realm_key,
99+
realm_value: result.credential.realm,
100+
status: result.status
101+
} .merge(service_data)
102+
invalidate_login(invalidate_data)
103+
print_status "#{ip}:#{rport} - LOGIN FAILED: #{result.credential} (#{result.status}: #{result.proof})"
104+
end
105+
end
56106
end
107+
end
57108

109+
def rport
110+
datastore['RPORT']
58111
end
59112

60113

0 commit comments

Comments
 (0)