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 Nov 17, 2022
1 parent 36ce981 commit 3cfd7ba
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/msf/core/data_store.rb
Original file line number Diff line number Diff line change
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.first}"]
end
end
v = opt.normalize(v)
Expand Down
6 changes: 3 additions & 3 deletions lib/msf/core/data_store_with_fallbacks.rb
Original file line number Diff line number Diff line change
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.first}"]
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
13 changes: 10 additions & 3 deletions lib/msf/ui/formatter/option_validate_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ 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|
option_examples = mod.options[error.options[i]].nil? ? [] : mod.options[error.options[i]].examples
option_value = mod.datastore[error.options[i]]

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.nil? || option_value.empty?)
mod.print_error("#{error.class} The following option failed to validate: A value is required for option '#{error.options[i]}'.")
elsif option_examples.empty?
mod.print_error("#{error.class} The following option failed to validate: Value '#{option_value}' is not valid for option '#{error.options[i]}'.")
elsif option_value.nil? || option_value.empty?
mod.print_error("#{error.class} The following option failed to validate: A value is required for option '#{error.options[i]}'. Example value: #{option_examples.first}")
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 '#{error.options[i]}'. Example value: #{option_examples.first}")
end
else
mod.print_error("#{error.class} The following options failed to validate:")
Expand Down
2 changes: 1 addition & 1 deletion modules/auxiliary/admin/kerberos/forge_ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def initialize(info = {})
OptString.new('NTHASH', [ true, 'The krbtgt/service nthash' ]),
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)'], regex: %r{.*/.*}, examples: %w[MSSqlSvc/host.domain.local:1433 MSSqlSvc/host.domain.local:1434]),
OptString.new('SPN', [ false, 'The Service Principal Name (Only used for silver ticket) Ex: MSSqlSvc/host.domain.local:1434'], 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])
]
)
Expand Down
10 changes: 5 additions & 5 deletions spec/lib/msf/ui/console/command_dispatcher/auxiliary_spec.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 3cfd7ba

Please sign in to comment.