Module: Wpxf::Cli::Help

Included in:
Console
Defined in:
lib/wpxf/cli/help.rb

Overview

Methods for handling commands that provide the user with help info.

Instance Method Summary collapse

Instance Method Details

#empty_option_table_dataObject



106
107
108
109
110
111
112
113
# File 'lib/wpxf/cli/help.rb', line 106

def empty_option_table_data
  [{
    name: 'Name',
    value: 'Current Setting',
    req: 'Required',
    desc: 'Description'
  }]
end

#helpObject



60
61
62
63
64
65
# File 'lib/wpxf/cli/help.rb', line 60

def help
  commands_file = Wpxf::DataFile.new('json', 'commands.json')
  data = JSON.parse(commands_file.content)['data']
  data.unshift('cmd' => 'Command', 'desc' => 'Description')
  print_table data
end

#module_options(mod, advanced) ⇒ Object



100
101
102
103
104
# File 'lib/wpxf/cli/help.rb', line 100

def module_options(mod, advanced)
  return [] if mod.nil?
  opts = mod.options.select { |o| o.advanced? == advanced }
  opts.sort_by(&:name)
end

#option_table_row(mod, opt) ⇒ Object



115
116
117
118
119
120
121
122
# File 'lib/wpxf/cli/help.rb', line 115

def option_table_row(mod, opt)
  {
    name: opt.name,
    value: mod.normalized_option_value(opt.name),
    req: opt.required?,
    desc: opt.desc
  }
end


44
45
46
47
48
49
# File 'lib/wpxf/cli/help.rb', line 44

def print_advanced_option(mod, opt)
  print_std "Name: #{opt.name}"
  print_std "Current setting: #{mod.normalized_option_value(opt.name)}"
  print_std "Required: #{opt.required?}"
  print_std "Description: #{opt.desc}"
end


9
10
11
12
13
14
15
# File 'lib/wpxf/cli/help.rb', line 9

def print_options(mod)
  print_std 'Module options:'
  puts
  indent_cursor do
    print_options_table(mod, module_options(mod, false))
  end
end


35
36
37
38
39
40
41
42
# File 'lib/wpxf/cli/help.rb', line 35

def print_options_table(mod, opts)
  data = empty_option_table_data
  opts.each do |opt|
    data.push(option_table_row(mod, opt))
  end

  print_table(data)
end


17
18
19
20
21
22
23
# File 'lib/wpxf/cli/help.rb', line 17

def print_payload_options(payload)
  print_std 'Payload options:'
  puts
  indent_cursor do
    print_options_table(payload, payload.options)
  end
end

#show(target) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/wpxf/cli/help.rb', line 85

def show(target)
  handlers = {
    'options' => 'show_options',
    'advanced' => 'show_advanced_options',
    'exploits' => 'show_exploits',
    'auxiliary' => 'show_auxiliary'
  }

  if handlers[target]
    send(handlers[target])
  else
    print_bad("\"#{target}\" is not a valid argument")
  end
end

#show_advanced_optionsObject



51
52
53
54
55
56
57
58
# File 'lib/wpxf/cli/help.rb', line 51

def show_advanced_options
  return unless module_loaded?(false)

  module_options(context.module, true).each do |opt|
    print_advanced_option(context.module, opt)
    puts
  end
end

#show_auxiliaryObject



76
77
78
79
80
81
82
83
# File 'lib/wpxf/cli/help.rb', line 76

def show_auxiliary
  modules = Wpxf::Models::Module.where(type: 'auxiliary')
                          .order(:path)
                          .map { |m| { path: m.path, title: m.name } }

  print_good "#{modules.length} Auxiliaries"
  print_module_table modules
end

#show_exploitsObject



67
68
69
70
71
72
73
74
# File 'lib/wpxf/cli/help.rb', line 67

def show_exploits
  modules = Wpxf::Models::Module.where(type: 'exploit')
                          .order(:path)
                          .map { |m| { path: m.path, title: m.name } }

  print_good "#{modules.length} Exploits"
  print_module_table modules
end

#show_optionsObject



25
26
27
28
29
30
31
32
33
# File 'lib/wpxf/cli/help.rb', line 25

def show_options
  return unless module_loaded?(false)

  print_options(context.module)
  return unless context.module.payload

  puts
  print_payload_options(context.module.payload)
end