|
| 1 | +## |
| 2 | +# This module requires Metasploit: https://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'ruby_smb/dcerpc/client' |
| 7 | + |
| 8 | +class MetasploitModule < Msf::Auxiliary |
| 9 | + include Msf::Exploit::Remote::SMB::Client::Authenticated |
| 10 | + include Msf::Exploit::Remote::DCERPC |
| 11 | + include Msf::Auxiliary::Report |
| 12 | + |
| 13 | + def initialize(info = {}) |
| 14 | + super( |
| 15 | + update_info( |
| 16 | + info, |
| 17 | + 'Name' => 'SAMR Computer Management', |
| 18 | + 'Description' => %q{ |
| 19 | + }, |
| 20 | + 'License' => MSF_LICENSE, |
| 21 | + 'Author' => [ |
| 22 | + 'Alberto Solino', # Original Impacket code # todo: verify this author credit |
| 23 | + 'Spencer McIntyre', |
| 24 | + ], |
| 25 | + 'References' => [ |
| 26 | + ['URL', 'https://github.com/SecureAuthCorp/impacket/blob/master/examples/addcomputer.py'], |
| 27 | + ], |
| 28 | + 'Notes' => { |
| 29 | + 'Reliability' => [], |
| 30 | + 'Stability' => [], |
| 31 | + 'SideEffects' => [ IOC_IN_LOGS ] |
| 32 | + }, |
| 33 | + 'Actions' => [ |
| 34 | + [ 'ADD', { 'Description' => 'Add a computer account' } ], |
| 35 | + ], |
| 36 | + 'DefaultAction' => 'ADD' |
| 37 | + ) |
| 38 | + ) |
| 39 | + |
| 40 | + register_options([ Opt::RPORT(445) ]) |
| 41 | + end |
| 42 | + |
| 43 | + def connect_samr |
| 44 | + vprint_status('Connecting to Security Account Manager (SAM) Remote Protocol') |
| 45 | + samr = @tree.open_file(filename: 'samr', write: true, read: true) |
| 46 | + |
| 47 | + vprint_status('Binding to \\samr...') |
| 48 | + samr.bind(endpoint: RubySMB::Dcerpc::Samr) |
| 49 | + vprint_good('Bound to \\samr') |
| 50 | + |
| 51 | + samr |
| 52 | + end |
| 53 | + |
| 54 | + def run |
| 55 | + connect |
| 56 | + begin |
| 57 | + smb_login |
| 58 | + rescue Rex::Proto::SMB::Exceptions::Error, RubySMB::Error::RubySMBError => e |
| 59 | + fail_with(Module::Failure::NoAccess, "Unable to authenticate ([#{e.class}] #{e}).") |
| 60 | + end |
| 61 | + report_service( |
| 62 | + host: rhost, |
| 63 | + port: rport, |
| 64 | + host_name: simple.client.default_name, |
| 65 | + proto: 'tcp', |
| 66 | + name: 'smb', |
| 67 | + info: "Module: #{fullname}, last negotiated version: SMBv#{simple.client.negotiated_smb_version} (dialect = #{simple.client.dialect})" |
| 68 | + ) |
| 69 | + |
| 70 | + begin |
| 71 | + @tree = simple.client.tree_connect("\\\\#{sock.peerhost}\\IPC$") |
| 72 | + rescue RubySMB::Error::RubySMBError => e |
| 73 | + fail_with(Module::Failure::Unreachable, "Unable to connect to the remote IPC$ share ([#{e.class}] #{e}).") |
| 74 | + end |
| 75 | + |
| 76 | + samr = connect_samr |
| 77 | + server_handle = samr.samr_connect(access: 0x30) |
| 78 | + domains = samr.samr_enumerate_domains_in_sam_server(server_handle: server_handle) |
| 79 | + print_status(domains.inspect) |
| 80 | + end |
| 81 | +end |
0 commit comments