From a58b7f829fac90e2571c46e76671d834be88f844 Mon Sep 17 00:00:00 2001 From: "wade@bindshell.net" Date: Sun, 21 Nov 2010 13:04:54 +0000 Subject: [PATCH] filters updated git-svn-id: https://beef.googlecode.com/svn/trunk@552 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9 --- lib/filter/base.rb | 68 ++++++++++++++++++++++++------------------- lib/filter/command.rb | 7 +++++ 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/lib/filter/base.rb b/lib/filter/base.rb index 9e0a6c2e9..c2505328c 100644 --- a/lib/filter/base.rb +++ b/lib/filter/base.rb @@ -10,59 +10,67 @@ module BeEF true end + # check if only the characters in 'chars' are in 'str' + def self.only?(chars, str) + regex = Regexp.new('[^' + chars + ']') + regex.match(str).nil? + end + + # check if one or more characters in 'chars' are in 'str' + def self.exists?(chars, str) + regex = Regexp.new(chars) + not regex.match(str).nil? + end + + # check for null char + def self.has_null? (str) + return false if not is_non_empty_string?(str) + exists?('\x00', str) + end + + # check for non-printalbe char + def self.has_non_printable_char?(str) + return false if not is_non_empty_string?(str) + not only?('[:print:]', str) + end + # check if num chars only def self.nums_only?(str) - not (str =~ /^[\d]+$/).nil? + return false if not is_non_empty_string?(str) + only?('0-9', str) end # check if valid float def self.is_valid_float?(str) + return false if not is_non_empty_string?(str) + return false if not only?('0-9\.', str) not (str =~ /^[\d]+\.[\d]+$/).nil? end # check if hex chars only def self.hexs_only?(str) - not (str =~ /^[0123456789ABCDEFabcdef]+$/).nil? + return false if not is_non_empty_string?(str) + only?('0123456789ABCDEFabcdef', str) end # check if first char is a num def self.first_char_is_num?(str) + return false if not is_non_empty_string?(str) not (str =~ /^\d.*/).nil? end - # check for word and some punc chars - def self.has_valid_key_chars?(str) - return false if not BeEF::Filter.is_non_empty_string?(str) - (str =~ /[^\w_-]/).nil? - end - - # check for word and underscore chars - def self.has_valid_param_chars?(str) - return false if str.nil? - return false if not str.is_a? String - return false if str.empty? - (str =~ /[^\w_]/).nil? - end - # check for space chars: \t\n\r\f def self.has_whitespace_char?(str) - not (str =~ /\s/).nil? - end - - # check for non word chars: a-zA-Z0-9 - def self.has_nonword_char?(str) - not (str =~ /\w/).nil? - end - - # check for null char - def self.has_null? (str) - not (str =~ /[\000]/).nil? + return false if not is_non_empty_string?(str) + exists?('\s', str) end - # check for non-printalbe char - def self.has_non_printable_char?(str) - not (str =~ /[^[:print:]]/m).nil? + # check for non word chars: a-zA-Z0-9 + def self.alphanums_only?(str) + return false if not is_non_empty_string?(str) + only?("a-zA-Z0-9", str) end + end diff --git a/lib/filter/command.rb b/lib/filter/command.rb index a770344f5..024d8a8e1 100644 --- a/lib/filter/command.rb +++ b/lib/filter/command.rb @@ -44,6 +44,13 @@ module BeEF (str =~ /[^\w_-]/).nil? end + # check for word and underscore chars + def self.has_valid_param_chars?(str) + return false if str.nil? + return false if not str.is_a? String + return false if str.empty? + (str =~ /[^\w_]/).nil? + end end