Skip to content

Instantly share code, notes, and snippets.

@manastungare
Created May 7, 2012 01:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save manastungare/2625391 to your computer and use it in GitHub Desktop.
Save manastungare/2625391 to your computer and use it in GitHub Desktop.
Laptop Theft Protector
<?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 = "test@example.com";
$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);
}
?>
#!/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
@cyberwani
Copy link

Hi @manastungare, nice script. Is there any way to do same with Windows system.

@SecureCloud-biz
Copy link

Actually there is... you can convert the .sh file to a .bat file

You can run the .bat file on windows, or use a program to convert .bat to .exe file
(I use -- Dr. Batcher)
and have it start everytime your computer starts, & rename it or even create a TSR App..

There are MANY ways to accomplish this.. just looking at the .sh code above, its similar
to a .bat file, with minor changes.. you would also have to install cURL separately, and so on...

But yes it could be done... 👻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment