Land #7350, add 'sess' command for direct session switching support
commit
6241e48b34
|
@ -42,6 +42,7 @@ Feature: Help command
|
|||
route Route traffic through a session
|
||||
save Saves the active datastores
|
||||
search Searches module names and descriptions
|
||||
sess Interact with a given session
|
||||
sessions Dump session listings and display information about sessions
|
||||
set Sets a context-specific variable to a value
|
||||
setg Sets a global variable to a value
|
||||
|
|
|
@ -136,6 +136,7 @@ class Core
|
|||
"route" => "Route traffic through a session",
|
||||
"save" => "Saves the active datastores",
|
||||
"search" => "Searches module names and descriptions",
|
||||
"sess" => "Interact with a given session",
|
||||
"sessions" => "Dump session listings and display information about sessions",
|
||||
"set" => "Sets a context-specific variable to a value",
|
||||
"setg" => "Sets a global variable to a value",
|
||||
|
@ -1753,6 +1754,25 @@ class Core
|
|||
return
|
||||
end
|
||||
|
||||
def cmd_sess_help
|
||||
print_line('Usage: sess <session id>')
|
||||
print_line
|
||||
print_line('Interact with the given session ID.')
|
||||
print_line('This works the same as: sessions -i <session id>')
|
||||
print_line
|
||||
end
|
||||
|
||||
#
|
||||
# Helper function to quickly select a session
|
||||
#
|
||||
def cmd_sess(*args)
|
||||
if args.length == 0 || args[0].to_i == 0
|
||||
cmd_sess_help
|
||||
else
|
||||
cmd_sessions('-i', args[0])
|
||||
end
|
||||
end
|
||||
|
||||
def cmd_sessions_help
|
||||
print_line "Usage: sessions [options]"
|
||||
print_line
|
||||
|
@ -1954,22 +1974,26 @@ class Core
|
|||
end
|
||||
end
|
||||
when 'interact'
|
||||
session = verify_session(sid)
|
||||
if session
|
||||
if session.respond_to?(:response_timeout)
|
||||
last_known_timeout = session.response_timeout
|
||||
session.response_timeout = response_timeout
|
||||
end
|
||||
print_status("Starting interaction with #{session.name}...\n") unless quiet
|
||||
begin
|
||||
self.active_session = session
|
||||
session.interact(driver.input.dup, driver.output)
|
||||
self.active_session = nil
|
||||
driver.input.reset_tab_completion if driver.input.supports_readline
|
||||
ensure
|
||||
if session.respond_to?(:response_timeout) && last_known_timeout
|
||||
session.response_timeout = last_known_timeout
|
||||
while sid
|
||||
session = verify_session(sid)
|
||||
if session
|
||||
if session.respond_to?(:response_timeout)
|
||||
last_known_timeout = session.response_timeout
|
||||
session.response_timeout = response_timeout
|
||||
end
|
||||
print_status("Starting interaction with #{session.name}...\n") unless quiet
|
||||
begin
|
||||
self.active_session = session
|
||||
sid = session.interact(driver.input.dup, driver.output)
|
||||
self.active_session = nil
|
||||
driver.input.reset_tab_completion if driver.input.supports_readline
|
||||
ensure
|
||||
if session.respond_to?(:response_timeout) && last_known_timeout
|
||||
session.response_timeout = last_known_timeout
|
||||
end
|
||||
end
|
||||
else
|
||||
sid = nil
|
||||
end
|
||||
end
|
||||
when 'scriptall'
|
||||
|
|
|
@ -65,6 +65,7 @@ class Console::CommandDispatcher::Core
|
|||
"bgkill" => "Kills a background meterpreter script",
|
||||
"get_timeouts" => "Get the current session timeout values",
|
||||
"set_timeouts" => "Set the current session timeout values",
|
||||
"sess" => "Quickly switch to another session",
|
||||
"bglist" => "Lists running background scripts",
|
||||
"write" => "Writes data to a channel",
|
||||
"enable_unicode_encoding" => "Enables encoding of unicode strings",
|
||||
|
@ -111,6 +112,28 @@ class Console::CommandDispatcher::Core
|
|||
"Core"
|
||||
end
|
||||
|
||||
def cmd_sess_help
|
||||
print_line('Usage: sess <session id>')
|
||||
print_line
|
||||
print_line('Interact with a different session Id.')
|
||||
print_line('This works the same as calling this from the MSF shell: sessions -i <session id>')
|
||||
print_line
|
||||
end
|
||||
|
||||
def cmd_sess(*args)
|
||||
if args.length == 0 || args[0].to_i == 0
|
||||
cmd_sess_help
|
||||
elsif args[0].to_s == client.name.to_s
|
||||
print_status("Session #{client.name} is already interactive.")
|
||||
else
|
||||
print_status("Backgrounding session #{client.name}...")
|
||||
# store the next session id so that it can be referenced as soon
|
||||
# as this session is no longer interacting
|
||||
client.next_session = args[0]
|
||||
client.interacting = false
|
||||
end
|
||||
end
|
||||
|
||||
def cmd_background_help
|
||||
print_line "Usage: background"
|
||||
print_line
|
||||
|
|
|
@ -83,8 +83,13 @@ module Interactive
|
|||
self.completed = true
|
||||
end
|
||||
|
||||
# Return whether or not EOF was reached
|
||||
return eof
|
||||
# if another session was requested, store it
|
||||
next_session = self.next_session
|
||||
# clear the value from the object
|
||||
self.next_session = nil
|
||||
|
||||
# return this session id
|
||||
return next_session
|
||||
end
|
||||
|
||||
#
|
||||
|
@ -104,6 +109,11 @@ module Interactive
|
|||
#
|
||||
attr_accessor :interacting
|
||||
|
||||
#
|
||||
# If another session needs interaction, this is where it goes
|
||||
#
|
||||
attr_accessor :next_session
|
||||
|
||||
#
|
||||
# Whether or not the session has completed interaction
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue