-
-
Save adamesss/39e07f3a98784f51c22f2e5063a89e36 to your computer and use it in GitHub Desktop.
Laptop Theft Protector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
------------------------------------------------------------------------------- | |
Laptop Theft Protector | |
Version 1.0 | |
Copyright (c) 2006, Manas Tungare | |
http://manas.tungare.name/ | |
------------------------------------------------------------------------------- | |
READ THIS CAFEFULLY: YOU MUST CUSTOMIZE ONE VARIABLE BEFORE USE. | |
------------------------------------------------------------------------------- | |
INSTALLATION: | |
1. Put the shell script ("antitheft.sh") on your Mac laptop, chmod +x and | |
all that. | |
2. Rename it to something that will not be very obvious to a thief. | |
3. Schedule it to run every few minutes via a cron job. | |
4. Put this file ("antitheft.php") on a webserver you own. | |
5. If and when your laptop gets stolen, you should change a variable in | |
the PHP script (instructions are within the file). | |
6. After that point, the laptop will start reporting results back to your | |
web server. Till then, no reports are generated or stored, for privacy. | |
7. The server will send you email and store screenshots and network logs. | |
8. Take them to the law enforcement agencies and ask ISPs to help you locate | |
the laptop. | |
WHAT THE SCRIPTS DO: | |
The shell script (on your laptop) checks with your webserver to ask if it | |
has been stolen. It usually receives no reply (0 bytes) which indicates | |
that everything is all right (minimal bandwidth usage). If it's ever | |
stolen, you would change a variable on the server, which sends a stream | |
of non-zero size to the laptop. If the laptop gets such a reply, it goes | |
into 'reporting mode' and starts keeping track of network connections | |
and starts taking screenshots. It sends both of these to your server. | |
The server stores them and sends you email. | |
------------------------------------------------------------------------------- | |
*/ | |
$isLaptopStolen = "no"; // Change this to 'yes' when laptop actually gets stolen! | |
$kMailRecipient = "[email protected]"; | |
$kMailSubject = "Info from Stolen Laptop"; | |
$kReportsDir = realpath("./reports"); // Make sure this is world-writeable. | |
if ($isLaptopStolen === "no") | |
exit(); | |
if ($_FILES['log']['size'] == 0) { // This is the first request. | |
echo("Yes, we're stolen!"); // Doesn't matter what the text says, just needs to be non-null. | |
exit(); | |
} | |
// Now we're definitely stolen, and laptop is attempting to send us network log and screenshot. | |
// Mail the Report | |
mail ($kMailRecipient, $kMailSubject.": ".$_POST["date"], file_get_contents($_FILES["log"]["tmp_name"])); | |
// Save Screenshot & Report on the Web Server | |
if ($_FILES['log']['size'] != 0) { | |
$logFile = $kReportsDir."/antitheft-".$_POST["date"].".log"; | |
move_uploaded_file($_FILES['log']['tmp_name'], $logFile); | |
chmod($logFile, 0777); | |
} | |
if ($_FILES['screenshot']['size'] != 0) { | |
$screenShotFile = $kReportsDir."/screenshot-".$_POST["date"].".png"; | |
move_uploaded_file($_FILES['screenshot']['tmp_name'], $screenShotFile); | |
chmod($screenShotFile, 0777); | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Must customize the URL below to the location of your PHP script. | |
PHONE_HOME_URL=http://www.example.com/laptop/911/ | |
VERSION=1.0 | |
USER_AGENT="Laptop Theft Protector/$VERSION" | |
ANTITHEFT_HOME=./ | |
LOG=$ANTITHEFT_HOME/antitheft.log | |
REPLY_LOG=$ANTITHEFT_HOME/reply.log | |
SCREENSHOT=$ANTITHEFT_HOME/screenshot.png | |
# First request, ask server if we are stolen. | |
curl --user-agent "$USER_AGENT" --output $REPLY_LOG $PHONE_HOME_URL | |
# If server sent us a reply, yes, we're stolen. Otherwise server will stay quiet. | |
if [ -f $REPLY_LOG ]; then | |
rm $REPLY_LOG | |
echo "Info from Stolen Laptop: `date \"+%Y-%m-%d %H:%M:%S\"`" > $LOG; | |
echo "Hostname: `hostname`" >> $LOG; | |
echo "" >> $LOG; | |
echo "Network Configuration:" >> $LOG; | |
ifconfig >> $LOG 2>&1; | |
echo "" >> $LOG; | |
echo "Traceroute to Google:" >> $LOG; | |
traceroute "www.google.com" >> $LOG 2>&1 | |
# First request without a screenshot, in case bandwidth is low. | |
curl \ | |
--user-agent "$USER_AGENT" \ | |
--output $REPLY_LOG \ | |
--form "date=`date +%Y%m%d-%H%M%S`" \ | |
--form "log=@$LOG" \ | |
$PHONE_HOME_URL | |
screencapture -Cx $SCREENSHOT | |
# Second request includes both, network log and screenshot. | |
curl \ | |
--user-agent "$USER_AGENT" \ | |
--output $REPLY_LOG \ | |
--form "date=`date +%Y%m%d-%H%M%S`" \ | |
--form "log=@$LOG" \ | |
--form "screenshot=@$SCREENSHOT" \ | |
$PHONE_HOME_URL | |
#Cleanup temp files, keep archives if enabled above. | |
rm $LOG; | |
rm $REPLY_LOG; | |
rm $SCREENSHOT; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment