Files tidied and renamed variables.
git-svn-id: https://beef.googlecode.com/svn/trunk@912 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
This commit is contained in:
@@ -2,9 +2,9 @@ module BeEF
|
||||
module Core
|
||||
module Handlers
|
||||
module Modules
|
||||
|
||||
|
||||
module Command
|
||||
|
||||
|
||||
#
|
||||
# Adds the command module instructions to a hooked browser's http response.
|
||||
#
|
||||
@@ -14,7 +14,7 @@ module Modules
|
||||
raise WEBrick::HTTPStatus::BadRequest, "hooked_browser.session is nil" if hooked_browser.session.nil?
|
||||
raise WEBrick::HTTPStatus::BadRequest, "hooked_browser is nil" if command.nil?
|
||||
raise WEBrick::HTTPStatus::BadRequest, "hooked_browser.command_module_id is nil" if command.command_module_id.nil?
|
||||
|
||||
|
||||
# get the command module
|
||||
command_module = BeEF::Core::Models::CommandModule.first(:id => command.command_module_id)
|
||||
raise WEBrick::HTTPStatus::BadRequest, "command_module is nil" if command_module.nil?
|
||||
@@ -28,9 +28,9 @@ module Modules
|
||||
command_module.session_id = hooked_browser.session
|
||||
command_module.build_datastore(command.data)
|
||||
command_module.pre_send
|
||||
|
||||
|
||||
build_missing_beefjs_components(command_module.beefjs_components) if not command_module.beefjs_components.empty?
|
||||
|
||||
|
||||
@body << command_module.output + "\n\n"
|
||||
|
||||
# prints the event to the console
|
||||
@@ -43,7 +43,7 @@ module Modules
|
||||
command.instructions_sent = true
|
||||
command.save
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -15,19 +15,19 @@ module Models
|
||||
# - hooked_browser_id
|
||||
#
|
||||
class Command
|
||||
|
||||
|
||||
include DataMapper::Resource
|
||||
|
||||
|
||||
storage_names[:default] = 'commands'
|
||||
|
||||
|
||||
property :id, Serial
|
||||
property :data, Text
|
||||
property :creationdate, String, :length => 15, :lazy => false
|
||||
property :label, Text, :lazy => false
|
||||
property :instructions_sent, Boolean, :default => false
|
||||
|
||||
|
||||
has n, :results
|
||||
|
||||
|
||||
#
|
||||
# Save results and flag that the command has been run on the hooked browser
|
||||
#
|
||||
@@ -39,38 +39,38 @@ module Models
|
||||
def self.save_result(hook_session_id, command_id, command_friendly_name, result)
|
||||
# enforcing arguments types
|
||||
command_id = command_id.to_i
|
||||
|
||||
|
||||
# argument type checking
|
||||
raise Exception::TypeError, '"hook_session_id" needs to be a string' if not hook_session_id.string?
|
||||
raise Exception::TypeError, '"command_id" needs to be an integer' if not command_id.integer?
|
||||
raise Exception::TypeError, '"command_friendly_name" needs to be a string' if not command_friendly_name.string?
|
||||
raise Exception::TypeError, '"result" needs to be a hash' if not result.hash?
|
||||
|
||||
|
||||
# get the hooked browser structure and id from the database
|
||||
zombie = BeEF::Core::Models::HookedBrowser.first(:session => hook_session_id) || nil
|
||||
raise Exception::TypeError, "zombie is nil" if zombie.nil?
|
||||
raise Exception::TypeError, "zombie.id is nil" if zombie.id.nil?
|
||||
zombie_id = zombie.id
|
||||
raise Exception::TypeError, "zombie.ip is nil" if zombie.ip.nil?
|
||||
zombie_ip = zombie.ip
|
||||
|
||||
hooked_browser = BeEF::Core::Models::HookedBrowser.first(:session => hook_session_id) || nil
|
||||
raise Exception::TypeError, "hooked_browser is nil" if hooked_browser.nil?
|
||||
raise Exception::TypeError, "hooked_browser.id is nil" if hooked_browser.id.nil?
|
||||
hooked_browser_id = hooked_browser.id
|
||||
raise Exception::TypeError, "hooked_browser.ip is nil" if hooked_browser.ip.nil?
|
||||
hooked_browser_ip = hooked_browser.ip
|
||||
|
||||
# get the command module data structure from the database
|
||||
command = first(:id => command_id.to_i, :hooked_browser_id => zombie_id) || nil
|
||||
command = first(:id => command_id.to_i, :hooked_browser_id => hooked_browser_id) || nil
|
||||
raise Exception::TypeError, "command is nil" if command.nil?
|
||||
|
||||
|
||||
# create the entry for the results
|
||||
command.results.new(:hooked_browser_id => zombie_id, :data => result.to_json, :date => Time.now.to_i)
|
||||
command.results.new(:hooked_browser_id => hooked_browser_id, :data => result.to_json, :date => Time.now.to_i)
|
||||
command.save
|
||||
|
||||
|
||||
# log that the result was returned
|
||||
BeEF::Core::Logger.instance.register('Command', "The '#{command_friendly_name}' command module was successfully executed against '#{zombie_ip}'", zombie_id)
|
||||
|
||||
BeEF::Core::Logger.instance.register('Command', "Hooked browser #{hooked_browser.ip} has executed instructions from command module '#{command_friendly_name}'", hooked_browser_id)
|
||||
|
||||
# prints the event into the console
|
||||
if BeEF::Settings.console?
|
||||
print_info "The '#{command_friendly_name}' command module was successfully executed against '#{zombie_ip}'"
|
||||
print_info "Hooked browser #{hooked_browser.ip} has executed instructions from command module '#{command_friendly_name}'"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user