From 5534b44101c435d780505dc0ec410f0049cfb3cd Mon Sep 17 00:00:00 2001 From: Zach Goldman Date: Mon, 26 Feb 2024 11:23:37 -0600 Subject: [PATCH] rename shell to query_interactive for sql session types, add -i flag --- .../ui/console/command_dispatcher/client.rb | 36 +++++++++++++++---- .../sql/ui/console/interactive_sql_client.rb | 4 +-- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/lib/rex/post/sql/ui/console/command_dispatcher/client.rb b/lib/rex/post/sql/ui/console/command_dispatcher/client.rb index c682d067d0ba1..89a0a73499627 100644 --- a/lib/rex/post/sql/ui/console/command_dispatcher/client.rb +++ b/lib/rex/post/sql/ui/console/command_dispatcher/client.rb @@ -33,7 +33,7 @@ def initialize(console) def commands cmds = { 'query' => 'Run a raw SQL query', - 'shell' => 'Enter a raw shell where SQL queries can be executed', + 'query_interactive' => 'Enter an interactive prompt for running multiple SQL queries', } reqs = {} @@ -54,17 +54,25 @@ def help_args?(args) args.include?('-h') || args.include?('--help') end - def cmd_shell_help - print_line 'Usage: shell' + # @param [Array] args An array of arguments passed in to a command + # @return [TrueClass, FalseClass] True if the array contains '-i', else false. + def interactive_args?(args) + return false unless args.instance_of?(::Array) + + args.include?('-i') + end + + def cmd_query_interactive_help + print_line 'Usage: query_interactive, query -i' print_line print_line 'Go into a raw SQL shell where SQL queries can be executed.' print_line "To exit, type 'exit', 'quit', 'end' or 'stop'." print_line end - def cmd_shell(*args) + def cmd_query_interactive(*args) if help_args?(args) - cmd_shell_help + cmd_query_interactive_help return end @@ -119,9 +127,23 @@ def run_query(query) { status: :success, result: result } end - def cmd_query(*args) - if help_args?(args) + def parse_args(args) + if help_args?(args) && interactive_args?(args) + cmd_query_interactive_help + return true + elsif help_args?(args) cmd_query_help + return true + elsif interactive_args?(args) + cmd_query_interactive + return true + else + return false + end + end + + def cmd_query(*args) + if parse_args(args) return end diff --git a/lib/rex/post/sql/ui/console/interactive_sql_client.rb b/lib/rex/post/sql/ui/console/interactive_sql_client.rb index 0cb2a87cb537c..e435cdaa50899 100644 --- a/lib/rex/post/sql/ui/console/interactive_sql_client.rb +++ b/lib/rex/post/sql/ui/console/interactive_sql_client.rb @@ -101,7 +101,7 @@ def _multiline if finished self.interacting = false - print_status 'Exiting Shell mode.' + print_status 'Exiting Interactive mode.' return { status: :exit, result: nil } end @@ -116,7 +116,7 @@ def _fallback if stop_words.include? line.chomp.downcase self.interacting = false - print_status 'Exiting Shell mode.' + print_status 'Exiting Interactive mode.' return { status: :exit, result: nil } end