Class: Wpxf::Cli::Console
- Inherits:
-
Object
- Object
- Wpxf::Cli::Console
- Includes:
- AutoComplete, Creds, Help, LoadedModule, Loot, ModuleCache, Modules, Options, Output, Workspace
- Defined in:
- lib/wpxf/cli/console.rb
Overview
Main class for running the WPXF console.
Instance Attribute Summary
Attributes included from Workspace
Attributes included from Output
Attributes included from Options
Attributes included from ModuleCache
Attributes included from Modules
Attributes included from AutoComplete
Instance Method Summary collapse
- #can_handle?(command) ⇒ Boolean
- #check_cache ⇒ Object
- #clear ⇒ Object
- #commands_without_output ⇒ Object
- #correct_number_of_args?(command, args) ⇒ Boolean
- #execute_user_command(command, args) ⇒ Object
-
#initialize ⇒ Console
constructor
A new instance of Console.
- #normalise_alised_commands(command) ⇒ Object
- #on_event_emitted(event) ⇒ Object
- #permitted_commands ⇒ Object
- #prompt_for_input ⇒ Object
- #start ⇒ Object
Methods included from Workspace
#add_workspace, #delete_workspace, #list_workspaces, #switch_workspace, #workspace, #workspaces
Methods included from Output
#calculate_col_widths, #indent_cursor, #indent_without_wrap, #print_bad, #print_good, #print_header_separator, #print_info, #print_std, #print_table, #print_table_header, #print_table_row, #print_warning, #remove_new_lines_and_wrap_text, #wrap_text
Methods included from Options
#apply_global_options, #gset, #gunset, #load_payload, #set, #set_option_value, #unset
Methods included from LoadedModule
#check, #execute_module, #module_can_execute?, #module_loaded?, #payload_prepared?, #run
Methods included from ModuleInfo
#formatted_module_description, #info, #print_author, #print_description, #print_module_summary, #print_references
Methods included from ModuleCache
#cache_valid?, #create_module_models, #rebuild_cache, #refresh_version_log
Methods included from Modules
#back, #context, #module_name_from_class, #print_module_table, #reload, #reset_context_stack, #search, #search_modules, #use
Methods included from Loot
#build_loot_table, #delete_loot, #find_loot_item, #home_directory, #list_loot, #loot, #print_loot_item
Methods included from Help
#empty_option_table_data, #help, #module_options, #option_table_row, #print_advanced_option, #print_options, #print_options_table, #print_payload_options, #show, #show_advanced_options, #show_auxiliary, #show_exploits, #show_options
Methods included from Creds
#creds, #delete_credential, #list_credentials
Methods included from AutoComplete
#auto_complete_proc, #build_cmd_list, #build_opts_hash, #build_payload_names_hash, #readline_completion_proc, #refresh_autocomplete_options, #setup_auto_complete
Constructor Details
#initialize ⇒ Console
Returns a new instance of Console.
34 35 36 37 |
# File 'lib/wpxf/cli/console.rb', line 34 def initialize super setup_auto_complete end |
Instance Method Details
#can_handle?(command) ⇒ Boolean
70 71 72 73 74 75 |
# File 'lib/wpxf/cli/console.rb', line 70 def can_handle?(command) return true if respond_to?(command) && permitted_commands.include?(command) puts print_bad "\"#{command}\" is not a recognised command." false end |
#check_cache ⇒ Object
123 124 125 126 127 |
# File 'lib/wpxf/cli/console.rb', line 123 def check_cache return if cache_valid? rebuild_cache puts end |
#clear ⇒ Object
48 49 50 |
# File 'lib/wpxf/cli/console.rb', line 48 def clear Gem.win_platform? ? (system 'cls') : (system 'clear') end |
#commands_without_output ⇒ Object
39 40 41 |
# File 'lib/wpxf/cli/console.rb', line 39 def commands_without_output %w[back] end |
#correct_number_of_args?(command, args) ⇒ Boolean
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/wpxf/cli/console.rb', line 77 def correct_number_of_args?(command, args) return true if command.match?(/workspace|loot|creds/) # Make an exception for set, unset and search, due to them taking # a variable number of strings that can contain white space. return true if command =~ /^(un)?set|search$/ && args.size > 1 expected_args = Console.instance_method(command).parameters.size return true if expected_args == args.size print_bad "#{args.size} arguments specified for \"#{command}\", expected #{expected_args}." false end |
#execute_user_command(command, args) ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/wpxf/cli/console.rb', line 114 def execute_user_command(command, args) command = normalise_alised_commands(command) if can_handle? command puts unless commands_without_output.include? command send(command, *args) if correct_number_of_args?(command, args) end puts unless commands_without_output.include? command end |
#normalise_alised_commands(command) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/wpxf/cli/console.rb', line 102 def normalise_alised_commands(command) if command == 'exit' 'quit' elsif command == 'setg' 'gset' elsif command == 'unsetg' 'gunset' else command end end |
#on_event_emitted(event) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/wpxf/cli/console.rb', line 91 def on_event_emitted(event) return unless !event[:verbose] || context.verbose? if event[:type] == :table indent_cursor(2) { print_table event[:rows], true } else handlers = { error: 'print_bad', success: 'print_good', info: 'print_info', warning: 'print_warning' } send(handlers[event[:type]], event[:msg]) end end |
#permitted_commands ⇒ Object
43 44 45 46 |
# File 'lib/wpxf/cli/console.rb', line 43 def permitted_commands %w[use back set show quit run unset check info gset setg gunset loot unsetg search clear reload help workspace rebuild_cache creds] end |
#prompt_for_input ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/wpxf/cli/console.rb', line 52 def prompt_for_input prompt = 'wpxf'.underline.light_blue # The ANSI characters cause problems with the Readline lib and # Windows, so if it's a Windows platform, use only plain chars. prompt = 'wpxf' if Gem.win_platform? prompt += " [#{context.module_path}]" if module_loaded? begin input = Readline.readline("#{prompt} > ", true).to_s rescue SignalException input = '' end puts if input.empty? input end |
#start ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/wpxf/cli/console.rb', line 129 def start loop do begin input = prompt_for_input break if input =~ /exit|quit/ command, *args = input.split(/\s/) execute_user_command(command, args) if command rescue StandardError => e print_bad "Uncaught error: #{e}" print_bad e.backtrace.join("\n\t") puts end end end |