diff --git a/lib/rex/socket.rb b/lib/rex/socket.rb index 6a0dca6262..11a48ffc82 100644 --- a/lib/rex/socket.rb +++ b/lib/rex/socket.rb @@ -201,6 +201,18 @@ module Socket addr_ntoi(resolv_nbo(host)) end + def self.resolv_to_cidr(mask) + mask_i = resolv_nbo_i(mask) + cidr = nil + 0.upto(32) do |i| + if ((1 << i)-1) << (32-i) == mask_i + cidr = i + break + end + end + return cidr + end + # # Resolves a host to a dotted address. # diff --git a/scripts/meterpreter/autoroute.rb b/scripts/meterpreter/autoroute.rb index 248277f41f..b50eefcaf0 100644 --- a/scripts/meterpreter/autoroute.rb +++ b/scripts/meterpreter/autoroute.rb @@ -124,7 +124,13 @@ def validate_cmd(subnet=nil,netmask=nil) end unless(check_ip(subnet)) - print_error "Subnet invalid" + print_error "Subnet invalid (must be IPv4)" + usage + return false + end + + if(netmask and !(Rex::Socket.resolv_to_cidr(netmask))) + print_error "Netmask invalid (must define contiguous IP addressing)" usage return false end