Cleaning up API. Fixes Issue 372
git-svn-id: https://beef.googlecode.com/svn/trunk@1171 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
This commit is contained in:
@@ -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'
|
||||
|
||||
29
core/api/main/migration.rb
Normal file
29
core/api/main/migration.rb
Normal file
@@ -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
|
||||
34
core/api/main/server/handler.rb
Normal file
34
core/api/main/server/handler.rb
Normal file
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user