CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/post/meterpreter/extensions/appapi/appapi.rb
Views: 11791
1
# -*- coding: binary -*-
2
3
require 'rex/post/meterpreter/extensions/appapi/tlv'
4
require 'rex/post/meterpreter/extensions/appapi/command_ids'
5
6
module Rex
7
module Post
8
module Meterpreter
9
module Extensions
10
module AppApi
11
12
###
13
#
14
# Application interface to control Applications on the device
15
#
16
###
17
class AppApi < Extension
18
19
def self.extension_id
20
EXTENSION_ID_APPAPI
21
end
22
23
#
24
# Typical extension initialization routine.
25
#
26
# @param client (see Extension#initialize)
27
def initialize(client)
28
super(client, 'appapi')
29
30
client.register_extension_aliases(
31
[
32
{
33
'name' => 'appapi',
34
'ext' => self
35
}
36
])
37
end
38
39
#
40
# Get list of installed applications
41
#
42
def app_list(app_opt)
43
request = Packet.create_request(COMMAND_ID_APPAPI_APP_LIST)
44
request.add_tlv(TLV_TYPE_APPS_LIST_OPT, app_opt)
45
response = client.send_request(request)
46
names = []
47
response.get_tlvs(TLV_TYPE_APPS_LIST).each do |tlv|
48
names << tlv.value
49
end
50
names
51
end
52
53
#
54
# Uninstall application
55
#
56
def app_uninstall(packagename)
57
58
request = Packet.create_request(COMMAND_ID_APPAPI_APP_UNINSTALL)
59
request.add_tlv(TLV_TYPE_APP_PACKAGE_NAME, packagename)
60
response = client.send_request(request)
61
62
response.get_tlv(TLV_TYPE_APP_ENUM).value
63
end
64
65
#
66
# Install application
67
#
68
def app_install(apk_path)
69
request = Packet.create_request(COMMAND_ID_APPAPI_APP_INSTALL)
70
request.add_tlv(TLV_TYPE_APP_APK_PATH, apk_path)
71
response = client.send_request(request)
72
73
response.get_tlv(TLV_TYPE_APP_ENUM).value
74
end
75
76
#
77
# Start Main Activity for installed application by Package name
78
#
79
def app_run(packagename)
80
request = Packet.create_request(COMMAND_ID_APPAPI_APP_RUN)
81
request.add_tlv(TLV_TYPE_APP_PACKAGE_NAME, packagename)
82
response = client.send_request(request)
83
response.get_tlv(TLV_TYPE_APP_RUN_ENUM).value
84
end
85
86
end
87
88
end; end; end; end; end
89
90
91