2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2005-07-19 04:21:15 +00:00
|
|
|
module Rex
|
|
|
|
module Post
|
|
|
|
module Meterpreter
|
|
|
|
module Ui
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# Mixin that is meant to extend the base channel class from meterpreter in a
|
|
|
|
# manner that adds interactive capabilities.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
module Console::InteractiveChannel
|
|
|
|
|
|
|
|
include Rex::Ui::Interactive
|
|
|
|
|
|
|
|
#
|
|
|
|
# Interacts with self.
|
|
|
|
#
|
|
|
|
def _interact
|
|
|
|
# If the channel has a left-side socket, then we can interact with it.
|
|
|
|
if (self.lsock)
|
|
|
|
self.interactive(true)
|
|
|
|
|
2005-07-26 04:08:01 +00:00
|
|
|
interact_stream(self)
|
2005-07-19 04:21:15 +00:00
|
|
|
|
|
|
|
self.interactive(false)
|
|
|
|
else
|
|
|
|
print_error("Channel #{self.cid} does not support interaction.")
|
|
|
|
|
|
|
|
self.interacting = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2005-11-15 05:22:13 +00:00
|
|
|
# Called when an interrupt is sent.
|
2005-07-19 04:21:15 +00:00
|
|
|
#
|
|
|
|
def _interrupt
|
2012-05-24 23:10:26 +00:00
|
|
|
prompt_yesno("Terminate channel #{self.cid}?")
|
2005-07-19 04:21:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2005-11-15 05:22:13 +00:00
|
|
|
# Suspends interaction with the channel.
|
2005-07-19 04:21:15 +00:00
|
|
|
#
|
|
|
|
def _suspend
|
|
|
|
# Ask the user if they would like to background the session
|
|
|
|
if (prompt_yesno("Background channel #{self.cid}?") == true)
|
2005-07-26 04:08:01 +00:00
|
|
|
self.interactive(false)
|
|
|
|
|
2005-07-19 04:21:15 +00:00
|
|
|
self.interacting = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Closes the channel like it aint no thang.
|
|
|
|
#
|
|
|
|
def _interact_complete
|
2005-07-26 04:08:01 +00:00
|
|
|
begin
|
|
|
|
self.interactive(false)
|
|
|
|
|
|
|
|
self.close
|
|
|
|
rescue IOError
|
|
|
|
end
|
2005-07-19 04:21:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Reads data from local input and writes it remotely.
|
|
|
|
#
|
|
|
|
def _stream_read_local_write_remote(channel)
|
|
|
|
data = user_input.gets
|
2008-11-09 21:40:03 +00:00
|
|
|
return if not data
|
2011-04-15 21:10:15 +00:00
|
|
|
|
|
|
|
self.on_command_proc.call(data.strip) if self.on_command_proc
|
2005-07-19 04:21:15 +00:00
|
|
|
self.write(data)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Reads from the channel and writes locally.
|
|
|
|
#
|
|
|
|
def _stream_read_remote_write_local(channel)
|
2005-07-26 04:08:01 +00:00
|
|
|
data = self.lsock.sysread(16384)
|
2005-07-19 04:21:15 +00:00
|
|
|
|
2011-04-15 21:10:15 +00:00
|
|
|
self.on_print_proc.call(data.strip) if self.on_print_proc
|
2005-07-19 04:21:15 +00:00
|
|
|
user_output.print(data)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the remote file descriptor to select on
|
|
|
|
#
|
2005-07-26 04:08:01 +00:00
|
|
|
def _remote_fd(stream)
|
2005-07-19 04:21:15 +00:00
|
|
|
self.lsock
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-11-09 21:40:03 +00:00
|
|
|
end
|