Finished commenting BeEF core. From this point on each developer should be commenting their own core changes

git-svn-id: https://beef.googlecode.com/svn/trunk@1362 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
This commit is contained in:
passbe
2011-10-15 03:59:24 +00:00
parent e22332e1f8
commit 65b8652f26
23 changed files with 253 additions and 329 deletions

View File

@@ -18,17 +18,16 @@ module Core
module NetworkStack
module RegisterHttpHandler
#
# Register the http handler for the network stack
#
# @param [Object] server HTTP server instance
def self.mount_handler(server)
#dynamic handler
# @note this mounts the dynamic handler
server.mount('/dh', true, BeEF::Core::NetworkStack::Handlers::DynamicReconstruction)
end
end
# Register core API calls
BeEF::API::Registrar.instance.register(BeEF::Core::NetworkStack::RegisterHttpHandler, BeEF::API::Server, 'mount_handler')
end

View File

@@ -18,25 +18,28 @@ module Core
module NetworkStack
module Handlers
#
# Class defining BeEF assets
#
# @note Class defining BeEF assets
class AssetHandler
# call BeEF::Core::NetworkStack::Handlers::AssetHandler.instance
# @note call BeEF::Core::NetworkStack::Handlers::AssetHandler.instance
include Singleton
attr_reader :allocations, :root_dir
# Starts the AssetHandler instance
def initialize
@allocations = {}
@http_server = BeEF::Core::Server.instance
@root_dir = File.expand_path('../../../../', __FILE__)
end
#
# Binds a file to a mount point
#
# @param [String] file File path to asset
# @param [String] path URL path to mount the asset to (can be nil for random path)
# @param [String] extension Extension to append to the URL path (can be nil for none)
# @param [Integer] count The amount of times the asset can be accessed before being automatically unbinded (-1 = unlimited)
# @return [String] URL Path of mounted asset
# @todo This function should accept a hooked browser session to limit the mounted file to a certain session
def bind(file, path=nil, extension=nil, count=-1)
url = buildURL(path, extension)
@allocations[url] = {'file' => "#{root_dir}"+file, 'path' => path, 'extension' => extension, 'count' => count}
@@ -45,26 +48,27 @@ module Handlers
return url
end
#
# Unbinds a file from a mount point
#
# @param [String] url URL path of asset to be unbinded
def unbind(url)
@allocations.delete(url)
@http_server.unmount(url, true)
end
#
# Builds a URL based on the path and extention, if neither are passed a random URL will be generated
#
# Builds a URL based on the path and extension, if neither are passed a random URL will be generated
# @param [String] path URL Path defined by bind()
# @param [String] extension Extension defined by bind()
# @param [Integer] length The amount of characters to be used when generating a random URL
# @return [String] Generated URL
def buildURL(path, extension, length=20)
url = (path == nil) ? '/'+rand(36**length).to_s(36) : path;
url += (extension == nil) ? '' : '.'+extension;
return url
end
#
# Checks if the file is allocated, if the file isn't return true to pass onto FileHandler.
#
# @param [String] url URL Path of mounted file
# @return [Boolean] Returns true if the file is mounted
def check(url)
if @allocations.has_key?(url)
count = @allocations[url]['count']

View File

@@ -18,19 +18,20 @@ module Core
module NetworkStack
module Handlers
#DynamicHanlder is used reconstruct segmented traffic from the zombies
# @note DynamicHanlder is used reconstruct segmented traffic from the hooked browser
class DynamicReconstruction < WEBrick::HTTPServlet::AbstractServlet
attr_reader :guard
#holds packet queue
# @note holds packet queue
PQ = Array.new()
#obtain dynamic mount points from HttpHookServer
# @note obtain dynamic mount points from HttpHookServer
MOUNTS = BeEF::Core::Server.instance.mounts
#Combines packet information and pushes to PQ, then checks packets
# Combines packet information and pushes to PQ, then checks packets
# @param [Object] request Request object
# @param [Object] response Response object
def do_POST(request, response)
@request = request
response.set_no_cache
@@ -48,9 +49,10 @@ module Handlers
check_packets()
end
# @note Alias do_GET function to do_POST
alias do_GET do_POST
#check packets goes through the PQ array and attempts to reconstruct the stream from multiple packets
# Check packets goes through the PQ array and attempts to reconstruct the stream from multiple packets
def check_packets()
checked = Array.new()
PQ.each do |packet|
@@ -88,14 +90,17 @@ module Handlers
end
end
#delete packets that have been reconstructed, return deleted packets
# Delete packets that have been reconstructed, return deleted packets
# @param [String] beefhook Beefhook of hooked browser
# @param [Integer] stream_id The stream ID
def expunge(beefhook, stream_id)
packets = PQ.select{ |p| p[:beefhook] == beefhook and p[:stream_id] == stream_id }
PQ.delete_if { |p| p[:beefhook] == beefhook and p[:stream_id] == stream_id }
return packets.sort_by { |p| p[:packet_id] }
end
#execute is called once a stream has been rebuilt. it searches the mounts and passes the data to the correct handler
# Execute is called once a stream has been rebuilt. it searches the mounts and passes the data to the correct handler
# @param [Hash] data Hash of data that has been rebuilt by the dynamic reconstruction
def execute(data)
handler = get_param(data, 'handler')
if (MOUNTS.has_key?(handler))
@@ -107,7 +112,10 @@ module Handlers
end
end
#assist function for getting parameter from hash
# Assist function for getting parameter from hash
# @param [Hash] query Hash to pull key from
# @param [String] key The key association to return from `query`
# @return Value associated with `key`
def get_param(query, key)
return nil if query[key].nil?
query[key]