Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case Insensitive OptEnum #19450

Open
smcintyre-r7 opened this issue Sep 10, 2024 · 1 comment
Open

Case Insensitive OptEnum #19450

smcintyre-r7 opened this issue Sep 10, 2024 · 1 comment
Labels
suggestion-feature New feature suggestions

Comments

@smcintyre-r7
Copy link
Contributor

It'd be really nice if OptEnum were updated to validate values without being case sensitive while preserving the case the author was expecting.

For example a setting OptEnum.new('PROTOCOL', [true, 'Protocol to use.', 'TCP', [ 'TCP', 'UDP', 'ALL' ]]), should accept all and normalize it to ALL.

In the vast majority (maybe all) cases of OptEnum's being used, the values are all unique regardless of case. Allowing the user to set them to their value without needing to worry about the details of how the casing was defined by the author would be a nice improvement. If the possible values are case sensitive
(opts.length == opts.map(&:upcase).uniq.length) then this should be disabled for the option.

Simple example

In this case "all" is explicit enough to be differentiated from "TCP" and "UDP".

msf6 post(multi/recon/multiport_egress_traffic) > show options 

Module options (post/multi/recon/multiport_egress_traffic):

   Name      Current Setting                     Required  Description
   ----      ---------------                     --------  -----------
   METHOD    NATIVE                              yes       The mechanism by which the packets are generated. Can be NATIVE or WINAPI (Windows only). (Accepted: NATIVE, WINAPI)
   PORTS     22,23,53,80,88,443,445,33434-33534  yes       Ports to test.
   PROTOCOL  TCP                                 yes       Protocol to use. (Accepted: TCP, UDP, ALL)
   SESSION                                       yes       The session to run this module on
   TARGET                                        yes       Destination IP address.
   THREADS   20                                  yes       Number of simultaneous threads/connections to try.


View the full module info with the info, or info -d command.

msf6 post(multi/recon/multiport_egress_traffic) > set PROTOCOL all
[-] The following options failed to validate: Value 'all' is not valid for option 'PROTOCOL'.
PROTOCOL => TCP
@smcintyre-r7 smcintyre-r7 added the suggestion-feature New feature suggestions label Sep 10, 2024
@adfoster-r7
Copy link
Contributor

Not a blocker to anything:

If the possible values are case sensitive
(opts.length == opts.map(&:upcase).uniq.length) then this should be disabled for the option.

Some data mining on more detailed module metadata cache shows that there isn't any modules that have case sensitive enums:

3.3.0 :016 > require 'json'
3.3.0 :017 > modules = JSON.parse(File.binread('./info/module_metadata.json')); nil
3.3.0 :018 > modules.select { |m| m['options'].any? { |o| o['type'] == 'enum' && (o['enums'].length != o['enums'].map(&:upcase).uniq.length) }  }.count
 => 0 

We could probably add validation to ensure this is always the case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion-feature New feature suggestions
Projects
None yet
Development

No branches or pull requests

2 participants