2007-02-10 18:07:08 +00:00
|
|
|
module Msf
|
|
|
|
module Ui
|
|
|
|
module Web
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This class implements a console instance for use by the web interface
|
|
|
|
#
|
|
|
|
###
|
|
|
|
|
|
|
|
class WebConsole
|
|
|
|
attr_accessor :pipe
|
|
|
|
attr_accessor :console
|
|
|
|
attr_accessor :console_id
|
|
|
|
attr_accessor :last_access
|
|
|
|
attr_accessor :framework
|
|
|
|
attr_accessor :thread
|
|
|
|
|
2007-03-11 19:14:10 +00:00
|
|
|
# Wrapper class in case we need to extend the pipe
|
2007-02-10 18:07:08 +00:00
|
|
|
class WebConsolePipe < Rex::IO::BidirectionalPipe
|
2007-04-04 05:35:29 +00:00
|
|
|
def prompting?
|
|
|
|
false
|
|
|
|
end
|
2007-02-10 18:07:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Provides some overrides for web-based consoles
|
|
|
|
#
|
|
|
|
module WebConsoleShell
|
|
|
|
|
|
|
|
def supports_color?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(framework, console_id)
|
|
|
|
# Configure the framework
|
|
|
|
self.framework = framework
|
|
|
|
|
|
|
|
# Configure the ID
|
|
|
|
self.console_id = console_id
|
|
|
|
|
|
|
|
# Create a new pipe
|
|
|
|
self.pipe = WebConsolePipe.new
|
|
|
|
|
|
|
|
# Create a read subscriber
|
|
|
|
self.pipe.create_subscriber('msfweb')
|
|
|
|
|
|
|
|
# Initialize the console with our pipe
|
|
|
|
self.console = Msf::Ui::Console::Driver.new(
|
|
|
|
'msf',
|
|
|
|
'>',
|
|
|
|
{
|
|
|
|
'Framework' => self.framework,
|
|
|
|
'LocalInput' => self.pipe,
|
|
|
|
'LocalOutput' => self.pipe,
|
2011-03-17 00:17:45 +00:00
|
|
|
'AllowCommandPassthru' => true,
|
2010-02-25 16:29:48 +00:00
|
|
|
'Resource' => [],
|
2007-02-10 18:07:08 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
self.console.extend(WebConsoleShell)
|
2007-09-22 20:20:10 +00:00
|
|
|
self.console.block_command('irb')
|
2010-02-25 16:29:48 +00:00
|
|
|
|
2010-11-12 06:19:49 +00:00
|
|
|
self.thread = framework.threads.spawn("WebConsoleShell", false) { self.console.run }
|
2007-02-10 18:07:08 +00:00
|
|
|
|
|
|
|
update_access()
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_access
|
|
|
|
self.last_access = Time.now
|
|
|
|
end
|
|
|
|
|
|
|
|
def read
|
|
|
|
update_access
|
|
|
|
self.pipe.read_subscriber('msfweb')
|
|
|
|
end
|
|
|
|
|
|
|
|
def write(buf)
|
|
|
|
update_access
|
|
|
|
self.pipe.write_input(buf)
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute(cmd)
|
|
|
|
self.console.run_single(cmd)
|
|
|
|
end
|
|
|
|
|
|
|
|
def prompt
|
|
|
|
self.pipe.prompt
|
|
|
|
end
|
|
|
|
|
|
|
|
def tab_complete(cmd)
|
2010-11-04 23:01:03 +00:00
|
|
|
if(self.console.active_session)
|
|
|
|
return self.console.active_session.console.tab_complete(cmd)
|
|
|
|
end
|
2007-02-10 18:07:08 +00:00
|
|
|
self.console.tab_complete(cmd)
|
|
|
|
end
|
|
|
|
|
|
|
|
def shutdown
|
|
|
|
self.pipe.close
|
|
|
|
self.thread.kill
|
|
|
|
end
|
2010-02-25 16:29:48 +00:00
|
|
|
|
2007-02-18 04:25:46 +00:00
|
|
|
def busy
|
|
|
|
self.console.busy
|
|
|
|
end
|
2010-02-25 16:29:48 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
def session_detach
|
2010-02-25 16:29:48 +00:00
|
|
|
if(self.console.active_session)
|
2010-10-15 22:38:06 +00:00
|
|
|
#background interactive meterpreter channel
|
2010-10-19 00:15:37 +00:00
|
|
|
if(self.console.active_session.respond_to?('channels'))
|
2010-10-15 22:38:06 +00:00
|
|
|
self.console.active_session.channels.each_value do |ch|
|
2010-10-16 15:21:06 +00:00
|
|
|
if(ch.respond_to?('interacting') && ch.interacting)
|
2010-10-15 22:38:06 +00:00
|
|
|
ch.detach()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
#background session
|
|
|
|
self.console.active_session.completed = true
|
2007-02-18 22:35:07 +00:00
|
|
|
self.console.active_session.detach()
|
|
|
|
end
|
|
|
|
end
|
2010-02-25 16:29:48 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
def session_kill
|
2011-04-16 23:03:30 +00:00
|
|
|
self.thread.raise(Interrupt)
|
2007-02-18 22:35:07 +00:00
|
|
|
end
|
2007-03-11 19:14:10 +00:00
|
|
|
|
|
|
|
def active_module
|
|
|
|
self.console.active_module
|
|
|
|
end
|
2010-02-25 16:29:48 +00:00
|
|
|
|
2007-03-11 19:14:10 +00:00
|
|
|
def active_module=(val)
|
|
|
|
self.console.active_module = val
|
|
|
|
end
|
2010-02-25 16:29:48 +00:00
|
|
|
|
2007-02-10 18:07:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2010-02-25 16:29:48 +00:00
|
|
|
end
|
|
|
|
|