This commit is contained in:
Brendan Coles
2016-02-06 08:04:29 +00:00
parent dde8034606
commit 83e1f596de
7 changed files with 40 additions and 40 deletions

View File

@@ -11,7 +11,7 @@ module Filters
# @return [Boolean] Whether the string is not empty
def self.is_non_empty_string?(str)
return false if str.nil?
return false if not str.is_a? String
return false unless str.is_a? String
return false if str.empty?
true
end
@@ -38,7 +38,7 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string has a null character
def self.has_null? (str)
return false if not is_non_empty_string?(str)
return false unless is_non_empty_string?(str)
exists?('\x00', str)
end
@@ -46,7 +46,7 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] Whether or not the string has non-printable characters
def self.has_non_printable_char?(str)
return false if not is_non_empty_string?(str)
return false unless is_non_empty_string?(str)
not only?('[:print:]', str)
end
@@ -54,7 +54,7 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string only contains numbers
def self.nums_only?(str)
return false if not is_non_empty_string?(str)
return false unless is_non_empty_string?(str)
only?('0-9', str)
end
@@ -62,8 +62,8 @@ module Filters
# @param [String] str String for float testing
# @return [Boolean] If the string is a 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)
return false unless is_non_empty_string?(str)
return false unless only?('0-9\.', str)
not (str =~ /^[\d]+\.[\d]+$/).nil?
end
@@ -71,7 +71,7 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string only contains hex characters
def self.hexs_only?(str)
return false if not is_non_empty_string?(str)
return false unless is_non_empty_string?(str)
only?('0123456789ABCDEFabcdef', str)
end
@@ -79,7 +79,7 @@ module Filters
# @param [String] String for testing
# @return [Boolean] If the first character of the string is a number
def self.first_char_is_num?(str)
return false if not is_non_empty_string?(str)
return false unless is_non_empty_string?(str)
not (str =~ /^\d.*/).nil?
end
@@ -87,7 +87,7 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string has a whitespace character
def self.has_whitespace_char?(str)
return false if not is_non_empty_string?(str)
return false unless is_non_empty_string?(str)
exists?('\s', str)
end
@@ -95,7 +95,7 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string only has alphanums
def self.alphanums_only?(str)
return false if not is_non_empty_string?(str)
return false unless is_non_empty_string?(str)
only?("a-zA-Z0-9", str)
end
@@ -177,7 +177,7 @@ module Filters
# @return [Boolean] If the string has valid browser details characters
# @note This function passes the \302\256 character which translates to the registered symbol (r)
def self.has_valid_browser_details_chars?(str)
return false if not is_non_empty_string?(str)
return false unless is_non_empty_string?(str)
not (str =~ /[^\w\d\s()-.,;:_\/!\302\256]/).nil?
end
@@ -187,7 +187,7 @@ module Filters
# @note This is for basic filtering where possible all specific filters must be implemented
# @note This function passes the \302\256 character which translates to the registered symbol (r)
def self.has_valid_base_chars?(str)
return false if not is_non_empty_string?(str)
return false unless is_non_empty_string?(str)
(str =~ /[^\302\256[:print:]]/).nil?
end

View File

