diff --git a/core/main/autorun_engine/parser.rb b/core/main/autorun_engine/parser.rb index 820c009f2..83a1075bc 100644 --- a/core/main/autorun_engine/parser.rb +++ b/core/main/autorun_engine/parser.rb @@ -69,8 +69,8 @@ module BeEF end end - exec_order.each { |order| return [false, 'execution_order values must be Integers'] unless order.integer? } - exec_delay.each { |delay| return [false, 'execution_delay values must be Integers'] unless delay.integer? } + exec_order.each { |order| return [false, 'execution_order values must be Integers'] unless order.is_a?(Integer) } + exec_delay.each { |delay| return [false, 'execution_delay values must be Integers'] unless delay.is_a?(Integer) } return [false, 'execution_order and execution_delay values must be consistent with modules numbers'] unless modules.size == exec_order.size && modules.size == exec_delay.size diff --git a/core/main/configuration.rb b/core/main/configuration.rb index f6565be4f..7b20d5a10 100644 --- a/core/main/configuration.rb +++ b/core/main/configuration.rb @@ -20,7 +20,7 @@ module BeEF # @param [String] configuration_file Configuration file to be loaded, # by default loads $root_dir/config.yaml def initialize(config) - raise TypeError, "'config' needs to be a string" unless config.string? + raise TypeError, "'config' needs to be a string" unless config.is_a?(String) raise TypeError, "Configuration file '#{config}' cannot be found" unless File.exist? config begin diff --git a/core/main/crypto.rb b/core/main/crypto.rb index 5122e0729..9c82960a7 100644 --- a/core/main/crypto.rb +++ b/core/main/crypto.rb @@ -54,8 +54,8 @@ module BeEF # @param length integer length of returned string # def self.random_alphanum_string(length = 10) - raise TypeError, 'Invalid length' unless length.integer? - raise TypeError, 'Invalid length' unless length.positive? + raise TypeError, "'length' is #{length.class}; expected Integer" unless length.is_a?(Integer) + raise TypeError, "Invalid length: #{length}" unless length.positive? [*('a'..'z'), *('A'..'Z'), *('0'..'9')].shuffle[0, length].join end @@ -66,8 +66,8 @@ module BeEF # @param length integer length of returned string # def self.random_hex_string(length = 10) - raise TypeError, 'Invalid length' unless length.integer? - raise TypeError, 'Invalid length' unless length.positive? + raise TypeError, "'length' is #{length.class}; expected Integer" unless length.is_a?(Integer) + raise TypeError, "Invalid length: #{length}" unless length.positive? SecureRandom.random_bytes(length).unpack1('H*')[0...length] end diff --git a/core/main/geoip.rb b/core/main/geoip.rb index 534f6e674..bb7d0fc2b 100644 --- a/core/main/geoip.rb +++ b/core/main/geoip.rb @@ -48,7 +48,7 @@ module BeEF # @return [Hash] IP address lookup results # def lookup(ip) - raise TypeError, '"ip" needs to be a string' unless ip.string? + raise TypeError, '"ip" needs to be a string' unless ip.is_a?(String) return unless @enabled diff --git a/core/main/handlers/commands.rb b/core/main/handlers/commands.rb index 131712080..b700f51f1 100644 --- a/core/main/handlers/commands.rb +++ b/core/main/handlers/commands.rb @@ -38,15 +38,15 @@ module BeEF # @note get and check command id from the request command_id = get_param(@data, 'cid') - unless command_id.integer? - print_error 'command_id is invalid' + unless command_id.is_a?(Integer) + print_error("Command ID is invalid") return end # @note get and check session id from the request beefhook = get_param(@data, 'beefhook') unless BeEF::Filters.is_valid_hook_session_id?(beefhook) - print_error 'BeEF hook is invalid' + print_error 'BeEF hook session ID is invalid' return end @@ -68,7 +68,7 @@ module BeEF end command_status = @data['status'] - unless command_status.integer? + unless command_status.is_a?(Integer) print_error 'command status is invalid' return end diff --git a/core/main/logger.rb b/core/main/logger.rb index 21f30ee26..b20b030bc 100644 --- a/core/main/logger.rb +++ b/core/main/logger.rb @@ -35,9 +35,9 @@ module BeEF time_now = Time.now # arguments type checking - raise TypeError, '"from" needs to be a string' unless from.string? - raise TypeError, '"event" needs to be a string' unless event.string? - raise TypeError, '"Hooked Browser ID" needs to be an integer' unless hb.integer? + raise TypeError, "'from' is #{from.class}; expected String" unless from.is_a?(String) + raise TypeError, "'event' is #{event.class}; expected String" unless event.is_a?(String) + raise TypeError, "'hb' hooked browser ID is #{hb.class}; expected Integer" unless hb.is_a?(Integer) # logging the new event into the database @logs.create(logtype: from.to_s, event: event.to_s, date: time_now, hooked_browser_id: hb).save! diff --git a/core/main/models/command.rb b/core/main/models/command.rb index c644e11e1..1ecfdcb63 100644 --- a/core/main/models/command.rb +++ b/core/main/models/command.rb @@ -23,11 +23,11 @@ module BeEF # def self.save_result(hook_session_id, command_id, command_friendly_name, result, status) # @note argument type checking - raise TypeError, '"hook_session_id" needs to be a string' unless hook_session_id.string? - raise TypeError, '"command_id" needs to be an integer' unless command_id.integer? - raise TypeError, '"command_friendly_name" needs to be a string' unless command_friendly_name.string? - raise TypeError, '"result" needs to be a hash' unless result.hash? - raise TypeError, '"status" needs to be an integer' unless status.integer? + raise TypeError, '"hook_session_id" needs to be a string' unless hook_session_id.is_a?(String) + raise TypeError, '"command_id" needs to be an integer' unless command_id.is_a?(Integer) + raise TypeError, '"command_friendly_name" needs to be a string' unless command_friendly_name.is_a?(String) + raise TypeError, '"result" needs to be a hash' unless result.is_a?(Hash) + raise TypeError, '"status" needs to be an integer' unless status.is_a?(Integer) # @note get the hooked browser structure and id from the database hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: hook_session_id).first || nil diff --git a/core/main/server.rb b/core/main/server.rb index 14ed26268..b9581d45c 100644 --- a/core/main/server.rb +++ b/core/main/server.rb @@ -48,7 +48,7 @@ module BeEF # def mount(url, http_handler_class, args = nil) # argument type checking - raise TypeError, '"url" needs to be a string' unless url.string? + raise TypeError, '"url" needs to be a string' unless url.is_a?(String) @mounts[url] = if args.nil? http_handler_class @@ -64,7 +64,7 @@ module BeEF # @param [String] url URL to unmount. # def unmount(url) - raise TypeError, '"url" needs to be a string' unless url.string? + raise TypeError, '"url" needs to be a string' unless url.is_a?(String) @mounts.delete url end diff --git a/core/ruby.rb b/core/ruby.rb index 897f4fc08..7e8d3fff5 100644 --- a/core/ruby.rb +++ b/core/ruby.rb @@ -9,7 +9,6 @@ require 'core/ruby/security' # @note Patching Ruby require 'core/ruby/module' -require 'core/ruby/object' require 'core/ruby/string' require 'core/ruby/print' require 'core/ruby/hash' diff --git a/core/ruby/object.rb b/core/ruby/object.rb deleted file mode 100644 index 4504ac33d..000000000 --- a/core/ruby/object.rb +++ /dev/null @@ -1,42 +0,0 @@ -# -# Copyright (c) 2006-2023 Wade Alcorn - wade@bindshell.net -# Browser Exploitation Framework (BeEF) - http://beefproject.com -# See the file 'doc/COPYING' for copying permission -# -class Object - # Returns true if the object is a Boolean - # @return [Boolean] Whether the object is boolean - def boolean? - is_a?(TrueClass) || is_a?(FalseClass) - end - - # Returns true if the object is a String - # @return [Boolean] Whether the object is a string - def string? - is_a?(String) - end - - # Returns true if the object is an Integer - # @return [Boolean] Whether the object is an integer - def integer? - is_a?(Integer) - end - - # Returns true if the object is a hash - # @return [Boolean] Whether the object is a hash - def hash? - is_a?(Hash) - end - - # Returns true if the object is a class - # @return [Boolean] Whether the object is a class - def class? - is_a?(Class) - end - - # Returns true if the object is nil, and empty string, or empty array - # @return [Boolean] - def blank? - respond_to?(:empty?) ? !!empty? : !self - end -end