Skip to content

Commit 2617ae7

Browse files
author
Brent Cook
committed
Land rapid7#8513, check extapi commands for dependencies
2 parents fda2e8c + 871c30c commit 2617ae7

File tree

14 files changed

+57
-102
lines changed

14 files changed

+57
-102
lines changed

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

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

52+
#
53+
# Returns the commands that meet the requirements
54+
#
55+
def filter_commands(all, reqs)
56+
all.delete_if do |cmd, _desc|
57+
reqs[cmd].any? { |req| !client.commands.include?(req) }
58+
end
59+
end
60+
5261
#
5362
# Returns true if the client has a framework object.
5463
#

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+
filter_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+
filter_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+
filter_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+
filter_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+
filter_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+
filter_commands(all, reqs)
3135
end
3236

3337
#

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def commands
2929
"dhcp_load_options" => "Load DHCP optionis from a datastore",
3030
"dhcp_log" => "Log DHCP server activity"
3131
}
32-
3332
reqs = {
3433
"dhcp_start" => [ "lanattacks_start_dhcp" ],
3534
"dhcp_stop" => [ "lanattacks_stop_dhcp" ],
@@ -38,19 +37,7 @@ def commands
3837
"dhcp_load_options" => [ "lanattacks_set_dhcp_option" ],
3938
"dhcp_log" => [ "lanattacks_dhcp_log" ]
4039
}
41-
42-
all.delete_if do |cmd, desc|
43-
del = false
44-
reqs[cmd].each do |req|
45-
next if client.commands.include? req
46-
del = true
47-
break
48-
end
49-
50-
del
51-
end
52-
53-
all
40+
filter_commands(all, reqs)
5441
end
5542

5643
#

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,13 @@ def commands
2727
"tftp_reset" => "Reset the TFTP server",
2828
"tftp_add_file" => "Add a file to the TFTP server"
2929
}
30-
3130
reqs = {
3231
"tftp_start" => [ "lanattacks_start_tftp" ],
3332
"tftp_stop" => [ "lanattacks_stop_tftp" ],
3433
"tftp_reset" => [ "lanattacks_reset_tftp" ],
3534
"tftp_add_file" => [ "lanattacks_add_tftp_file" ],
3635
}
37-
38-
all.delete_if do |cmd, desc|
39-
del = false
40-
reqs[cmd].each do |req|
41-
next if client.commands.include? req
42-
del = true
43-
break
44-
end
45-
46-
del
47-
end
48-
49-
all
36+
filter_commands(all, reqs)
5037
end
5138

5239
#

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,7 @@ def commands
104104
'show_mount' => ['stdapi_fs_mount_show'],
105105
}
106106

107-
all.delete_if do |cmd, desc|
108-
del = false
109-
reqs[cmd].each do |req|
110-
next if client.commands.include? req
111-
del = true
112-
break
113-
end
114-
115-
del
116-
end
117-
118-
all
107+
filter_commands(all, reqs)
119108
end
120109

121110
#

0 commit comments

Comments
 (0)