M extensions/admin_ui/controllers/modules/modules.rb
M extensions/initialization/handler.rb
M core/main/client/browser.js
Example output on details tab:
Screen Params: {"width"=>1024, "height"=>768, "colordepth"==>24}
Window Size: {"width"=>1024, "height"=>640}
git-svn-id: https://beef.googlecode.com/svn/trunk@1067 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
131 lines
5.4 KiB
Ruby
131 lines
5.4 KiB
Ruby
#
|
|
# 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 Extension
|
|
module Initialization
|
|
|
|
#
|
|
# The http handler that manages the return of the initial browser details.
|
|
#
|
|
class Handler
|
|
|
|
attr_reader :guard
|
|
@data = {}
|
|
|
|
HB = BeEF::Core::Models::HookedBrowser
|
|
BD = BeEF::Extension::Initialization::Models::BrowserDetails
|
|
|
|
def initialize(data)
|
|
@guard = Mutex.new
|
|
@data = data
|
|
setup()
|
|
end
|
|
|
|
def setup()
|
|
# validate hook session value
|
|
session_id = get_param(@data, 'beefhook')
|
|
raise WEBrick::HTTPStatus::BadRequest, "session id is invalid" if not BeEF::Filters.is_valid_hook_session_id?(session_id)
|
|
hooked_browser = HB.first(:session => session_id)
|
|
return if not hooked_browser.nil? # browser is already registered with framework
|
|
|
|
# create the structure repesenting the hooked browser
|
|
zombie = BeEF::Core::Models::HookedBrowser.new(:ip => @data['request'].peeraddr[3], :session => session_id)
|
|
zombie.firstseen = Time.new.to_i
|
|
zombie.httpheaders = @data['request'].header.to_json
|
|
|
|
zombie.save # the save needs to be conducted before any hooked browser specific logging
|
|
|
|
# add a log entry for the newly hooked browser
|
|
log_zombie_domain = zombie.domain
|
|
log_zombie_domain = "(blank)" if log_zombie_domain.nil? or log_zombie_domain.empty?
|
|
BeEF::Core::Logger.instance.register('Zombie', "#{zombie.ip} just joined the horde from the domain: #{log_zombie_domain}", "#{zombie.id}")
|
|
# get and store browser name
|
|
browser_name = get_param(@data['results'], 'BrowserName')
|
|
raise WEBrick::HTTPStatus::BadRequest, "Invalid browser name" if not BeEF::Filters.is_valid_browsername?(browser_name)
|
|
BD.set(session_id, 'BrowserName', browser_name)
|
|
|
|
# get and store browser version
|
|
browser_version = get_param(@data['results'], 'BrowserVersion')
|
|
raise WEBrick::HTTPStatus::BadRequest, "Invalid browser version" if not BeEF::Filters.is_valid_browserversion?(browser_version)
|
|
BD.set(session_id, 'BrowserVersion', browser_version)
|
|
|
|
# get and store browser string
|
|
browser_string = get_param(@data['results'], 'BrowserReportedName')
|
|
raise WEBrick::HTTPStatus::BadRequest, "Invalid browser browser string" if not BeEF::Filters.is_valid_browserstring?(browser_string)
|
|
BD.set(session_id, 'BrowserReportedName', browser_string)
|
|
|
|
# get and store the os name
|
|
os_name = get_param(@data['results'], 'OsName')
|
|
raise WEBrick::HTTPStatus::BadRequest, "Invalid browser os name" if not BeEF::Filters.is_valid_osname?(os_name)
|
|
BD.set(session_id, 'OsName', os_name)
|
|
|
|
# get and store page title
|
|
page_title = get_param(@data['results'], 'PageTitle')
|
|
raise WEBrick::HTTPStatus::BadRequest, "Invalid page title name" if not BeEF::Filters.is_valid_pagetitle?(page_title)
|
|
BD.set(session_id, 'PageTitle', page_title)
|
|
|
|
# get and store page title
|
|
host_name = get_param(@data['results'], 'HostName')
|
|
raise WEBrick::HTTPStatus::BadRequest, "Invalid host name" if not BeEF::Filters.is_valid_hostname?(host_name)
|
|
BD.set(session_id, 'HostName', host_name)
|
|
|
|
# get and store the browser plugins
|
|
browser_plugins = get_param(@data['results'], 'BrowserPlugins')
|
|
raise WEBrick::HTTPStatus::BadRequest, "Invalid browser plugins" if not BeEF::Filters.is_valid_browser_plugins?(browser_plugins)
|
|
BD.set(session_id, 'BrowserPlugins', browser_plugins)
|
|
|
|
# get and store the internal ip address
|
|
internal_ip = get_param(@data['results'], 'InternalIP')
|
|
if not internal_ip.nil?
|
|
raise WEBrick::HTTPStatus::BadRequest, "Invalid internal IP address" if not BeEF::Filters.is_valid_ip?(internal_ip)
|
|
BD.set(session_id, 'InternalIP', internal_ip)
|
|
end
|
|
|
|
# get and store the internal hostname
|
|
internal_hostname = get_param(@data['results'], 'InternalHostname')
|
|
if not internal_hostname.nil?
|
|
raise WEBrick::HTTPStatus::BadRequest, "Invalid internal host name" if not BeEF::Filters.is_valid_hostname?(host_name)
|
|
BD.set(session_id, 'InternalHostname', internal_hostname)
|
|
end
|
|
|
|
# get and store the zombie screen size and color depth
|
|
screen_params = get_param(@data['results'], 'ScreenParams')
|
|
if screen_params.nil?
|
|
raise WEBrick::HTTPStatus::BadRequest, "Invalid screen size and color depth"
|
|
else
|
|
BD.set(session_id, 'ScreenParams', screen_params)
|
|
end
|
|
|
|
# get and store the window size
|
|
window_size = get_param(@data['results'], 'WindowSize')
|
|
if window_size.nil?
|
|
raise WEBrick::HTTPStatus::BadRequest, "Invalid window size"
|
|
else
|
|
BD.set(session_id, 'WindowSize', window_size)
|
|
end
|
|
|
|
end
|
|
|
|
def get_param(query, key)
|
|
return (query.class == Hash and query.has_key?(key)) ? query[key] : nil
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|