Skip to content

Commit 40f7539

Browse files
authored
Land rapid7#19186, don't show regular option groups when viewing advanced options
2 parents bbf096e + ce49fa4 commit 40f7539

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

lib/msf/base/serializer/readable_text.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -569,15 +569,15 @@ def self.dump_generic_module(mod, indent = '')
569569
# @param missing [Boolean] dump only empty required options.
570570
# @return [String] the string form of the information.
571571
def self.dump_options(mod, indent = '', missing = false, advanced: false, evasion: false)
572-
filtered_options = mod.options.values.select { |opt| opt.advanced? == advanced && opt.evasion? == evasion }
572+
filtered_options = mod.options.select { |_name, opt| opt.advanced? == advanced && opt.evasion? == evasion }
573573

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

582582
option_tables = []
583583

spec/lib/msf/base/serializer/readable_text_spec.rb

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def initialize
186186
context 'when some options are grouped' do
187187
let(:group_name) { 'group_name' }
188188
let(:group_description) { 'Used for example reasons' }
189-
let(:option_names) { %w[RHOSTS SMBUser SMBDomain] }
189+
let(:option_names) { %w[DigestAlgorithm RHOSTS SMBUser SMBDomain] }
190190
let(:group) { Msf::OptionGroup.new(name: group_name, description: group_description, option_names: option_names) }
191191
let(:aux_mod_with_grouped_options) do
192192
mod = aux_mod_with_set_options.replicant
@@ -297,6 +297,35 @@ def initialize
297297
TABLE
298298
end
299299
end
300+
301+
context 'when some options are grouped' do
302+
let(:group_name) { 'group_name' }
303+
let(:group_description) { 'Used for example reasons' }
304+
let(:option_names) { %w[DigestAlgorithm RHOSTS SMBUser SMBDomain] }
305+
let(:group) { Msf::OptionGroup.new(name: group_name, description: group_description, option_names: option_names) }
306+
let(:aux_mod_with_grouped_options) do
307+
mod = aux_mod_with_set_options.replicant
308+
mod.options.add_group(group)
309+
mod
310+
end
311+
312+
it 'should return the grouped options separate to the rest of the options' do
313+
expect(described_class.dump_advanced_options(aux_mod_with_grouped_options, indent_string)).to match_table <<~TABLE
314+
Name Current Setting Required Description
315+
---- --------------- -------- -----------
316+
VERBOSE false no Enable detailed status messages
317+
WORKSPACE no Specify the workspace for this module
318+
319+
320+
#{group_description}:
321+
322+
Name Current Setting Required Description
323+
---- --------------- -------- -----------
324+
DigestAlgorithm SHA256 yes The digest algorithm to use (Accepted: SHA1, SHA256)
325+
326+
TABLE
327+
end
328+
end
300329
end
301330

302331
describe '.dump_evasion_options' do

0 commit comments

Comments
 (0)