diff --git a/core/api.rb b/core/api.rb index 4dee7d32b..b4bbfb77a 100644 --- a/core/api.rb +++ b/core/api.rb @@ -52,8 +52,8 @@ module API end end -require 'core/api/command' +require 'core/api/module' require 'core/api/extension' -require 'core/api/migration' -require 'core/api/server/handler' -require 'core/api/server/hook' +require 'core/api/main/migration' +require 'core/api/main/server/handler' +require 'core/api/main/server/hook' diff --git a/core/api/main/migration.rb b/core/api/main/migration.rb new file mode 100644 index 000000000..ff27af0ef --- /dev/null +++ b/core/api/main/migration.rb @@ -0,0 +1,29 @@ +# +# Copyright 2011 Wade Alcorn wade@bindshell.net +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +module BeEF +module API + module Migration + + API_PATHS = { + 'migrate_commands' => :migrate_commands + } + + def migrate_commands; end + + end + +end +end diff --git a/core/api/main/server/handler.rb b/core/api/main/server/handler.rb new file mode 100644 index 000000000..bdd82dbc2 --- /dev/null +++ b/core/api/main/server/handler.rb @@ -0,0 +1,34 @@ +# +# Copyright 2011 Wade Alcorn wade@bindshell.net +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +module BeEF +module API +module Server + module Handler + + API_PATHS = { + 'pre_http_start' => :pre_http_start, + 'mount_handlers' => :mount_handlers + } + + def mount_handlers(beef_server); end + + def pre_http_start(http_hook_server); end + + end + +end +end +end diff --git a/core/api/server/hook.rb b/core/api/main/server/hook.rb similarity index 50% rename from core/api/server/hook.rb rename to core/api/main/server/hook.rb index dc5c04a93..a050e7791 100644 --- a/core/api/server/hook.rb +++ b/core/api/main/server/hook.rb @@ -16,45 +16,12 @@ module BeEF module API module Server - # - # All modules that extend the Handler API will be called during handler mounting, - # dismounting, managing operations. - # - # You want to use that API if you are developing an extension that requires to create - # a new http handler to receive responses. - # - # Example: - # - # module A - # extend BeEF::API::Server::Handler - # end - # - # - # BeEF Core then calls all the Handler extension modules like this: - # - # BeEF::API::Server::Handler.extended_in_modules.each do |mod| - # ... - # end - # module Hook API_PATHS = { 'pre_hook_send' => :pre_hook_send } - # - # This method is being called as the hooked response is being built - # - # Example: - # - # module A - # extend BeEF::API::Server::Hook - # - # def pre_hook_send() - # ... - # end - # end - # def pre_hook_send(handler) end diff --git a/core/api/migration.rb b/core/api/migration.rb deleted file mode 100644 index 68536bb91..000000000 --- a/core/api/migration.rb +++ /dev/null @@ -1,52 +0,0 @@ -# -# Copyright 2011 Wade Alcorn wade@bindshell.net -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -module BeEF -module API - # - # All modules that extend the Migration module will be called during the database - # migration phase of BeEF. - # - # So if you are developing an extension that requires injecting new commands into - # the database. You will want to use that. - # - # See the Metasploit extension for example. - # - # Example: - # - # module A - # extend BeEF::API::Migration - # end - # - # - # BeEF Core then calls all the migration modules like this: - # - # BeEF::API::Migration.extended_in_modules.each do |mod| - # ... - # end - # - module Migration - - # - # This function gets called by the core when migrating new commands into the framework. - # For example, the metasploit examples needs to store the list of exploits into BeEF's - # database. - # - def migrate_commands!; end - - end - -end -end \ No newline at end of file diff --git a/core/api/command.rb b/core/api/module.rb similarity index 56% rename from core/api/command.rb rename to core/api/module.rb index 32ddb1316..b25ef0e5d 100644 --- a/core/api/command.rb +++ b/core/api/module.rb @@ -15,31 +15,12 @@ # module BeEF module API - # - # Use this API call if you want to add new methods and variables to the default - # BeEF::Core::Command module. - # - # Here's an example: - # - # module A - # extend BeEF::API::Command - # - # def hello - # p 'hi there' - # end - # end - # - # b = BeEF::Core::Command.new - # b.hello # => 'hi there' - # - # c = BeEF::Core::Command::Detect_details.new - # c.hello # => 'hi there' - # - # - # For a real life example, have a look at BeEF::Extension::AdminUI::API::Command - # + module Command end + + module Module + end end end diff --git a/core/api/server/handler.rb b/core/api/server/handler.rb deleted file mode 100644 index 13331be4f..000000000 --- a/core/api/server/handler.rb +++ /dev/null @@ -1,77 +0,0 @@ -# -# Copyright 2011 Wade Alcorn wade@bindshell.net -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -module BeEF -module API -module Server - # - # All modules that extend the Handler API will be called during handler mounting, - # dismounting, managing operations. - # - # You want to use that API if you are developing an extension that requires to create - # a new http handler to receive responses. - # - # Example: - # - # module A - # extend BeEF::API::Server::Handler - # end - # - # - # BeEF Core then calls all the Handler extension modules like this: - # - # BeEF::API::Server::Handler.extended_in_modules.each do |mod| - # ... - # end - # - module Handler - - API_PATHS = { - 'pre_http_start' => :pre_http_start, - 'mount_handlers' => :mount_handlers - } - - # - # This method is being called when the BeEF server mounts handlers - # - # See BeEF::Extension::AdminUI::API::Handler as an example. - # - # Example: - # - # module A - # extend BeEF::API::Server::Handler - # - # def mount_handlers(beef_server) - # ... - # end - # end - # - def mount_handlers(beef_server) - # - # Here's an example of how you could use it: - # - # beef_server.mount('/demos/', true, WEBrick::HTTPServlet::FileHandler, "#{$root_dir}/demos/") - # - end - - def pre_http_start(http_hook_server) - - end - - end - -end -end -end diff --git a/core/main/migration.rb b/core/main/migration.rb index 1bebdc2c0..3091cce2d 100644 --- a/core/main/migration.rb +++ b/core/main/migration.rb @@ -65,17 +65,10 @@ module Core config.set('beef.module.'+mod.name+'.db.path', mod.path) end } + + # Call Migration method + BeEF::API.fire(BeEF::API::Migration, 'migrate_commands') - # We use the API to execute the migration code for each extensions that needs it. - # For example, the metasploit extensions requires to add new commands into the database. - BeEF::API::Migration.extended_in_modules.each do |mod| - begin - mod.migrate_commands! - rescue Exception => e - puts e.message - puts e.backtrace - end - end end end end diff --git a/extensions/console/banners.rb b/extensions/console/banners.rb index 13858f973..e82b22fee 100644 --- a/extensions/console/banners.rb +++ b/extensions/console/banners.rb @@ -115,6 +115,7 @@ module Banners # # Print loaded modules def print_loaded_modules + puts BeEF::API::Module.extended_in_modules print_info "#{BeEF::Modules::get_enabled.count} modules loaded." end end diff --git a/extensions/metasploit/dbmigration.rb b/extensions/metasploit/dbmigration.rb index 02b39e9ac..c00a13979 100644 --- a/extensions/metasploit/dbmigration.rb +++ b/extensions/metasploit/dbmigration.rb @@ -21,7 +21,7 @@ module Metasploit extend BeEF::API::Migration - def self.migrate_commands! + def self.migrate_commands msf = BeEF::Extension::Metasploit::RpcClient.instance # verify that metasploit is enabled and we are logged in. diff --git a/extensions/metasploit/msfcommand.rb b/extensions/metasploit/msfcommand.rb index ead4d59b2..3ae64ff34 100644 --- a/extensions/metasploit/msfcommand.rb +++ b/extensions/metasploit/msfcommand.rb @@ -20,19 +20,15 @@ module Commands class Msf < BeEF::Core::Command def initialize - super({ - 'Name' => 'Generic Metasploit Exploit', + h = { + 'name' => 'Generic Metasploit Exploit', + 'description' => 'This module will launch a Metasploit exploit against the host', + 'category' => 'Metasploit', + 'author' => ['sussurro'] + } - 'Description' => %Q{ - This module will launch a Metasploit exploit against the host - }, - 'Category' => 'Metasploit', - 'Author' => ['sussurro'], - 'Data' => [ ], - 'File' => __FILE__, - }) - - use 'beef.dom' + BeEF::Core::Configuration.instance.set('beef.module.gmsf', h) + super('gmsf') end def callback