From ea8d331b4760ddd83ba601bac7a191c154f93e84 Mon Sep 17 00:00:00 2001 From: Brendan Coles Date: Sun, 13 Dec 2015 06:51:40 +0000 Subject: [PATCH] Add BeEF::Filters.is_valid_private_ip() --- core/filters/base.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/filters/base.rb b/core/filters/base.rb index 0a28968e2..bc85e0c2c 100644 --- a/core/filters/base.rb +++ b/core/filters/base.rb @@ -142,6 +142,16 @@ module Filters valid end + # Checks if the given string is a valid private IP address + # @param [String] ip string for testing + # @return [Boolean] true if the string is a valid private IP address, otherwise false + # @note Includes RFC1918 private IPv4, private IPv6, and localhost 127.0.0.0/8, + # but does not include local-link addresses. + def self.is_valid_private_ip?(ip) + return false unless is_valid_ip?(ip) + return ip =~ /\A(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])\z/ ? true : false + end + # Checks if the given string is a valid TCP port # @param [String] port string for testing # @return [Boolean] true if the string is a valid TCP port, otherwise false