|
| 1 | +## |
| 2 | +# This module requires Metasploit: http//metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | + |
| 8 | +class Metasploit3 < Msf::Auxiliary |
| 9 | + |
| 10 | + # Exploit mixins should be called first |
| 11 | + include Msf::Exploit::Remote::SMB |
| 12 | + include Msf::Exploit::Remote::SMB::Authenticated |
| 13 | + include Msf::Auxiliary::Report |
| 14 | + |
| 15 | + # Aliases for common classes |
| 16 | + SIMPLE = Rex::Proto::SMB::SimpleClient |
| 17 | + XCEPT = Rex::Proto::SMB::Exceptions |
| 18 | + CONST = Rex::Proto::SMB::Constants |
| 19 | + |
| 20 | + |
| 21 | + def initialize |
| 22 | + super( |
| 23 | + 'Name' => 'SMB File Download Utility', |
| 24 | + 'Description' => %Q{ |
| 25 | + This module downloads a file from a target share and path. The only reason |
| 26 | + to use this module is if your existing SMB client is not able to support the features |
| 27 | + of the Metasploit Framework that you need, like pass-the-hash authentication. |
| 28 | + }, |
| 29 | + 'Author' => |
| 30 | + [ |
| 31 | + 'mubix' # copied from hdm upload_file module |
| 32 | + ], |
| 33 | + 'References' => |
| 34 | + [ |
| 35 | + ], |
| 36 | + 'License' => MSF_LICENSE |
| 37 | + ) |
| 38 | + |
| 39 | + register_options([ |
| 40 | + OptString.new('SMBSHARE', [true, 'The name of a share on the RHOST', 'C$']), |
| 41 | + OptString.new('RPATH', [true, 'The name of the remote file relative to the share']) |
| 42 | + ], self.class) |
| 43 | + |
| 44 | + end |
| 45 | + |
| 46 | + def smb_download |
| 47 | + print_status("Connecting to the #{rhost}:#{rport}...") |
| 48 | + connect() |
| 49 | + smb_login() |
| 50 | + |
| 51 | + print_status("Mounting the remote share \\\\#{datastore['RHOST']}\\#{datastore['SMBSHARE']}'...") |
| 52 | + self.simple.connect("\\\\#{rhost}\\#{datastore['SMBSHARE']}") |
| 53 | + |
| 54 | + print_status("Trying to download #{datastore['RPATH']}...") |
| 55 | + |
| 56 | + data = '' |
| 57 | + fd = simple.open("\\#{datastore['RPATH']}", 'ro') |
| 58 | + begin |
| 59 | + data = fd.read |
| 60 | + ensure |
| 61 | + fd.close |
| 62 | + end |
| 63 | + |
| 64 | + fname = datastore['RPATH'].split("\\")[-1] |
| 65 | + path = store_loot("smb.shares.file", "application/octet-stream", rhost, data, fname) |
| 66 | + print_good("#{fname} saved as: #{path}") |
| 67 | + end |
| 68 | + |
| 69 | + def run |
| 70 | + begin |
| 71 | + smb_download |
| 72 | + rescue Rex::Proto::SMB::Exceptions::LoginError => e |
| 73 | + print_error("Unable to login: #{e.message}") |
| 74 | + rescue Rex::Proto::SMB::Exceptions::ErrorCode => e |
| 75 | + print_error("Unable to download the file: #{e.message}") |
| 76 | + end |
| 77 | + end |
| 78 | + |
| 79 | +end |
0 commit comments