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/console/command_dispatcher.rb
Views: 11783
# -*- coding: binary -*-123module Msf4module Ui5module Console67###8#9# The common command dispatcher base class that is shared for component-specific10# command dispatching.11#12###13module CommandDispatcher1415include Rex::Ui::Text::DispatcherShell::CommandDispatcher1617#18# Initializes a command dispatcher instance.19#20def initialize(driver)21super2223self.driver = driver24self.driver.on_command_proc = Proc.new { |command| framework.events.on_ui_command(command) }25end2627#28# Returns the framework instance associated with this command dispatcher.29#30def framework31return driver.framework32end3334#35# Returns the active module if one has been selected, otherwise nil is36# returned.37#38def active_module39driver.active_module40end4142#43# Sets the active module for this driver instance.44#45def active_module=(mod)46driver.active_module = mod47end4849#50# Returns the active session if one has been selected, otherwise nil is51# returned.52#53def active_session54driver.active_session55end5657#58# Sets the active session for this driver instance.59#60def active_session=(mod)61driver.active_session = mod62end6364#65# Logs an error message to the screen and the log file. The callstack is66# also printed.67#68def log_error(err)69print_error(err)7071wlog(err)7273# If it's a syntax error, log the call stack that it originated from.74dlog("Call stack:\n#{$@.join("\n")}", 'core', LEV_1)75end7677#78# Load the configuration required for this CommandDispatcher, configuring79# any internal state as required.80#81def load_config(_path = nil)82# noop83end8485#86# Return the subdir of the `documentation/` directory that should be used87# to find usage documentation88#89def docs_dir90File.join(super, 'msfconsole')91end9293#94# Generate an array of job or session IDs from a given range String.95# Always returns an Array unless an incorrect input is given.96# In that case, the result will always be nil, even if only one argument is incorrect.97#98# @param id_list [String] Range or list description such as 1-5 or 1,3,5 etc99# @return [Array<String>, nil] Representing the range100def build_range_array(id_list)101item_list = []102unless id_list.blank?103temp_list = id_list.split(',')104temp_list.each do |ele|105return if ele.count('-') > 1 # Eg. 'sessions -u -1-,5', incorrect syntax106return if ele.last == '-' # Last item of array is a '-', resulting in an incomplete range107return if ele.first == '.' || ele.last == '.' #Eg. 'sessions -u .1..' or 'sessions -u ..108return unless ele =~ (/^\d+((\.\.|-)\d+)?$/) || ele =~ (/^-?\d+$/) # Not a number or range109110# Check if the item is negative, as this will not always be a range111if ele =~ (/^-?\d+$/) && ele.to_i < 0 # if ele is a single negative number112item_list.push(ele.to_i)113elsif ele.include? '-'114temp_array = (ele.split("-").inject { |s, e| s.to_i..e.to_i }).to_a115item_list.concat(temp_array)116elsif ele.include? '..'117temp_array = (ele.split("..").inject { |s, e| s.to_i..e.to_i }).to_a118item_list.concat(temp_array)119else120item_list.push(ele.to_i)121end122end123end124125item_list.uniq.sort126end127128#129# Remove lines with specific substring130#131# @param text [String] Block of text to search over132# @param to_match [String] String that when found, causes the whole line to133# be removed, including trailing "\n" if present134# @return [String] Text sans lines containing to_match135#136def remove_lines(text, to_match)137to_match = Regexp.escape(to_match)138text.gsub(/^.*(#{to_match}).*(#{Regexp.escape $/})?/, '')139end140141#142# The driver that this command dispatcher is associated with.143#144attr_accessor :driver145146end147end end end148149150