From 3857bef9f68a386fac521e26b6b2215fefeb6dc2 Mon Sep 17 00:00:00 2001 From: James Lee Date: Tue, 21 Feb 2012 10:07:27 -0700 Subject: [PATCH] Adds help and tabs for commands in meterpreter core --- .../ui/console/command_dispatcher/core.rb | 107 ++++++++++++++---- 1 file changed, 86 insertions(+), 21 deletions(-) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb index 0a85d3ce1f..b1c14492eb 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb @@ -109,7 +109,7 @@ class Console::CommandDispatcher::Core # Performs operations on the supplied channel. # def cmd_channel(*args) - if args.include?("-h") or args.include?("--help") + if args.empty? or args.include?("-h") or args.include?("--help") cmd_channel_help return end @@ -180,14 +180,35 @@ class Console::CommandDispatcher::Core end end + def cmd_channel_tabs(str, words) + case words.length + when 1 + @@channel_opts.fmt.keys + when 2 + case words[1] + when "-c", "-i", "-r", "-w" + tab_complete_channels + else + [] + end + else + [] + end + end + + def cmd_close_help + print_line "Usage: close " + print_line + print_line "Closes the supplied channel." + print_line + end + # # Closes a supplied channel. # def cmd_close(*args) if (args.length == 0) - print_line( - "Usage: close channel_id\n\n" + - "Closes the supplied channel.") + cmd_close_help return true end @@ -204,6 +225,12 @@ class Console::CommandDispatcher::Core end end + def cmd_close_tabs(str, words) + return [] if words.length > 1 + + return tab_complete_channels + end + # # Terminates the meterpreter session. # @@ -216,6 +243,17 @@ class Console::CommandDispatcher::Core alias cmd_quit cmd_exit + def cmd_detach_help + print_line "Detach from the victim. Only possible for non-stream sessions (http/https)" + print_line + print_line "The victim will continue to attempt to call back to the handler until it" + print_line "successfully connects (which may happen immediately if you have a handler" + print_line "running in the background), or reaches its expiration." + print_line + print_line "This session may #{client.passive_service ? "" : "NOT"} be detached." + print_line + end + # # Disconnects the session # @@ -228,14 +266,19 @@ class Console::CommandDispatcher::Core shell.stop end + def cmd_interact_help + print_line "Usage: interact " + print_line + print_line "Interacts with the supplied channel." + print_line + end + # # Interacts with a channel. # def cmd_interact(*args) if (args.length == 0) - print_line( - "Usage: interact channel_id\n\n" + - "Interacts with the supplied channel.") + cmd_info_help return true end @@ -251,6 +294,8 @@ class Console::CommandDispatcher::Core end end + alias cmd_interact_tabs cmd_close_tabs + # # Runs the IRB scripting shell # @@ -261,15 +306,20 @@ class Console::CommandDispatcher::Core Rex::Ui::Text::IrbShell.new(binding).run end + def cmd_migrate_help + print_line "Usage: migrate " + print_line + print_line "Migrates the server instance to another process." + print_line "NOTE: Any open channels or other dynamic state will be lost." + print_line + end + # # Migrates the server to the supplied process identifier. # def cmd_migrate(*args) if (args.length == 0) - print_line( - "Usage: migrate pid\n\n" + - "Migrates the server instance to another process.\n" + - "Note: Any open channels or other dynamic state will be lost.") + cmd_migrate_help return true end @@ -371,14 +421,19 @@ class Console::CommandDispatcher::Core alias cmd_use_help cmd_load_help alias cmd_use_tabs cmd_load_tabs + def cmd_read_help + print_line "Usage: read [length]" + print_line + print_line "Reads data from the supplied channel." + print_line + end + # # Reads data from a channel. # def cmd_read(*args) if (args.length == 0) - print_line( - "Usage: read channel_id [length]\n\n" + - "Reads data from the supplied channel.") + cmd_read_help return true end @@ -402,6 +457,8 @@ class Console::CommandDispatcher::Core return true end + alias cmd_read_tabs cmd_close_tabs + def cmd_run_help print_line "Usage: run