Skip to content

Commit b0123ea

Browse files
authored
Land rapid7#18890, rename shell to query_interactive for sql session types, add -i flag
2 parents d8abd2b + 17d8fa2 commit b0123ea

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
lines changed

lib/rex/post/mssql/ui/console/command_dispatcher/client.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def name
2424
def cmd_query_help
2525
print_line 'Usage: query'
2626
print_line
27-
print_line 'Run a raw SQL query on the target.'
28-
print_line
27+
print_line 'Run a single SQL query on the target.'
28+
print_line @@query_opts.usage
2929
print_line 'Examples:'
3030
print_line
3131
print_line ' query select @@version;'
@@ -34,7 +34,7 @@ def cmd_query_help
3434
print_line
3535
end
3636

37-
# @param [Hash] result The MSQQL query result
37+
# @param [Hash] result The MSSQL query result
3838
# @return [Hash] Hash containing rows, columns and errors.
3939
def normalise_sql_result(result)
4040
{ rows: result[:rows], columns: result[:colnames], errors: result[:errors] }

lib/rex/post/mysql/ui/console/command_dispatcher/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def name
2121
def cmd_query_help
2222
print_line 'Usage: query'
2323
print_line
24-
print_line 'Run a raw SQL query on the target.'
25-
print_line
24+
print_line 'Run a single SQL query on the target.'
25+
print_line @@query_opts.usage
2626
print_line 'Examples:'
2727
print_line
2828
print_line ' query SHOW DATABASES;'

lib/rex/post/postgresql/ui/console/command_dispatcher/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def name
2525
def cmd_query_help
2626
print_line 'Usage: query'
2727
print_line
28-
print_line 'Run a raw SQL query on the target.'
29-
print_line
28+
print_line 'Run a single SQL query on the target.'
29+
print_line @@query_opts.usage
3030
print_line 'Examples:'
3131
print_line
3232
print_line ' query SELECT user;'

lib/rex/post/sql/ui/console/command_dispatcher/client.rb

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ module Client
1616

1717
include Rex::Post::Sql::Ui::Console::CommandDispatcher
1818

19+
@@query_opts = Rex::Parser::Arguments.new(
20+
['-h', '--help'] => [false, 'Help menu.'],
21+
['-i', '--interact'] => [false, 'Enter an interactive prompt for running multiple SQL queries'],
22+
)
23+
1924
#
2025
# Initializes an instance of the core command set using the supplied console
2126
# for interactivity.
@@ -32,8 +37,8 @@ def initialize(console)
3237
#
3338
def commands
3439
cmds = {
35-
'query' => 'Run a raw SQL query',
36-
'shell' => 'Enter a raw shell where SQL queries can be executed',
40+
'query' => 'Run a single SQL query',
41+
'query_interactive' => 'Enter an interactive prompt for running multiple SQL queries',
3742
}
3843

3944
reqs = {}
@@ -54,17 +59,17 @@ def help_args?(args)
5459
args.include?('-h') || args.include?('--help')
5560
end
5661

57-
def cmd_shell_help
58-
print_line 'Usage: shell'
62+
def cmd_query_interactive_help
63+
print_line 'Usage: query_interactive'
5964
print_line
60-
print_line 'Go into a raw SQL shell where SQL queries can be executed.'
65+
print_line 'Go into an interactive SQL shell where SQL queries can be executed.'
6166
print_line "To exit, type 'exit', 'quit', 'end' or 'stop'."
6267
print_line
6368
end
6469

65-
def cmd_shell(*args)
70+
def cmd_query_interactive(*args)
6671
if help_args?(args)
67-
cmd_shell_help
72+
cmd_query_interactive_help
6873
return
6974
end
7075

@@ -120,9 +125,15 @@ def run_query(query)
120125
end
121126

122127
def cmd_query(*args)
123-
if help_args?(args)
124-
cmd_query_help
125-
return
128+
@@query_opts.parse(args) do |opt, idx, val|
129+
case opt
130+
when '-h', '--help'
131+
cmd_query_help
132+
return
133+
when '-i', '--interact'
134+
cmd_query_interactive
135+
return
136+
end
126137
end
127138

128139
result = run_query(args.join(' '))

lib/rex/post/sql/ui/console/interactive_sql_client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def _multiline
117117

118118
if finished
119119
self.interacting = false
120-
print_status 'Exiting Shell mode.'
120+
print_status 'Exiting Interactive mode.'
121121
return { status: :exit, result: nil }
122122
end
123123

@@ -132,7 +132,7 @@ def _fallback
132132

133133
if stop_words.include? line.chomp.downcase
134134
self.interacting = false
135-
print_status 'Exiting Shell mode.'
135+
print_status 'Exiting Interactive mode.'
136136
return { status: :exit, result: nil }
137137
end
138138

0 commit comments

Comments
 (0)