Files
metasploit-gs/lib/msf/ui/web/web_console.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

163 lines
3.1 KiB
Ruby
Raw Normal View History

# -*- coding: binary -*-
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
2013-08-30 16:28:33 -05:00
# Wrapper class in case we need to extend the pipe
2016-08-26 13:51:26 -05:00
class WebConsolePipe < Rex::Ui::Text::BidirectionalPipe
2007-04-04 05:35:29 +00:00
def prompting?
false
end
2007-02-10 18:07:08 +00:00
end
2013-08-30 16:28:33 -05:00
2007-02-10 18:07:08 +00:00
#
# Provides some overrides for web-based consoles
#
module WebConsoleShell
2013-08-30 16:28:33 -05:00
2007-02-10 18:07:08 +00:00
def supports_color?
false
end
def run_unknown_command(command)
Open3.popen2e(command) {|stdin,output,thread|
output.each {|outline|
print_line(outline.chomp)
}
}
end
2007-02-10 18:07:08 +00:00
end
2013-08-30 16:28:33 -05:00
def initialize(framework, console_id, opts={})
2007-02-10 18:07:08 +00:00
# Configure the framework
self.framework = framework
2013-08-30 16:28:33 -05:00
2007-02-10 18:07:08 +00:00
# Configure the ID
self.console_id = console_id
2013-08-30 16:28:33 -05:00
2007-02-10 18:07:08 +00:00
# Create a new pipe
self.pipe = WebConsolePipe.new
2013-08-30 16:28:33 -05:00
2007-02-10 18:07:08 +00:00
# Create a read subscriber
self.pipe.create_subscriber('msfweb')
2013-08-30 16:28:33 -05:00
# Skip database initialization if it is already configured
2019-08-21 09:35:15 -04:00
if framework.db && framework.db.active
opts['SkipDatabaseInit'] = true
2019-11-27 14:54:09 -06:00
if opts['workspace']
wspace = framework.db.find_workspace(opts['workspace'])
framework.db.workspace = wspace
end
end
2013-08-30 16:28:33 -05:00
2007-02-10 18:07:08 +00:00
# Initialize the console with our pipe
self.console = Msf::Ui::Console::Driver.new(
'msf',
'>',
opts.merge({
2007-02-10 18:07:08 +00:00
'Framework' => self.framework,
'LocalInput' => self.pipe,
'LocalOutput' => self.pipe,
'AllowCommandPassthru' => true,
'Resource' => [],
})
2007-02-10 18:07:08 +00:00
)
2013-08-30 16:28:33 -05:00
2007-02-10 18:07:08 +00:00
self.console.extend(WebConsoleShell)
self.console.block_command('irb')
2013-08-30 16:28:33 -05:00
self.thread = framework.threads.spawn("WebConsoleShell", false) { self.console.run }
2013-08-30 16:28:33 -05:00
2007-02-10 18:07:08 +00:00
update_access()
end
2013-08-30 16:28:33 -05:00
2007-02-10 18:07:08 +00:00
def update_access
self.last_access = Time.now
end
2013-08-30 16:28:33 -05:00
2007-02-10 18:07:08 +00:00
def read
update_access
self.pipe.read_subscriber('msfweb')
end
2013-08-30 16:28:33 -05:00
2007-02-10 18:07:08 +00:00
def write(buf)
update_access
self.pipe.write_input(buf)
end
2013-08-30 16:28:33 -05:00
2007-02-10 18:07:08 +00:00
def execute(cmd)
self.console.run_single(cmd)
end
2013-08-30 16:28:33 -05:00
2007-02-10 18:07:08 +00:00
def prompt
self.pipe.prompt
end
2013-08-30 16:28:33 -05:00
2007-02-10 18:07:08 +00:00
def tab_complete(cmd)
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
2013-08-30 16:28:33 -05:00
2007-02-10 18:07:08 +00:00
def shutdown
self.pipe.close
self.thread.kill
end
2013-08-30 16:28:33 -05:00
def busy
self.console.busy
end
2013-08-30 16:28:33 -05:00
def session_detach
if(self.console.active_session)
#background interactive meterpreter channel
if(self.console.active_session.respond_to?('channels'))
self.console.active_session.channels.each_value do |ch|
if(ch.respond_to?('interacting') && ch.interacting)
ch.detach()
return
end
end
end
#background session
self.console.active_session.completed = true
self.console.active_session.detach()
end
end
2013-08-30 16:28:33 -05:00
def session_kill
2011-04-16 23:03:30 +00:00
self.thread.raise(Interrupt)
end
2013-08-30 16:28:33 -05:00
def active_module
self.console.active_module
end
2013-08-30 16:28:33 -05:00
def active_module=(val)
self.console.active_module = val
end
2007-02-10 18:07:08 +00:00
end
end
end
end