From 7625d36c1c971657472625e78c4f05bfb807fbe9 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 5 Jun 2017 14:34:39 +0800 Subject: [PATCH] fix #8199, check extapi for dependencies --- .../ui/console/command_dispatcher.rb | 17 +++++++++++++++++ .../ui/console/command_dispatcher/android.rb | 7 +------ .../console/command_dispatcher/extapi/adsi.rb | 11 ++++++++++- .../command_dispatcher/extapi/clipboard.rb | 13 ++++++++++++- .../command_dispatcher/extapi/service.rb | 8 +++++++- .../console/command_dispatcher/extapi/window.rb | 6 +++++- .../ui/console/command_dispatcher/extapi/wmi.rb | 8 ++++++-- 7 files changed, 58 insertions(+), 12 deletions(-) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher.rb index 95d8a21a6f..0b62101eeb 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher.rb @@ -49,6 +49,23 @@ module Console::CommandDispatcher shell.client end + # + # Returns the commands that meet the requirements + # + def check_commands(all, reqs=nil) + all.delete_if do |cmd, _desc| + del = false + reqs[cmd].each do |req| + next if client.commands.include? req + del = true + break + end + del + end + + all + end + # # Returns true if the client has a framework object. # diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/android.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/android.rb index 63203eeef9..11ff4a25ad 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/android.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/android.rb @@ -36,7 +36,6 @@ class Console::CommandDispatcher::Android 'set_audio_mode' => 'Set Ringer Mode', 'wakelock' => 'Enable/Disable Wakelock', } - reqs = { 'dump_sms' => ['android_dump_sms'], 'dump_contacts' => ['android_dump_contacts'], @@ -53,11 +52,7 @@ class Console::CommandDispatcher::Android 'set_audio_mode' => ['android_set_audio_mode'], 'wakelock' => ['android_wakelock'], } - - # Ensure any requirements of the command are met - all.delete_if do |cmd, _desc| - reqs[cmd].any? { |req| !client.commands.include?(req) } - end + check_commands(all, reqs) end def interval_collect_usage diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/adsi.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/adsi.rb index 1cb866af3b..7e3043408a 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/adsi.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/adsi.rb @@ -25,7 +25,7 @@ class Console::CommandDispatcher::Extapi::Adsi # List of supported commands. # def commands - { + all = { 'adsi_user_enum' => 'Enumerate all users on the specified domain.', 'adsi_group_enum' => 'Enumerate all groups on the specified domain.', 'adsi_nested_group_user_enum' => 'Recursively enumerate users who are effectively members of the group specified.', @@ -33,6 +33,15 @@ class Console::CommandDispatcher::Extapi::Adsi 'adsi_dc_enum' => 'Enumerate all domain controllers on the specified domain.', 'adsi_domain_query' => 'Enumerate all objects on the specified domain that match a filter.' } + reqs = { + "adsi_user_enum" => [ "extapi_adsi_domain_query" ], + "adsi_group_enum" => [ "extapi_adsi_domain_query" ], + "adsi_nested_group_user_enum" => [ "extapi_adsi_domain_query" ], + "adsi_computer_enum" => [ "extapi_adsi_domain_query" ], + "adsi_dc_enum" => [ "extapi_adsi_domain_query" ], + "adsi_domain_query" => [ "extapi_adsi_domain_query" ], + } + check_commands(all, reqs) end # diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb index 7707e53c77..013d769005 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb @@ -20,7 +20,7 @@ class Console::CommandDispatcher::Extapi::Clipboard # List of supported commands. # def commands - { + all = { "clipboard_get_data" => "Read the target's current clipboard (text, files, images)", "clipboard_set_text" => "Write text to the target's clipboard", "clipboard_monitor_start" => "Start the clipboard monitor", @@ -30,6 +30,17 @@ class Console::CommandDispatcher::Extapi::Clipboard "clipboard_monitor_purge" => "Delete all captured cilpboard content without dumping it", "clipboard_monitor_stop" => "Stop the clipboard monitor" } + reqs = { + "clipboard_get_data" => [ "extapi_clipboard_get_data" ], + "clipboard_set_text" => [ "extapi_clipboard_set_data" ], + "clipboard_monitor_start" => [ "extapi_clipboard_monitor_start" ], + "clipboard_monitor_pause" => [ "extapi_clipboard_monitor_pause" ], + "clipboard_monitor_resume" => [ "extapi_clipboard_monitor_resume" ], + "clipboard_monitor_dump" => [ "extapi_clipboard_monitor_dump" ], + "clipboard_monitor_purge" => [ "extapi_clipboard_monitor_purge" ], + "clipboard_monitor_stop" => [ "extapi_clipboard_monitor_stop" ], + } + check_commands(all, reqs) end # diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/service.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/service.rb index 45df08bd33..9e433cd084 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/service.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/service.rb @@ -21,11 +21,17 @@ class Console::CommandDispatcher::Extapi::Service # List of supported commands. # def commands - { + all = { "service_enum" => "Enumerate all registered Windows services", "service_query" => "Query more detail about a specific Windows service", "service_control" => "Control a single service (start/pause/resume/stop/restart)" } + reqs = { + "service_enum" => [ "extapi_service_enum" ], + "service_query" => [ "extapi_service_query" ], + "service_control" => [ "extapi_service_control" ], + } + check_commands(all, reqs) end # diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/window.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/window.rb index 72c0210fbd..1edf85ad07 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/window.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/window.rb @@ -21,9 +21,13 @@ class Console::CommandDispatcher::Extapi::Window # List of supported commands. # def commands - { + all = { "window_enum" => "Enumerate all current open windows" } + reqs = { + "window_enum" => [ "extapi_window_enum" ], + } + check_commands(all, reqs) end # diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/wmi.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/wmi.rb index 68c5612893..910ae05d4c 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/wmi.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/wmi.rb @@ -25,9 +25,13 @@ class Console::CommandDispatcher::Extapi::Wmi # List of supported commands. # def commands - { - "wmi_query" => "Perform a generic WMI query and return the results" + all = { + "wmi_query" => "Perform a generic WMI query and return the results", } + reqs = { + "wmi_query" => [ "extapi_wmi_query" ], + } + check_commands(all, reqs) end #