Skip to content

Commit

Permalink
Core: Resolve many Rubocop violations (#2282)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoles authored Jan 24, 2022
1 parent 9f7e1ec commit 124c9d6
Show file tree
Hide file tree
Showing 105 changed files with 3,415 additions and 3,650 deletions.
20 changes: 8 additions & 12 deletions core/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def get_owners(clss, method, params = [])
next unless r['method'] == method
next unless is_matched_params? r, params

owners << { :owner => r['owner'], :id => r['id'] }
owners << { owner: r['owner'], id: r['id'] }
end
owners
end
Expand Down Expand Up @@ -192,17 +192,13 @@ def fire(clss, mthd, *args)
data = []
method = get_api_path(clss, mthd)
mods.each do |mod|
begin
# Only used for API Development (very verbose)
# print_info "API: #{mod} fired #{method}"

result = mod[:owner].method(method).call(*args)
unless result.nil?
data << { :api_id => mod[:id], :data => result }
end
rescue => e
print_error "API Fire Error: #{e.message} in #{mod}.#{method}()"
end
# Only used for API Development (very verbose)
# print_info "API: #{mod} fired #{method}"

result = mod[:owner].method(method).call(*args)
data << { api_id: mod[:id], data: result } unless result.nil?
rescue StandardError => e
print_error "API Fire Error: #{e.message} in #{mod}.#{method}()"
end

data
Expand Down
3 changes: 0 additions & 3 deletions core/api/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
module BeEF
module API
module Extension

attr_reader :full_name, :short_name, :description

@full_name = ''
@short_name = ''
@description = ''

end

end
end
9 changes: 3 additions & 6 deletions core/api/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
module BeEF
module API
module Extensions

# @note Defined API Paths
API_PATHS = {
'post_load' => :post_load
}
'post_load' => :post_load
}.freeze

# API hook fired after all extensions have been loaded
def post_load;
end

def post_load; end
end
end
end
21 changes: 9 additions & 12 deletions core/api/main/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
# See the file 'doc/COPYING' for copying permission
#
module BeEF
module API
module Configuration

# @note Defined API Paths
API_PATHS = {
module API
module Configuration
# @note Defined API Paths
API_PATHS = {
'module_configuration_load' => :module_configuration_load
}

# Fires just after module configuration is loaded and merged
# @param [String] mod module key
def module_configuration_load(mod); end
}.freeze

# Fires just after module configuration is loaded and merged
# @param [String] mod module key
def module_configuration_load(mod); end
end
end

end
end
19 changes: 8 additions & 11 deletions core/api/main/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
# See the file 'doc/COPYING' for copying permission
#
module BeEF
module API
module Migration

# @note Defined API Paths
API_PATHS = {
module API
module Migration
# @note Defined API Paths
API_PATHS = {
'migrate_commands' => :migrate_commands
}
}.freeze

# Fired just after the migration process
def migrate_commands; end

# Fired just after the migration process
def migrate_commands; end
end
end

end
end
52 changes: 25 additions & 27 deletions core/api/main/network_stack/assethandler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,31 @@
# See the file 'doc/COPYING' for copying permission
#
module BeEF
module API
module NetworkStack
module Handlers
module AssetHandler
module API
module NetworkStack
module Handlers
module AssetHandler
# Binds a file to be accessible by the hooked browser
# @param [String] file file to be served
# @param [String] path URL path to be bound, if no path is specified a randomly generated one will be used
# @param [String] extension to be used in the URL
# @param [Integer] count amount of times the file can be accessed before being automatically unbound. (-1 = no limit)
# @return [String] URL bound to the specified file
# @todo Add hooked browser parameter to only allow specified hooked browsers access to the bound URL. Waiting on Issue #336
# @note This is a direct API call and does not have to be registered to be used
def self.bind(file, path = nil, extension = nil, count = -1)
BeEF::Core::NetworkStack::Handlers::AssetHandler.instance.bind(file, path, extension, count)
end

# Binds a file to be accessible by the hooked browser
# @param [String] file file to be served
# @param [String] path URL path to be bound, if no path is specified a randomly generated one will be used
# @param [String] extension to be used in the URL
# @param [Integer] count amount of times the file can be accessed before being automatically unbound. (-1 = no limit)
# @return [String] URL bound to the specified file
# @todo Add hooked browser parameter to only allow specified hooked browsers access to the bound URL. Waiting on Issue #336
# @note This is a direct API call and does not have to be registered to be used
def self.bind(file, path=nil, extension=nil, count=-1)
return BeEF::Core::NetworkStack::Handlers::AssetHandler.instance.bind(file, path, extension, count)
# Unbinds a file made accessible to hooked browsers
# @param [String] url the bound URL
# @todo Add hooked browser parameter to only unbind specified hooked browsers binds. Waiting on Issue #336
# @note This is a direct API call and does not have to be registered to be used
def self.unbind(url)
BeEF::Core::NetworkStack::Handlers::AssetHandler.instance.unbind(url)
end
end
end
end

