Skip to content

Commit cfc1acf

Browse files
committed
Fix rapid7#4307 - Check action for nil
Auxiiary modules already do this, but looks like we forgot to do the same for post modules. I also changed the error to allow "reason" in order to be more informative about what the user should do. Fix rapid7#4307
1 parent 8f2e444 commit cfc1acf

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

lib/msf/base/simple/auxiliary.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def self.run_simple(omod, opts = {}, &block)
5555

5656
# Verify the ACTION
5757
if (mod.actions.length > 0 and not mod.action)
58-
raise MissingActionError, "You must specify a valid Action", caller
58+
raise MissingActionError, "Please use: #{mod.actions.collect {|e| e.name} * ", "}"
5959
end
6060

6161
# Verify the options

lib/msf/core/exceptions.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,15 @@ def to_s
210210
###
211211
class MissingActionError < ArgumentError
212212
include AuxiliaryError
213+
attr_accessor :reason
214+
215+
def initialize(reason='')
216+
self.reason = reason
217+
super
218+
end
213219

214220
def to_s
215-
"A valid action has not been selected."
221+
"Invalid action: #{reason}"
216222
end
217223
end
218224

lib/msf/core/post.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ class Msf::Post < Msf::Module
1919

2020
include Msf::PostMixin
2121

22-
def setup; end
22+
def setup
23+
m = replicant
24+
action = datastore['ACTION']
25+
if m.actions.length > 0 && !m.action
26+
raise Msf::MissingActionError, "Please use: #{m.actions.collect {|e| e.name} * ", "}"
27+
end
28+
end
2329

2430
def type
2531
Msf::MODULE_POST

0 commit comments

Comments
 (0)