lib/ronin/extensions/regexp.rb in ronin-support-0.4.0.rc2 vs lib/ronin/extensions/regexp.rb in ronin-support-0.4.0

- old
+ new

@@ -26,35 +26,54 @@ # Regular expression for finding MAC addresses in text MAC = /[0-9a-fA-F]{2}(?::[0-9a-fA-F]{2}){5}/ # A regular expression for matching IPv4 Addresses. - IPv4 = /#{OCTET}(?:\.#{OCTET}){3}/ + IPv4 = /#{OCTET}(?:\.#{OCTET}){3}(?:\/\d{1,2})?/ # A regular expression for matching IPv6 Addresses. - IPv6 = /:(:[0-9a-f]{1,4}){1,7}|([0-9a-f]{1,4}::?){1,7}[0-9a-f]{1,4}(:#{IPv4})?/ + IPv6 = union( + /(?:[0-9a-f]{1,4}:){6}#{IPv4}/, + /(?:[0-9a-f]{1,4}:){5}[0-9a-f]{1,4}:#{IPv4}/, + /(?:[0-9a-f]{1,4}:){5}:[0-9a-f]{1,4}:#{IPv4}/, + /(?:[0-9a-f]{1,4}:){1,1}(?::[0-9a-f]{1,4}){1,4}:#{IPv4}/, + /(?:[0-9a-f]{1,4}:){1,2}(?::[0-9a-f]{1,4}){1,3}:#{IPv4}/, + /(?:[0-9a-f]{1,4}:){1,3}(?::[0-9a-f]{1,4}){1,2}:#{IPv4}/, + /(?:[0-9a-f]{1,4}:){1,4}(?::[0-9a-f]{1,4}){1,1}:#{IPv4}/, + /:(?::[0-9a-f]{1,4}){1,5}:#{IPv4}/, + /(?:(?:[0-9a-f]{1,4}:){1,5}|:):#{IPv4}/, + /(?:[0-9a-f]{1,4}:){1,1}(?::[0-9a-f]{1,4}){1,6}(?:\/\d{1,3})?/, + /(?:[0-9a-f]{1,4}:){1,2}(?::[0-9a-f]{1,4}){1,5}(?:\/\d{1,3})?/, + /(?:[0-9a-f]{1,4}:){1,3}(?::[0-9a-f]{1,4}){1,4}(?:\/\d{1,3})?/, + /(?:[0-9a-f]{1,4}:){1,4}(?::[0-9a-f]{1,4}){1,3}(?:\/\d{1,3})?/, + /(?:[0-9a-f]{1,4}:){1,5}(?::[0-9a-f]{1,4}){1,2}(?:\/\d{1,3})?/, + /(?:[0-9a-f]{1,4}:){1,6}(?::[0-9a-f]{1,4}){1,1}(?:\/\d{1,3})?/, + /[0-9a-f]{1,4}(?::[0-9a-f]{1,4}){7}(?:\/\d{1,3})?/, + /:(?::[0-9a-f]{1,4}){1,7}(?:\/\d{1,3})?/, + /(?:(?:[0-9a-f]{1,4}:){1,7}|:):(?:\/\d{1,3})?/ + ) # A regular expression for matching IP Addresses. IP = /#{IPv4}|#{IPv6}/ # Regular expression used to find host-names in text HOST_NAME = /(?:[a-zA-Z0-9]+(?:[_-][a-zA-Z0-9]+)*\.)+(?:#{union(Resolv::TLDS)})/i # Regular expression to match a word in the username of an email address - USER_NAME = /[A-Za-z](?:[A-Za-z0-9]+[\._-])*[A-Za-z0-9]+/ + USER_NAME = /[A-Za-z](?:[A-Za-z0-9]*[\._-])*[A-Za-z0-9]+/ # Regular expression to find email addresses in text - EMAIL_ADDR = /#{USER_NAME}(?:\.#{USER_NAME})*\@#{HOST_NAME}/ + EMAIL_ADDR = /#{USER_NAME}\@#{HOST_NAME}/ # Regular expression to find deliminators in text DELIM = /[;&\n\r]/ # Regular expression to find identifier in text - IDENTIFIER = /[_a-zA-Z][a-zA-Z0-9_-]*/ + IDENTIFIER = /[_]*[a-zA-Z]+[a-zA-Z0-9_-]*/ # Regular expression to find File extensions in text - FILE_EXT = /(?:\.[A-Za-z0-9_-]+)+/ + FILE_EXT = /(?:\.[A-Za-z0-9]+)+/ # Regular expression to find File names in text FILE_NAME = /(?:[^\/\\\. ]|\\[\/\\ ])+/ # Regular expression to find Files in text @@ -62,28 +81,28 @@ # Regular expression to find Directory names in text DIRECTORY = /(?:\.\.|\.|#{FILE})/ # Regular expression to find local UNIX Paths in text - LOCAL_UNIX_PATH = /(?:#{DIRECTORY}\/)+#{DIRECTORY}\/?/ + RELATIVE_UNIX_PATH = /(?:#{DIRECTORY}\/)+#{DIRECTORY}\/?/ # Regular expression to find absolute UNIX Paths in text ABSOLUTE_UNIX_PATH = /(?:\/#{FILE})+\/?/ # Regular expression to find UNIX Paths in text - UNIX_PATH = /#{ABSOLUTE_UNIX_PATH}|#{LOCAL_UNIX_PATH}/ + UNIX_PATH = /#{ABSOLUTE_UNIX_PATH}|#{RELATIVE_UNIX_PATH}/ # Regular expression to find local Windows Paths in text - LOCAL_WINDOWS_PATH = /(?:#{DIRECTORY}\\)+#{DIRECTORY}\\?/ + RELATIVE_WINDOWS_PATH = /(?:#{DIRECTORY}\\)+#{DIRECTORY}\\?/ # Regular expression to find absolute Windows Paths in text - ABSOLUTE_WINDOWS_PATH = /[A-Za-z]:(?:\\#{DIRECTORY})+\\?/ + ABSOLUTE_WINDOWS_PATH = /[A-Za-z]:(?:\\#{FILE})+\\?/ # Regular expression to find Windows Paths in text - WINDOWS_PATH = /#{ABSOLUTE_WINDOWS_PATH}|#{LOCAL_WINDOWS_PATH}/ + WINDOWS_PATH = /#{ABSOLUTE_WINDOWS_PATH}|#{RELATIVE_WINDOWS_PATH}/ # Regular expression to find local Paths in text - LOCAL_PATH = /#{LOCAL_UNIX_PATH}|#{LOCAL_WINDOWS_PATH}/ + RELATIVE_PATH = /#{RELATIVE_UNIX_PATH}|#{RELATIVE_WINDOWS_PATH}/ # Regular expression to find absolute Paths in text ABSOLUTE_PATH = /#{ABSOLUTE_UNIX_PATH}|#{ABSOLUTE_WINDOWS_PATH}/ # Regular expression to find Paths in text