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/base/sessions/sql.rb
Views: 11784
# -*- coding: binary -*-12class Msf::Sessions::Sql34# This interface supports basic interaction.5include Msf::Session::Basic6include Msf::Sessions::Scriptable78# @return console The interactive console9attr_accessor :console10# @return client The underlying client object used to make SQL queries11attr_accessor :client12attr_accessor :platform, :arch1314def process_autoruns(datastore)15['InitialAutoRunScript', 'AutoRunScript'].each do |key|16next if datastore[key].nil? || datastore[key].empty?1718args = ::Shellwords.shellwords(datastore[key])19print_status("Session ID #{sid} (#{tunnel_to_s}) processing #{key} '#{datastore[key]}'")20execute_script(args.shift, *args)21end22end2324def execute_file(full_path, args)25if File.extname(full_path) == '.rb'26Rex::Script::Shell.new(self, full_path).run(args)27else28console.load_resource(full_path)29end30end3132# @param [String] cmd The command to execute in the context of a session using the '-c' flag.33# @param [IO] output_object The IO where output should be written to34# For example, 'query select version()' for a PostgreSQL session.35def run_cmd(cmd, output_object=nil)36# This implementation is taken from Meterpreter.37stored_output_state = nil38# If the user supplied an Output IO object, then we tell39# the console to use that, while saving it's previous output/40if output_object41stored_output_state = console.output42console.send(:output=, output_object)43end44success = console.run_single(cmd)45# If we stored the previous output object of the channel46# we restore it here to put everything back the way we found it47# We re-use the conditional above, because we expect in many cases for48# the stored state to actually be nil here.49if output_object50console.send(:output=, stored_output_state)51end52success53end5455# @return [String]56def type57self.class.type58end5960# @return [String] The type of the session61def self.type62raise ::NotImplementedError63end6465# @return [Boolean] Can the session clean up after itself66def self.can_cleanup_files67raise ::NotImplementedError68end6970# @return [String] The session description71def desc72raise ::NotImplementedError73end7475# @return [String] The peer address76def address77client.peerhost78end7980# @return [Integer] The peer port81def port82client.peerport83end8485# Initializes the console's I/O handles.86#87# @param [Object] input88# @param [Object] output89# @return [String]90def init_ui(input, output)91super(input, output)9293console.init_ui(input, output)94console.set_log_source(log_source)95end9697# Resets the console's I/O handles.98#99# @return [Object]100def reset_ui101console.unset_log_source102console.reset_ui103end104105# Exit the console106#107# @return [TrueClass]108def exit109console.stop110end111112protected113114# Override the basic session interaction to use shell_read and115# shell_write instead of operating on rstream directly.116#117# @return [Object]118def _interact119framework.events.on_session_interact(self)120framework.history_manager.with_context(name: type.to_sym) { _interact_stream }121end122123# @return [Object]124def _interact_stream125framework.events.on_session_interact(self)126127console.framework = framework128# Call the console interaction of the mysql client and129# pass it a block that returns whether or not we should still be130# interacting. This will allow the shell to abort if interaction is131# canceled.132console.interact { interacting != true }133console.framework = nil134135# If the stop flag has been set, then that means the user exited. Raise136# the EOFError so we can drop this handle like a bad habit.137raise ::EOFError if (console.stopped? == true)138end139end140141142