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/driver.rb
Views: 11783
# -*- coding: binary -*-123module Msf4module Ui5module Web6789###10#11# This class implements a user interface driver on a web interface.12#13###14class Driver < Msf::Ui::Driver151617attr_accessor :framework # :nodoc:18attr_accessor :consoles # :nodoc:19attr_accessor :sessions # :nodoc:20attr_accessor :last_console # :nodoc:2122ConfigCore = "framework/core"23ConfigGroup = "framework/ui/web"2425#26# Initializes a web driver instance and prepares it for listening to HTTP27# requests. The constructor takes a hash of options that can control how28# the web server will operate.29#30def initialize(opts = {})31# Call the parent32super()3334# Set the passed options hash for referencing later on.35self.opts = opts3637self.consoles = {}38self.sessions = {}3940if(opts[:framework])41self.framework = opts[:framework]42else43# Initialize configuration44Msf::Config.init4546# Initialize logging47initialize_logging4849# Initialize attributes50self.framework = Msf::Simple::Framework.create51end5253# Initialize the console count54self.last_console = 055end5657def create_console(opts={})58# Destroy any unused consoles59clean_consoles6061console = WebConsole.new(self.framework, self.last_console, opts)62self.last_console += 163self.consoles[console.console_id.to_s] = console64console.console_id.to_s65end6667def destroy_console(cid)68con = self.consoles[cid]69if(con)70con.shutdown71self.consoles.delete(cid)72end73end747576def write_console(id, buf)77self.consoles[id] ? self.consoles[id].write(buf) : nil78end7980def read_console(id)81self.consoles[id] ? self.consoles[id].read() : nil82end8384def clean_consoles(timeout=300)85self.consoles.each_pair do |id, con|86if (con.last_access + timeout < Time.now)87con.shutdown88self.consoles.delete(id)89end90end91end9293def write_session(id, buf)94ses = self.framework.sessions[id]95return if not ses96return if not ses.user_input97ses.user_input.put(buf)98end99100def read_session(id)101ses = self.framework.sessions[id]102return if not ses103return if not ses.user_output104ses.user_output.read_subscriber('session_reader')105end106107# Detach the session from an existing input/output pair108def connect_session(id)109110# Ignore invalid sessions111ses = self.framework.sessions[id]112return if not ses113114# Has this session already been detached?115if (ses.user_output)116return if ses.user_output.has_subscriber?('session_reader')117end118119# Create a new pipe120spipe = WebConsole::WebConsolePipe.new121spipe.input = spipe.pipe_input122123# Create a read subscriber124spipe.create_subscriber('session_reader')125126framework.threads.spawn("ConnectSessionInteraction", false) do127ses.interact(spipe.input, spipe)128end129end130131def sessions132self.framework.sessions133end134135#136# Stub137#138def run139true140end141142protected143144attr_accessor :opts # :nodoc:145146#147# Initializes logging for the web interface148#149def initialize_logging150level = (opts['LogLevel'] || 0).to_i151152Msf::Logging.enable_log_source(LogSource, level)153end154155end156157end158end159end160161162163