@@ -10,7 +10,7 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string has valid browser name characters
def self.is_valid_browsername?(str)
return false if not is_non_empty_string?(str)
return false unless is_non_empty_string?(str)
return false if str.length > 2
return false if has_non_printable_char?(str)
true
@@ -20,7 +20,7 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string has valid browser type characters
def self.is_valid_browsertype?(str)
return false if not is_non_empty_string?(str)
return false unless is_non_empty_string?(str)
return false if str.length < 10
return false if str.length > 500 #CxF - had to increase this because the Chrome detection JSON String is getting bigger.
return false if has_non_printable_char?(str)
@@ -31,7 +31,7 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string has valid Operating System name characters
def self.is_valid_osname?(str)
return false if not is_non_empty_string?(str)
return false unless is_non_empty_string?(str)
return false if has_non_printable_char?(str)
return false if str.length < 2
true
@@ -41,7 +41,7 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string has valid Hardware name characters
def self.is_valid_hwname?(str)
return false if not is_non_empty_string?(str)
return false unless is_non_empty_string?(str)
return false if has_non_printable_char?(str)
return false if str.length < 2
true
@@ -77,7 +77,7 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string has valid browser / ua string characters
def self.is_valid_browserstring?(str)
return false if not is_non_empty_string?(str)
return false unless is_non_empty_string?(str)
return false if has_non_printable_char?(str)
return false if str.length > 300
true
@@ -132,7 +132,7 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string has valid CPU type characters
def self.is_valid_cpu?(str)
return false if not is_non_empty_string?(str)
return false unless is_non_empty_string?(str)
return false if has_non_printable_char?(str)
return false if str.length > 200
true
@@ -144,7 +144,7 @@ module Filters
# @note This string can be empty if there are no browser plugins
# @todo Verify if the ruby version statement is still necessary
def self.is_valid_browser_plugins?(str)
return true if not is_non_empty_string?(str)
return true unless is_non_empty_string?(str)
return false if str.length > 1000
if RUBY_VERSION >= "1.9" && str.encoding === Encoding.find('UTF-8')
return (str =~ /[^\w\d\s()-.,';_!\302\256]/u).nil?

View File

@@ -11,7 +11,7 @@ module Filters
# @return [Boolean] If the string has valid path characters
def self.is_valid_path_info?(str)
return false if str.nil?
return false if not str.is_a? String
return false unless str.is_a? String
return false if has_non_printable_char?(str)
true
end
@@ -20,8 +20,8 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string is a valid command id
def self.is_valid_command_id?(str)
return false if not is_non_empty_string?(str)
return false if not nums_only?(str)
return false unless is_non_empty_string?(str)
return false unless nums_only?(str)
true
end
@@ -29,8 +29,8 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string has valid hook session id characters
def self.is_valid_hook_session_id?(str)
return false if not is_non_empty_string?(str)
return false if not has_valid_key_chars?(str)
return false unless is_non_empty_string?(str)
return false unless has_valid_key_chars?(str)
true
end
@@ -38,8 +38,8 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string has valid command module datastore key characters
def self.is_valid_command_module_datastore_key?(str)
return false if not is_non_empty_string?(str)
return false if not has_valid_key_chars?(str)
return false unless is_non_empty_string?(str)
return false unless has_valid_key_chars?(str)
true
end
@@ -48,7 +48,7 @@ module Filters
# @return [Boolean] If the string has valid command module datastore param characters
def self.is_valid_command_module_datastore_param?(str)
return false if has_null?(str)
return false if not has_valid_base_chars?(str)
return false unless has_valid_base_chars?(str)
true
end
@@ -56,8 +56,8 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string has valid key characters
def self.has_valid_key_chars?(str)
return false if not is_non_empty_string?(str)
return false if not has_valid_base_chars?(str)
return false unless is_non_empty_string?(str)
return false unless has_valid_base_chars?(str)
true
end
@@ -66,9 +66,9 @@ module Filters
# @return [Boolean] If the sting has valid param characters
def self.has_valid_param_chars?(str)
return false if str.nil?
return false if not str.is_a? String
return false unless str.is_a? String
return false if str.empty?
return false if not (str =~ /[^\w_\:]/).nil?
return false unless (str =~ /[^\w_\:]/).nil?
true
end

View File

@@ -10,7 +10,7 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string is a valid hostname
def self.is_valid_hostname?(str)
return false if not is_non_empty_string?(str)
return false unless is_non_empty_string?(str)
return false if has_non_printable_char?(str)
return false if str.length > 255
return false if (str =~ /^[a-zA-Z0-9][a-zA-Z0-9\-\.]*[a-zA-Z0-9]$/).nil?

View File

@@ -10,7 +10,7 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string is a valid page title
def self.is_valid_pagetitle?(str)
return false if not str.is_a? String
return false unless str.is_a? String
return false if has_non_printable_char?(str)
return false if str.length > 500 # CxF Increased this because some page titles are MUCH longer
true
@@ -20,7 +20,7 @@ module Filters
# @param [String] str String for testing
# @return [Boolean] If the string is a valid referrer
def self.is_valid_pagereferrer?(str)
return false if not str.is_a? String
return false unless str.is_a? String
return false if has_non_printable_char?(str)
return false if str.length > 350
true

View File

@@ -13,7 +13,7 @@ require 'selenium/webdriver'
class BeefTest
def self.save_screenshot(session)
Dir.mkdir(BEEF_TEST_DIR) if not File.directory?(BEEF_TEST_DIR)
Dir.mkdir(BEEF_TEST_DIR) unless File.directory?(BEEF_TEST_DIR)
session.driver.browser.save_screenshot(BEEF_TEST_DIR + Time.now.strftime("%Y-%m-%d--%H-%M-%S-%N") + ".png")
end

View File

@@ -68,7 +68,7 @@ class TC_WebRTCRest < Test::Unit::TestCase
end
def test_1_webrtc_check_for_two_hooked_browsers
return if not @@activated
return unless @@activated
rest_response = nil
assert_nothing_raised do
@@ -83,7 +83,7 @@ class TC_WebRTCRest < Test::Unit::TestCase
end
def test_2_webrtc_establishing_p2p
return if not @@activated
return unless @@activated
rest_response = nil
assert_nothing_raised do
@@ -119,7 +119,7 @@ class TC_WebRTCRest < Test::Unit::TestCase
end
def test_3_webrtc_send_msg # assumes test 2 has run
return if not @@activated
return unless @@activated
rest_response = nil
assert_nothing_raised do
@@ -157,7 +157,7 @@ class TC_WebRTCRest < Test::Unit::TestCase
end
def test_4_webrtc_stealthmode # assumes test 2 has run
return if not @@activated
return unless @@activated
# Test our two browsers are still online
rest_response = nil
@@ -241,7 +241,7 @@ class TC_WebRTCRest < Test::Unit::TestCase
end
def test_5_webrtc_execcmd # assumes test 2 has run
return if not @@activated
return unless @@activated
#