PI PROJECTS: Hacking a Mobile with Python
What is it?Seen those films where they track mobile phone calls and texting logs? Ever wanted to try it? Here we combine Twilio and Python to create a simple code that will return call details and text messages sent from your own phone. This a simulated environment where you can code and practice.
Getting startedFirst ensure that you are signed up for a Twilio account and number. This is free but will only allow you to send SMS to and from the registered phone. You will receive a verification code via SMS to the registered phone. When promoted enter this onto the Twilio site to authenticate your account and phone. Instructions and installation guide are found here
Getting a List of the Phone Calls MadeThis simple program looks up and returns a complete list of all the phones calls made to and from the Mobile Phone. It includes the number that called and the number of the phone that received the call.
Simple code to retrieve call logs: from twilio.rest import TwilioRestClient account_sid = "A666666777777767672d" #use your sid auth_token = "777777777777777773f0" #use your token client = TwilioRestClient(account_sid, auth_token) for call in client.calls.list(): print "From: " + call.from_formatted + " To: " + call.to_formatted Save the code with a suitable file name such as phonelogs.py and execute the code in the LX Terminal, sudo python phone_logs.py |
Retrieve a List of Sent MessagesNow for the fun hack where Python will grab a list of sent SMS messages and return them to your console LX terminal. The simple code to do this is client.sms.messages.list() This returns a list of all the SMS messages sent to the phone. Then a for loop is used to iterate through the list and print out each message.
You can combine this with date_sent and to / from to return the phone numbers of the sender and the receiver and the date the text message was sent from the phone.
Combining these features creates the following code: from twilio.rest import TwilioRestClient account_sid = "AC2e4444444444442d" #use your sid auth_token = "4f343434343434343434343" #use your token client = TwilioRestClient(account_sid, auth_token) smss = client.sms.messages.list() #grabs a list of messages for i in smss: print i.body #prints the message print i.date_sent #prints the date the text was sent print i.to #prints who the text was sent to Save the code with a suitable file name such as text_logs.py and execute the code in the LX Terminal, sudo python text_logs.py |