Browse Source

Fix #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 #4307
sinn3r 5 years ago
parent
commit
cfc1acfcae
3 changed files with 15 additions and 3 deletions
  1. 1
    1
      lib/msf/base/simple/auxiliary.rb
  2. 7
    1
      lib/msf/core/exceptions.rb
  3. 7
    1
      lib/msf/core/post.rb

+ 1
- 1
lib/msf/base/simple/auxiliary.rb View File

@@ -55,7 +55,7 @@ module Auxiliary
55 55
 
56 56
     # Verify the ACTION
57 57
     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} * ", "}"
59 59
     end
60 60
 
61 61
     # Verify the options

+ 7
- 1
lib/msf/core/exceptions.rb View File

@@ -210,9 +210,15 @@ end
210 210
 ###
211 211
 class MissingActionError < ArgumentError
212 212
   include AuxiliaryError
213
+  attr_accessor :reason
214
+
215
+  def initialize(reason='')
216
+    self.reason = reason
217
+    super
218
+  end
213 219
 
214 220
   def to_s
215
-    "A valid action has not been selected."
221
+    "Invalid action: #{reason}"
216 222
   end
217 223
 end
218 224
 

+ 7
- 1
lib/msf/core/post.rb View File

@@ -19,7 +19,13 @@ class Msf::Post < Msf::Module
19 19
 
20 20
   include Msf::PostMixin
21 21
 
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
23 29
 
24 30
   def type
25 31
     Msf::MODULE_POST

Loading…
Cancel
Save