Class: Msf::OptAddressRange

Inherits:
OptBase
  • Object
show all
Defined in:
lib/msf/core/opt_address_range.rb

Overview

Network address range option.

Instance Attribute Summary

Attributes inherited from OptBase

#advanced, #aliases, #conditions, #default, #desc, #enums, #evasion, #fallbacks, #max_length, #name, #owner, #regex, #required

Instance Method Summary collapse

Methods inherited from OptBase

#advanced?, #display_value, #empty_required_value?, #evasion?, #initialize, #invalid_value_length?, #required?, #type?

Constructor Details

This class inherits a constructor from Msf::OptBase

Instance Method Details

#normalize(value) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/msf/core/opt_address_range.rb', line 19

def normalize(value)
  return nil unless value.kind_of?(String)
  # accept both "file://<path>" and "file:<path>" syntax
  if (value =~ /^file:\/\/(.*)/) || (value =~ /^file:(.*)/)
    path = $1
    return false if not File.exist?(path) or File.directory?(path)
    return File.readlines(path).map{ |s| s.strip}.join(" ")
  elsif (value =~ /^rand:(.*)/)
    count = $1.to_i
    return false if count < 1
    ret = ''
    count.times {
      ret << " " if not ret.empty?
      ret << [ rand(0x100000000) ].pack("N").unpack("C*").map{|x| x.to_s }.join(".")
    }
    return ret
  end
  return value
end

#typeObject



11
12
13
# File 'lib/msf/core/opt_address_range.rb', line 11

def type
  return 'addressrange'
end

#valid?(value, check_empty: true) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/msf/core/opt_address_range.rb', line 39

def valid?(value, check_empty: true)
  return false if check_empty && empty_required_value?(value)
  return false unless value.kind_of?(String) or value.kind_of?(NilClass)

  if (value != nil and value.empty? == false)
    normalized = normalize(value)
    return false if normalized.nil?
    walker = Rex::Socket::RangeWalker.new(normalized)
    if (not walker or not walker.valid?)
      return false
    end
  end

  return super
end

#validate_on_assignment?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/msf/core/opt_address_range.rb', line 15

def validate_on_assignment?
  false
end