Class: Msf::OptAddressRange

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

Overview

Network address range option.

Instance Attribute Summary

Attributes inherited from OptBase

#advanced, #default, #desc, #enums, #evasion, #name, #owner, #required

Instance Method Summary collapse

Methods inherited from OptBase

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

Constructor Details

This class inherits a constructor from Msf::OptBase

Instance Method Details

#normalize(value) ⇒ Object


364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/msf/core/option_container.rb', line 364

def normalize(value)
  return nil unless value.kind_of?(String)
  if (value =~ /^file:(.*)/)
    path = $1
    return false if not File.exists?(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


360
361
362
# File 'lib/msf/core/option_container.rb', line 360

def type
  return 'addressrange'
end

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)

383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'lib/msf/core/option_container.rb', line 383

def valid?(value)
  return false if 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