parent
81bcf2ca70
commit
fee0fb5e90
|
@ -28,7 +28,7 @@ module Msf
|
|||
|
||||
# @return [OptAddress]
|
||||
def self.LHOST(default=nil, required=true, desc="The listen address")
|
||||
Msf::OptAddress.new(__method__.to_s, [ required, desc, default ])
|
||||
Msf::OptAddressLocal.new(__method__.to_s, [ required, desc, default ])
|
||||
end
|
||||
|
||||
# @return [OptPort]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# -*- coding: binary -*-
|
||||
require 'network_interface'
|
||||
|
||||
module Msf
|
||||
|
||||
|
@ -7,19 +8,12 @@ module Msf
|
|||
# Network address option.
|
||||
#
|
||||
###
|
||||
class OptAddressLocal < OptBase
|
||||
def type
|
||||
return 'address'
|
||||
end
|
||||
|
||||
class OptAddressLocal < OptAddress
|
||||
def normalize(value)
|
||||
return nil unless value.kind_of?(String)
|
||||
|
||||
if (value =~ /^iface:(.*)/)
|
||||
iface = $1
|
||||
return false if not NetworkInterface.interfaces.include?(iface)
|
||||
|
||||
ip_address = NetworkInterface.addresses(iface).values.flatten.collect{|x| x['addr']}.select do |addr|
|
||||
if NetworkInterface.interfaces.include?(value)
|
||||
ip_address = NetworkInterface.addresses(value).values.flatten.collect{|x| x['addr']}.select do |addr|
|
||||
begin
|
||||
IPAddr.new(addr).ipv4?
|
||||
rescue IPAddr::InvalidAddressError => e
|
||||
|
@ -28,7 +22,7 @@ class OptAddressLocal < OptBase
|
|||
end
|
||||
|
||||
return false if ip_address.blank?
|
||||
return ip_address
|
||||
return ip_address.first
|
||||
end
|
||||
|
||||
return value
|
||||
|
@ -37,20 +31,8 @@ class OptAddressLocal < OptBase
|
|||
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 not value.empty?)
|
||||
begin
|
||||
getaddr_result = ::Rex::Socket.getaddress(value, true)
|
||||
# Covers a wierdcase where an incomplete ipv4 address will have it's
|
||||
# missing octets filled in with 0's. (e.g 192.168 become 192.0.0.168)
|
||||
# which does not feel like a legit behaviour
|
||||
if value =~ /^\d{1,3}(\.\d{1,3}){1,3}$/
|
||||
return false unless value =~ Rex::Socket::MATCH_IPV4
|
||||
end
|
||||
rescue
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true if NetworkInterface.interfaces.include?(value)
|
||||
|
||||
return super
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue