Skip to content

Commit 7625d36

Browse files
committed
fix rapid7#8199, check extapi for dependencies
1 parent 8c35e54 commit 7625d36

File tree

7 files changed

+58
-12
lines changed

7 files changed

+58
-12
lines changed

lib/rex/post/meterpreter/ui/console/command_dispatcher.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ def client
4949
shell.client
5050
end
5151

52+
#
53+
# Returns the commands that meet the requirements
54+
#
55+
def check_commands(all, reqs=nil)
56+
all.delete_if do |cmd, _desc|
57+
del = false
58+
reqs[cmd].each do |req|
59+
next if client.commands.include? req
60+
del = true
61+
break
62+
end
63+
del
64+
end
65+
66+
all
67+
end
68+
5269
#
5370
# Returns true if the client has a framework object.
5471
#

lib/rex/post/meterpreter/ui/console/command_dispatcher/android.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def commands
3636
'set_audio_mode' => 'Set Ringer Mode',
3737
'wakelock' => 'Enable/Disable Wakelock',
3838
}
39-
4039
reqs = {
4140
'dump_sms' => ['android_dump_sms'],
4241
'dump_contacts' => ['android_dump_contacts'],
@@ -53,11 +52,7 @@ def commands
5352
'set_audio_mode' => ['android_set_audio_mode'],
5453
'wakelock' => ['android_wakelock'],
5554
}
56-
57-
# Ensure any requirements of the command are met
58-
all.delete_if do |cmd, _desc|
59-
reqs[cmd].any? { |req| !client.commands.include?(req) }
60-
end
55+
check_commands(all, reqs)
6156
end
6257

6358
def interval_collect_usage

lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/adsi.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,23 @@ class Console::CommandDispatcher::Extapi::Adsi
2525
# List of supported commands.
2626
#
2727
def commands
28-
{
28+
all = {
2929
'adsi_user_enum' => 'Enumerate all users on the specified domain.',
3030
'adsi_group_enum' => 'Enumerate all groups on the specified domain.',
3131
'adsi_nested_group_user_enum' => 'Recursively enumerate users who are effectively members of the group specified.',
3232
'adsi_computer_enum' => 'Enumerate all computers on the specified domain.',
3333
'adsi_dc_enum' => 'Enumerate all domain controllers on the specified domain.',
3434
'adsi_domain_query' => 'Enumerate all objects on the specified domain that match a filter.'
3535
}
36+
reqs = {
37+
"adsi_user_enum" => [ "extapi_adsi_domain_query" ],
38+
"adsi_group_enum" => [ "extapi_adsi_domain_query" ],
39+
"adsi_nested_group_user_enum" => [ "extapi_adsi_domain_query" ],
40+
"adsi_computer_enum" => [ "extapi_adsi_domain_query" ],
41+
"adsi_dc_enum" => [ "extapi_adsi_domain_query" ],
42+
"adsi_domain_query" => [ "extapi_adsi_domain_query" ],
43+
}
44+
check_commands(all, reqs)
3645
end
3746

3847
#

lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Console::CommandDispatcher::Extapi::Clipboard
2020
# List of supported commands.
2121
#
2222
def commands
23-
{
23+
all = {
2424
"clipboard_get_data" => "Read the target's current clipboard (text, files, images)",
2525
"clipboard_set_text" => "Write text to the target's clipboard",
2626
"clipboard_monitor_start" => "Start the clipboard monitor",
@@ -30,6 +30,17 @@ def commands
3030
"clipboard_monitor_purge" => "Delete all captured cilpboard content without dumping it",
3131
"clipboard_monitor_stop" => "Stop the clipboard monitor"
3232
}
33+
reqs = {
34+
"clipboard_get_data" => [ "extapi_clipboard_get_data" ],
35+
"clipboard_set_text" => [ "extapi_clipboard_set_data" ],
36+
"clipboard_monitor_start" => [ "extapi_clipboard_monitor_start" ],
37+
"clipboard_monitor_pause" => [ "extapi_clipboard_monitor_pause" ],
38+
"clipboard_monitor_resume" => [ "extapi_clipboard_monitor_resume" ],
39+
"clipboard_monitor_dump" => [ "extapi_clipboard_monitor_dump" ],
40+
"clipboard_monitor_purge" => [ "extapi_clipboard_monitor_purge" ],
41+
"clipboard_monitor_stop" => [ "extapi_clipboard_monitor_stop" ],
42+
}
43+
check_commands(all, reqs)
3344
end
3445

3546
#

lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/service.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ class Console::CommandDispatcher::Extapi::Service
2121
# List of supported commands.
2222
#
2323
def commands
24-
{
24+
all = {
2525
"service_enum" => "Enumerate all registered Windows services",
2626
"service_query" => "Query more detail about a specific Windows service",
2727
"service_control" => "Control a single service (start/pause/resume/stop/restart)"
2828
}
29+
reqs = {
30+
"service_enum" => [ "extapi_service_enum" ],
31+
"service_query" => [ "extapi_service_query" ],
32+
"service_control" => [ "extapi_service_control" ],
33+
}
34+
check_commands(all, reqs)
2935
end
3036

3137
#

lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/window.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ class Console::CommandDispatcher::Extapi::Window
2121
# List of supported commands.
2222
#
2323
def commands
24-
{
24+
all = {
2525
"window_enum" => "Enumerate all current open windows"
2626
}
27+
reqs = {
28+
"window_enum" => [ "extapi_window_enum" ],
29+
}
30+
check_commands(all, reqs)
2731
end
2832

2933
#

lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/wmi.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ class Console::CommandDispatcher::Extapi::Wmi
2525
# List of supported commands.
2626
#
2727
def commands
28-
{
29-
"wmi_query" => "Perform a generic WMI query and return the results"
28+
all = {
29+
"wmi_query" => "Perform a generic WMI query and return the results",
3030
}
31+
reqs = {
32+
"wmi_query" => [ "extapi_wmi_query" ],
33+
}
34+
check_commands(all, reqs)
3135
end
3236

3337
#

0 commit comments

Comments
 (0)