Browse Source

avoid validating file-based datastore options on assignment

file:/ strings are special with some datastore options, causing them to read a
file rather than emitting the exact string. This causes a couple of problems.

1. the valid? check needs to be special on assignment, since normalization
   really means normalizing the path, not playing with the value as we would do
   for other types

2. there are races or simply out-of-order assignments when running commands
   like 'services -p 80 -R', where the datastore option is assigned before the
   file is actually written.

This is the 'easy' fix of disabling assignment validation (which we didn't have
before anyway) for types that can expect a file:/ prefix.
Brent Cook 3 years ago
parent
commit
e25525b4a7

+ 5
- 3
lib/msf/core/data_store.rb View File

@@ -29,10 +29,12 @@ class DataStore < Hash
29 29
 
30 30
     opt = @options[k]
31 31
     unless opt.nil?
32
-      unless opt.valid?(v)
33
-        raise OptionValidateError.new(["Value '#{v}' is not valid for option '#{k}'#{['', ', try harder'].sample}"])
32
+      if opt.validate_on_assignment?
33
+        unless opt.valid?(v)
34
+          raise OptionValidateError.new(["Value '#{v}' is not valid for option '#{k}'"])
35
+        end
36
+        v = opt.normalize(v)
34 37
       end
35
-      v = opt.normalize(v)
36 38
     end
37 39
 
38 40
     super(k,v)

+ 4
- 0
lib/msf/core/opt_address_range.rb View File

@@ -12,6 +12,10 @@ class OptAddressRange < OptBase
12 12
     return 'addressrange'
13 13
   end
14 14
 
15
+  def validate_on_assignment?
16
+    false
17
+  end
18
+
15 19
   def normalize(value)
16 20
     return nil unless value.kind_of?(String)
17 21
     if (value =~ /^file:(.*)/)

+ 7
- 0
lib/msf/core/opt_base.rb View File

@@ -75,6 +75,13 @@ module Msf
75 75
       return (type == in_type)
76 76
     end
77 77
 
78
+    #
79
+    # Returns true if this option can be validated on assignment
80
+    #
81
+    def validate_on_assignment?
82
+      true
83
+    end
84
+
78 85
     #
79 86
     # If it's required and the value is nil or empty, then it's not valid.
80 87
     #

+ 4
- 0
lib/msf/core/opt_path.rb View File

@@ -12,6 +12,10 @@ class OptPath < OptBase
12 12
     return 'path'
13 13
   end
14 14
 
15
+  def validate_on_assignment?
16
+    false
17
+  end
18
+
15 19
   # Generally, 'value' should be a file that exists.
16 20
   def valid?(value)
17 21
     return false if empty_required_value?(value)

+ 4
- 0
lib/msf/core/opt_raw.rb View File

@@ -12,6 +12,10 @@ class OptRaw < OptBase
12 12
     return 'raw'
13 13
   end
14 14
 
15
+  def validate_on_assignment?
16
+    false
17
+  end
18
+
15 19
   def normalize(value)
16 20
     if (value.to_s =~ /^file:(.*)/)
17 21
       path = $1

+ 4
- 0
lib/msf/core/opt_string.rb View File

@@ -12,6 +12,10 @@ class OptString < OptBase
12 12
     return 'string'
13 13
   end
14 14
 
15
+  def validate_on_assignment?
16
+    false
17
+  end
18
+
15 19
   def normalize(value)
16 20
     if (value.to_s =~ /^file:(.*)/)
17 21
       path = $1

Loading…
Cancel
Save