Skip to content

Commit

Permalink
Fixes nil error issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cgranleese-r7 committed Feb 1, 2023
1 parent 081b72a commit a661cdf
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 24 deletions.
4 changes: 2 additions & 2 deletions lib/msf/core/data_store.rb
Expand Up @@ -52,9 +52,9 @@ def []=(k, v)
if opt.validate_on_assignment?
unless opt.valid?(v, check_empty: false)
if self.options[k].examples.empty?
raise Msf::OptionValidateError.new(["Value '#{v}' is not TESTTESTTESTTESTTEST valid for option '#{k}'"])
raise Msf::OptionValidateError, ["Value '#{v}' is not valid for option '#{k}'"]
else
raise Msf::OptionValidateError.new(["Value '#{v}' is not TESTTESTTESTTESTTEST valid for option '#{k}'. Example value: #{self.options[k].examples.first}"])
raise Msf::OptionValidateError, ["Value '#{v}' is not valid for option '#{k}'. Example value: #{self.options[k].examples.join(', ')}"]
end
end
v = opt.normalize(v)
Expand Down
6 changes: 3 additions & 3 deletions lib/msf/core/data_store_with_fallbacks.rb
Expand Up @@ -71,9 +71,9 @@ def []=(k, v)
if opt.validate_on_assignment?
unless opt.valid?(v, check_empty: false)
if self.options[k].examples.empty?
raise Msf::OptionValidateError.new(["Value '#{v}' is not valid for option '#{k}'"])
raise Msf::OptionValidateError, ["Value '#{v}' is not valid for option '#{k}'"]
else
raise Msf::OptionValidateError.new(["Value '#{v}' is not valid for option '#{k}'. Example value: #{self.options[k].examples.first}"])
raise Msf::OptionValidateError, ["Value '#{v}' is not valid for option '#{k}'. Example value: #{self.options[k].examples.join(', ')}"]
end
end
v = opt.normalize(v)
Expand Down Expand Up @@ -417,7 +417,7 @@ def each_key(&block)
# Case-insensitive key lookup
#
# @return [String]
def find_key_case(k)
def find_key_case(k)
# Scan each alias looking for a key
search_k = k.downcase
if self.aliases.has_key?(search_k)
Expand Down
20 changes: 15 additions & 5 deletions lib/msf/ui/formatter/option_validate_error.rb
Expand Up @@ -12,16 +12,26 @@ class OptionValidateError
def self.print_error(mod, error)
raise ArgumentError, "invalid error type #{error.class}, expected ::Msf::OptionValidateError" unless error.is_a?(::Msf::OptionValidateError)

(0...error.options.length).each do |i|
error.options.each do |option|
# Assign module examples unless the value is not available within options as it wasn't created as an option object.
# example: value assigned directly to datastore without being created as an options object via `OptString.new` or similar.
# See spec/lib/msf/ui/console/command_dispatcher/exploit_spec.rb:279
option_examples = mod.options[option].nil? ? [] : mod.options[option].examples
option_value = mod.datastore[option]

if error.reasons.empty?
if mod.options[error.options[i]].examples.empty?
mod.print_error("#{error.class} The following option failed to validate: Value '#{mod.datastore.user_defined[error.options[i]]}' is not valid for option '#{error.options[i]}'.")
if option_examples.empty? && option_value.blank?
mod.print_error("#{error.class} The following option failed to validate: A value is required for option '#{option}'.")
elsif option_examples.empty?
mod.print_error("#{error.class} The following option failed to validate: Value '#{option_value}' is not valid for option '#{option}'.")
elsif option_value.blank?
mod.print_error("#{error.class} The following option failed to validate: A value is required for option '#{option}'. Example value: #{option_examples.join(', ')}")
else
mod.print_error("#{error.class} The following option failed to validate: Value '#{mod.datastore.user_defined[error.options[i]]}' is not valid for option '#{error.options[i]}'. Example value: #{mod.options[error.options[i]].examples.first}")
mod.print_error("#{error.class} The following option failed to validate: Value '#{option_value}' is not valid for option '#{option}'. Example value: #{option_examples.join(', ')}")
end
else
mod.print_error("#{error.class} The following options failed to validate:")
error.options.sort.each do |option_name|
option.sort.each do |option_name|
reasons = error.reasons[option_name]
if reasons
mod.print_error("Invalid option #{option_name}: #{reasons.join(', ')}")
Expand Down
11 changes: 6 additions & 5 deletions modules/auxiliary/admin/kerberos/forge_ticket.rb
Expand Up @@ -42,12 +42,13 @@ def initialize(info = {})
[
OptString.new('USER', [ true, 'The Domain User' ]),
OptInt.new('USER_RID', [ true, "The Domain User's relative identifier(RID)", Rex::Proto::Kerberos::Pac::DEFAULT_ADMIN_RID]),
OptString.new('NTHASH', [ true, 'The krbtgt/service nthash' ]),
OptString.new('NTHASH', [ false, 'The krbtgt/service nthash' ]),
OptString.new('AES_KEY', [ false, 'The krbtgt/service AES key' ]),
OptString.new('DOMAIN', [ true, 'The Domain (upper case) Ex: DEMO.LOCAL' ]),
OptString.new('DOMAIN_SID', [ true, 'The Domain SID, Ex: S-1-5-21-1755879683-3641577184-3486455962'], regex: /^S-\d-\d+-(\d+-){1,14}\d+$/, examples: %w[S-1-5-21-1755879683-3641577184-3486455962 S-1-5-21-1180699209-877415012-3182924384-1004]),
OptString.new('SPN', [ false, 'The Service Principal Name (Only used for silver ticket)'], conditions: %w[ACTION == FORGE_SILVER], regex: %r{.*/.*}, examples: %w[MSSqlSvc/host.domain.local:1433 MSSqlSvc/host.domain.local:1434]),
OptInt.new('DURATION', [ false, 'Duration of the ticket in days', 3650])
OptString.new('DOMAIN', [ false, 'The Domain (upper case) Ex: DEMO.LOCAL' ]),
OptString.new('DOMAIN_SID', [ false, 'The Domain SID, Ex: S-1-5-21-1755879683-3641577184-3486455962'], regex: /^S-\d-\d+-(\d+-){1,14}\d+$/, examples: %w[S-1-5-21-1755879683-3641577184-3486455962 S-1-5-21-1180699209-877415012-3182924384-1004]),
OptString.new('SPN', [ false, 'The Service Principal Name (Only used for silver ticket) Ex: MSSqlSvc/host.domain.local:1434'], conditions: %w[ACTION == FORGE_SILVER], regex: %r{.*/.*}, examples: %w[MSSqlSvc/host.domain.local:1433 MSSqlSvc/host.domain.local:1434]),
OptInt.new('DURATION', [ false, 'Duration of the ticket in days', 3650]),
OptString.new('TICKET_PATH', [false, 'Path to the ticket you wish to debug'])
]
)
deregister_options('RHOSTS', 'RPORT', 'Timeout')
Expand Down
10 changes: 5 additions & 5 deletions spec/lib/msf/ui/console/command_dispatcher/auxiliary_spec.rb
Expand Up @@ -168,7 +168,7 @@ def cleanup

