:ipv4
or :ipv6
)
+ # @return [Boolean] true if the string is a valid IP address, otherwise false
+ #
+ # @overload self.is_valid_ip?(ip)
+ # Checks if the given string is either a valid IPv4 or IPv6 address
+ # @param [String] ip string to be tested
+ # @return [Boolean] true if the string is a valid IPv4 or IPV6 address, otherwise false
+ def self.is_valid_ip?(ip, version = :both)
+ return false unless is_non_empty_string?(ip)
+
+ if case version.inspect.downcase
+ when /^:ipv4$/
+ ip =~ /^((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}
+ (25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])$/x
+ when /^:ipv6$/
+ ip =~ /^(([0-9a-f]{1,4}:){7,7}[0-9a-f]{1,4}|
+ ([0-9a-f]{1,4}:){1,7}:|
+ ([0-9a-f]{1,4}:){1,6}:[0-9a-f]{1,4}|
+ ([0-9a-f]{1,4}:){1,5}(:[0-9a-f]{1,4}){1,2}|
+ ([0-9a-f]{1,4}:){1,4}(:[0-9a-f]{1,4}){1,3}|
+ ([0-9a-f]{1,4}:){1,3}(:[0-9a-f]{1,4}){1,4}|
+ ([0-9a-f]{1,4}:){1,2}(:[0-9a-f]{1,4}){1,5}|
+ [0-9a-f]{1,4}:((:[0-9a-f]{1,4}){1,6})|
+ :((:[0-9a-f]{1,4}){1,7}|:)|
+ fe80:(:[0-9a-f]{0,4}){0,4}%[0-9a-z]{1,}|
+ ::(ffff(:0{1,4}){0,1}:){0,1}
+ ((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}
+ (25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|
+ ([0-9a-f]{1,4}:){1,4}:
+ ((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}
+ (25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/ix
+ when /^:both$/
+ is_valid_ip?(ip, :ipv4) || is_valid_ip?(ip, :ipv6)
+ end
+ true
+ else
+ false
+ end
+ 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)
+
+ 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
+ def self.is_valid_port?(port)
+ valid = false
+ valid = true if port.to_i > 0 && port.to_i < 2**16
+ valid
+ end
+
+ # Checks if string is a valid domain name
+ # @param [String] domain string for testing
+ # @return [Boolean] If the string is a valid domain name
+ # @note Only validates the string format. It does not check for a valid TLD since ICANN's list of TLD's is not static.
+ def self.is_valid_domain?(domain)
+ return false unless is_non_empty_string?(domain)
+ return true if domain =~ /^[0-9a-z-]+(\.[0-9a-z-]+)*(\.[a-z]{2,}).?$/i
+
+ false
+ end
+
+ # Check for valid browser details characters
+ # @param [String] str String for testing
+ # @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 unless is_non_empty_string?(str)
+
+ !(str =~ %r{[^\w\d\s()-.,;:_/!\302\256]}).nil?
+ end
+
+ # Check for valid base details characters
+ # @param [String] str String for testing
+ # @return [Boolean] If the string has only valid base characters
+ # @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 unless is_non_empty_string?(str)
+
+ (str =~ /[^\302\256[:print:]]/).nil?
+ end
+
+ # Verify the yes and no is valid
+ # @param [String] str String for testing
+ # @return [Boolean] If the string is either 'yes' or 'no'
+ def self.is_valid_yes_no?(str)
+ return false if has_non_printable_char?(str)
+ return false if str !~ /\A(Yes|No)\z/i
+
+ true
+ end
end
-
- # Check if only the characters in 'chars' are in 'str'
- # @param [String] chars List of characters to match
- # @param [String] str String for testing
- # @return [Boolean] Whether or not the only characters in str are specified in chars
- def self.only?(chars, str)
- regex = Regexp.new('[^' + chars + ']')
- regex.match(str.encode('UTF-8', invalid: :replace, undef: :replace, replace: '')).nil?
- end
-
- # Check if one or more characters in 'chars' are in 'str'
- # @param [String] chars List of characters to match
- # @param [String] str String for testing
- # @return [Boolean] Whether one of the characters exists in the string
- def self.exists?(chars, str)
- regex = Regexp.new(chars)
- not regex.match(str.encode('UTF-8', invalid: :replace, undef: :replace, replace: '')).nil?
- end
-
- # Check for null char
- # @param [String] str String for testing
- # @return [Boolean] If the string has a null character
- def self.has_null? (str)
- return false unless is_non_empty_string?(str)
- exists?('\x00', str)
- end
-
- # Check for non-printable char
- # @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 unless is_non_empty_string?(str)
- not only?('[:print:]', str)
- end
-
- # Check if num characters only
- # @param [String] str String for testing
- # @return [Boolean] If the string only contains numbers
- def self.nums_only?(str)
- return false unless is_non_empty_string?(str)
- only?('0-9', str)
- end
-
- # Check if valid float
- # @param [String] str String for float testing
- # @return [Boolean] If the string is a valid float
- def self.is_valid_float?(str)
- return false unless is_non_empty_string?(str)
- return false unless only?('0-9\.', str)
- not (str =~ /^[\d]+\.[\d]+$/).nil?
- end
-
- # Check if hex characters only
- # @param [String] str String for testing
- # @return [Boolean] If the string only contains hex characters
- def self.hexs_only?(str)
- return false unless is_non_empty_string?(str)
- only?('0123456789ABCDEFabcdef', str)
- end
-
- # Check if first character is a number
- # @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 unless is_non_empty_string?(str)
- not (str =~ /^\d.*/).nil?
- end
-
- # Check for space characters: \t\n\r\f
- # @param [String] str String for testing
- # @return [Boolean] If the string has a whitespace character
- def self.has_whitespace_char?(str)
- return false unless is_non_empty_string?(str)
- exists?('\s', str)
- end
-
- # Check for non word characters: a-zA-Z0-9
- # @param [String] str String for testing
- # @return [Boolean] If the string only has alphanums
- def self.alphanums_only?(str)
- return false unless is_non_empty_string?(str)
- only?("a-zA-Z0-9", str)
- end
-
- # @overload self.is_valid_ip?(ip, version)
- # Checks if the given string is a valid IP address
- # @param [String] ip string to be tested
- # @param [Symbol] version IP version (either :ipv4
or :ipv6
)
- # @return [Boolean] true if the string is a valid IP address, otherwise false
- #
- # @overload self.is_valid_ip?(ip)
- # Checks if the given string is either a valid IPv4 or IPv6 address
- # @param [String] ip string to be tested
- # @return [Boolean] true if the string is a valid IPv4 or IPV6 address, otherwise false
- def self.is_valid_ip?(ip, version = :both)
- return false unless is_non_empty_string?(ip)
- valid = case version.inspect.downcase
- when /^:ipv4$/
- ip =~ /^((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}
- (25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])$/x
- when /^:ipv6$/
- ip =~ /^(([0-9a-f]{1,4}:){7,7}[0-9a-f]{1,4}|
- ([0-9a-f]{1,4}:){1,7}:|
- ([0-9a-f]{1,4}:){1,6}:[0-9a-f]{1,4}|
- ([0-9a-f]{1,4}:){1,5}(:[0-9a-f]{1,4}){1,2}|
- ([0-9a-f]{1,4}:){1,4}(:[0-9a-f]{1,4}){1,3}|
- ([0-9a-f]{1,4}:){1,3}(:[0-9a-f]{1,4}){1,4}|
- ([0-9a-f]{1,4}:){1,2}(:[0-9a-f]{1,4}){1,5}|
- [0-9a-f]{1,4}:((:[0-9a-f]{1,4}){1,6})|
- :((:[0-9a-f]{1,4}){1,7}|:)|
- fe80:(:[0-9a-f]{0,4}){0,4}%[0-9a-z]{1,}|
- ::(ffff(:0{1,4}){0,1}:){0,1}
- ((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}
- (25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|
- ([0-9a-f]{1,4}:){1,4}:
- ((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}
- (25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/ix
- when /^:both$/
- is_valid_ip?(ip, :ipv4) || is_valid_ip?(ip, :ipv6)
- end ? true : false
-
- 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
- def self.is_valid_port?(port)
- valid = false
- valid = true if port.to_i > 0 && port.to_i < 2**16
- valid
- end
-
- # Checks if string is a valid domain name
- # @param [String] domain string for testing
- # @return [Boolean] If the string is a valid domain name
- # @note Only validates the string format. It does not check for a valid TLD since ICANN's list of TLD's is not static.
- def self.is_valid_domain?(domain)
- return false unless is_non_empty_string?(domain)
- return true if domain =~ /^[0-9a-z-]+(\.[0-9a-z-]+)*(\.[a-z]{2,}).?$/i
- false
- end
-
- # Check for valid browser details characters
- # @param [String] str String for testing
- # @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 unless is_non_empty_string?(str)
- not (str =~ /[^\w\d\s()-.,;:_\/!\302\256]/).nil?
- end
-
- # Check for valid base details characters
- # @param [String] str String for testing
- # @return [Boolean] If the string has only valid base characters
- # @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 unless is_non_empty_string?(str)
- (str =~ /[^\302\256[:print:]]/).nil?
- end
-
- # Verify the yes and no is valid
- # @param [String] str String for testing
- # @return [Boolean] If the string is either 'yes' or 'no'
- def self.is_valid_yes_no?(str)
- return false if has_non_printable_char?(str)
- return false if str !~ /\A(Yes|No)\z/i
- true
- end
-
-end
end
diff --git a/core/filters/browser.rb b/core/filters/browser.rb
index 2ecc37f2b2..5b019af40a 100644
--- a/core/filters/browser.rb
+++ b/core/filters/browser.rb
@@ -4,148 +4,159 @@
# See the file 'doc/COPYING' for copying permission
#
module BeEF
-module Filters
-
- # Check the browser type value - for example, 'FF'
- # @param [String] str String for testing
- # @return [Boolean] If the string has valid browser name characters
- def self.is_valid_browsername?(str)
- return false unless is_non_empty_string?(str)
- return false if str.length > 2
- return false if has_non_printable_char?(str)
- true
- end
+ module Filters
+ # Check the browser type value - for example, 'FF'
+ # @param [String] str String for testing
+ # @return [Boolean] If the string has valid browser name characters
+ def self.is_valid_browsername?(str)
+ return false unless is_non_empty_string?(str)
+ return false if str.length > 2
+ return false if has_non_printable_char?(str)
- # Check the Operating System name value - for example, 'Windows XP'
- # @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 unless is_non_empty_string?(str)
- return false if has_non_printable_char?(str)
- return false if str.length < 2
- true
- end
+ true
+ end
- # Check the Hardware name value - for example, 'iPhone'
- # @param [String] str String for testing
- # @return [Boolean] If the string has valid Hardware name characters
- def self.is_valid_hwname?(str)
- return false unless is_non_empty_string?(str)
- return false if has_non_printable_char?(str)
- return false if str.length < 2
- true
- end
+ # Check the Operating System name value - for example, 'Windows XP'
+ # @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 unless is_non_empty_string?(str)
+ return false if has_non_printable_char?(str)
+ return false if str.length < 2
- # Verify the browser version string is valid
- # @param [String] str String for testing
- # @return [Boolean] If the string has valid browser version characters
- def self.is_valid_browserversion?(str)
- return false unless is_non_empty_string?(str)
- return false if has_non_printable_char?(str)
- return true if str.eql? "UNKNOWN"
- return true if str.eql? "ALL"
- return false if not nums_only?(str) and not is_valid_float?(str)
- return false if str.length > 20
- true
- end
+ true
+ end
- # Verify the os version string is valid
- # @param [String] str String for testing
- # @return [Boolean] If the string has valid os version characters
- def self.is_valid_osversion?(str)
- return false unless is_non_empty_string?(str)
- return false if has_non_printable_char?(str)
- return true if str.eql? "UNKNOWN"
- return true if str.eql? "ALL"
- return false unless BeEF::Filters::only?("a-zA-Z0-9.<=> ", str)
- return false if str.length > 20
- true
- end
+ # Check the Hardware name value - for example, 'iPhone'
+ # @param [String] str String for testing
+ # @return [Boolean] If the string has valid Hardware name characters
+ def self.is_valid_hwname?(str)
+ return false unless is_non_empty_string?(str)
+ return false if has_non_printable_char?(str)
+ return false if str.length < 2
- # Verify the browser/UA string is valid
- # @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 unless is_non_empty_string?(str)
- return false if has_non_printable_char?(str)
- return false if str.length > 300
- true
- end
-
- # Verify the cookies are valid
- # @param [String] str String for testing
- # @return [Boolean] If the string has valid cookie characters
- def self.is_valid_cookies?(str)
- return false unless is_non_empty_string?(str)
- return false if has_non_printable_char?(str)
- return false if str.length > 2000
- true
- end
+ true
+ end
- # Verify the system platform is valid
- # @param [String] str String for testing
- # @return [Boolean] If the string has valid system platform characters
- def self.is_valid_system_platform?(str)
- return false unless is_non_empty_string?(str)
- return false if has_non_printable_char?(str)
- return false if str.length > 200
- true
- end
+ # Verify the browser version string is valid
+ # @param [String] str String for testing
+ # @return [Boolean] If the string has valid browser version characters
+ def self.is_valid_browserversion?(str)
+ return false unless is_non_empty_string?(str)
+ return false if has_non_printable_char?(str)
+ return true if str.eql? 'UNKNOWN'
+ return true if str.eql? 'ALL'
+ return false if !nums_only?(str) and !is_valid_float?(str)
+ return false if str.length > 20
- # Verify the date stamp is valid
- # @param [String] str String for testing
- # @return [Boolean] If the string has valid date stamp characters
- def self.is_valid_date_stamp?(str)
- return false unless is_non_empty_string?(str)
- return false if has_non_printable_char?(str)
- return false if str.length > 200
- true
- end
+ true
+ end
- # Verify the CPU type string is valid
- # @param [String] str String for testing
- # @return [Boolean] If the string has valid CPU type characters
- def self.is_valid_cpu?(str)
- return false unless is_non_empty_string?(str)
- return false if has_non_printable_char?(str)
- return false if str.length > 200
- true
- end
+ # Verify the os version string is valid
+ # @param [String] str String for testing
+ # @return [Boolean] If the string has valid os version characters
+ def self.is_valid_osversion?(str)
+ return false unless is_non_empty_string?(str)
+ return false if has_non_printable_char?(str)
+ return true if str.eql? 'UNKNOWN'
+ return true if str.eql? 'ALL'
+ return false unless BeEF::Filters.only?('a-zA-Z0-9.<=> ', str)
+ return false if str.length > 20
- # Verify the memory string is valid
- # @param [String] str String for testing
- # @return [Boolean] If the string has valid memory type characters
- def self.is_valid_memory?(str)
- return false unless is_non_empty_string?(str)
- return false if has_non_printable_char?(str)
- return false if str.length > 200
- true
- end
+ true
+ end
- # Verify the GPU type string is valid
- # @param [String] str String for testing
- # @return [Boolean] If the string has valid GPU type characters
- def self.is_valid_gpu?(str)
- return false unless is_non_empty_string?(str)
- return false if has_non_printable_char?(str)
- return false if str.length > 200
- true
- end
+ # Verify the browser/UA string is valid
+ # @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 unless is_non_empty_string?(str)
+ return false if has_non_printable_char?(str)
+ return false if str.length > 300
- # Verify the browser_plugins string is valid
- # @param [String] str String for testing
- # @return [Boolean] If the string has valid browser plugin characters
- # @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 false unless is_non_empty_string?(str)
- return false if str.length > 1000
- if str.encoding === Encoding.find('UTF-8')
- return (str =~ /[^\w\d\s()-.,';_!\302\256]/u).nil?
- else
- return (str =~ /[^\w\d\s()-.,';_!\302\256]/n).nil?
+ true
end
- end
-end
+ # Verify the cookies are valid
+ # @param [String] str String for testing
+ # @return [Boolean] If the string has valid cookie characters
+ def self.is_valid_cookies?(str)
+ return false unless is_non_empty_string?(str)
+ return false if has_non_printable_char?(str)
+ return false if str.length > 2000
+
+ true
+ end
+
+ # Verify the system platform is valid
+ # @param [String] str String for testing
+ # @return [Boolean] If the string has valid system platform characters
+ def self.is_valid_system_platform?(str)
+ return false unless is_non_empty_string?(str)
+ return false if has_non_printable_char?(str)
+ return false if str.length > 200
+
+ true
+ end
+
+ # Verify the date stamp is valid
+ # @param [String] str String for testing
+ # @return [Boolean] If the string has valid date stamp characters
+ def self.is_valid_date_stamp?(str)
+ return false unless is_non_empty_string?(str)
+ return false if has_non_printable_char?(str)
+ return false if str.length > 200
+
+ true
+ end
+
+ # Verify the CPU type string is valid
+ # @param [String] str String for testing
+ # @return [Boolean] If the string has valid CPU type characters
+ def self.is_valid_cpu?(str)
+ return false unless is_non_empty_string?(str)
+ return false if has_non_printable_char?(str)
+ return false if str.length > 200
+
+ true
+ end
+
+ # Verify the memory string is valid
+ # @param [String] str String for testing
+ # @return [Boolean] If the string has valid memory type characters
+ def self.is_valid_memory?(str)
+ return false unless is_non_empty_string?(str)
+ return false if has_non_printable_char?(str)
+ return false if str.length > 200
+
+ true
+ end
+
+ # Verify the GPU type string is valid
+ # @param [String] str String for testing
+ # @return [Boolean] If the string has valid GPU type characters
+ def self.is_valid_gpu?(str)
+ return false unless is_non_empty_string?(str)
+ return false if has_non_printable_char?(str)
+ return false if str.length > 200
+
+ true
+ end
+
+ # Verify the browser_plugins string is valid
+ # @param [String] str String for testing
+ # @return [Boolean] If the string has valid browser plugin characters
+ # @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 false unless is_non_empty_string?(str)
+ return false if str.length > 1000
+
+ if str.encoding === Encoding.find('UTF-8')
+ (str =~ /[^\w\d\s()-.,';_!\302\256]/u).nil?
+ else
+ (str =~ /[^\w\d\s()-.,';_!\302\256]/n).nil?
+ end
+ end
+ end
end
diff --git a/core/filters/command.rb b/core/filters/command.rb
index 7607a0fdf0..65d2f5880c 100644
--- a/core/filters/command.rb
+++ b/core/filters/command.rb
@@ -4,64 +4,68 @@
# See the file 'doc/COPYING' for copying permission
#
module BeEF
-module Filters
-
- # Check if the string is a valid path from a HTTP request
- # @param [String] str String for testing
- # @return [Boolean] If the string has valid path characters
- def self.is_valid_path_info?(str)
- return false if str.nil?
- return false unless str.is_a? String
- return false if has_non_printable_char?(str)
- true
- end
+ module Filters
+ # Check if the string is a valid path from a HTTP request
+ # @param [String] str String for testing
+ # @return [Boolean] If the string has valid path characters
+ def self.is_valid_path_info?(str)
+ return false if str.nil?
+ return false unless str.is_a? String
+ return false if has_non_printable_char?(str)
- # Check if the session id valid
- # @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 unless is_non_empty_string?(str)
- return false unless has_valid_key_chars?(str)
- true
- end
+ true
+ end
- # Check if valid command module datastore key
- # @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 unless is_non_empty_string?(str)
- return false unless has_valid_key_chars?(str)
- true
- end
+ # Check if the session id valid
+ # @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 unless is_non_empty_string?(str)
+ return false unless has_valid_key_chars?(str)
- # Check if valid command module datastore value
- # @param [String] str String for testing
- # @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 unless has_valid_base_chars?(str)
- true
- end
+ true
+ end
- # Check for word and some punc chars
- # @param [String] str String for testing
- # @return [Boolean] If the string has valid key characters
- def self.has_valid_key_chars?(str)
- return false unless is_non_empty_string?(str)
- return false unless has_valid_base_chars?(str)
- true
- end
+ # Check if valid command module datastore key
+ # @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 unless is_non_empty_string?(str)
+ return false unless has_valid_key_chars?(str)
- # Check for word and underscore chars
- # @param [String] str String for testing
- # @return [Boolean] If the sting has valid param characters
- def self.has_valid_param_chars?(str)
- return false if str.nil?
- return false unless str.is_a? String
- return false if str.empty?
- return false unless (str =~ /[^\w_\:]/).nil?
- true
- end
+ true
+ end
-end
+ # Check if valid command module datastore value
+ # @param [String] str String for testing
+ # @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 unless has_valid_base_chars?(str)
+
+ true
+ end
+
+ # Check for word and some punc chars
+ # @param [String] str String for testing
+ # @return [Boolean] If the string has valid key characters
+ def self.has_valid_key_chars?(str)
+ return false unless is_non_empty_string?(str)
+ return false unless has_valid_base_chars?(str)
+
+ true
+ end
+
+ # Check for word and underscore chars
+ # @param [String] str String for testing
+ # @return [Boolean] If the sting has valid param characters
+ def self.has_valid_param_chars?(str)
+ return false if str.nil?
+ return false unless str.is_a? String
+ return false if str.empty?
+ return false unless (str =~ /[^\w_:]/).nil?
+
+ true
+ end
+ end
end
diff --git a/core/filters/http.rb b/core/filters/http.rb
index 4b049bf583..db3613a4a9 100644
--- a/core/filters/http.rb
+++ b/core/filters/http.rb
@@ -3,59 +3,60 @@
# Browser Exploitation Framework (BeEF) - http://beefproject.com
# See the file 'doc/COPYING' for copying permission
#
-module BeEF
-module Filters
-
- # Verify the hostname string is valid
- # @param [String] str String for testing
- # @return [Boolean] If the string is a valid hostname
- def self.is_valid_hostname?(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?
- true
+module BeEF
+ module Filters
+ # Verify the hostname string is valid
+ # @param [String] str String for testing
+ # @return [Boolean] If the string is a valid hostname
+ def self.is_valid_hostname?(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?
+
+ true
+ end
+
+ def self.is_valid_verb?(verb)
+ %w[HEAD GET POST OPTIONS PUT DELETE].each { |v| return true if verb.eql? v }
+ false
+ end
+
+ def self.is_valid_url?(uri)
+ return true unless uri.nil?
+
+ # OPTIONS * is not yet supported
+ # return true if uri.eql? "*"
+ # TODO : CHECK THE normalize_path method and include it somewhere (maybe here)
+ # return true if uri.eql? self.normalize_path(uri)
+ false
+ end
+
+ def self.is_valid_http_version?(version)
+ # from browsers the http version contains a space at the end ("HTTP/1.0\r")
+ version.gsub!(/\r+/, '')
+ ['HTTP/1.0', 'HTTP/1.1'].each { |v| return true if version.eql? v }
+ false
+ end
+
+ def self.is_valid_host_str?(host_str)
+ # from browsers the host header contains a space at the end
+ host_str.gsub!(/\r+/, '')
+ return true if 'Host:'.eql?(host_str)
+
+ false
+ end
+
+ def normalize_path(path)
+ print_error "abnormal path `#{path}'" if path[0] != '/'
+ ret = path.dup
+
+ ret.gsub!(%r{/+}o, '/') # // => /
+ while ret.sub!(%r{/\.(?:/|\Z)}, '/'); end # /. => /
+ while ret.sub!(%r{/(?!\.\./)[^/]+/\.\.(?:/|\Z)}, '/'); end # /foo/.. => /foo
+
+ print_error "abnormal path `#{path}'" if %r{/\.\.(/|\Z)} =~ ret
+ ret
+ end
end
-
- def self.is_valid_verb?(verb)
- ["HEAD", "GET", "POST", "OPTIONS", "PUT", "DELETE"].each {|v| return true if verb.eql? v }
- false
- end
-
- def self.is_valid_url?(uri)
- return true if !uri.nil?
- # OPTIONS * is not yet supported
- #return true if uri.eql? "*"
- # TODO : CHECK THE normalize_path method and include it somewhere (maybe here)
- #return true if uri.eql? self.normalize_path(uri)
- false
- end
-
- def self.is_valid_http_version?(version)
- # from browsers the http version contains a space at the end ("HTTP/1.0\r")
- version.gsub!(/[\r]+/,"")
- ["HTTP/1.0", "HTTP/1.1"].each {|v| return true if version.eql? v }
- false
- end
-
- def self.is_valid_host_str?(host_str)
- # from browsers the host header contains a space at the end
- host_str.gsub!(/[\r]+/,"")
- return true if "Host:".eql?(host_str)
- false
- end
-
- def normalize_path(path)
- print_error "abnormal path `#{path}'" if path[0] != ?/
- ret = path.dup
-
- ret.gsub!(%r{/+}o, '/') # // => /
- while ret.sub!(%r'/\.(?:/|\Z)', '/'); end # /. => /
- while ret.sub!(%r'/(?!\.\./)[^/]+/\.\.(?:/|\Z)', '/'); end # /foo/.. => /foo
-
- print_error "abnormal path `#{path}'" if %r{/\.\.(/|\Z)} =~ ret
- ret
- end
-
-end
end
diff --git a/core/filters/page.rb b/core/filters/page.rb
index 9aa594adbd..e6b9986d2a 100644
--- a/core/filters/page.rb
+++ b/core/filters/page.rb
@@ -4,27 +4,27 @@
# See the file 'doc/COPYING' for copying permission
#
module BeEF
-module Filters
-
- # Verify the page title string is valid
- # @param [String] str String for testing
- # @return [Boolean] If the string is a valid page title
- def self.is_valid_pagetitle?(str)
- 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
- end
+ module Filters
+ # Verify the page title string is valid
+ # @param [String] str String for testing
+ # @return [Boolean] If the string is a valid page title
+ def self.is_valid_pagetitle?(str)
+ 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
+ end
- # Verify the page referrer string is valid
- # @param [String] str String for testing
- # @return [Boolean] If the string is a valid referrer
- def self.is_valid_pagereferrer?(str)
- return false unless str.is_a? String
- return false if has_non_printable_char?(str)
- return false if str.length > 350
- true
+ # Verify the page referrer string is valid
+ # @param [String] str String for testing
+ # @return [Boolean] If the string is a valid referrer
+ def self.is_valid_pagereferrer?(str)
+ return false unless str.is_a? String
+ return false if has_non_printable_char?(str)
+ return false if str.length > 350
+
+ true
+ end
end
-
-end
end
diff --git a/core/hbmanager.rb b/core/hbmanager.rb
index dab1a6ac15..09f194708e 100644
--- a/core/hbmanager.rb
+++ b/core/hbmanager.rb
@@ -5,12 +5,11 @@
#
module BeEF
module HBManager
-
# Get hooked browser by session id
# @param [String] sid hooked browser session id string
# @return [BeEF::Core::Models::HookedBrowser] returns the associated Hooked Browser
def self.get_by_session(sid)
- BeEF::Core::Models::HookedBrowser.where(:session => sid).first
+ BeEF::Core::Models::HookedBrowser.where(session: sid).first
end
# Get hooked browser by id
@@ -19,6 +18,5 @@ def self.get_by_session(sid)
def self.get_by_id(id)
BeEF::Core::Models::HookedBrowser.find(id)
end
-
end
end
diff --git a/core/logger.rb b/core/logger.rb
index d2ca88d7ce..487244fac2 100644
--- a/core/logger.rb
+++ b/core/logger.rb
@@ -12,8 +12,8 @@ class << self
attr_writer :logger
def logger
- @logger ||= Logger.new("#{$home_dir}/beef.log").tap do |log|
- log.progname = self.name
+ @logger ||= Logger.new("#{$home_dir}/beef.log").tap do |log|
+ log.progname = name
log.level = Logger::WARN
end
end
diff --git a/core/main/ar-migrations/001_create_command_modules.rb b/core/main/ar-migrations/001_create_command_modules.rb
index d43259b894..646554b772 100644
--- a/core/main/ar-migrations/001_create_command_modules.rb
+++ b/core/main/ar-migrations/001_create_command_modules.rb
@@ -1,12 +1,8 @@
class CreateCommandModules < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :command_modules do |t|
- t.text :name
- t.text :path
- end
-
- end
-
+ def change
+ create_table :command_modules do |t|
+ t.text :name
+ t.text :path
+ end
+ end
end
diff --git a/core/main/ar-migrations/002_create_hooked_browsers.rb b/core/main/ar-migrations/002_create_hooked_browsers.rb
index c1e932888c..4fb6aaf0a7 100644
--- a/core/main/ar-migrations/002_create_hooked_browsers.rb
+++ b/core/main/ar-migrations/002_create_hooked_browsers.rb
@@ -1,19 +1,15 @@
class CreateHookedBrowsers < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :hooked_browsers do |t|
- t.text :session
- t.text :ip
- t.text :firstseen
- t.text :lastseen
- t.text :httpheaders
- t.text :domain
- t.integer :port
- t.integer :count
- t.boolean :is_proxy
- end
-
- end
-
+ def change
+ create_table :hooked_browsers do |t|
+ t.text :session
+ t.text :ip
+ t.text :firstseen
+ t.text :lastseen
+ t.text :httpheaders
+ t.text :domain
+ t.integer :port
+ t.integer :count
+ t.boolean :is_proxy
+ end
+ end
end
diff --git a/core/main/ar-migrations/003_create_logs.rb b/core/main/ar-migrations/003_create_logs.rb
index e3614718ae..1a83c0d614 100644
--- a/core/main/ar-migrations/003_create_logs.rb
+++ b/core/main/ar-migrations/003_create_logs.rb
@@ -1,14 +1,10 @@
class CreateLogs < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :logs do |t|
- t.text :logtype
- t.text :event
- t.datetime :date
- t.references :hooked_browser
- end
-
- end
-
+ def change
+ create_table :logs do |t|
+ t.text :logtype
+ t.text :event
+ t.datetime :date
+ t.references :hooked_browser
+ end
+ end
end
diff --git a/core/main/ar-migrations/004_create_commands.rb b/core/main/ar-migrations/004_create_commands.rb
index 20c9d632ac..fe8cad65c9 100644
--- a/core/main/ar-migrations/004_create_commands.rb
+++ b/core/main/ar-migrations/004_create_commands.rb
@@ -1,16 +1,12 @@
class CreateCommands < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :commands do |t|
- t.references :command_module
- t.references :hooked_browser
- t.text :data
- t.datetime :creationdate
- t.text :label
- t.boolean :instructions_sent, default: false
- end
-
- end
-
+ def change
+ create_table :commands do |t|
+ t.references :command_module
+ t.references :hooked_browser
+ t.text :data
+ t.datetime :creationdate
+ t.text :label
+ t.boolean :instructions_sent, default: false
+ end
+ end
end
diff --git a/core/main/ar-migrations/005_create_results.rb b/core/main/ar-migrations/005_create_results.rb
index 97d1c6fad7..bd79f9e507 100644
--- a/core/main/ar-migrations/005_create_results.rb
+++ b/core/main/ar-migrations/005_create_results.rb
@@ -1,15 +1,11 @@
class CreateResults < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :results do |t|
- t.references :command
- t.references :hooked_browser
- t.datetime :date
- t.integer :status
- t.text :data
- end
-
- end
-
+ def change
+ create_table :results do |t|
+ t.references :command
+ t.references :hooked_browser
+ t.datetime :date
+ t.integer :status
+ t.text :data
+ end
+ end
end
diff --git a/core/main/ar-migrations/006_create_option_caches.rb b/core/main/ar-migrations/006_create_option_caches.rb
index 6f605663ad..02d871d66e 100644
--- a/core/main/ar-migrations/006_create_option_caches.rb
+++ b/core/main/ar-migrations/006_create_option_caches.rb
@@ -1,12 +1,8 @@
class CreateOptionCaches < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :option_caches do |t|
- t.text :name
- t.text :value
- end
-
- end
-
+ def change
+ create_table :option_caches do |t|
+ t.text :name
+ t.text :value
+ end
+ end
end
diff --git a/core/main/ar-migrations/007_create_browser_details.rb b/core/main/ar-migrations/007_create_browser_details.rb
index 5404453d26..8aa0512778 100644
--- a/core/main/ar-migrations/007_create_browser_details.rb
+++ b/core/main/ar-migrations/007_create_browser_details.rb
@@ -1,13 +1,9 @@
class CreateBrowserDetails < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :browser_details do |t|
- t.text :session_id
- t.text :detail_key
- t.text :detail_value
- end
-
- end
-
+ def change
+ create_table :browser_details do |t|
+ t.text :session_id
+ t.text :detail_key
+ t.text :detail_value
+ end
+ end
end
diff --git a/core/main/ar-migrations/008_create_executions.rb b/core/main/ar-migrations/008_create_executions.rb
index deeb4206e6..b209e444db 100644
--- a/core/main/ar-migrations/008_create_executions.rb
+++ b/core/main/ar-migrations/008_create_executions.rb
@@ -1,18 +1,14 @@
class CreateExecutions < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :executions do |t|
- t.text :session_id
- t.integer :mod_count
- t.integer :mod_successful
- t.text :mod_body
- t.text :exec_time
- t.text :rule_token
- t.boolean :is_sent
- t.integer :rule_id
- end
-
- end
-
+ def change
+ create_table :executions do |t|
+ t.text :session_id
+ t.integer :mod_count
+ t.integer :mod_successful
+ t.text :mod_body
+ t.text :exec_time
+ t.text :rule_token
+ t.boolean :is_sent
+ t.integer :rule_id
+ end
+ end
end
diff --git a/core/main/ar-migrations/009_create_rules.rb b/core/main/ar-migrations/009_create_rules.rb
index de53677912..80cf2f79ab 100644
--- a/core/main/ar-migrations/009_create_rules.rb
+++ b/core/main/ar-migrations/009_create_rules.rb
@@ -1,20 +1,16 @@
class CreateRules < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :rules do |t|
- t.text :name
- t.text :author
- t.text :browser
- t.text :browser_version
- t.text :os
- t.text :os_version
- t.text :modules
- t.text :execution_order
- t.text :execution_delay
- t.text :chain_mode
- end
-
- end
-
+ def change
+ create_table :rules do |t|
+ t.text :name
+ t.text :author
+ t.text :browser
+ t.text :browser_version
+ t.text :os
+ t.text :os_version
+ t.text :modules
+ t.text :execution_order
+ t.text :execution_delay
+ t.text :chain_mode
+ end
+ end
end
diff --git a/core/main/ar-migrations/010_create_interceptor.rb b/core/main/ar-migrations/010_create_interceptor.rb
index 1dbb6d6b75..2edca9d08b 100644
--- a/core/main/ar-migrations/010_create_interceptor.rb
+++ b/core/main/ar-migrations/010_create_interceptor.rb
@@ -1,12 +1,8 @@
class CreateInterceptor < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :interceptors do |t|
- t.text :ip
- t.text :post_data
- end
-
- end
-
+ def change
+ create_table :interceptors do |t|
+ t.text :ip
+ t.text :post_data
+ end
+ end
end
diff --git a/core/main/ar-migrations/011_create_web_cloner.rb b/core/main/ar-migrations/011_create_web_cloner.rb
index 38c351ad6d..1b7457c6ef 100644
--- a/core/main/ar-migrations/011_create_web_cloner.rb
+++ b/core/main/ar-migrations/011_create_web_cloner.rb
@@ -1,12 +1,8 @@
class CreateWebCloner < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :web_cloners do |t|
- t.text :uri
- t.text :mount
- end
-
- end
-
+ def change
+ create_table :web_cloners do |t|
+ t.text :uri
+ t.text :mount
+ end
+ end
end
diff --git a/core/main/ar-migrations/012_create_mass_mailer.rb b/core/main/ar-migrations/012_create_mass_mailer.rb
index d4816f186a..5225639e19 100644
--- a/core/main/ar-migrations/012_create_mass_mailer.rb
+++ b/core/main/ar-migrations/012_create_mass_mailer.rb
@@ -1,11 +1,7 @@
class CreateMassMailer < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :mass_mailers do |t|
- #todo fields
- end
-
- end
-
+ def change
+ create_table :mass_mailers do |t|
+ # TODO: fields
+ end
+ end
end
diff --git a/core/main/ar-migrations/013_create_network_host.rb b/core/main/ar-migrations/013_create_network_host.rb
index 3c977b2476..4381042b7e 100644
--- a/core/main/ar-migrations/013_create_network_host.rb
+++ b/core/main/ar-migrations/013_create_network_host.rb
@@ -1,17 +1,13 @@
class CreateNetworkHost < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :network_hosts do |t|
- t.references :hooked_browser
- t.text :ip
- t.text :hostname
- t.text :ntype
- t.text :os
- t.text :mac
- t.text :lastseen
- end
-
- end
-
+ def change
+ create_table :network_hosts do |t|
+ t.references :hooked_browser
+ t.text :ip
+ t.text :hostname
+ t.text :ntype
+ t.text :os
+ t.text :mac
+ t.text :lastseen
+ end
+ end
end
diff --git a/core/main/ar-migrations/014_create_network_service.rb b/core/main/ar-migrations/014_create_network_service.rb
index 1f521a19e0..abe1d57654 100644
--- a/core/main/ar-migrations/014_create_network_service.rb
+++ b/core/main/ar-migrations/014_create_network_service.rb
@@ -1,15 +1,11 @@
class CreateNetworkService < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :network_services do |t|
- t.references :hooked_browser
- t.text :proto
- t.text :ip
- t.text :port
- t.text :ntype
- end
-
- end
-
+ def change
+ create_table :network_services do |t|
+ t.references :hooked_browser
+ t.text :proto
+ t.text :ip
+ t.text :port
+ t.text :ntype
+ end
+ end
end
diff --git a/core/main/ar-migrations/015_create_http.rb b/core/main/ar-migrations/015_create_http.rb
index 184f8844bf..aa3823f8b9 100644
--- a/core/main/ar-migrations/015_create_http.rb
+++ b/core/main/ar-migrations/015_create_http.rb
@@ -1,44 +1,40 @@
class CreateHttp < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :https do |t|
- t.text :hooked_browser_id
- # The http request to perform. In clear text.
- t.text :request
- # Boolean value as string to say whether cross-domain requests are allowed
- t.boolean :allow_cross_domain, :default => true
- # The http response body received. In clear text.
- t.text :response_data
- # The http response code. Useful to handle cases like 404, 500, 302, ...
- t.integer :response_status_code
- # The http response code. Human-readable code: success, error, ecc..
- t.text :response_status_text
- # The port status. closed, open or not http
- t.text :response_port_status
- # The XHR Http response raw headers
- t.text :response_headers
- # The http response method. GET or POST.
- t.text :method
- # The content length for the request.
- t.text :content_length, :default => 0
- # The request protocol/scheme (http/https)
- t.text :proto
- # The domain on which perform the request.
- t.text :domain
- # The port on which perform the request.
- t.text :port
- # Boolean value to say if the request was cross-domain
- t.text :has_ran, :default => "waiting"
- # The path of the request.
- # Example: /secret.html
- t.text :path
- # The date at which the http response has been saved.
- t.datetime :response_date
- # The date at which the http request has been saved.
- t.datetime :request_date
- end
-
- end
-
+ def change
+ create_table :https do |t|
+ t.text :hooked_browser_id
+ # The http request to perform. In clear text.
+ t.text :request
+ # Boolean value as string to say whether cross-domain requests are allowed
+ t.boolean :allow_cross_domain, default: true
+ # The http response body received. In clear text.
+ t.text :response_data
+ # The http response code. Useful to handle cases like 404, 500, 302, ...
+ t.integer :response_status_code
+ # The http response code. Human-readable code: success, error, ecc..
+ t.text :response_status_text
+ # The port status. closed, open or not http
+ t.text :response_port_status
+ # The XHR Http response raw headers
+ t.text :response_headers
+ # The http response method. GET or POST.
+ t.text :method
+ # The content length for the request.
+ t.text :content_length, default: 0
+ # The request protocol/scheme (http/https)
+ t.text :proto
+ # The domain on which perform the request.
+ t.text :domain
+ # The port on which perform the request.
+ t.text :port
+ # Boolean value to say if the request was cross-domain
+ t.text :has_ran, default: 'waiting'
+ # The path of the request.
+ # Example: /secret.html
+ t.text :path
+ # The date at which the http response has been saved.
+ t.datetime :response_date
+ # The date at which the http request has been saved.
+ t.datetime :request_date
+ end
+ end
end
diff --git a/core/main/ar-migrations/016_create_rtc_status.rb b/core/main/ar-migrations/016_create_rtc_status.rb
index dae86650e7..f80bd18f69 100644
--- a/core/main/ar-migrations/016_create_rtc_status.rb
+++ b/core/main/ar-migrations/016_create_rtc_status.rb
@@ -1,13 +1,9 @@
class CreateRtcStatus < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :rtc_statuss do |t|
- t.references :hooked_browser
- t.integer :target_hooked_browser_id
- t.text :status
- end
-
- end
-
+ def change
+ create_table :rtc_statuss do |t|
+ t.references :hooked_browser
+ t.integer :target_hooked_browser_id
+ t.text :status
+ end
+ end
end
diff --git a/core/main/ar-migrations/017_create_rtc_manage.rb b/core/main/ar-migrations/017_create_rtc_manage.rb
index 16239ad7ef..3a1d001b4b 100644
--- a/core/main/ar-migrations/017_create_rtc_manage.rb
+++ b/core/main/ar-migrations/017_create_rtc_manage.rb
@@ -1,13 +1,9 @@
class CreateRtcManage < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :rtc_manages do |t|
- t.references :hooked_browser
- t.text :message
- t.text :has_sent, default: "waiting"
- end
-
- end
-
+ def change
+ create_table :rtc_manages do |t|
+ t.references :hooked_browser
+ t.text :message
+ t.text :has_sent, default: 'waiting'
+ end
+ end
end
diff --git a/core/main/ar-migrations/018_create_rtc_signal.rb b/core/main/ar-migrations/018_create_rtc_signal.rb
index 5d1b0b7cc6..4ee451dd41 100644
--- a/core/main/ar-migrations/018_create_rtc_signal.rb
+++ b/core/main/ar-migrations/018_create_rtc_signal.rb
@@ -1,14 +1,10 @@
class CreateRtcSignal < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :rtc_signals do |t|
- t.references :hooked_browser
- t.integer :target_hooked_browser_id
- t.text :signal
- t.text :has_sent, default: "waiting"
- end
-
- end
-
+ def change
+ create_table :rtc_signals do |t|
+ t.references :hooked_browser
+ t.integer :target_hooked_browser_id
+ t.text :signal
+ t.text :has_sent, default: 'waiting'
+ end
+ end
end
diff --git a/core/main/ar-migrations/019_create_rtc_module_status.rb b/core/main/ar-migrations/019_create_rtc_module_status.rb
index abeb941c37..9638643da2 100644
--- a/core/main/ar-migrations/019_create_rtc_module_status.rb
+++ b/core/main/ar-migrations/019_create_rtc_module_status.rb
@@ -1,14 +1,10 @@
class CreateRtcModuleStatus < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :rtc_module_statuss do |t|
- t.references :hooked_browser
- t.references :command_module
- t.integer :target_hooked_browser_id
- t.text :status
- end
-
- end
-
+ def change
+ create_table :rtc_module_statuss do |t|
+ t.references :hooked_browser
+ t.references :command_module
+ t.integer :target_hooked_browser_id
+ t.text :status
+ end
+ end
end
diff --git a/core/main/ar-migrations/020_create_xssrays_detail.rb b/core/main/ar-migrations/020_create_xssrays_detail.rb
index 22900b5018..e8f065d58f 100644
--- a/core/main/ar-migrations/020_create_xssrays_detail.rb
+++ b/core/main/ar-migrations/020_create_xssrays_detail.rb
@@ -1,14 +1,10 @@
class CreateXssraysDetail < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :xssraysdetails do |t|
- t.references :hooked_browser
- t.text :vector_name
- t.text :vector_method
- t.text :vector_poc
- end
-
- end
-
+ def change
+ create_table :xssraysdetails do |t|
+ t.references :hooked_browser
+ t.text :vector_name
+ t.text :vector_method
+ t.text :vector_poc
+ end
+ end
end
diff --git a/core/main/ar-migrations/021_create_dns_rule.rb b/core/main/ar-migrations/021_create_dns_rule.rb
index bcc877b36a..daf1e274b2 100644
--- a/core/main/ar-migrations/021_create_dns_rule.rb
+++ b/core/main/ar-migrations/021_create_dns_rule.rb
@@ -1,14 +1,10 @@
class CreateDnsRule < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :dns_rules do |t|
- t.text :pattern
- t.text :resource
- t.text :response
- t.text :callback
- end
-
- end
-
+ def change
+ create_table :dns_rules do |t|
+ t.text :pattern
+ t.text :resource
+ t.text :response
+ t.text :callback
+ end
+ end
end
diff --git a/core/main/ar-migrations/022_create_ipec_exploit.rb b/core/main/ar-migrations/022_create_ipec_exploit.rb
index 228d1afc0b..6bf6ed46aa 100644
--- a/core/main/ar-migrations/022_create_ipec_exploit.rb
+++ b/core/main/ar-migrations/022_create_ipec_exploit.rb
@@ -1,13 +1,9 @@
class CreateIpecExploit < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :ipec_exploits do |t|
- t.text :name
- t.text :protocol
- t.text :os
- end
-
- end
-
+ def change
+ create_table :ipec_exploits do |t|
+ t.text :name
+ t.text :protocol
+ t.text :os
+ end
+ end
end
diff --git a/core/main/ar-migrations/023_create_ipec_exploit_run.rb b/core/main/ar-migrations/023_create_ipec_exploit_run.rb
index 7b7526665c..d48c8eabf7 100644
--- a/core/main/ar-migrations/023_create_ipec_exploit_run.rb
+++ b/core/main/ar-migrations/023_create_ipec_exploit_run.rb
@@ -1,13 +1,9 @@
class CreateIpecExploitRun < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :ipec_exploit_runs do |t|
- t.boolean :launched
- t.text :http_headers
- t.text :junk_size
- end
-
- end
-
+ def change
+ create_table :ipec_exploit_runs do |t|
+ t.boolean :launched
+ t.text :http_headers
+ t.text :junk_size
+ end
+ end
end
diff --git a/core/main/ar-migrations/024_create_autoloader.rb b/core/main/ar-migrations/024_create_autoloader.rb
index 4ebe1197af..a88e06d8f1 100644
--- a/core/main/ar-migrations/024_create_autoloader.rb
+++ b/core/main/ar-migrations/024_create_autoloader.rb
@@ -1,12 +1,8 @@
class CreateAutoloader < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :autoloaders do |t|
- t.references :command
- t.boolean :in_use
- end
-
- end
-
+ def change
+ create_table :autoloaders do |t|
+ t.references :command
+ t.boolean :in_use
+ end
+ end
end
diff --git a/core/main/ar-migrations/025_create_xssrays_scan.rb b/core/main/ar-migrations/025_create_xssrays_scan.rb
index 67122a5f9a..04bf642667 100644
--- a/core/main/ar-migrations/025_create_xssrays_scan.rb
+++ b/core/main/ar-migrations/025_create_xssrays_scan.rb
@@ -1,18 +1,14 @@
class CreateXssraysScan < ActiveRecord::Migration[6.0]
-
- def change
-
- create_table :xssraysscans do |t|
- t.references :hooked_browser
- t.datetime :scan_start
- t.datetime :scan_finish
- t.text :domain
- t.text :cross_domain
- t.integer :clean_timeout
- t.boolean :is_started
- t.boolean :is_finished
- end
-
- end
-
+ def change
+ create_table :xssraysscans do |t|
+ t.references :hooked_browser
+ t.datetime :scan_start
+ t.datetime :scan_finish
+ t.text :domain
+ t.text :cross_domain
+ t.integer :clean_timeout
+ t.boolean :is_started
+ t.boolean :is_finished
+ end
+ end
end
diff --git a/core/main/autorun_engine/engine.rb b/core/main/autorun_engine/engine.rb
index 88d0c9f193..99b9d225e4 100644
--- a/core/main/autorun_engine/engine.rb
+++ b/core/main/autorun_engine/engine.rb
@@ -6,9 +6,7 @@
module BeEF
module Core
module AutorunEngine
-
class Engine
-
include Singleton
def initialize
@@ -20,8 +18,8 @@ def initialize
@debug_on = @config.get('beef.debug')
- @VERSION = ['<','<=','==','>=','>','ALL']
- @VERSION_STR = ['XP','Vista']
+ @VERSION = ['<', '<=', '==', '>=', '>', 'ALL']
+ @VERSION_STR = %w[XP Vista]
end
# Check if the hooked browser type/version and OS type/version match any Rule-sets
@@ -30,13 +28,12 @@ def initialize
def run(hb_id, browser_name, browser_version, os_name, os_version)
are = BeEF::Core::AutorunEngine::Engine.instance
match_rules = are.match(browser_name, browser_version, os_name, os_version)
- are.trigger(match_rules, hb_id) if match_rules !=nil && match_rules.length > 0
+ are.trigger(match_rules, hb_id) if !match_rules.nil? && match_rules.length > 0
end
# Prepare and return the JavaScript of the modules to be sent.
# It also updates the rules ARE execution table with timings
def trigger(rule_ids, hb_id)
-
hb = BeEF::HBManager.get_by_id(hb_id)
hb_session = hb.session
@@ -48,26 +45,25 @@ def trigger(rule_ids, hb_id)
execution_delay = JSON.parse(rule.execution_delay)
chain_mode = rule.chain_mode
- mods_bodies = Array.new
- mods_codes = Array.new
- mods_conditions = Array.new
+ mods_bodies = []
+ mods_codes = []
+ mods_conditions = []
# this ensures that if both rule A and rule B call the same module in sequential mode,
# execution will be correct preventing wrapper functions to be called with equal names.
rule_token = SecureRandom.hex(5)
modules.each do |cmd_mod|
- mod = BeEF::Core::Models::CommandModule.where(:name => cmd_mod['name']).first
+ mod = BeEF::Core::Models::CommandModule.where(name: cmd_mod['name']).first
options = []
replace_input = false
- cmd_mod['options'].each do|k,v|
- options.push({'name' => k, 'value' => v})
+ cmd_mod['options'].each do |k, v|
+ options.push({ 'name' => k, 'value' => v })
replace_input = true if v == '<The requested URL was not found on this server.
" + - "" +
- "The page cannot be found" + - "The page you are looking for might have been removed, had its name changed, or is temporarily unavailable." + - "" + - " Please try the following: " + - "
HTTP Error 404 - File or directory not found." +
- " |
The requested URL was not found on this server.
' \ + '' \
+ 'The page cannot be found' \ + 'The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.' \ + '' \ + ' Please try the following: ' \ + '
HTTP Error 404 - File or directory not found.' \
+ ' |
This page is used to test the proper operation of the Apache HTTP server after it has been installed. If you can read this page it means that the Apache HTTP server installed at this site is working properly.
" + - "The fact that you are seeing this page indicates that the website you just visited is either experiencing problems or is undergoing routine maintenance.
" + - "If you would like to let the administrators of this website know that you've seen this page instead of the page you expected, you should send them e-mail. In general, mail sent to the name \"webmaster\" and directed to the website's domain should reach the appropriate person.
" + - "For example, if you experienced problems while visiting www.example.com, you should send e-mail to \"webmaster@example.com\".
" + - "You may now add content to the directory /var/www/html/. Note that until you do so, people visiting your website will see this page and not your content. To prevent this page from ever being used, follow the instructions in the file /etc/httpd/conf.d/welcome.conf.
" + - "You are free to use the images below on Apache and CentOS Linux powered HTTP servers. Thanks for using Apache and CentOS!
" + - "" + - "For information on CentOS please visit the CentOS website.
" + - "CentOS is an Operating System and it is used to power this website; however, the webserver is owned by the domain owner and not the CentOS Project. If you have issues with the content of this site, contact the owner of the domain, not the CentOS project." + - "
Unless this server is on the CentOS.org domain, the CentOS Project doesn't have anything to do with the content on this webserver or any e-mails that directed you to this site.
" + - "For example, if this website is www.example.com, you would find the owner of the example.com domain at the following WHOIS server:
" + - "" + - "