Adds help and tabs for commands in meterpreter core

unstable
James Lee 2012-02-21 10:07:27 -07:00
parent 4a631e463c
commit 3857bef9f6
1 changed files with 86 additions and 21 deletions

View File

@ -109,7 +109,7 @@ class Console::CommandDispatcher::Core
# Performs operations on the supplied channel. # Performs operations on the supplied channel.
# #
def cmd_channel(*args) 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 cmd_channel_help
return return
end end
@ -180,14 +180,35 @@ class Console::CommandDispatcher::Core
end end
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 <channel_id>"
print_line
print_line "Closes the supplied channel."
print_line
end
# #
# Closes a supplied channel. # Closes a supplied channel.
# #
def cmd_close(*args) def cmd_close(*args)
if (args.length == 0) if (args.length == 0)
print_line( cmd_close_help
"Usage: close channel_id\n\n" +
"Closes the supplied channel.")
return true return true
end end
@ -204,6 +225,12 @@ class Console::CommandDispatcher::Core
end end
end end
def cmd_close_tabs(str, words)
return [] if words.length > 1
return tab_complete_channels
end
# #
# Terminates the meterpreter session. # Terminates the meterpreter session.
# #
@ -216,6 +243,17 @@ class Console::CommandDispatcher::Core
alias cmd_quit cmd_exit 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 # Disconnects the session
# #
@ -228,14 +266,19 @@ class Console::CommandDispatcher::Core
shell.stop shell.stop
end end
def cmd_interact_help
print_line "Usage: interact <channel_id>"
print_line
print_line "Interacts with the supplied channel."
print_line
end
# #
# Interacts with a channel. # Interacts with a channel.
# #
def cmd_interact(*args) def cmd_interact(*args)
if (args.length == 0) if (args.length == 0)
print_line( cmd_info_help
"Usage: interact channel_id\n\n" +
"Interacts with the supplied channel.")
return true return true
end end
@ -251,6 +294,8 @@ class Console::CommandDispatcher::Core
end end
end end
alias cmd_interact_tabs cmd_close_tabs
# #
# Runs the IRB scripting shell # Runs the IRB scripting shell
# #
@ -261,15 +306,20 @@ class Console::CommandDispatcher::Core
Rex::Ui::Text::IrbShell.new(binding).run Rex::Ui::Text::IrbShell.new(binding).run
end end
def cmd_migrate_help
print_line "Usage: migrate <pid>"
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. # Migrates the server to the supplied process identifier.
# #
def cmd_migrate(*args) def cmd_migrate(*args)
if (args.length == 0) if (args.length == 0)
print_line( cmd_migrate_help
"Usage: migrate pid\n\n" +
"Migrates the server instance to another process.\n" +
"Note: Any open channels or other dynamic state will be lost.")
return true return true
end end
@ -371,14 +421,19 @@ class Console::CommandDispatcher::Core
alias cmd_use_help cmd_load_help alias cmd_use_help cmd_load_help
alias cmd_use_tabs cmd_load_tabs alias cmd_use_tabs cmd_load_tabs
def cmd_read_help
print_line "Usage: read <channel_id> [length]"
print_line
print_line "Reads data from the supplied channel."
print_line
end
# #
# Reads data from a channel. # Reads data from a channel.
# #
def cmd_read(*args) def cmd_read(*args)
if (args.length == 0) if (args.length == 0)
print_line( cmd_read_help
"Usage: read channel_id [length]\n\n" +
"Reads data from the supplied channel.")
return true return true
end end
@ -402,6 +457,8 @@ class Console::CommandDispatcher::Core
return true return true
end end
alias cmd_read_tabs cmd_close_tabs
def cmd_run_help def cmd_run_help
print_line "Usage: run <script> [arguments]" print_line "Usage: run <script> [arguments]"
print_line print_line
@ -669,17 +726,15 @@ class Console::CommandDispatcher::Core
return true return true
end end
def cmd_resource_tabs(str, words) def cmd_resource_help
return [] if words.length > 1 print_line "Usage: resource <path1> [path2 ...]"
print_line
tab_complete_filenames(str, words) print_line "Run the commands stored in the supplied files."
print_line
end end
def cmd_resource(*args) def cmd_resource(*args)
if args.empty? if args.empty?
print(
"Usage: resource path1 path2" +
"Run the commands stored in the supplied files.\n")
return false return false
end end
args.each do |glob| args.each do |glob|
@ -710,6 +765,12 @@ class Console::CommandDispatcher::Core
end end
end end
def cmd_resource_tabs(str, words)
return [] if words.length > 1
tab_complete_filenames(str, words)
end
def cmd_enable_unicode_encoding def cmd_enable_unicode_encoding
client.encode_unicode = true client.encode_unicode = true
print_status("Unicode encoding is enabled") print_status("Unicode encoding is enabled")
@ -799,6 +860,10 @@ protected
tabs.compact tabs.compact
end end
def tab_complete_channels
client.channels.keys.map { |k| k.to_s }
end
end end
end end