TEAMFORREST

Asterisk, VoIP, and IT Consulting

Archive for the ‘asterisk’ tag

Use ENUM to Save Real MONey

with 2 comments

Ok — it almost rhymed.

ENUM (read the wiki) refers to the mapping of telephone numbers to internet addresses. Think of it almost as reverse DNS for your phone number. Although there are many methods of integrating ENUM into your system, our current “favorite” is ENUMPlus.org.

From their website:

ENUM sources are very segregated and there was no global repository – until now. ENUMPlus queries all of the top ENUM lookup sources and returns the most accurate result with minimal overhead; meaning you only need to specify one source. ENUMPlus allows you to offload all of the query processing to our powerful servers so you don’t have to waste time and precious resources.

Integrating ENUMplus into Asterisk can be very quick and there’s a few choices/methods of going about it. You can choose to use their php scripts, go direct from the dialplan, or run your own lookup script. Here, we’ve chosen to write our own lookup script that basically does the following:

  1. Checks ENUMplus.org for a result (with a 2 second timeout)
  2. Sets a variable of ENUMRESULT and returns to dialplan
  3. The dialplan then evaluates that variable, and if a sip value is provided calls the number directly via SIP.

Here’s an example dialplan:

exten => _X.,1,Set(CALLTO=${EXTEN})
exten => _X.,n,Goto(out,1)
exten => out,1,AGI(enumcheck.pl,${CALLTO})
exten => out,n,GotoIf($["${ENUMRESULT}" = "FAIL"]?pstn)
exten => out,n,GotoIf($[${ISNULL(${ENUMRESULT})}]?pstn)
exten => out,n,Dial(${ENUMRESULT},55)
exten => out,n,GotoIf($["${DIALSTATUS}" = "CHANUNAVAIL" ]?pstn)
exten => out,n,GotoIf($["${DIALSTATUS}" = "CONGESTION" ]?pstn)
exten => out,n,GotoIf($["${DIALSTATUS}" = "BUSY" ]?busy)
exten => out,n,Hangup()
exten => out,n(pstn),Dial(SIP/${CALLTO}@yourprovider); or DAHDI, etc.
exten => out,n,GotoIf($["${DIALSTATUS}" = "CHANUNAVAIL" ]?busy)
exten => out,n,GotoIf($["${DIALSTATUS}" = "CONGESTION" ]?busy)
exten => out,n,GotoIf($["${DIALSTATUS}" = "BUSY" ]?busy)
exten => out,n,Hangup()
exten => out,n(busy),Busy(5)
exten => out,n,Hangup()

And here’s the script:

#!/usr/bin/perl -w
use strict;
$|=1;
my ($phone, $url, $apikey, $result, @sip);

while(<STDIN>) {
	chomp;
	last unless length($_);
}

if ($ARGV[0]) {
	$phone = &URLEncode($ARGV[0]);
} else {
	&setvar("ENUMRESULT", "FAIL");
	&printverbose("enumlookup: No CALLTO received.",2);
	exit(0);
}

#Get via WEB
$apikey = "REPLACE WITH YOUR KEY";
$url = "http://enumplus.org/api";

$result = qx(curl -m 2 -s -d 'key=$apikey' $url/$phone);

if ($result) {
	if ($result =~ /SIP/i) {
		@sip = split(/\|/, $result);
		&setvar("ENUMRESULT", $sip[0]);
		&printverbose("enumlookup: $sip[0]",2);
	} else {
		&setvar("ENUMRESULT", "FAIL");
		&printverbose("enumlookup: No sip address found.",2);
	}
} else {
	&setvar("ENUMRESULT", "FAIL");
	&printverbose("enumlookup: Timeout or error",2);
}

sub URLEncode {
   my $theURL = $_[0];
   $theURL =~ s/([\W])/"%" . uc(sprintf("%2.2x",ord($1)))/eg;
   return $theURL;
}

sub setvar {
	my ($var, $val) = @_;
	print STDOUT "SET VARIABLE $var \"$val\" \n";
	while(<STDIN>) {
		m/200 result=1/ && last;
	}
	return;
}

sub printverbose {
	my ($var, $val) = @_;
	print STDOUT "VERBOSE \"$var\" $val\n";
	while(<STDIN>) {
		m/200 result=1/ && last;
	}
	return;
}

Happy Coding!

Written by Team Forrest

May 27th, 2010 at 7:07 pm

Posted in VoIP

Tagged with , ,

Automatically Block Failed SIP Peer Registrations

with 10 comments

