-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.js
More file actions
108 lines (85 loc) · 3.08 KB
/
client.js
File metadata and controls
108 lines (85 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// client.js - User9684
// This JavaScript file is injected into all pages to modify geolocation
// functionality, resulting in spoofed geolocation.
(() => {
const events = [];
const watchers = new Map();
let watcherIdCounter = 0;
async function generateFakeCoords(config) {
const coords = {
latitude: config.latitude,
longitude: config.longitude,
accuracy: config.accuracy,
altitude: null,
altitudeAccuracy: null,
heading: null,
speed: null,
};
Object.setPrototypeOf(coords, GeolocationCoordinates.prototype);
return coords;
}
async function generateFakePosition(config) {
const coords = await generateFakeCoords(config);
const position = {
coords: coords,
timestamp: Date.now(),
};
Object.setPrototypeOf(position, GeolocationPosition.prototype);
return position;
}
function generateSpoofedFunction(originalFunction, newFunction) {
function spoofedFunction(...args) {
return newFunction(...args);
}
Object.setPrototypeOf(
spoofedFunction,
Object.getPrototypeOf(originalFunction)
);
Object.defineProperty(spoofedFunction, "toString", {
value: originalFunction.toString.bind(originalFunction),
writable: true,
configurable: true,
});
return spoofedFunction;
}
window.navigator.geolocation.getCurrentPosition = generateSpoofedFunction(
window.navigator.geolocation.getCurrentPosition,
function (success, fail) {
const newEvent = new CustomEvent("gs-request-cpos");
events[newEvent] = success;
document.documentElement.dispatchEvent(newEvent);
}
);
window.navigator.geolocation.watchPosition = generateSpoofedFunction(
window.navigator.geolocation.watchPosition,
function (success, fail) {
const watcherId = ++watcherIdCounter;
const newEvent = new CustomEvent("gs-request-watchpos");
watchers.set(watcherId, success);
document.documentElement.dispatchEvent(newEvent);
return watcherId;
}
);
window.navigator.geolocation.clearWatch = generateSpoofedFunction(
window.navigator.geolocation.clearWatch,
function (watcherId) {
if (watchers.has(watcherId)) {
watchers.delete(watcherId);
}
}
);
document.documentElement.addEventListener("gs-response-cpos", async (e) => {
const generatedPosition = await generateFakePosition(e.detail);
events[e](generatedPosition);
});
document.documentElement.addEventListener(
"gs-response-watchpos",
async (e) => {
const { watcherId, detail } = e.detail;
if (watchers.has(watcherId)) {
const generatedPosition = await generateFakePosition(detail);
watchers.get(watcherId)(generatedPosition);
}
}
);
})();