Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/ui/web/web_console.rb
Views: 11783
# -*- coding: binary -*-1module Msf2module Ui3module Web45###6#7# This class implements a console instance for use by the web interface8#9###1011class WebConsole12attr_accessor :pipe13attr_accessor :console14attr_accessor :console_id15attr_accessor :last_access16attr_accessor :framework17attr_accessor :thread1819# Wrapper class in case we need to extend the pipe20class WebConsolePipe < Rex::Ui::Text::BidirectionalPipe21def prompting?22false23end24end2526#27# Provides some overrides for web-based consoles28#29module WebConsoleShell3031def supports_color?32false33end3435def run_unknown_command(command)36Open3.popen2e(command) {|stdin,output,thread|37output.each {|outline|38print_line(outline.chomp)39}40}41end4243end4445def initialize(framework, console_id, opts={})46# Configure the framework47self.framework = framework4849# Configure the ID50self.console_id = console_id5152# Create a new pipe53self.pipe = WebConsolePipe.new5455# Create a read subscriber56self.pipe.create_subscriber('msfweb')5758# Skip database initialization if it is already configured59if framework.db && framework.db.active60opts['SkipDatabaseInit'] = true61if opts['workspace']62wspace = framework.db.find_workspace(opts['workspace'])63framework.db.workspace = wspace64end65end6667# Initialize the console with our pipe68self.console = Msf::Ui::Console::Driver.new(69'msf',70'>',71opts.merge({72'Framework' => self.framework,73'LocalInput' => self.pipe,74'LocalOutput' => self.pipe,75'AllowCommandPassthru' => true,76'Resource' => [],77})78)7980self.console.extend(WebConsoleShell)81self.console.block_command('irb')8283self.thread = framework.threads.spawn("WebConsoleShell", false) { self.console.run }8485update_access()86end8788def update_access89self.last_access = Time.now90end9192def read93update_access94self.pipe.read_subscriber('msfweb')95end9697def write(buf)98update_access99self.pipe.write_input(buf)100end101102def execute(cmd)103self.console.run_single(cmd)104end105106def prompt107self.pipe.prompt108end109110def tab_complete(cmd)111if(self.console.active_session)112return self.console.active_session.console.tab_complete(cmd)113end114self.console.tab_complete(cmd)115end116117def shutdown118self.pipe.close119self.thread.kill120end121122def busy123self.console.busy124end125126def session_detach127if(self.console.active_session)128#background interactive meterpreter channel129if(self.console.active_session.respond_to?('channels'))130self.console.active_session.channels.each_value do |ch|131if(ch.respond_to?('interacting') && ch.interacting)132ch.detach()133return134end135end136end137#background session138self.console.active_session.completed = true139self.console.active_session.detach()140end141end142143def session_kill144self.thread.raise(Interrupt)145end146147def active_module148self.console.active_module149end150151def active_module=(val)152self.console.active_module = val153end154155end156157158end159end160end161162163164