Previously we posted a little script for quickly checking your asterisk log for failed peer registrations. Building on that script, and with the use of iptables and cron, you can easily (and automatically) block flooding traffic from your system. Iptables, a linux command line program to filter IP traffic, provides high level packet filtering before the traffic can be used to corrupt a program. Cron, the linux time scheduler, enables you to automatically run commands at scheduled time periods.

Set up IP Tables

We will not be discussing the intricacies of iptables in this post. There are excellent tutorials on iptables, and with most things linux, help is only a google away. To help identify the traffic blocked as asterisk related, a new chain will be created appropriately called… asterisk.

Here’s how to add the new chain:

iptables -N asterisk
iptables -A INPUT -j asterisk
iptables -A FORWARD -j asterisk

This will help identify hosts blocked for failed registrations.

Asterisk’s Log for Failed Registrations

In most cases of a sip flood attack, the host attempts registration to Asterisk. These hosts are identified in the Asterisk log (/var/log/messages) as “No matching peer found.” The following perl script scans /var/log/messages for these patterns, strips the IP address, and puts the IP address into an array.

After the file has been read, the IP addresses are counted (each count is a failed attempt), compared against the existing blocked hosts, and new occurrences are blocked. With this script we are blocking any host after the 4th failed attempt.

Here’s the script (last updated 21 APR 2010):

#!/usr/bin/perl -w
use strict;
use warnings;
my (@failhost);
my %currblocked;
my %addblocked;
my $action;

open (MYINPUTFILE, "/var/log/asterisk/messages") or die "\n", $!, "Does log file file exist\?\n\n";

while (<MYINPUTFILE>) {
	my ($line) = $_;
	chomp($line);
	if ($line =~ m/\' failed for \'(.*?)\' - No matching peer found/) {
		push(@failhost,$1);
	}
}

my $blockedhosts = `/sbin/iptables -n -L asterisk`;

while ($blockedhosts =~ /(.*)/g) {
	my ($line2) = $1;
	chomp($line2);
	if ($line2 =~ m/(\d+\.\d+\.\d+\.\d+)(\s+)/) {
		$currblocked{ $1 } = 'blocked';
	}
}

while (my ($key, $value) = each(%currblocked)){
	print $key . "\n";
}

if (@failhost) {
	&count_unique(@failhost);
	while (my ($ip, $count) = each(%addblocked)) {
		if (exists $currblocked{ $ip }) {
			print "$ip already blocked\n";
		} else {
			$action = `/sbin/iptables -I asterisk -s $ip -j DROP`;
			print "$ip blocked. $count attempts.\n";
		}
	}
} else {
	print "no failed registrations.\n";
}

sub count_unique {
    my @array = @_;
    my %count;
    map { $count{$_}++ } @array;
    map {($addblocked{ $_ } = ${count{$_}})} sort keys(%count);
}

Schedule the script with cron

The final step is to schedule your script to run every X minutes in cron. We’ve chosen to run our script every 2 minutes, but you can change this to 1 minute or any other time period you choose. Just remember… you can receive thousands of attempts within 2 minutes.

If you have named your script check-failed-regs.pl and placed it in your /usr/local/bin directory, your cron statement would look like this:

*/2 * * * * perl /usr/local/bin/check-failed-regs.pl &> /dev/null

Questions? Comments? We love feedback. Or, contact us for more information.

Written by Team Forrest

April 13th, 2010 at 12:54 pm

Perl Script for Asterisk Failed Peer Registrations

with 2 comments

I guess this might be better titled as the Quick and Dirty Perl Script… but here we go:

#!/usr/bin/perl -w
use strict;
use warnings;
my (@failhost);

open (MYINPUTFILE, "/var/log/asterisk/$ARGV[0]") or die "\n", $!, "Does log file file exist\?\n\n";

while (<MYINPUTFILE>) {
	my ($line) = $_;
	chomp($line);
	if ($line =~ m/\' failed for \'(.*?)\' - No matching peer found/) {
		push(@failhost,$1);
	}
}

if (@failhost) {
	&count_unique(@failhost);
} else {
	print "no failed registrations.\n";
}

sub count_unique {
    my @array = @_;
    my %count;
    map { $count{$_}++ } @array;

	#print them out:

    map {print "$_ = ${count{$_}}\n"} sort keys(%count);

}

And while we duck from @Merlyn’s criticisms (although we love his criticism), the basic usage is:

perl [Whatever you named it].pl messages
or perl [Whatever you named it].pl messages.1

Results look like:

184.73.53.22 = 13586
64.76.45.100 = 9895
78.46.87.14 = 9960

