|
5 | 5 |
|
6 | 6 |
|
7 | 7 | require 'msf/core'
|
8 |
| -require 'openssl' |
9 |
| -require 'snmp' |
| 8 | +require 'metasploit/framework/community_string_collection' |
| 9 | +require 'metasploit/framework/login_scanner/snmp' |
10 | 10 |
|
11 | 11 | class Metasploit3 < Msf::Auxiliary
|
12 | 12 |
|
@@ -50,11 +50,64 @@ def run_batch_size
|
50 | 50 | def run_batch(batch)
|
51 | 51 |
|
52 | 52 | 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 |
56 | 106 | end
|
| 107 | + end |
57 | 108 |
|
| 109 | + def rport |
| 110 | + datastore['RPORT'] |
58 | 111 | end
|
59 | 112 |
|
60 | 113 |
|
|
0 commit comments