Files
beef/extensions/proxy/handlers/zombie/handler.rb
2011-05-26 06:46:19 +00:00

69 lines
1.8 KiB
Ruby

module BeEF
module Extension
module Proxy
module Handlers
module Zombie
module Handler
# Variable representing the Http DB model.
H = BeEF::Core::Models::Http
# This function will forward requests to the target and
# the browser will perform the request. Then the results
# will be sent back to use
def forward_request(hooked_browser_id, req, res)
# Generate an id for the req in the http table and check it doesnt already exist
http_id = rand(10000)
http_db = H.first(:id => http_id) || nil
while !http_db.nil?
http_id = rand(10000)
http_db = H.first(:id => http_id) || nil
end
# Append port to domain string if not 80 or 443
if req.port != 80 or req.port != 443
domain = req.host.to_s + ':' + req.port.to_s
else
domain = req.host.to_s
end
# Saves the new HTTP request to the db for processing by browser
http = H.new(
:id => http_id,
:request => req,
:method => req.request_method.to_s,
:domain => domain,
:path => req.path.to_s,
:date => Time.now,
:hooked_browser_id => hooked_browser_id
)
http.save
print_debug "[PROXY] Request #" + http_id.to_s + " to " + domain + req.path.to_s + " added to queue for browser id #" + hooked_browser_id.to_s
# Polls the DB for the response and then sets it when present
http_db = H.first(:id => http_id)
while !http_db.has_ran
http_db = H.first(:id => http_id)
end
print_debug "[PROXY] Response to request #" + http_id.to_s + " to " + req.host.to_s + req.path.to_s + " using browser id #" + hooked_browser_id.to_s + " recieved"
res.body = http_db.response
res
end
module_function :forward_request
end
end
end
end
end
end