Or “no failed registrations.” if you have no failed attempts.

Written by Team Forrest

April 12th, 2010 at 6:46 pm

Integrating Fax for Asterisk

with 15 comments

Asterisk provides an open-source solution for IP Telephony (aka VoIP). Customizing your telephone system to increase productivity remains one of Asterisk’s greatest features. Today, we will look at using Asterisk to replace your need for a fax machine.

Benefits

  • Store faxes electronically
  • Reduce printing costs
  • Share faxes via email

Requirements

  • Server running Asterisk (32 bit compatibility needed)
  • Fax for Asterisk Software Add-on

Step One: Get the Fax for Asterisk Software License

First, choose the licensing based on your needs. If you will only need to support 1 simultaneous fax Read the rest of this entry »

Written by Team Forrest

November 16th, 2009 at 11:08 pm

Posted in VoIP

Tagged with , ,

Skype for Asterisk Public Beta

without comments

VoIP Tech Chat posted an article about Digium’s public Beta launch of Skype for Asterisk.

They wrote the article in a Billy Mays style:

Limited Time Offer – Skype for Asterisk Public Beta

Written by Team Forrest

July 30th, 2009 at 4:14 pm

Posted in VoIP

Tagged with , ,

Asterisk Consulting Services

without comments

Asterisk is a registered trademark of Digium

Team Forrest offers Asterisk Consulting Services for a wide variety of VoIP, Call Center, and other Telephony Based needs. From small, family business to large Corporations, Team Forrest’s simple philosophy of “Help the Client” ensures we provide great service to meet your needs.

Asterisk Consulting

From carrier services to traditional PBX services, Team Forrest’s Asterisk Consulting Service provides you the solution you need. Services include:

  • IVR Development
  • Custom AGI Scripting / Programming
  • OpenSER Integration
  • Calling Card Systems
  • Call Center / Sales Queue Development
  • Call Recording (call spying, call barging, whisper, etc.)
  • Database Integration (Microsoft SQL MSSQL, MySQL, Oracle, etc.)
  • Custom Solutions

Emergency Asterisk Support

When a problem comes along, we provide 24/7 Emergency Support to bring your system back to life. Both new and existing clients benefit from our immediate support response.

For immediate support please contact us or call +1 (212) 937-7844.

Remote and Onsite Support

Team Forrest offers immediate remote assistance across the globe. Local, onsite service is also available, with quick response to Michigan, Florida, and New York locations.

Asterisk? Ask us.

With Team Forrest, you get professional consulting at a great price — increased productivity at a lower cost. To see how Team Forrest can help improve your communication needs, contact us. We enjoy talking with clients and look forward to seeing how we can help you.

Asterisk, developed and released by Digium, Inc., is the world’s leading open source telephony engine and tool kit. Asterisk empowers communication with it’s flexibility. Whether working as a simple office telephone system, a robust Call Center platform, or anything in-between, Asterisk provides advanced features at a very low deployment cost.  Asterisk is released as open source under the GNU General Public License (GPL), and it is available for download free of charge. Asterisk is the most popular open source software available, with the Asterisk Community being the top influencer in VoIP.

Written by Team Forrest

June 16th, 2009 at 8:38 am

Asterisk Security Advisory AST-2009-002

without comments

Digium announced today a Remote Crash Vulnerability in the SIP Channel Driver affecting recent versions of Asterisk 1.4 and 1.6 branches. The full Advisory can be read directly from the Asterisk Project Security Advisory:

Description: When configured with pedantic=yes the SIP channel driver performs extra request URI checking on an INVITE received as a result of a SIP spiral. As part of this extra checking the headers from the outgoing SIP INVITE sent and the received SIP INVITE are compared. The code incorrectly assumes that the string for each header passed in will be non-NULL in all cases. This is incorrect because if no headers are present the value passed in will be NULL.

The values passed into the code are now checked to be non-NULL before being compared.

Resolution: Upgrade to revision 174082 of the 1.4 branch, 174085 of the 1.6.0 branch, 174086 of the 1.6.1 branch, or one of the releases noted below.

The pedantic option in the SIP channel driver can also be turned off to prevent this issue from occurring.

Affected Versions

1.4.x (Versions 1.4.22, 1.4.23, 1.4.23.1)
1.6.0.x (All versions prior to 1.6.0.6)
1.6.1.x (All versions prior to 1.6.1.0-rc2)
C.x.x (Only version C.2.3)

If you need assistance in updating or reviewing your Asterisk installation, please contact Team Forrest today.

Written by Team Forrest

March 10th, 2009 at 3:52 pm

Posted in VoIP

Tagged with , , , ,

The Asterisk S-Prize

with one comment

John Todd, with Digium, announced a very cool contest — The Asterisk S-Prize.

To encourage the improvement and testing of larger-scale Asterisk systems, I’d like to repeat here what I mentioned today on the asterisk-dev mailing list: I’m putting out a semi-official challenge in place. The first person to get an Asterisk system moving 10,000 G.711 call legs through a single instance on a single machine will get a first-class steak dinner at Astricon. And a great bottle of wine, if that is your preference.

To read more about the contest, check out the official post at Digium.

Written by Team Forrest

February 19th, 2009 at 2:35 am

Posted in VoIP

Tagged with , ,

Asterisk Security Advisory

without comments

Digium, the makers of Asterisk, announced today a new release of the Asterisk Telephony Software. The updated software contains a security release affecting all previously released versions of the software. It is recommended that you make sure you have upgraded to the most current version of this software; available for free from Digium.

The announcement issued follows:

The Asterisk.org development team has announced the release of Asterisk 1.2.31.1, 1.4.22.2, 1.4.23.1, and 1.6.0.5. These releases are available for immediate download from http://downloads.digium.com/.

This update for Asterisk includes a security fix for chan_iax2. Please see the associated security adivisory for more details:

http://downloads.digium.com/pub/security/AST-2009-001.html

These updates are a fix to a previous security release (released as versions 1.2.31, 1.4.22.1, and 1.6.0.3).

The new versions are being released after additional testing revealed some issues with the way that scanning for users was blocked. Those issues have been corrected in this release.

This security issue affects the 1.2, 1.4, and 1.6 series of Asterisk.

Also note, that Asterisk 1.6.0.4-rc1 was released yesterday prior to the security update. That release has been removed as there will be no 1.6.0.4 release, but rather will be reincarnated as 1.6.0.6-rc1. The reason for the dead release is to avoid 5 digit release numbers.

ChangeLogs for the various releases are available at:

http://downloads.digium.com/pub/asterisk/ChangeLog-1.2.31.1

http://downloads.digium.com/pub/asterisk/ChangeLog-1.4.22.2

http://downloads.digium.com/pub/asterisk/ChangeLog-1.4.23.1

http://downloads.digium.com/pub/asterisk/ChangeLog-1.6.0.5

Thank you for your continued support of Asterisk!

If you would like assistance with upgrading your software, or simply would like us to verify which version you are using, please contact Team Forrest today. We will be glad to assist you.

Written by Team Forrest

January 23rd, 2009 at 6:24 pm

Posted in VoIP

Tagged with , ,

Parking Availability, Team Forrest, and Asterisk

without comments

Ann Arbor Parking

Recently, Fred Posner of Team Forrest, assisted Edward Vielmetti with a simple idea — help make information accessible. In this case, the information was the availability of Parking Spots in Ann Arbor, Michigan.

The Ann Arbor Downtown Development Authority (A2DDA) publishes data regarding parking spot availability on the web, however, when you’re driving to the garage navigating to a web site is the least of your worries. So, an idea was born to make parking information readily accessible — and with that, Team Forrest’s Fred Posner built a quick prototype to demonstrate how Asterisk (by Digium) can help rethink how data can be accessed.

In the prototype, a caller can select which garage to query. The system will then speak to the caller the remaining number of spaces and offer 3 options — select another garage, exit (and hear the local weather), or choose to be notified if there are fewer than 10 spaces remaining. If the caller selects the notification option, the system will automatically check once a minute (for 30 minutes) and initiate a call out to the user. The call will remind the user which garage they selected and inform them of the current number of available spaces.

The prototype for this project can be accessed from the Team Forrest main line, at +1 (212) 937-7844. Then, choose 6 for check local Ann Arbor Parking availability.

About Team Forrest

Team Forrest offers complete Internet Consulting services, specializing in VoIP and Asterisk solutions. Team Forrest has one simple goal: Help the client. Whether you need emergency assistance or if you are planning a deployment, Team Forrest is here to help. With over 15 years experience, our team can quickly assess your needs and help deploy the most appropriate solution.

About Asterisk

Asterisk (by Digium) is the world’s leading open source telephony engine and tool kit. Asterisk empowers communication with it’s flexibility. Asterisk is released as open source under the GNU General Public License (GPL), and it is available for download free of charge. Asterisk is the most popular open source software available, with the Asterisk Community being the top influencer in VoIP.

Related Information:

Written by Team Forrest

January 11th, 2009 at 12:45 pm