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 5c11a97ee8ac..2c7938c4c42a 100644 --- a/lib/rex/post/sql/ui/console/interactive_sql_client.rb +++ b/lib/rex/post/sql/ui/console/interactive_sql_client.rb @@ -80,6 +80,7 @@ def _multiline finished = false begin + result = nil prompt_proc_before = ::Reline.prompt_proc ::Reline.prompt_proc = proc { |line_buffer| line_buffer.each_with_index.map { |_line, i| i > 0 ? 'SQL *> ' : 'SQL >> ' } } @@ -87,12 +88,16 @@ def _multiline # multiline_input is the whole string that the user has input, not just the current line. raw_query = ::Reline.readmultiline('SQL >> ', use_history = true) do |multiline_input| # The user pressed ctrl + c or ctrl + z and wants to background our SQL prompt - return { status: :exit, result: nil } unless self.interacting + unless self.interacting + result = { status: :exit, result: nil } + next true + end + # When the user has pressed the enter key with no input, don't run any queries; # simply give them a new prompt on a new line. if multiline_input.chomp.empty? - print_blank_line - return { status: :success, result: nil } + result = { status: :success, result: nil } + next true end # In the case only a stop word was input, exit out of the REPL shell @@ -106,6 +111,10 @@ def _multiline ::Reline.prompt_proc = prompt_proc_before end + if result + return result + end + if finished self.interacting = false print_status 'Exiting Shell mode.'