Archive for July, 2012

Scripting an Ice Cream Delivery with the Android SDK

Today, a smartphone-connected taxi company called Uber is operating five ice cream trucks in Seattle. You click a button in the Uber app and select your location, and an ice cream truck comes to you. Or at least that’s what should happen. Even with today’s weather (read: periodic torrential rain), people are clamoring to get their ice cream due to the fact that it’s only available for one day… meaning almost nobody is actually able to get a spot in the queue. Uber’s Twitter feed is full of advice telling customers just keep hitting the button, but man, I have work to do. I can’t sit here and press the little ice cream icon all day. Something has got to give.

The Android SDK contains a tool called monkeyrunner. Monkeyrunner lets you simulate touch events, take screenshots, etc… and it does it through a very simple Python library. I decided to see if I could write a little script to keep pressing the ice cream button in Uber’s app, and it only took a few minutes.

from time import sleep
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

# Attach to Android device
d = MonkeyRunner.waitForConnection()

# Take a screenshot of the "sorry, keep trying" screen for reference
raw_input("Get to the error screen, then hit enter.\n")
oldpic = d.takeSnapshot()

while True:
    # Touch the ice cream button
    d.touch(540, 200, MonkeyDevice.DOWN_AND_UP)
    sleep(4)
    newpic = d.takeSnapshot()
	# If the screen looks like our old error
	# screen (95%), hit OK and just keep going (in 10 seconds)
    if newpic.sameAs(oldpic, .95):
        d.touch(460, 700, MonkeyDevice.DOWN_AND_UP)
        sleep(10)
	# But if the screen has changed, stop running the loop.
    else:
		break

I still don’t have ice cream, but the script is running and working.

Bi-directional Caller ID Spoofing with Asterisk

Caller ID spoofing has been around for a long time. Way back when (well, 2004), an article was published on rootsecure.net with an included Perl script, detailing how to use Asterisk to change your caller ID information, in order to pretend to be somebody else. I had some fun toying with that (heh...), and noticed that some commercial services began to pop up which offered the same capability for a price. SpoofCard is the one that I’ve seen around the most, but many exist. Bah. Setting up an Asterisk server is free if you have access to a Linux box, and outbound SIP trunking is dead cheap. With flowroute.com, I pay less than a cent per minute to place calls within the U.S. The perl script, obviously, is also free.

The other day I saw something as part of a commercial spoofing service that I hadn’t seen before: bidirectional caller ID spoofing. Basically, it will call friend A from friend B’s number, friend B from friend A’s number, and record the result. This leads to something along the lines of “You called me!” “No, you called me!” As fun as that is, websites like PrankDial are charging a lot of money to do something that is, in practice, very simple.

I haven’t seen a script to do this posted on the internet yet, so I created one and put it on github. You’ll have to set up the Asterisk server by yourself, but implementing the script is easy.

  1. Put dual_cid_spoof.py in the /usr/share/asterisk/agi-bin directory
  2. Make it executable to the asterisk user
  3. Add an extension to extensions.conf that calls the script, using pattern matching to give it arguments. For example:
[spoof]
exten => _37NXXNXXXXXXNXXNXXXXXX,1,Answer
exten => _37NXXNXXXXXXNXXNXXXXXX,2,AGI(dualcidspoof.py,${EXTEN:2:10},${EXTEN:12:10})

This uses the extension 37, but that part can be changed. This pattern matches any calls that have the number 37 followed by two 10-digit phone numbers, and then pulls those numbers out and uses them as arguments to the AGI script ${EXTEN:2:10} means take the extension, at index 2, and pull out 10 digits. To execute it with phone numbers 123-123-1111 and 222-202-2020, I would dial 3712312311112222022020.

MeetMe is required to use this script, since it works by placing both users into a conference room together. The default conference room number is 1234, but that can be changed in the script. Also necessary is changing the outgoing SIP trunk in the Python script from “flowroute” to whatever the name of your outgoing SIP trunk is. Both of these are variables at the top of the script. Execution flow works like this:

  • Create two .call files, each with opposite CID/destination info. These files are set to dump the callees into a conference room when they answer.
  • Place the files in /var/spool/outgoing/asterisk, to be automatically processed by the Asterisk spooler.
  • Connect you into the same conference room as a muted admin, giving you the ability to kick users and listen without being heard.

Enjoy, and feel free to ask questions. Again, you can get the script here.