From fee0fb5e901d72fc79d58d15ef012f2f93fe250e Mon Sep 17 00:00:00 2001 From: darkbushido Date: Tue, 2 May 2017 12:37:59 -0500 Subject: [PATCH] Missed an LHOST option making OptAddressLocal inherit from OptAddress --- lib/msf/core/opt.rb | 2 +- lib/msf/core/opt_address_local.rb | 32 +++++++------------------------ 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/lib/msf/core/opt.rb b/lib/msf/core/opt.rb index a1a53a2c87..2d0a719fd2 100644 --- a/lib/msf/core/opt.rb +++ b/lib/msf/core/opt.rb @@ -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] diff --git a/lib/msf/core/opt_address_local.rb b/lib/msf/core/opt_address_local.rb index 6e8e14a111..f5eb40050c 100644 --- a/lib/msf/core/opt_address_local.rb +++ b/lib/msf/core/opt_address_local.rb @@ -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