subject.cmd_check
expected_output = [
'Msf::OptionValidateError The following options failed to validate: RHOSTS'
"Msf::OptionValidateError The following option failed to validate: A value is required for option 'RHOSTS'."
]

expect(@combined_output).to match_array(expected_output)
Expand Down Expand Up @@ -296,7 +296,7 @@ def cleanup
current_mod.datastore['RHOSTS'] = ''
subject.cmd_check
expected_output = [
'Msf::OptionValidateError The following options failed to validate: RHOSTS'
"Msf::OptionValidateError The following option failed to validate: A value is required for option 'RHOSTS'."
]

expect(@combined_output).to match_array(expected_output)
Expand Down Expand Up @@ -397,7 +397,7 @@ def cleanup

subject.cmd_run
expected_output = [
'Msf::OptionValidateError The following options failed to validate: RHOSTS'
"Msf::OptionValidateError The following option failed to validate: A value is required for option 'RHOSTS'."
]

expect(@combined_output).to match_array(expected_output)
Expand Down Expand Up @@ -508,7 +508,7 @@ def cleanup

subject.cmd_run
expected_output = [
'Msf::OptionValidateError The following options failed to validate: RHOSTS'
"Msf::OptionValidateError The following option failed to validate: A value is required for option 'RHOSTS'."
]

expect(@combined_output).to match_array(expected_output)
Expand Down Expand Up @@ -609,7 +609,7 @@ def cleanup
current_mod.datastore['RHOSTS'] = ''
subject.cmd_run
expected_output = [
'Msf::OptionValidateError The following options failed to validate: RHOSTS'
"Msf::OptionValidateError The following option failed to validate: A value is required for option 'RHOSTS'."
]

expect(@combined_output).to match_array(expected_output)
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/msf/ui/console/command_dispatcher/exploit_spec.rb
Expand Up @@ -126,7 +126,7 @@ def set_default_payload(mod)
current_mod.datastore['RHOSTS'] = ''
subject.cmd_check
expected_output = [
'Msf::OptionValidateError The following options failed to validate: RHOSTS'
"Msf::OptionValidateError The following option failed to validate: A value is required for option 'RHOSTS'."
]

expect(@combined_output).to match_array(expected_output)
Expand Down Expand Up @@ -243,7 +243,7 @@ def set_default_payload(mod)
current_mod.datastore['RHOSTS'] = nil
subject.cmd_run
expected_output = [
'Msf::OptionValidateError The following options failed to validate: RHOSTS'
"Msf::OptionValidateError The following option failed to validate: A value is required for option 'RHOSTS'."
]

expect(@combined_output).to match_array(expected_output)
Expand All @@ -255,7 +255,7 @@ def set_default_payload(mod)
current_mod.datastore['RHOSTS'] = ''
subject.cmd_run
expected_output = [
'Msf::OptionValidateError The following options failed to validate: RHOSTS'
"Msf::OptionValidateError The following option failed to validate: A value is required for option 'RHOSTS'."
]

expect(@combined_output).to match_array(expected_output)
Expand Down Expand Up @@ -284,7 +284,7 @@ def set_default_payload(mod)
subject.cmd_run
expected_output = [
'Exploit completed, but no session was created.',
'Msf::OptionValidateError The following options failed to validate: REQUIRED_PAYLOAD_OPTION'
"Msf::OptionValidateError The following option failed to validate: Value 'foo' is not valid for option 'REQUIRED_PAYLOAD_OPTION'."
]

expect(@combined_output).to match_array(expected_output)
Expand Down

0 comments on commit a661cdf

Please sign in to comment.