Archive for December, 2011
Prey – Auto Update Stolen Status for OS X
by Jaku on Dec.03, 2011, under Code
If you haven’t heard of the Prey Project, then I suggest you check out http://preyproject.com. Prey, is an open source anti-theft solution for your mobile device. You can install their package on your laptop or phone and then if your device is stolen you can then mark it as such and track it and take screenshots and even use your camera if your device has one.
The only “bad’ thing about it, is that it is software based and relies on having an active internet connection. So if the thief wipes your device clean, or can’t login to connect to the internet then it won’t be able to check if it’s stolen and provide updates. So a majority of users will create a dummy account on their laptop with limited access and then hide their main account. I won’t get into that part to much, but if you are running OS X and want to know how you can hide your account from the login screen check out this site http://emeadeployment.blogspot.com/2011/09/how-to-configure-hidden-account-that.html.
Now not everyone is going to realize exactly when their laptop is stolen and it could be many hours or even days before the person realizes it. And every second counts when trying to recover a lost item so the sooner you’re able to start getting information the faster you’ll be able to recover your device. This is where my script comes in. Remember the dummy account with limited access? What if we could have it so that when that account logs in, it would automatically update the devices own status as stolen? Will we can, and it’s actually quite simple.
sudo defaults write com.apple.loginwindow LoginHook /var/root/prey.sh
Running the above command will create a hook so that whenever any account logs in this script will run. You can put the script anywhere you’d like but remember that it will be ran by the root user.
Now the contents of the script should look something like this.
#!/bin/bash
while true; do
sleep 10
if [ "$1" == "Apple" ]; then
if [ "`ping -c 1 google.com`" ]; then #tell prey I'm missing
curl --user $APIKEY:x "http://control.preyproject.com/devices/$DEVICEKEY.xml" -X PUT -d "device[missing]=1"
exit
fi
fi
exit
done
You can find your API key under your Account Information and the device key can be found under your Device Information, all on the Prey website. Both should be a random string. So as an example if your API key was “9g2bi3rsdsd” and your Device Key was “kjr22y”. The line above should look like.
curl --user 9g2bi3rsdsd:x "http://control.preyproject.com/devices/kjr22y.xml" -X PUT -d "device[missing]=1"
The only thing left to change is the “Apple” in the code that checks what user is logged in. If you create a dummy user named “tom” then put “tom” there instead of “Apple”. Otherwise when the account logs in it won’t update as stolen. Other than that it should be all set. Feel free to leave any comments if you have any issues or improvements!