# Unbinds a file made accessible to hooked browsers
# @param [String] url the bound URL
# @todo Add hooked browser parameter to only unbind specified hooked browsers binds. Waiting on Issue #336
# @note This is a direct API call and does not have to be registered to be used
def self.unbind(url)
BeEF::Core::NetworkStack::Handlers::AssetHandler.instance.unbind(url)
end

end
end
end
end
end
end
59 changes: 28 additions & 31 deletions core/api/main/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,37 @@
# See the file 'doc/COPYING' for copying permission
#
module BeEF
module API
module Server

# @note Defined API Paths
API_PATHS = {
module API
module Server
# @note Defined API Paths
API_PATHS = {
'mount_handler' => :mount_handler,
'pre_http_start' => :pre_http_start
}

# Fires just before the HTTP Server is started
# @param [Object] http_hook_server HTTP Server object
def pre_http_start(http_hook_server); end

# Fires just after handlers have been mounted
# @param [Object] server HTTP Server object
def mount_handler(server); end

# Mounts a handler
# @param [String] url URL to be mounted
# @param [Class] http_handler_class the handler Class
# @param [Array] args an array of arguments
# @note This is a direct API call and does not have to be registered to be used
def self.mount(url, http_handler_class, args = nil)
BeEF::Core::Server.instance.mount(url, http_handler_class, *args)
end
}.freeze

# Fires just before the HTTP Server is started
# @param [Object] http_hook_server HTTP Server object
def pre_http_start(http_hook_server); end

# Fires just after handlers have been mounted
# @param [Object] server HTTP Server object
def mount_handler(server); end

# Unmounts a handler
# @param [String] url URL to be unmounted
# @note This is a direct API call and does not have to be registered to be used
def self.unmount(url)
# Mounts a handler
# @param [String] url URL to be mounted
# @param [Class] http_handler_class the handler Class
# @param [Array] args an array of arguments
# @note This is a direct API call and does not have to be registered to be used
def self.mount(url, http_handler_class, args = nil)
BeEF::Core::Server.instance.mount(url, http_handler_class, *args)
end

# Unmounts a handler
# @param [String] url URL to be unmounted
# @note This is a direct API call and does not have to be registered to be used
def self.unmount(url)
BeEF::Core::Server.instance.unmount(url)
end
end


end
end
end
end
27 changes: 12 additions & 15 deletions core/api/main/server/hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
# See the file 'doc/COPYING' for copying permission
#
module BeEF
module API
module Server
module Hook
module API
module Server
module Hook
# @note Defined API Paths
API_PATHS = {
'pre_hook_send' => :pre_hook_send
}.freeze

# @note Defined API Paths
API_PATHS = {
'pre_hook_send' => :pre_hook_send
}

# Fires just before the hook is sent to the hooked browser
# @param [Class] handler the associated handler Class
def pre_hook_send(handler); end

# Fires just before the hook is sent to the hooked browser
# @param [Class] handler the associated handler Class
def pre_hook_send(handler); end
end
end
end

end
end
end
20 changes: 8 additions & 12 deletions core/api/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@
#
module BeEF
module API

module Command
end

module Module

# @note Defined API Paths
API_PATHS = {
'pre_soft_load' => :pre_soft_load,
'post_soft_load' => :post_soft_load,
'pre_hard_load' => :pre_hard_load,
'post_hard_load' => :post_hard_load,
'get_options' => :get_options,
'get_payload_options' => :get_payload_options,
'override_execute' => :override_execute
}
'pre_soft_load' => :pre_soft_load,
'post_soft_load' => :post_soft_load,
'pre_hard_load' => :pre_hard_load,
'post_hard_load' => :post_hard_load,
'get_options' => :get_options,
'get_payload_options' => :get_payload_options,
'override_execute' => :override_execute
}.freeze

# Fired before a module soft load
# @param [String] mod module key of module about to be soft loaded
Expand Down Expand Up @@ -54,8 +52,6 @@ def override_execute(mod, hbsession, opts); end
# @return [Hash] a hash of options
# @note the option hash is merged with all other API hook's returned hash. Hooking this API method prevents the default options being returned.
def get_payload_options; end

end

end
end
8 changes: 2 additions & 6 deletions core/api/modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@
#
module BeEF
module API

module Modules

# @note Defined API Paths
API_PATHS = {
'post_soft_load' => :post_soft_load
}
'post_soft_load' => :post_soft_load
}.freeze

# Fires just after all modules are soft loaded
def post_soft_load; end

end

end
end
2 changes: 0 additions & 2 deletions core/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#
module BeEF
module Core

end
end

Expand All @@ -14,7 +13,6 @@ module Core
require 'core/main/router/api'
require 'core/main/router/error_responses'


## @note Include http server functions for beef
require 'core/main/server'
require 'core/main/handlers/modules/beefjs'
Expand Down
6 changes: 2 additions & 4 deletions core/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
# See the file 'doc/COPYING' for copying permission
#
module BeEF
module Core

end
module Core
end
end

# @note Includes database models - the order must be consistent otherwise DataMapper goes crazy
Expand Down Expand Up @@ -38,4 +37,3 @@ module Core
# @note Include the command line parser and the banner printer
require 'core/main/console/commandline'
require 'core/main/console/banners'

Loading

0 comments on commit 124c9d6

Please sign in to comment.