Land #10094, Improve network interface support for LHOST
parent
122af6b143
commit
87c6befb45
|
@ -25,8 +25,8 @@ module Msf
|
|||
Msf::OptPort.new(__method__.to_s, [ required, desc, default ])
|
||||
end
|
||||
|
||||
# @return [OptAddress]
|
||||
def self.LHOST(default=nil, required=true, desc="The listen address")
|
||||
# @return [OptAddressLocal]
|
||||
def self.LHOST(default=nil, required=true, desc="The listen address (an interface may be specified)")
|
||||
Msf::OptAddressLocal.new(__method__.to_s, [ required, desc, default ])
|
||||
end
|
||||
|
||||
|
|
|
@ -5,36 +5,39 @@ module Msf
|
|||
|
||||
###
|
||||
#
|
||||
# Network address option.
|
||||
# Local network address option.
|
||||
#
|
||||
###
|
||||
class OptAddressLocal < OptAddress
|
||||
def normalize(value)
|
||||
return nil unless value.kind_of?(String)
|
||||
|
||||
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
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
return false if ip_address.blank?
|
||||
return ip_address.first
|
||||
end
|
||||
|
||||
return value
|
||||
def interfaces
|
||||
NetworkInterface.interfaces || []
|
||||
end
|
||||
|
||||
|
||||
def normalize(value)
|
||||
return unless value.kind_of?(String)
|
||||
return value unless interfaces.include?(value)
|
||||
|
||||
addrs = NetworkInterface.addresses(value).values.flatten
|
||||
|
||||
# Strip interface name from address (see getifaddrs(3))
|
||||
addrs = addrs.map { |x| x['addr'].split('%').first }.select do |addr|
|
||||
begin
|
||||
IPAddr.new(addr)
|
||||
rescue IPAddr::InvalidAddressError
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
addrs.any? ? addrs.first : ''
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
return true if NetworkInterface.interfaces.include?(value)
|
||||
return false unless value.kind_of?(String) || value.kind_of?(NilClass)
|
||||
|
||||
return super
|
||||
return true if interfaces.include?(value)
|
||||
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2189,6 +2189,12 @@ class Core
|
|||
return res
|
||||
end
|
||||
|
||||
# XXX: We repurpose OptAddressLocal#interfaces, so we can't put this in Rex
|
||||
def tab_complete_source_interface(o)
|
||||
return [] unless o.is_a?(Msf::OptAddressLocal)
|
||||
o.interfaces
|
||||
end
|
||||
|
||||
#
|
||||
# Provide possible option values based on type
|
||||
#
|
||||
|
@ -2210,8 +2216,8 @@ class Core
|
|||
res << Rex::Socket.source_address(rh)
|
||||
else
|
||||
res += tab_complete_source_address
|
||||
res += tab_complete_source_interface(o)
|
||||
end
|
||||
else
|
||||
end
|
||||
|
||||
when Msf::OptAddressRange
|
||||
|
|
|
@ -289,11 +289,9 @@ module DispatcherShell
|
|||
def tab_complete_source_address
|
||||
addresses = [Rex::Socket.source_address]
|
||||
# getifaddrs was introduced in 2.1.2
|
||||
if Socket.respond_to?(:getifaddrs)
|
||||
ifaddrs = Socket.getifaddrs.find_all do |ifaddr|
|
||||
((ifaddr.flags & Socket::IFF_LOOPBACK) == 0) &&
|
||||
ifaddr.addr &&
|
||||
ifaddr.addr.ip?
|
||||
if ::Socket.respond_to?(:getifaddrs)
|
||||
ifaddrs = ::Socket.getifaddrs.select do |ifaddr|
|
||||
ifaddr.addr && ifaddr.addr.ip?
|
||||
end
|
||||
addresses += ifaddrs.map { |ifaddr| ifaddr.addr.ip_address }
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue