Spamming With Asterisk

I wrote this simple script years ago when I needed to load test a bunch of Asterisk machines and simply scaled it back down to a level that’s simply annoying. Be aware that this can completely tie up every line you have if you set it to. I don’t advocate using this for malicious purposes. You could cron it to set a reminder or something less nefarious. To use this you need to have followed my previous guide on how to set up Asterisk. The code and functionality is pretty simple.

#!/usr/bin/perl

$numbertocall = "15552223333";
$numberofcalls = "200";

for($j=0;$j<$numberofcalls;$j++)
{
        $first = int(rand(899) + 100);
        $second = int(rand(899) + 100);
        $last = int(rand(8999) + 1000);
        $callerid = $first.$second.$last;
        open($fh, '>', "/tmp/$number.call");
        print $fh "Channel: SIP/flowroute/$numbertocall\n";
        print $fh "Application: Playback\n";
        print $fh "Data: tt-weasels\n";
        print $fh "CallerID: $callerid\n";
        close $fh;
        system("chown asterisk /tmp/$number.call");
        system("mv /tmp/$number.call /var/spool/asterisk/outgoing/");
        print "Called $numbertocall using $first-$second-$last\n";
        sleep(30);
}

Let’s go over the code.

This should be fairly self evident. You plug in the number to dial and how many time it’s supposed to dial it. It’s currently set to 200. Note that if you keep this set at 200 and ignore the resulting calls that it will leave a voicemail saying “weasels have eaten your phone system” from a random number 200 times.

$numbertocall = "15552223333";
$numberofcalls = "200";

Our for loop simply keeps creating calls until the limit is reached or you ctrl+c

for($j=0;$j<$numberofcalls;$j++)
{
...
}

Here’s the fun part. We generate a random caller-id that will get set and shown on the recipient’s phone. Every time.

$first = int(rand(899) + 100);
$second = int(rand(899) + 100);
$last = int(rand(8999) + 1000);
$callerid = $first.$second.$last;

Now, we write a file to /tmp containing the actual call information. This includes using flowroute as our outbound SIP trunk, the built in Asterisk application called Playback, the included sound file called “tt-weasels”, and we set our caller-id to what we generated earlier.

open($fh, '>', "/tmp/$number.call");
print $fh "Channel: SIP/flowroute/$numbertocall\n";
print $fh "Application: Playback\n";
print $fh "Data: tt-weasels\n";
print $fh "CallerID: $callerid\n";
close $fh;

Next, we chown the file so that the asterisk user can manage it and move it to “/var/spool/asterisk/outgoing”. This folder is special. Asterisk is constantly watching it for .call files like we’re generating and automatically picks them up and spawns a call with the contained information. You could achieve something similar using the AMI but this works perfectly fine as well. Once the call is moved we sleep for 30 seconds before generating another.

system("chown asterisk /tmp/$number.call");
system("mv /tmp/$number.call /var/spool/asterisk/outgoing/");
print "Called $numbertocall using $first-$second-$last\n";
sleep(30);

Assuming you named the file “dialer.pl” you can simply run “perl dialer.pl” to start it. Output should look similar to this

root@asterisk:~# perl dialer.pl 
Called 15552223333 using 555-111-4444

If you’d like to watch the calls being picked up and processed by asterisk you can run “asterisk -rvvv” to get verbose output

asterisk*CLI> 
    -- Attempting call on SIP/flowroute/15552223333 for application Playback(tt-weasels) (Retry 1)
  == Using SIP RTP CoS mark 5
    -- <SIP/flowroute-00000004> Playing 'tt-weasels.gsm' (language 'en')
[Feb 24 00:30:44] NOTICE[1365]: pbx_spool.c:402 attempt_thread: Call completed to SIP/flowroute/15552223333
asterisk*CLI> 

Use this responsibly and don’t encapsulate the existing for loop with another to generate a lot of concurrent calls to completely tie up the phone system of telemarketers forcing them to change their DID blocks.

2 thoughts on “Spamming With Asterisk

  1. Daniel Fielder April 6, 2016 / 10:03 pm

    Got a customer who is being harassed by this as of today, on their cell phone. Any ideas on how to trace back to the source? I can’t think of any, since it’s going out via a SIP provider with spoofed CID.

    • tully May 10, 2016 / 4:08 am

      Call the cops

Leave a Reply

Your email address will not be published. Required fields are marked *