|
| 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 MetasploitModule < Msf::Post |
| 9 | + |
| 10 | + include Msf::Post::File |
| 11 | + |
| 12 | + def initialize(info={}) |
| 13 | + super(update_info(info, |
| 14 | + 'Name' => 'Multi Manage File Compressor', |
| 15 | + 'Description' => %q{ |
| 16 | + This module zips a directory or a directory. On Linux, it uses the zip command. |
| 17 | + On Windows, it will try to use remote target's 7Zip if found. If not, it falls |
| 18 | + back to its own VBScript. |
| 19 | + }, |
| 20 | + 'License' => MSF_LICENSE, |
| 21 | + 'Author' => [ 'sinn3r' ], |
| 22 | + 'Platform' => [ 'win', 'linux' ], |
| 23 | + 'SessionTypes' => [ 'meterpreter', 'shell' ] |
| 24 | + )) |
| 25 | + |
| 26 | + register_options( |
| 27 | + [ |
| 28 | + OptString.new('DESTINATION', [false, 'The destination path']), |
| 29 | + OptString.new('SOURCE', [true, 'The directory or file to compress']) |
| 30 | + ], self.class) |
| 31 | + end |
| 32 | + |
| 33 | + def get_program_file_path |
| 34 | + @program_file_path ||= lambda { |
| 35 | + session.sys.config.getenvs("ProgramFiles")['ProgramFiles'] |
| 36 | + }.call |
| 37 | + end |
| 38 | + |
| 39 | + def has_7zip? |
| 40 | + file?("#{get_program_file_path}\\7-Zip\\7z.exe") |
| 41 | + end |
| 42 | + |
| 43 | + def vbs(dest, src) |
| 44 | + vbs_file = File.read(File.join(Msf::Config.data_directory, "post", "zip", "zip.vbs")) |
| 45 | + vbs_file << "WindowsZip \"#{src}\",\"#{dest}\"" |
| 46 | + vbs_file |
| 47 | + end |
| 48 | + |
| 49 | + def upload_exec_vbs_zip |
| 50 | + script = vbs(datastore['DESTINATION'], datastore['SOURCE']) |
| 51 | + tmp_path = "#{session.sys.config.getenvs('TEMP')['TEMP']}\\zip.vbs" |
| 52 | + print_status("VBS file uploaded to #{tmp_path}") |
| 53 | + write_file(tmp_path, script) |
| 54 | + cmd_exec("wscript.exe #{tmp_path}") |
| 55 | + end |
| 56 | + |
| 57 | + def do_7zip |
| 58 | + program_file_path = get_program_file_path |
| 59 | + output = cmd_exec("#{program_file_path}\\7-Zip\\7z.exe a -tzip \"#{datastore['DESTINATION']}\" \"#{datastore['SOURCE']}\"") |
| 60 | + vprint_line(output) |
| 61 | + end |
| 62 | + |
| 63 | + def do_zip |
| 64 | + output = cmd_exec("zip -D -d -q -r #{datastore['DESTINATION']} #{datastore['SOURCE']}") |
| 65 | + vprint_line(output) |
| 66 | + end |
| 67 | + |
| 68 | + def windows_zip |
| 69 | + if has_7zip? |
| 70 | + print_status("Compressing #{datastore['DESTINATION']} via 7zip") |
| 71 | + do_7zip |
| 72 | + else |
| 73 | + print_status("Compressing #{datastore['DESTINATION']} via VBS") |
| 74 | + upload_exec_vbs_zip |
| 75 | + end |
| 76 | + end |
| 77 | + |
| 78 | + def linux_zip |
| 79 | + print_status("Compressing #{datastore['DESTINATION']} via zip") |
| 80 | + do_zip |
| 81 | + end |
| 82 | + |
| 83 | + def run |
| 84 | + os = get_target_os |
| 85 | + case os |
| 86 | + when Msf::Module::Platform::Windows.realname.downcase |
| 87 | + windows_zip |
| 88 | + else |
| 89 | + linux_zip |
| 90 | + end |
| 91 | + end |
| 92 | + |
| 93 | +end |
| 94 | + |
0 commit comments