Class: Msf::Plugin::FuzzyUse::ConsoleCommandDispatcher
- Inherits:
-
Object
- Object
- Msf::Plugin::FuzzyUse::ConsoleCommandDispatcher
- Includes:
- Ui::Console::CommandDispatcher
- Defined in:
- plugins/fzuse.rb
Constant Summary collapse
- FZF_THEME =
{ 'fg' => '-1', 'fg+' => 'white:regular:bold', 'bg' => '-1', 'bg+' => '-1', 'hl' => '-1', 'hl+' => 'red:regular:bold', 'info' => '-1', 'marker' => '-1', 'prompt' => '-1', 'spinner' => '-1', 'pointer' => 'blue:bold', 'header' => '-1', 'border' => '-1', 'label' => '-1', 'query' => '-1' }.freeze
Instance Attribute Summary
Attributes included from Ui::Console::CommandDispatcher
Attributes included from Rex::Ui::Text::DispatcherShell::CommandDispatcher
Instance Method Summary collapse
-
#cmd_fzuse(*args) ⇒ Object
This method handles the fzuse command.
-
#commands ⇒ Object
Returns the hash of commands supported by this dispatcher.
-
#initialize(driver) ⇒ ConsoleCommandDispatcher
constructor
A new instance of ConsoleCommandDispatcher.
- #name ⇒ Object
- #pipe_server(socket_path) ⇒ Object
Methods included from Ui::Console::CommandDispatcher
#active_module, #active_module=, #active_session, #active_session=, #build_range_array, #docs_dir, #framework, #load_config, #log_error, #remove_lines
Methods included from Rex::Ui::Text::DispatcherShell::CommandDispatcher
#cmd_help, #cmd_help_help, #cmd_help_tabs, #deprecated_cmd, #deprecated_commands, #deprecated_help, #docs_dir, #help_to_s, included, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #tab_complete_directory, #tab_complete_filenames, #tab_complete_generic, #tab_complete_source_address, #unknown_command, #update_prompt
Constructor Details
#initialize(driver) ⇒ ConsoleCommandDispatcher
Returns a new instance of ConsoleCommandDispatcher.
39 40 41 42 43 |
# File 'plugins/fzuse.rb', line 39 def initialize(driver) super @module_dispatcher = Msf::Ui::Console::CommandDispatcher::Modules.new(driver) end |
Instance Method Details
#cmd_fzuse(*args) ⇒ Object
This method handles the fzuse command.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'plugins/fzuse.rb', line 82 def cmd_fzuse(*args) selection = nil Dir.mktmpdir('msf-fzuse-') do |dir| socket_path = File.join(dir, "msf-fzuse.sock") server_thread = Thread.new { pipe_server(socket_path) } query = args.empty? ? '' : args.first ruby = RbConfig::CONFIG['bindir'] + '/' + RbConfig::CONFIG['ruby_install_name'] + RbConfig::CONFIG['EXEEXT'] color = "--color=#{FZF_THEME.map { |key, value| "#{key}:#{value}" }.join(',')}" Open3.popen3('fzf', '--select-1', '--query', query, '--pointer=->', color, '--preview', "'#{ruby}' '#{__FILE__}' '#{socket_path}' '{1}'", '--preview-label', "Module Information") do |stdin, stdout, stderr, wait_thr| framework.modules.module_types.each do |module_type| framework.modules.module_names(module_type).each do |module_name| stdin.puts "#{module_type}/#{module_name}" end end stdin.close selection = stdout.read end server_thread.kill server_thread.join end return if selection.blank? selection.strip! @module_dispatcher.cmd_use(selection) end |
#commands ⇒ Object
Returns the hash of commands supported by this dispatcher.
52 53 54 55 56 |
# File 'plugins/fzuse.rb', line 52 def commands { 'fzuse' => 'A fuzzy use command added by the FuzzyUse plugin' } end |
#name ⇒ Object
45 46 47 |
# File 'plugins/fzuse.rb', line 45 def name 'FuzzyUse' end |
#pipe_server(socket_path) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'plugins/fzuse.rb', line 58 def pipe_server(socket_path) server = UNIXServer.new(socket_path) File.chmod(0600, socket_path) loop do client = server.accept begin unless (input_string = client.gets&.chomp).blank? if (mod = framework.modules.create(input_string)) client.puts(Serializer::ReadableText.dump_module(mod)) end end rescue StandardError end client.close end rescue EOFError ensure server.close if server File.delete(socket_path) if File.exist?(socket_path) end |