maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   SMS-based stolen phone locator (https://talk.maemo.org/showthread.php?t=60516)

boxhead 2010-08-17 03:52

SMS-based stolen phone locator
 
1 Attachment(s)
This script was born out of my rage of having my N900 stolen earlier this year. I wanted a simple SMS-based solution for retrieving my new N900 if it were ever stolen again. I used some python code for SMS send/recv and GPS tracking from the wiki and put it together for this.

Here's how it works:
At phone startup, the script reads the SIM card number and compares it to your own valid number. If invalid, it'll send an SMS every x seconds to a pre-defined phone number that includes IMSI and GPS coordinates. It also makes a phone call to the same number after a user-defined number of seconds (to lower chance of thief closing out the phone app).

Whether the SIM card is valid or not, the script listens for a user-defined SMS alert-code. When alert mode is activated, it returns texts to the incoming number with the same info as above (IMSI and GPS).

Installation:
1. Send thief-be-caught.tar.gz to n900
2. Extract: tar cvf thief-be-found.tar.gz -C /
3. Fill out variables at the top of /etc/event.d/banana
3. Reboot
4. Check if script is running with: ps | grep sms

Prereqs: python libraries (incl. python-location)

To close the daemon:
sh /usr/sbin/sms-quit.sh

Notes:
* Some alert code strings seem to be interpreted incorrectly by the SMS receiving procedure, so try changing the alert code if nothing happens.
* Every time the GPS coordinates are read, the internal GPS and network positioning are enabled in case they were ever disabled. The location server will also be set to supl.google.com.

I hope this helps someone get their phone back if anything unfortunate happens. I am new to sh and python scripting, so please test and improve or offer feedback.

Reeby 2010-08-17 11:35

Re: SMS-based stolen phone locator
 
Thanks for that!
Do I have to activate it by sending SMS only?

benh_n900 2010-08-17 13:15

Re: SMS-based stolen phone locator
 
You may also be interested in http://www.whereismydevice.com, (see http://talk.maemo.org/showthread.php?t=51027) - you could integrate your script with this, which will then keep you updated even if the stolen n900 has no capability to send SMS, by updating the details on the website for you to monitor.

Cheers,

Ben

boxhead 2010-08-17 14:43

Re: SMS-based stolen phone locator
 
@Reeby
Yes, just send the ALERT_CODE you define.

@benh
Thanks. I'm setting up your scripts right now in case this falls through.

AlexV12 2010-08-17 16:24

Re: SMS-based stolen phone locator
 
Quote:

Originally Posted by boxhead (Post 788860)

Installation:
* banana -- place in /etc/event.d and edit the variables at the top
* sms.py, sms_gps.py -- place in /usr/sbin and chmod 755
* reboot
.

how do i place the files in /usr/sbin and chmod 755,

I now do it:

cp /home/user/MyDocs/newfolder/* /usr/sbin

and: cp /home/user/MyDocs/newfolder* /home/user/MyDocs/chmod 775

but that doesn't work :P


do i have to follow the banana documents steps? don't really understand them

Marcus 2010-08-17 16:37

Re: SMS-based stolen phone locator
 
AlexV12:
It requires either SSH or using XTerm.

But please, don't do anything you don't know what is.

EDIT: You updated right before me.

Remember to do it as root.
sudo gainroot

luizcesta 2010-08-17 16:58

Re: SMS-based stolen phone locator
 
Can somebody upload it to devel repository?

Thanks!

AlexV12 2010-08-17 17:24

Re: SMS-based stolen phone locator
 
Quote:

Originally Posted by Marcus (Post 789548)
AlexV12:
It requires either SSH or using XTerm.

But please, don't do anything you don't know what is.

EDIT: You updated right before me.

Remember to do it as root.
sudo gainroot

i did, but unfortunatly nothing happens.

well it doesn't give an error but what do i do after i've copied the files to sbin and chmod?

boxhead 2010-08-17 17:46

Re: SMS-based stolen phone locator
 
@alex
You must copy sms.py and sms_gps.py to the /usr/sbin folder. There is no chmod folder. chmod is a unix command that lets you change file permissions. In this case, we need these files to execute, so type in:
Code:

cd /usr/sbin
chmod 755 sms.py
chmod 755 sms_gps.py

Finally, the file 'banana' is the script that runs at bootup. It must be copied to /etc/event.d

Make sure you edit the parameters at the top of this file.

VALID_IMSI=XXXXXXXXXXX # this is your own IMSI
SEND_TEXT_INTERVAL=120.0 # how often (sec) to send SMS
HOME_PHONE=XXXXXXXXXX # designated phone number to send SMS and phone calls
TIME_WAIT_TO_CALL=60 # time to wait (sec) after invalid SIM card detected before making phone call
ALERT_CODE="XXXXXXXXX" # SMS code used to activate alert mode

To fill out the VALID_IMSI field, you can find your own IMSI by entering this into the terminal:
Code:

dbus-send --system --type=method_call --print-reply --dest=com.nokia.phone.SIM /com/nokia/phone/SIM Phone.Sim.get_imsi

AlexV12 2010-08-17 21:39

Re: SMS-based stolen phone locator
 
allright, i've done all that. how do you know when itms working?

like always xterm just goes to the next line (which normally means it worked what you typed)

but how do you shut it off? i'm not going to try it before i can turn it off.

boxhead 2010-08-17 22:14

Re: SMS-based stolen phone locator
 
good point.. need to have a way to shut it off. I've added a new file to the ZIP archive, sms-quit.sh.

Use this to shut the script down:
Code:

sh /usr/sbin/sms-quit.sh
To confirm that it's closed:
Code:

ps | grep "sms.py"

AlexV12 2010-08-18 09:22

Re: SMS-based stolen phone locator
 
allright, i'll see if ican get it to work.

is there a possibility that when you sms the code or when the sim is changed, it will take photo's from front and rear camera so we might be able to get a headshot of the guy who's stolen your phone and sent it email or mms. and if you slide open the keyboard?

i know there is aprogram called "i am here" which already does this, but unfortunatly it doesn't work anymore..

anyway, just to make sure i did everything right.

this is what i have done so far: (i filled in the XXXXXX in banana)

http://img529.imageshack.us/img529/7...0081811405.png

now i rebooted and restarted xterminal

http://a.yfrog.com/img59/840/screens...0081811480.png

is this correct?

boxhead 2010-08-18 15:49

Re: SMS-based stolen phone locator
 
yea, that's correct so far. Also, do chmod on sms-quit.sh so that you can run that later.

After a reboot, run: ps | grep "sms.py"

If you see python /usr/sbin/sms.py --listen..., then it's working.

This is when you can send yourself a text message with your alert code and the script will text back with info. You should see the GPS icon up in the status bar if it's working.

I'll look into the front cam taking pics when the keyboard slides open. Not sure about it though, because the image quality is so bad.

AlexV12 2010-08-18 16:00

Re: SMS-based stolen phone locator
 
when i run: ps | grep "sms.py" i get:

1577 root [allot of spaces] 2088 S [allot of spaces] grep sms.py

boxhead 2010-08-18 16:08

Re: SMS-based stolen phone locator
 
What happens when you run:

python /usr/sbin/sms.py --sendinfo phone_number 120 000 "alert"
(replace phone_number with your #)

Sonny_Jim 2010-08-18 16:09

Re: SMS-based stolen phone locator
 
This looks great, exactly the sort of thing I was looking for! Haven't delved too deeply into it but it would be great if it had the following:

The ability to change the 'home' phone number via the alert message, as it may be that your 'home' phone number may change when you no longer have access to the N900. So an SMS like: "$ALERT_CODE 0123456789" will send the info to 0123456789. If you don't supply a trailing number, it should use the stored 'home' phone number.

With regard to taking a picture via the front camera, the best way would probably be to automatically take a picture if the IMEI isn't the valid one and a call has just finished. Hopefully the thief will be in the process of moving the phone away from their head so it'll catch a half decent picture of them.

Also, I find that it takes a ridiculous amount of time (like 5-15 minutes) for my GPS to get a lock, does the script take this into account?

The only issue I see is if the thief decides to wipe the OS, but I don't think the average crim is going to be bothered enough to do that, probably too busy looking through all your photo's and music!

But good work! Even if it saves just one N900 from the crack heads then it has to be worth it.

eti1 2010-08-18 16:10

Re: SMS-based stolen phone locator
 
Nice work;
btw, i would replace
VALID_IMSI=XXXXXXXXXXX
by
VALID_IMSI=`dbus-send --system --type=method_call --print-reply --dest=com.nokia.phone.SIM /com/nokia/phone/SIM Phone.Sim.get_imsi | head -2 | tail -1 | tr -s '"' ' ' | cut -d ' ' -f 3`

Sonny_Jim 2010-08-18 16:15

Re: SMS-based stolen phone locator
 
Erm, wouldn't that mean that the IMSI is always valid?

boxhead 2010-08-18 16:28

Re: SMS-based stolen phone locator
 
Quote:

Originally Posted by Sonny_Jim (Post 790670)
This looks great, exactly the sort of thing I was looking for! Haven't delved too deeply into it but it would be great if it had the following:

The ability to change the 'home' phone number via the alert message, as it may be that your 'home' phone number may change when you no longer have access to the N900. So an SMS like: "$ALERT_CODE 0123456789" will send the info to 0123456789. If you don't supply a trailing number, it should use the stored 'home' phone number.

With regard to taking a picture via the front camera, the best way would probably be to automatically take a picture if the IMEI isn't the valid one and a call has just finished. Hopefully the thief will be in the process of moving the phone away from their head so it'll catch a half decent picture of them.

Also, I find that it takes a ridiculous amount of time (like 5-15 minutes) for my GPS to get a lock, does the script take this into account?

The only issue I see is if the thief decides to wipe the OS, but I don't think the average crim is going to be bothered enough to do that, probably too busy looking through all your photo's and music!

But good work! Even if it saves just one N900 from the crack heads then it has to be worth it.

Hi Sonny, thanks for your input.

The 'home' number is irrelevant when alert mode is activated via text. The information will be replied back to the number that sent the alert.

The GPS lock should be faster because I only require 3+ satellites to be locked on. Anyway, you'll be fine since the script waits for the GPS to provide a coordinate before sending a text.

Finally, I don't think most phone thieves are advanced enough to flash rootfs. I have a good story about that. The guy who stole my phone took a full picture of himself in the mirror and had the bright idea to share it to my pixelpipe account lol. I had a good laugh when it popped up on my facebook page. I got his comcast IP address from pixelpipe, but my detective wasn't too advanced either, and never did get subscriber information from comcast.

boxhead 2010-08-18 16:31

Re: SMS-based stolen phone locator
 
Quote:

Originally Posted by Sonny_Jim (Post 790677)
Erm, wouldn't that mean that the IMSI is always valid?

Yea, it does. Thanks for the advice, eti, but that would never trigger an invalid sim card situation.

Sonny_Jim 2010-08-18 16:43

Re: SMS-based stolen phone locator
 
I'm having trouble with the banana script, it seems to never launch on boot?

I've not chmod'd, just put it into /etc/event.d, is there anything else I need to do apart from edit the top? Is there anyway to see debug upstart?

EDIT: Also, how about sending the cell tower info as well?

boxhead 2010-08-18 16:47

Re: SMS-based stolen phone locator
 
Try commenting out these lines:
start on started hildon-desktop
stop on starting shutdown
script
end script

Then run it from terminal. What output do you get?

Sonny_Jim 2010-08-18 16:58

Re: SMS-based stolen phone locator
 
Nokia-N900:/etc/event.d# sh banana
: not founde 2:
: not founde 5:
: not founde 6:
: not founde 9:
: not founde 17:
: not founde 22:
banana: line 26: syntax error: "done" unexpected (expecting "do")

I didn't do anything apart from download it from the 1st post, put it into event.d and edit the top of the file

EDIT: I think it needs bash?

boxhead 2010-08-18 17:05

Re: SMS-based stolen phone locator
 
did you copy over the sms files? also, maybe you're missing python runtime?

Sonny_Jim 2010-08-18 17:10

Re: SMS-based stolen phone locator
 
Nope, I can run the files just fine manually, it's just the upstart script. The one thing I did do was edit banana using vim for windows, so maybe it's screwing up the line endings or something. I'll try with a 'vanilla' banana and not edit it before copying it across.

EDIT: Nope, still not working. I hate to ask this but have you tried using the files from your zipfile? Are you sure that the zip program isn't doing something strange to the line endings?

boxhead 2010-08-18 17:16

Re: SMS-based stolen phone locator
 
fyi i wrote it using winscp's built-in text editor

EDIT: I tried downloading the zip file, copying banana using winscp, and editing it using winscp's editor and the python program still runs as it should.

Sonny_Jim 2010-08-18 17:44

Re: SMS-based stolen phone locator
 
I ended up having to format it like this to get it to work without errors:

export VALID_IMSI=
export SEND_TEXT_INTERVAL=120.0
export HOME_PHONE=
export TIME_WAIT_TO_CALL=60
export ALERT_CODE="XXXXXX"
touch /tmp/imsi
export imsiFile=/tmp/imsi
dbus-send --system --type=method_call --print-reply --dest=com.nokia.phone.SIM /com/nokia/phone/SIM Phone.Sim.get_imsi | grep string | cut -f 2 -d '"' > $imsiFile
while read line
do
imsiNum=$line
done < $imsiFile

if [ $imsiNum -ne $VALID_IMSI ]; then
python /usr/sbin/sms.py --sendinfo $HOME_PHONE $SEND_TEXT_INTERVAL $imsiNum $ALERT_CODE
python /usr/sbin/sms.py --listen 0 $SEND_TEXT_INTERVAL $imsiNum $ALERT_CODE &
sleep $TIME_WAIT_TO_CALL
run-standalone.sh dbus-send --system --type=method_call --print-reply --dest=com.nokia.csd.Call /com/nokia/csd/call com.nokia.csd.Call.CreateWith string:"$HOME_PHONE" uint32:0
else
python /usr/sbin/sms.py --listen 0 $SEND_TEXT_INTERVAL $imsiNum $ALERT_CODE &

boxhead 2010-08-18 17:53

Re: SMS-based stolen phone locator
 
What does 'export' do? Also, is it working with upstart now? If so, could you attach your file to the post so I can test it and update the zip. Thx.

Sonny_Jim 2010-08-18 17:55

Re: SMS-based stolen phone locator
 
You are asking me what 'export' does? Sheesh.

Ok, I'll sit down and have a go at doing it properly and then get back to you.

boxhead 2010-08-18 18:00

Re: SMS-based stolen phone locator
 
hah yeah.. as i mentioned, I'm new to sh scripting. I see that it makes the variables global, but I don't see how that fixes the script on your end.

AlexV12 2010-08-18 18:09

Re: SMS-based stolen phone locator
 
Quote:

Originally Posted by boxhead (Post 790669)
What happens when you run:

python /usr/sbin/sms.py --sendinfo phone_number 120 000 "alert"
(replace phone_number with your #)


My GPS icon appears. it's flashing, but no solid connection after 1 minute

boxhead 2010-08-18 18:16

Re: SMS-based stolen phone locator
 
Quote:

Originally Posted by AlexV12 (Post 790829)
My GPS icon appears. it's flashing, but no solid connection after 1 minute

Sometimes, you'll have to wait 5-10 min. But it's good that the GPS is flashing -- we know the python script is working. We just need to get the banana script running properly on all devices, which Sonny is working on.

Caballero 2010-08-18 18:18

Re: SMS-based stolen phone locator
 
They have something like this in Firefox https://addons.mozilla.org/en-US/firefox/addon/51329/ Who wants to try and report back if its any good. I will try it in Minefield or Fennec mobile if they have for it.

digitalvoid 2010-08-18 18:26

Re: SMS-based stolen phone locator
 
Quote:

Originally Posted by boxhead (Post 788860)
This script was born out of my rage of having my N900 stolen earlier this year. I wanted a simple SMS-based solution for retrieving my new N900 if it were ever stolen again. I used some python code for SMS send/recv and GPS tracking from the wiki and put it together for this.

...

I made a two part Python script for the CLI (control app & background daemon) which does just the same and more...

Control app:

Code:

Nokia-N900:~# smscon
== smscon - remote control utility ==
Options:
  -start  : start smscon
  -stop    : stop smscon
  -boot    : set start at device boot
  -unboot  : remove start at device boot
  -status  : get smscon_daemon status
  -log    : show the logfile
  -clear  : erase the log file
  -help    : this help menu

It also creates a log file:

Code:

Nokia-N900:~# smscon -log
(Tue Aug 17 13:28:05 2010) START: smscon_daemon active
(Tue Aug 17 13:28:05 2010) DAEMON: no arguments passed for daemon
(Tue Aug 17 13:28:05 2010) DAEMON: reading valid IMSI code (XXXXXXXXXXXXXXX) from file
(Tue Aug 17 13:28:05 2010) DAEMON: authorized IMSI code found
(Tue Aug 17 13:28:05 2010) DAEMON: smscon autoloads at boot

I can send specific SMS messages to my phone and so can control my phone with it.

The current functions are: reboot, shutdown, show remaining battery charge, send current gps coordinates, send frontcam picture to my own server, set up ssh connection with available connection (WLAN/GPRS) to my own server)

Sonny_Jim 2010-08-18 18:29

Re: SMS-based stolen phone locator
 
Quote:

Originally Posted by boxhead (Post 790804)
What does 'export' do? Also, is it working with upstart now?

No, not yet. I'll let you know when it does

Quote:

If so, could you attach your file to the post so I can test it and update the zip. Thx.
Don't take this the wrong way, but why are you using .zip files? The better way to do it would be with tar:

tar cvjf thief-be-found.tar.gz /etc/event.d/banana /usr/sbin/sms*

Which would package them all up in a friendly manner so a user can unpack with this:

tar xvjf thief-be-found.tar.gz -C /

No need for changing directories or chmod.

@digitalvoid:
Yeah, well I drive a ferrari and shag a supermodel, fancy sharing your code or what?

Laughing Man 2010-08-18 18:41

Re: SMS-based stolen phone locator
 
Quote:

Originally Posted by Sonny_Jim (Post 790670)
The only issue I see is if the thief decides to wipe the OS, but I don't think the average crim is going to be bothered enough to do that, probably too busy looking through all your photo's and music!

But good work! Even if it saves just one N900 from the crack heads then it has to be worth it.

The positive and negative side of having an N900..

Most people can't use it. Especially if they're looking for the user friendliness of an iPhone or Android device. I keep forgetting how to reflash my device myself once in a while.

Heck install openssh, create a reverse tunnel and you'll be able to mess with the thief's head by using command line commands to make the device do what you want. =P

AlexV12 2010-08-18 18:42

Re: SMS-based stolen phone locator
 
Quote:

Originally Posted by digitalvoid (Post 790854)
I made a two part Python script for the CLI (control app & background daemon) which does just the same and more...

Control app:

Code:

Nokia-N900:~# smscon
== smscon - remote control utility ==
Options:
  -start  : start smscon
  -stop    : stop smscon
  -boot    : set start at device boot
  -unboot  : remove start at device boot
  -status  : get smscon_daemon status
  -log    : show the logfile
  -clear  : erase the log file
  -help    : this help menu

It also creates a log file:

Code:

Nokia-N900:~# smscon -log
(Tue Aug 17 13:28:05 2010) START: smscon_daemon active
(Tue Aug 17 13:28:05 2010) DAEMON: no arguments passed for daemon
(Tue Aug 17 13:28:05 2010) DAEMON: reading valid IMSI code (XXXXXXXXXXXXXXX) from file
(Tue Aug 17 13:28:05 2010) DAEMON: authorized IMSI code found
(Tue Aug 17 13:28:05 2010) DAEMON: smscon autoloads at boot

I can send specific SMS messages to my phone and so can control my phone with it.

The current functions are: reboot, shutdown, show remaining battery charge, send current gps coordinates, send frontcam picture to my own server, set up ssh connection with available connection (WLAN/GPRS) to my own server)

perhaps ik would be good to combine your programs? sounds like you could help each other allot!

Sonny_Jim 2010-08-18 18:43

Re: SMS-based stolen phone locator
 
You are far, far more likely to have a cell connection than a wifi connection if the phone is stolen, so it's best to use the GSM side rather than relying on the thief to connect to the internet.

boxhead 2010-08-18 19:10

Re: SMS-based stolen phone locator
 
Quote:

Originally Posted by Sonny_Jim (Post 790858)
Don't take this the wrong way, but why are you using .zip files? The better way to do it would be with tar:

tar cvjf thief-be-found.tar.gz /etc/event.d/banana /usr/sbin/sms*

Which would package them all up in a friendly manner so a user can unpack with this:

tar xvjf thief-be-found.tar.gz -C /

No need for changing directories or chmod.

That works great. Maybe archiving it this way will fix the possible file formatting issues. I've updated the OP with the new file.

Sonny_Jim 2010-08-18 19:16

Re: SMS-based stolen phone locator
 
There's other issues as well, like you don't need the tmp file. Here is what I have at the moment:

#!/bin/sh
VALID_IMSI=
SEND_TEXT_INTERVAL=120.0
HOME_PHONE=
TIME_WAIT_TO_CALL=60
ALERT_CODE=""
imsiNum=`dbus-send --system --type=method_call --print-reply --dest=com.nokia.phone.SIM /com/nokia/phone/SIM Phone.Sim.get_imsi | grep string | cut -f 2 -d '"'`
echo $imsiNum
if [ $imsiNum -ne $VALID_IMSI ]; then
python /usr/sbin/sms.py --sendinfo $HOME_PHONE $SEND_TEXT_INTERVAL $imsiNum $ALERT_CODE
python /usr/sbin/sms.py --listen 0 $SEND_TEXT_INTERVAL $imsiNum $ALERT_CODE &
sleep $TIME_WAIT_TO_CALL
run-standalone.sh dbus-send --system --type=method_call --print-reply --dest=com.nokia.csd.Call /com/nokia/csd/call com.nokia.csd.Call.CreateWith string:"$HOME_PHONE" uint32:0
else
python /usr/sbin/sms.py --listen 0 $SEND_TEXT_INTERVAL $imsiNum $ALERT_CODE &
fi


Notice that you don't need to write/read a tmpfile, you can just use a backtick. But for some really annoying reason it still isn't working,

p.s You didn't just copy and paste my tar command? I think you might have picked up sms-manager with the wildcard if you did.


All times are GMT. The time now is 13:18.

vBulletin® Version 3.8.8