Class: Rex::Post::Meterpreter::Ui::Console::CommandDispatcher::AppApi

Inherits:
Object
  • Object
show all
Includes:
Extensions::AppApi, Rex::Post::Meterpreter::Ui::Console::CommandDispatcher
Defined in:
lib/rex/post/meterpreter/ui/console/command_dispatcher/appapi.rb

Overview

Application controller - run, get app list, install and uninstall applications. Extension by Islam Nofl (@CorrM)

Constant Summary

Constants included from Extensions::AppApi

Extensions::AppApi::COMMAND_ID_APPAPI_APP_INSTALL, Extensions::AppApi::COMMAND_ID_APPAPI_APP_LIST, Extensions::AppApi::COMMAND_ID_APPAPI_APP_RUN, Extensions::AppApi::COMMAND_ID_APPAPI_APP_UNINSTALL, Extensions::AppApi::EXTENSION_ID_APPAPI, Extensions::AppApi::TLV_TYPE_APPS_LIST, Extensions::AppApi::TLV_TYPE_APPS_LIST_OPT, Extensions::AppApi::TLV_TYPE_APP_APK_PATH, Extensions::AppApi::TLV_TYPE_APP_ENUM, Extensions::AppApi::TLV_TYPE_APP_PACKAGE_NAME, Extensions::AppApi::TLV_TYPE_APP_RUN_ENUM

Instance Attribute Summary

Attributes included from Ui::Text::DispatcherShell::CommandDispatcher

#shell, #tab_complete_items

Instance Method Summary collapse

Methods included from Rex::Post::Meterpreter::Ui::Console::CommandDispatcher

check_hash, #client, #docs_dir, #filter_commands, #initialize, #log_error, #msf_loaded?, #session, set_hash, #unknown_command

Methods included from Msf::Ui::Console::CommandDispatcher::Session

#cmd_background, #cmd_background_help, #cmd_exit, #cmd_irb, #cmd_irb_help, #cmd_irb_tabs, #cmd_pry, #cmd_pry_help, #cmd_resource, #cmd_resource_help, #cmd_resource_tabs, #cmd_sessions, #cmd_sessions_help

Methods included from Ui::Text::DispatcherShell::CommandDispatcher

#cmd_help, #cmd_help_help, #cmd_help_tabs, #deprecated_cmd, #deprecated_commands, #deprecated_help, #docs_dir, #help_to_s, included, #initialize, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #tab_complete_directory, #tab_complete_filenames, #tab_complete_generic, #tab_complete_source_address, #unknown_command, #update_prompt

Instance Method Details

#cmd_app_install(*args) ⇒ Object

Request to install application (user mode => ask the use to install)



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/appapi.rb', line 106

def cmd_app_install(*args)
  if (args.length < 1)
    print_error('[-] Usage: app_install <filepath>')
    print_error('[-] Request to install application.')
    print_status('eg. app_install "/sdcard/Download/corrm.apk"')
    return
  end

  full_path = args[0]

  # Send install request
  case client.appapi.app_install(full_path)
  when 1
    print_good('Request Done.')
  when 2
    print_error('File Not Found.')
  when 3
    print_error('Root access rejected.')
  end
end

#cmd_app_list(*args) ⇒ Object

Get list of android device installed applications



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/appapi.rb', line 50

def cmd_app_list(*args)
  app_list_opts = Rex::Parser::Arguments.new(
    '-h' => [false, 'Help Banner'],
    '-u' => [false, 'Get User apps ONLY'],
    '-s' => [false, 'Get System apps ONLY']
  )

  ret = []
  init = 0

  app_list_opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      print_line('Usage: app_list [options]')
      print_line('List the installed applications.')
      print_line(app_list_opts.usage)
      return
    when '-u'
      init = 1
    when '-s'
      init = 2
    end
  end

  ret = client.appapi.app_list(init)
  print_line(to_table(ret).to_s)
end

#cmd_app_run(*args) ⇒ Object

Start Main Activity for installed application by Package name



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/appapi.rb', line 130

def cmd_app_run(*args)
  if (args.length < 1)
    print_error('[-] Usage: app_run <package_name>')
    print_error('[-] Start Main Activity for package name.')
    print_error('[-] You can use "app_list" to pick your packagename.')
    print_status('eg. app_run com.corrm.clac')
    return
  end

  package_name = args[0]

  case client.appapi.app_run(package_name)
  when 1
    print_good("Main Activity for '#{package_name}' has started.")
  when 2
    print_error("'#{package_name}' Not Found.")
  end
end

#cmd_app_uninstall(*args) ⇒ Object

Request to unistall application (user mode => ask the use to uninstall)



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/appapi.rb', line 81

def cmd_app_uninstall(*args)
  if (args.length < 1)
    print_error('[-] Usage: app_uninstall <packagename>')
    print_error('[-] Request to uninstall application.')
    print_error('[-] You can use "app_list" to pick your packagename.')
    print_status('eg. app_uninstall com.corrm.clac')
    return
  end

  package_name = args[0]

  # Send uninstall request
  case client.appapi.app_uninstall(package_name)
  when 1
    print_good('Request Done.')
  when 2
    print_error('File Not Found.')
  when 11
    print_error("package '#{package_name}' not found.")
  end
end

#commandsObject

List of supported commands.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/appapi.rb', line 24

def commands
  all = {
    'app_list'      => 'List installed apps in the device',
    'app_run'       => 'Start Main Activity for package name',
    'app_install'   => 'Request to install apk file',
    'app_uninstall' => 'Request to uninstall application'
  }
  reqs = {
    'app_list'      => [COMMAND_ID_APPAPI_APP_LIST],
    'app_run'       => [COMMAND_ID_APPAPI_APP_RUN],
    'app_install'   => [COMMAND_ID_APPAPI_APP_INSTALL],
    'app_uninstall' => [COMMAND_ID_APPAPI_APP_UNINSTALL]
  }
  filter_commands(all, reqs)
end

#nameObject

Name for this dispatcher



43
44
45
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/appapi.rb', line 43

def name
  'Application Controller'
end

#to_table(data) ⇒ Object

Function to help printing list of information



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/appapi.rb', line 152

def to_table(data)
  column_headers = ['Name', 'Package', 'Running', 'IsSystem']

  opts = {
    'Header' => 'Application List',
    'Indent' => 2,
    'Columns' => column_headers
  }

  tbl = Rex::Text::Table.new(opts)
  (0 ... data.length).step(4).each do |index|
    tbl << [data[index],
      (data[index + 1] == nil ? '' : data[index + 1]),
      (data[index + 2] == nil ? '' : data[index + 2]),
      (data[index + 3] == nil ? '' : data[index + 3])]
  end

  tbl
end