Mirror of metasploit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

opt_address_range.rb 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: binary -*-
  2. module Msf
  3. ###
  4. #
  5. # Network address range option.
  6. #
  7. ###
  8. class OptAddressRange < OptBase
  9. def type
  10. return 'addressrange'
  11. end
  12. def validate_on_assignment?
  13. false
  14. end
  15. def normalize(value)
  16. return nil unless value.kind_of?(String)
  17. if (value =~ /^file:(.*)/)
  18. path = $1
  19. return false if not File.exist?(path) or File.directory?(path)
  20. return File.readlines(path).map{ |s| s.strip}.join(" ")
  21. elsif (value =~ /^rand:(.*)/)
  22. count = $1.to_i
  23. return false if count < 1
  24. ret = ''
  25. count.times {
  26. ret << " " if not ret.empty?
  27. ret << [ rand(0x100000000) ].pack("N").unpack("C*").map{|x| x.to_s }.join(".")
  28. }
  29. return ret
  30. end
  31. return value
  32. end
  33. def valid?(value, check_empty: true)
  34. return false if check_empty && empty_required_value?(value)
  35. return false unless value.kind_of?(String) or value.kind_of?(NilClass)
  36. if (value != nil and value.empty? == false)
  37. normalized = normalize(value)
  38. return false if normalized.nil?
  39. walker = Rex::Socket::RangeWalker.new(normalized)
  40. if (not walker or not walker.valid?)
  41. return false
  42. end
  43. end
  44. return super
  45. end
  46. end
  47. end