Skip to content

Commit

Permalink
don't show regular option groups when viewing advanced options
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelch-r7 committed May 17, 2024
1 parent 28396ff commit ce49fa4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/msf/base/serializer/readable_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -569,15 +569,15 @@ def self.dump_generic_module(mod, indent = '')
# @param missing [Boolean] dump only empty required options.
# @return [String] the string form of the information.
def self.dump_options(mod, indent = '', missing = false, advanced: false, evasion: false)
filtered_options = mod.options.values.select { |opt| opt.advanced? == advanced && opt.evasion? == evasion }
filtered_options = mod.options.select { |_name, opt| opt.advanced? == advanced && opt.evasion? == evasion }

option_groups = mod.options.groups.map { |_name, group| group }.sort_by(&:name)
option_groups = mod.options.groups.values.select { |group| group.option_names.any? { |name| filtered_options.keys.include?(name) } }
options_by_group = option_groups.map do |group|
[group, group.option_names.map { |name| mod.options[name] }.compact]
[group, group.option_names.map { |name| filtered_options[name] }.compact]
end.to_h
grouped_option_names = option_groups.flat_map(&:option_names)
remaining_options = filtered_options.reject { |option| grouped_option_names.include?(option.name) }
options_grouped_by_conditions = remaining_options.group_by(&:conditions)
remaining_options = filtered_options.reject { |_name, option| grouped_option_names.include?(option.name) }
options_grouped_by_conditions = remaining_options.values.group_by(&:conditions)

option_tables = []

Expand Down
31 changes: 30 additions & 1 deletion spec/lib/msf/base/serializer/readable_text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def initialize
context 'when some options are grouped' do
let(:group_name) { 'group_name' }
let(:group_description) { 'Used for example reasons' }
let(:option_names) { %w[RHOSTS SMBUser SMBDomain] }
let(:option_names) { %w[DigestAlgorithm RHOSTS SMBUser SMBDomain] }
let(:group) { Msf::OptionGroup.new(name: group_name, description: group_description, option_names: option_names) }
let(:aux_mod_with_grouped_options) do
mod = aux_mod_with_set_options.replicant
Expand Down Expand Up @@ -297,6 +297,35 @@ def initialize
TABLE
end
end

context 'when some options are grouped' do
let(:group_name) { 'group_name' }
let(:group_description) { 'Used for example reasons' }
let(:option_names) { %w[DigestAlgorithm RHOSTS SMBUser SMBDomain] }
let(:group) { Msf::OptionGroup.new(name: group_name, description: group_description, option_names: option_names) }
let(:aux_mod_with_grouped_options) do
mod = aux_mod_with_set_options.replicant
mod.options.add_group(group)
mod
end

it 'should return the grouped options separate to the rest of the options' do
expect(described_class.dump_advanced_options(aux_mod_with_grouped_options, indent_string)).to match_table <<~TABLE
Name Current Setting Required Description
---- --------------- -------- -----------
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
#{group_description}:
Name Current Setting Required Description
---- --------------- -------- -----------
DigestAlgorithm SHA256 yes The digest algorithm to use (Accepted: SHA1, SHA256)
TABLE
end
end
end

describe '.dump_evasion_options' do
Expand Down

0 comments on commit ce49fa4

Please sign in to comment.