Skip to content

Commit 09475fc

Browse files
committed
peer review
1 parent e855938 commit 09475fc

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

documentation/modules/post/multi/recon/persistence_suggester.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ This option lets us toggle whether or not Meterpreter commands that are missing
3434
### Colors
3535

3636
Similar to the option used for `HttpTrace`. This lets us change the colors used to show valid, invalid and ignored options or incompatibilities. Unsetting this option results in no colored output.
37+
Defaults to `grn/red/blu`. Additional options are [here](https://github.com/rapid7/rex-text/blob/a72151d409cd812978f63ad0c330efbc8f44b977/lib/rex/text/color.rb#L13)
3738

3839
## Scenarios
3940

modules/post/multi/recon/local_exploit_suggester.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ def is_session_type?(mod)
7373
end
7474

7575
def is_module_platform?(mod)
76-
platform_obj = Msf::Module::Platform.find_platform session.platform
7776
return false if mod.target.nil?
7877

78+
platform_obj = Msf::Module::Platform.find_platform session.platform
79+
7980
module_platforms = mod.target.platform ? mod.target.platform.platforms : mod.platform.platforms
8081
module_platforms.include? platform_obj
8182
rescue ArgumentError => e
@@ -260,7 +261,7 @@ def run
260261
report_note(
261262
host: session.session_host,
262263
type: 'local.suggested_exploits',
263-
data: { :suggested_exploits => report_data }
264+
data: { suggested_exploits: report_data }
264265
)
265266
end
266267

modules/post/multi/recon/persistence_suggester.rb

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,25 @@ def initialize(info = {})
4545
Msf::OptBool.new('ValidateArch', [true, 'Validate architecture', false]),
4646
Msf::OptBool.new('ValidatePlatform', [true, 'Validate platform', true]),
4747
Msf::OptBool.new('ValidateMeterpreterCommands', [true, 'Validate Meterpreter commands', false]),
48+
# https://github.com/rapid7/rex-text/blob/a72151d409cd812978f63ad0c330efbc8f44b977/lib/rex/text/color.rb#L13
4849
Msf::OptString.new('Colors', [false, 'Valid, Invalid and Ignored colors for module checks (unset to disable)', 'grn/red/blu'])
4950
]
5051
)
5152
end
5253

54+
def valid_colors?(color_str = datastore['Colors'])
55+
tokens = color_str.split('/')
56+
tokens.each do |tok|
57+
print_warning "#{tok} is unlikely to have any functionality for printing colors." if tok == 'clr'
58+
59+
unless Rex::Text::Color::SUPPORTED_FORMAT_CODES.include?("%#{tok}")
60+
print_error "#{tok} is NOT valid color. Please see https://github.com/rapid7/rex-text/blob/a72151d409cd812978f63ad0c330efbc8f44b977/lib/rex/text/color.rb#L13 for valid color options"
61+
return false
62+
end
63+
end
64+
true
65+
end
66+
5367
def all_platforms
5468
Msf::Module::Platform.subclasses.collect { |c| c.realname.downcase }
5569
end
@@ -78,9 +92,10 @@ def is_session_type?(mod)
7892
end
7993

8094
def is_module_platform?(mod)
81-
platform_obj = Msf::Module::Platform.find_platform session.platform
8295
return false if mod.target.nil?
8396

97+
platform_obj = Msf::Module::Platform.find_platform session.platform
98+
8499
module_platforms = mod.target.platform ? mod.target.platform.platforms : mod.platform.platforms
85100
module_platforms.include? platform_obj
86101
rescue ArgumentError => e
@@ -145,7 +160,11 @@ def setup
145160
print_status "Collecting persistence modules for #{session.session_type}..."
146161

147162
setup_validation_options
148-
setup_color_options
163+
if valid_colors?
164+
setup_color_options
165+
else
166+
fail_with(Failure::BadConfig, 'Colors options set incorrectly')
167+
end
149168

150169
# Collects persistence modules into an array
151170
@persistence_modules = []

0 commit comments

Comments
 (0)