Archive for Security

Installing FusionPBX successfully — Part 2: Installing FusionPBX

Continued from Installing FusionPBX successfully — Part 1: Installing Debian Linux

I apologize that these are so hard to read unless you click on them, but I’ll try to put the pertinent points in text.

This is the login screen you get once the Debian installation is complete and the system reboots:

To get the FusionPBX install started, enter

sudo apt-get install subversion

Since this is the first time you are using sudo, you’ll be asked to enter your password:

When that operation finishes, enter

sudo svn checkout https://fusionpbx.googlecode.com/svn/trunk/scripts/install/ubuntu/ /usr/src/install_fusionpbx

sudo chmod 755 /usr/src/install_fusionpbx/install_fusionpbx.sh

sudo ln -s /usr/src/install_fusionpbx/install_fusionpbx.sh /usr/local/bin/

sudo /usr/local/bin/install_fusionpbx.sh install-both user |tee /tmp/install_fusion.log

IMPORTANT: Instead of that last line, if you want to have fewer pauses in the script than the number shown below, you might want to try this instead, but if you use this option, you need to manually change the variables in the script (use sudo nano /usr/local/bin/install_fusionpbx.sh and look at the top of the file; the variables to be edited are quite obvious.  For the database I strongly suggest that you select SQlite, which is the default, unless you want a botched installation — see my comments below).  You might also add more modules (if you need/want them) in the defines section. See the comment by soapee01 in the comments section:

sudo /usr/local/bin/install_fusionpbx.sh install-both auto |tee /tmp/install_fusion.log

I’m told that by using “auto” instead of “user“, the script will have fewer pauses where you are asked to press “ENTER”, but you do have to manually edit the script first. I didn’t know that at the time, so I went with the first option:

When you get to this point, you might question whether you are running the wrong script. You aren’t; there’s only one script for both Ubuntu and Debian, so answer y:

If you are doing a brand new install as we are doing here, then you just downloaded the latest install script, so answer y when asked if you want to continue. Otherwise the script will abort and you will just need to start over:

This is the first of several places where the script will stop and ask you to press ENTER. Presumably you won’t see most such screens if you run the script in auto mode:

This is the part that got me. “Press ENTER to continue (check for errors)” — you see this a lot, and honestly I probably wouldn’t know an error unless it printed blinking red text saying “THIS IS AN ERROR”.

“Press ENTER to continue (check for errors)” again…

And again…

And again…

And again…

And again…

And again, after some attempt to display something unreadable in large ASCII art…

And again…

And again (by about this point you start to wonder if it will ever end)…

And again…

And again (just shoot me now)…

FINALLY, an actual question, asking if you prefer Apache or Ngnix.  When I did this, I couldn’t care less, and Ngnix is the default, so I accepted that. But now I realize that this may have been the wrong choice, if only because you can’t use .htaccess files to secure Ngnix.  If I ever do this again, I’ll choose Apache:

Oh no, we are back to this again…

Aaaaaaarrrrrrrggggggghhhhhhh…….

Can I get a robot that will just press ENTER for me?

And finally another actual question, asking whether you want to use MySQL, PostgreSQL, or SQlite. Since SQlite is already installed and required, why would I want a second database? Well, I might if I were running a system with a higher number of users or phones (see soapee01′s comment in the comments section), or if I plan on adding any software that depends on MySQL.  The default is to use SQlite, so I accepted it, but there have been a couple of times when I wished I had chosen MySQL.  Then again, when I tried doing a reinstall and choosing MySQL, it turned into a disaster that basically meant I had wasted a couple hours of my life (see Oh, FusionPBX, how you vex me for the details, but I’ll warn you ahead of time that I was not in particularly good humor when I wrote that).  If you don’t need anything more than SQlite, pick that, but if you do need something more than SQlite then I would personally avoid FusionPBX until they can get their documentation and the instructions given in the install script to match reality, unless you don’t mind the frustration of doing the installation process multiple times until you get it right.

Finally you get to the point where you need to go to the web-based GUI and enter some information. It will display this message, and wait for you to use the browser to complete the installation:

When you get to this screen on your browser, the Username and Password are probably the only things you need to fill in (and maybe change the Database Type if you selected something other than SQlite). BE CAREFUL when you fill these in – if you make a typo and don’t notice it, you will not be able to access the GUI and will probably need to restart the installation from scratch! So take a careful look at what you have entered, and make use that you actually typed what you think you’ve typed before clicking on “Next”:

On this screen, you will most likely only want to click “Next”, which completes the installation:

The install is finished, and you are returned to a command prompt:

The browser will go to a login screen:

And that completes the FusionPBX installation. It’s not difficult, but there is sometimes a considerable amount of time between the prompts to press ENTER, so most people would tend to wander off and do something more interesting, only to come back later and find it sitting on the next prompt to press ENTER. In my opinion, the Wiki page containing the instructions should advise inexperienced users to run the script in auto mode rather than user mode. I was going to go in and add something to that effect, but something is broken in the registration process and I could not complete a registration for the Wiki. I’m told the Wiki was recently moved to a new server, and apparently the configuration got messed up a bit.

After completing the installation this way, FusionPBX actually seems to run without errors. Configuration via the web-based GUI doesn’t appear to be difficult, although there are a couple of “gotchas” if you are attempting to connect to an Asterisk server (it works, but the configuration involves a couple of non-obvious things that are probably just differences between FreeSWITCH and Asterisk). Since I am just getting started with this and only working on it in my spare time, I’ll try to cover those in my next article.

By the way, if you ever want to upgrade FusionPBX to the latest version and you have installed it essentially the same way I did, there are a couple ways to do it. Probably the easiest way is to go to the Linux command prompt and issue these commands:

cd /var/www/fusionpbx
sudo svn update

It should show you a list of added and updated files, followed by “Updated to revision nnnn.” (where nnnn is the revision number).

The other option is to run this command:

sudo /usr/local/bin/install_fusionpbx.sh upgrade-fusionpbx auto

If you ever want to upgrade FreeSWITCH, you can do this, BUT AT YOUR OWN RISK. I temporarily broke a working system doing this, so if you don’t have the skills to troubleshoot a broken installation then don’t do this, at least not without making a full system backup first. That said, if things don’t work immediately after the upgrade (or even after a system reboot, for that matter), don’t immediately panic – it seems that it may take a few minutes for everything to start working again.

sudo /usr/local/bin/install_fusionpbx.sh upgrade-freeswitch auto
sudo /usr/local/bin/install_fusionpbx.sh fix-permissions auto
sudo service freeswitch restart

Note that the use of “auto” at the end of the above lines will skip many of the pauses and prompts to press ENTER.  If you really want those, substitute “user” for “auto“.

A word about firewalls:

The Easy Install script did not appear to install a firewall, though in theory it probably should have. It does install Fail2Ban, but if there’s no firewall that doesn’t help much. To see if the firewall is running, enter

ufw status

from the Debian or Ubuntu Linux command prompt. If it shows you a list of firewall rules, then it is installed. But if you get a “command not found” message, then you will need to install it using:

apt-get install ufw

Then you need to add the firewall rules. Go to the Ubuntu Firewall page on the FusionPBX wiki and enter the lines in both text boxes, in the order shown, except for the last one (don’t enter the ufw delete 3 line).

If you know what you are doing you can modify those rules as necessary. In my experience, after making any changes to the firewall you may need to restart Fail2Ban (service restart fail2ban). I’m still not quite sure how all this works, since my experience with Linux firewalls is entirely with iptables on CentOS, and even then I generally use Webmin to do my firewall configuration. So, if you see any holes in this strategy, or anything else that needs to be done to tighten up the firewall or make Fail2Ban work as it should, please leave a comment in the comments section!

Configuring E-mail if you elected to install a mail server during Debian installation in part 1:

To configure e-mail if you elected to install a mail server when installing Debian, from a Linux command prompt run:

sudo dpkg-reconfigure exim4-config

How you answer the questions will depend on your installation, and what you want the mail server to do. If you only want to use it to send mail to the Internet (for example, voicemail notifications/recordings), AND your server is on a fixed IP address, you can probably select “internet site; mail is sent and received directly using SMTP” on the first screen, and pretty much accept the defaults from there (this may or may not work if you are on a dynamic IP address — some hosts will reject your mail in that situation). I don’t advise using your PBX server to also handle general e-mail traffic but I suppose that if you have low volumes of voice and mail traffic, you might get away with it.

Limiting access to Apache:

If you installed Apache as I suggested, perhaps you would not like the entire world to be able to get to the login screen of your PBX.  There is a way to limit access to certain IP address, but I will tell you right now that most of the methods you see on the web won’t work.  In particular, using a .htaccess file won’t work (there may be a way to make it work, but I have read those are rather insecure anyway) and in my experience, modifying httpd.conf (which has nothing in it to begin with) doesn’t work (you will either block everyone including yourself, or no one).  What DID work for me was adding lines similar to these to the top of /etc/apache2/apache2.conf (before the initial comments):

<Location />
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
   <— localhost address
Allow from 192.168.0.111   <— an individual IP address
Allow from 192.168.1.0/24   <— a range of IP addresses
</Location>

The above took me THREE hours to figure out, primarily because most of the pages obtained from Google gave other advice that did not work. And people wonder why I do not enjoy trying to figure out these puzzles. All you Linux people who would say that doing something like this “builds character” or “is a good learning experience” can go stick your heads in a bucket of shit and then go jump off a high cliff!

Comments (12)

If you are a Ubuntu user and you value your privacy or security AT ALL, go read this NOW!

This is a REALLY big deal for anyone that is the slightest bit protective of their privacy or security, or that doesn’t want to be a potential victim of identity theft.  Seriously, if you use Ubuntu version 12.10, don’t do another single thing on your system before you go read this.  And if you use an earlier version, do NOT upgrade to 12.10, at least not until this situation is rectified.  I’d say now is a very good time to check out other popular Linux distributions (feel free to leave suggestions in the comments).

Ubuntu has a bigger problem than its Amazon blunder (InfoWorld)

Comments (7)

The Linux equivalent of Little Snitch, ZoneAlarm, and similar per-application firewalls?

This article has been moved. Please click here to read it.

Comments (2)

Link: FreePBX security advisory – SIP extension types

This article has been moved.  Please click here to read it.

Comments (2)

How to isolate a second router from the rest of your local network

This article has been moved. Please click here to read it.

Comments (20)

Running Asterisk 1.8 and Fail2Ban? You need a new configuration file…

This article has been moved.  Please click here to read it.

Comments off

Link: Interesting security technique for Asterisk and FreePBX users (may work with other SIP-based PBX’s also)

This article has been moved.  Please click here to read it.

Comments (5)

Link: Using IP tables to secure Linux server against common TCP hack attempts

This article has been moved.  Please click here to read it.

Comments off

Perl scripts to notify, block failed SIP peer registrations in Asterisk

Just came across these on the Team Forrest blog:

The first one is script that goes through your messages log and tell you how many failed connection attempts have been logged from each IP address, so it’s easy to see if you are under attack from a particular address. I will just note that depending on your installation, you may need to change the path in line 6 from “/var/log/asterisk/$ARGV[0]” to “/var/log/$ARGV[0]” (depending on which directory contains your messages logs). I wish there were an option to email the results if there are more than a certain number of failed attempts from any given IP address (I know it would probably be easy to add, just don’t feel like doing it today), but then again, if you have fail2ban running it should take care of automatically blocking any offender. As for the second article, it seems like an alternative to running fail2ban that’s more limited in scope — still, it might enough for some users.

I just thought these might be useful to some readers and wanted to pass them along.

Comments off

United Airlines fliers must now ask yourselves: If I speak to a flight attendant will I get thrown off the plane?

Saw an item on The Consumerist site today, entitled “United Removes Passenger From Flight After He Asks Whether A Meal Will Be Served.” It contained a link to an original blog post that details the story of one Joe Sugarman, an Internet marketing consultant who was on his way home from a seminar in Austin, Texas (why does this sort of crap always happen in Texas or Florida?).  And his blog post tells the story:

I get to the airport, boarded my plane and I’m sitting in first class. The flight attendant was right in front of me and was curious if they were going to serve meals onboard. So I asked her, “Are you serving any meals during our flight?”

She looked at me kinda funny and said, “I can’t answer that for security reasons.”

A little puzzled, I wondered how it affected security but I let it pass as she went into the cockpit. About three minutes later, two armed Austin police officers boarded the plane, looked at me and said, “Sugarman, follow us.”

Picking up the story a bit further down…

Finally a United representative approached me with my bags and said “We are taking you off this flight for security reasons.”

“Why” I asked.

“You apparently asked the flight attendant if the Police were onboard,” said the United representative. We’re not taking any chances and the captain asked that you be removed.”

“But I only asked her if a meal was being served,” I said. Only to be told that it was her word against mine and the Captain was not going to take any chances based on what the flight attendant claims I said.

Thrown off the plane for asking if a meal was being served was ridiculous. And why would I care if there was a policeman onboard anyway?

Strangely, United had a customer service representative ready and willing to book Mr. Sugarman on the next flight, so apparently at least someone in United has common sense. But, as The Consumerist said about the incident,

… WTF, seriously flight attendant? You couldn’t even say, “I beg your pardon” or “Would you repeat the question” to confirm that you had an evil ‘sploding terrorist on board?

Then there is the lazy Captain, who apparently could not be bothered to go talk to the passenger and do his own assessment of the situation.

Mr. Sugarman further comments,

Another thing that puzzles me is that I am what is called a 1K flyer on United flying over 100,000 miles a year at a minimum. I have flown 2.5 million miles on their airline through the years as well. Couldn’t they use common sense and realize that I didn’t suddenly go off my rocker after being such a good customer of theirs. And why did they believe the flight attendant over me when they let terrorists on board with bombs in their suitcase? Can you make sense of this?

Now, when I read Mr. Sugarman’s blog post, I scrolled down and viewed some of the comments, and noticed this one by Robert Clay:

This reinforces something I have observed for some time. It is often said that the United States is the land of the free, and at gatherings people are often asked to celebrate their freedom. But I wonder if this is all really brainwashing. After all, for all it’s many excellent qualities America right now has the largest percentage of its population in prison of any country on Earth. One out of four people, one out of four humans in prison in the WORLD are Americans, imprisoned in America. This excellent TED talk by Chris Jordan really makes the point” http://www.ted.com/talks/chris_jordan_pictures_some_shocking_stats.html

The ridiculous experience you had is another symptom of this. Interestingly I saw a TV program where Russians were being interviewed about why they were seemingly so disinterested in “democracy,” and what came out is that they just don’t need democracy. Nobody bothers them. They get on and can live their lives without interference.

That said, I don’t suppose the authorities would be too impressed if you were a political activist pushing views that oppose their own. But it’s no different in the US. Or Singapore. Or China.

But I agree with you, it’s right to ask what America is coming to when the average person really isn’t as free as they’ve been brainwashed to believe, and freedom and America are far from being synonymous for millions of people.

Mr Clay sort of verbalizes a feeling I’ve had for a long time. When I was a kid, our teachers tried very hard to brainwash us into thinking that America was the greatest country on earth. Of course, the way they framed it was that if we didn’t love America, our only other option was to live in a place like the “evil” Soviet Union, where people might be shot for asking for a loaf of stale bread to feed their families (seriously, you can’t begin to imagine the lies we were told about the Soviet Union as kids – it actually came as quite a shock to me when I finally realized that Moscow was a major city with modern buildings and electricity, even if not exactly up to U.S. standards).

But the worst thing about the old U.S.S.R., or so we were taught, is that the people there had no freedom – the government basically dictated their every move, morning, noon, and night. The U.S.A. was the closest thing to heaven on Earth, while the Soviet Union was the closest thing to hell, and if there were other choices our teachers sure weren’t about to mention any of them.  We weren’t even taught anything about our closest neighbors, Canada or Mexico, except perhaps in passing references. According to our educational experience, the only countries that mattered were the United States, England (primarily for historical reasons), Germany and Japan (primarily because of their involvement in then-recent wars), and the U.S.S.R.  Occasionally we’d be taught about what we now call a third-world country, like Malaysia (where the natives were still slaving over rice paddies or running around using blow darts to get their food when they weren’t dying of malaria, according to my elementary school education), but probably only to reinforce how lucky we all were to be living in the United States.

This kind of teaching occurred with some regularity throughout elementary and junior high schools, and didn’t really even begin change until about the time I got into high school, when the VietNam War basically divided the country and started causing many people, including some of my teachers apparently, to start questioning whether the U.S.A. always took the most noble course of action. The fact that we had two fairly awful presidents in a row (Lyndon Johnson, a Democrat, followed by Richard Nixon, a Republican) probably didn’t help matters any. But then the war ended and the Bicentennial came along in 1976, and that invoked a new wave of patriotic fervor.

But back in 1967, just about the time that our teachers were starting to sound a bit more enlightened, a movie called “The President’s Analyst” came out. It’s probably one of the few movies I ever saw in a theater (suffice it to say that I am not a big fan of the “theater experience”). And at the time, there was a line in the move that impressed me as being somewhat prescient, at least for the U.S.A.  No, not the one about everyone hating the phone company, although I did get quite a chuckle out of that one.  I actually could not recall the exact line until I went to the The Internet Movie Database, and right there it was, posted in a user review by Merwyn Grote, who wrote,

My lasting view of Soviet-U.S. relations was clearly defined after watching THE PRESIDENT’S ANALYST. Soviet spy/assassin V.I. Kydor Kropotkin, played by Severn Darden, explains to kidnapped American psychiatrist Dr. Sidney Schaefer, played by the irrepressible James Coburn: “Logic is on our side: this isn’t a case of a world struggle between two divergent ideologies, of different economic systems. Every day your country becomes more socialistic and mine becomes more capitalistic. Pretty soon we will meet in the middle and join hands.” Beautiful, simple logic, clearly stated in a whacked-out, slightly psychedelic satirical farce about Cold War paranoia. A gem of genius in a world gone mad.

The trouble is that, in my opinion, we’re not just becoming more socialistic – we’re also beginning to take on some of the negative attributes that our generation was warned about, only we were warned they would happen if we allowed the “evil Communists” to take over our country.  Well, virtually all the recent laws that have seriously curtailed our freedoms were passed during the junior Bush administration, and I don’t think the Republican party is quite ready to take on the mantle of “socialist” or “communist”, though at times they seem to approve of actions that seem not too far removed from something Joseph Stalin would have approved of. Admittedly, the current administration doesn’t seem to be in any big hurry to give us back our stolen freedoms, and that worries me a lot – if we can’t trust either of our political parties to do the right thing, what hope do we have as a nation?

The incident with Mr. Sugarman and United Airlines is certainly not the worst thing that’s happened to an air traveler in our post-9/11 society, but it is symptomatic of how wacko our nation has become, both in that this sort of thing could happen and that most who read about it will think, “Well, that’s just what you have to put up with when you fly nowadays.” Most people in the U.S.A. don’t even blink when TSA screeners do full body scans on children (as this article explains, “In the United Kingdom, scans are not performed on anyone under 18 because they would violate child pornography laws”). And the people of the former U.S.S.R. are probably saying, “Welcome to our world.”

Comments (2)

Geolock — a Perl script for Asterisk or FreePBX users to enhance security

This article has been moved. Please click here to read it.

Comments (2)

Script or module wanted: Geolocation for FreePBX users for added security

Today the Nerd Vittles folks released a new web app called Travelin’ Man, which is described as follows:

Ever wrestled with one of those thorny problems for weeks only to wake up in the middle of the night with the answer? Thus was born Travelin’ Man, a web- based, one-click Asterisk application that automatically reconfigures your Asterisk PBX to enable remote SIP phone access from your cellphone, iPad, remote PC, NetBook, or desktop telephone.

This is a great step in security of those who have remote users that travel from place to place, and that use a phone or device with web access, and that are running the so-called “Incredible PBX” (the current “all-in-one” package from Nerd Vittles, that includes CentOS, FreePBX, Asterisk, and a few extras).  Unfortunately, it’s not real helpful for those of us that may be using a different distribution (EDIT: but, see the comment by NerdUno following this article, where he says “We’d be happy to consider sharing the source code with anyone that would like to write an equivalent system for other aggregations or even generic Asterisk systems”), or who have users with endpoints that do not necessarily have web access (for example, someone who carries a VoIP adapter with them), or for remote users at fixed locations that may not even be aware that their IP address has changed.

It appears at first glance that the Nerd Vittles solution locks each extension to one and only one IP address (which is also possible from within the FreePBX extension configuration screen, in all versions from 2.5 on).  The Travelin’ Man solution appears to use a web app that detects the user’s current IP address, then resets the extension configuration to allow connections from that extension at that IP address only.  However, even with that, there may be a security issue.  As the article notes:

The installer has been encrypted for your/our own protection. In source form, the script would allow anyone to defeat the Incredible PBX requirement. Doing so would mean the required IPtables security component would not be in place and properly configured to protect the underlying system from attack. So we’ve opted to play Big Brother to avoid potential security problems for all of us down the road.

From the above, it sounds to me like perhaps they are hoping that no one will be able to reverse-engineer what they are doing.  Unfortunately, given that Asterisk and FreePBX both use unencrypted configuration files, I’m not certain how successful they will be in keeping their method obscure, so I really hope they are not counting on “security through obscurity.”  I wish them the best, and congratulate them on coming up with a solution that will work for many users, but personally I might have preferred a slightly different approach.

On any FreePBX system, you basically have two categories of extensions – those that are on your local network, and those that aren’t.  It’s very easy to secure the ones on your local network using the permit and deny fields in the extension configuration. For example, if your router assigns addresses in the 192.168.0.x range, then you would use deny 0.0.0.0/0.0.0.0 and permit 192.168.0.0/255.255.255.0 to make sure that no one could connect using that extension’s credentials from outside your local network.  Even if they could somehow guess the correct password, they would not be allowed in. If you have also set up fail2ban on your system, and use good passwords, the chances that anyone will be able to get into your system fall significantly.

Still, if you have remote extension (such as family members or friends that connect from elsewhere on the Internet), you might want to be able to qualify them, or at least take notice if an IP address change looks suspicious.

Asterisk provides a way to find out where are your remote extensions are connecting from. From the Asterisk CLI, you can enter sip show peers to see all your sip-connected extensions, and iax2 show peers to see all your iax2 connected extensions. One of the pieces of information available is the IP address that the extension is connecting from (or (Unspecified) if the extension is not currently connecting). I’m guessing that this same information is available in the Asterisk database (where it could perhaps be accessed using an AGI or similar script?), or if all else fails, in the Asterisk log file. The trick would be to have a script, or maybe even a FreeBX module, that determines the current address that each off-site extension is connecting from, and then checks a local database to see if it matches the address that extension connected from on the previous check (ignoring (Unspecified) extensions).  You could run this check once each minute, or even every few seconds if it doesn’t put a load on your system.

If you do find that the address a particular extension is connecting from suddenly changes, then you could go to a site that will give you some information about where the new IP address is geographically located.  You program or module could allow you to set up rules that would determine whether you want to allow connections from the new IP address.

Let me give you an example.  Let’s say that you had a user whose IP address suddenly changed to 173.194.33.104 (this is just an example, that’s actually Google’s IP address).  Now, since you know that’s not the same as the last address that user connected from, you might do something like this (Warning: don’t click on this link unless you are willing to use one of your daily lookup credits – see below):

http://www.ip2location.com/173.194.33.104

Note that the ip2location service only allows you 20 lookups per IP address per day (200 if you open a free account), so you only would want to query it when a user’s address changes, which hopefully would be a rare event.  So, continuing with the example, you go to that address and get this:

IP2Location demo page (partial page)

Now, as you can see, there is plenty of information there that might help you determine whether this is actually your user. Maybe you know that your user’s ISP is not google.com, or maybe they are always connecting from Michigan, not California. With a properly written script or module, you could say something like “If they are not in time zone -05:00 don’t allow a connection” or “If they are not in Minnesota don’t allow a connection”, or you could get even more specific and narrow it down to a particular zip code. The advantage of this would be that it requires no effort or knowledge by your users, as long as they stay in the area they’re “supposed” to be in, or connect from the ISP they are “supposed” to be using. ISP identification would be particularly useful for external users at fixed locations, where the ISP may randomly assign them some new IP address.

I am not really what you call a programmer, and I definitely don’t have the ability to write a FreePBX module. The best I can do is, on occasion, hack together a small script, but in this case there are two things I don’t know. One is how to get a list of extensions and associated IP addresses out of Asterisk and into an external program or script, into a form that program or script can utilize (basically, the information in sip show peers and/or iax2 show peers, but just the extensions and associated IP addresses). EDIT: Okay, I have figured this much out.  The secret command is  asterisk -rx “sip show peers” (or asterisk -rx “iax2 show peers”) which can then be filtered or piped as necessary.  Just as an example:

asterisk -rx “sip show peers” | grep -v 192\.168\.[12]\. | grep ^1[01] | grep / | sort -n > /tmp/peers.txt

Breaking the above line down:

asterisk -rx “sip show peers” — dump the list of SIP peers
grep -v 192\.168\.[12]\. — filter out the ones on the local network (starting with 192.168.1 or 192.168.2 in this example)
grep ^1[01] — filter out the entries that don’t begin with 10 or 11 (our extension range) (those are probably trunks)
grep / — filter out the ones not currently connected (only keep those with a / character on the line)
sort -n — sort in numeric order
> /tmp/peers.txt — redirect output to the file /tmp/peers.txt

Here’s another example, this one for iax2:

asterisk -rx “iax2 show peers” | grep -v 192\.168\.[0-9]\. | grep ^[1-9] | grep -v “(Unspecified)” | grep -v “iax2 peers” | sort -n

Breaking this line down:

asterisk -rx “iax2 show peers” — dump the list of IAX2 peers
grep -v 192\.168\.[0-9]\. — filter out the ones on the local network (starting with 192.168.0 through 192.168.9 in this example)
grep ^[1-9] — filter out the entries that don’t begin with a digit 1 through 9
grep -v “(Unspecified)” — filter out the ones not currently connected (iax2 doesn’t use the / character on the line)
grep -v “iax2 peers” — filter out the status line
sort -n — sort in numeric order

Point is, you may have to play around with this line a bit to see what works on your system to show connected remote extensions only. NOTE: WordPress changes regular double quotes to “fancy” quotes; in all examples here, if you cut and paste you’ll have to change the quotes back to regular double quotes. Sorry about that.

I also found out that there is a Perl module called Geo::IP, which calls the GeoIP C API.  If you install that API (when downloading, I’d go into the test/ directory and get the latest beta) using the directions on the linked page, and then install the Perl module (you must do it in that order, or installation of the Perl module will fail), you could run a Perl script that shows the location that your off-site extensions are coming in from.  If you don’t want to install the API, or can’t figure out how (not difficult if you follow the directions), you can use the Geo::IP::PurePerl Module which is slower, but does not require the additional C library. Just so you know, GeoIP puts its data file at /usr/local/share/GeoIP/GeoIPCity.dat and they suggest that you go to http://www.maxmind.com/download/geoip/database/ every month or so to grab the latest database (the full link for the country database is currently http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz or you can get a much larger city-level database at http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz — just make sure you don’t grab a CSV version by mistake!). If you need them, there are installation instructions for the database, although they are primarily for the city-level database. If you buy an account, they’ll give you automatic updates, though I can’t imagine it would be that hard to write a script to do that (or maybe Google could help you find one, or see this message thread).

Here’s a really rough first cut at a Perl script which may or may not work as intended, which in theory looks at each of your SIP extensions and if they are connecting from outside the US, then the IP address they are connecting from is banned, and a notice is posted to the syslog and e-mailed to whomever you like — of course this could be modified to check for a different country, or even to add exceptions for various extensions that might have reason to connect from other countries (I warn you, I am NOT a Perl expert – suggestions for improvement are welcome, as are reports of it working or not working):

#!/usr/bin/perl
use strict;
use warnings;
use Geo::IP;
use Sys::Syslog;
my $gi = Geo::IP->new(GEOIP_STANDARD);
my ($ext, @peerline, @extension, $ipaddress, $country, $shellcmd);
my $flag = 0;
# change grep statements in next line to match your local IP range (1st grep) and first digits of extensions (2nd grep)
my @sippeers = `asterisk -rx “sip show peers” | grep -v 192\.168\.1\. | grep ^[1-9] | grep / | sort -n`;
foreach (@sippeers) {
@peerline = split(” “);
$ipaddress = $peerline[1];
$country = $gi->country_code_by_name($ipaddress);
@extension = split(“/”,$peerline[0]);
$ext = $extension[0];
# The next line is a diagnostic you can uncomment if things aren’t working as expected
# print “Extension $ext has IP address $ipaddress which is in country $country\n”;
# In next line change US to your country’s code if necessary
if ($country && $country ne ‘US’) {
$shellcmd = `iptables -D INPUT -p ALL -s $ipaddress -j DROP 2>&1`;
system(“iptables -A INPUT -p ALL -s $ipaddress -j DROP”);
openlog($0,’pid’,'user’);
syslog(‘notice’, “Banning IP address $ipaddress in $country because Asterisk Extension $ext is connecting from there”);
closelog;
if (index($shellcmd, “Bad rule”) >= 0) {
# Change you@yourisp.com to your actual e-mail address in next line
$shellcmd = ‘echo “This is an automated message – please do not reply. IP address ‘ . $ipaddress . ‘ in country ‘ . $country . ‘ was banned in iptables because Asterisk SIP extension ‘ . $ext . ‘ was connecting from there.” | mail -s “IP address banned on Asterisk box” you@yourisp.com’;
system($shellcmd);
$flag = 1;
}
}
}
# If an IP address was banned, the next line totally restarts Asterisk (interrupting all in-progress calls) – you may want to do something different.
if ($flag == 1) {
`asterisk -rx “restart now”`;
}
else {
openlog($0,’pid’,'user’);
syslog(‘info’, “Completed normally”);
closelog;
}

EDIT: After working on this some more, I think I have come up with a better script than the above — see my follow-up article, Geolock — a Perl script for Asterisk or FreePBX users to enhance security for details.

Note there’s a few lines up there that may wrap on your screen but are really all one line — I suggest using cut-and-paste to get the lines in their entirety. In case you are wondering, the reason I try to delete the iptables rule before creating it is because I don’t want to create the same rule multiple times (iptables happily accepts duplicates, unfortunately).  If I get an error when trying to delete the rule, then I know that what follows will be the first attempt to create it, and I should send an e-mail and restart Asterisk when we’re all finished.  Basically, it’s supposed to be a safety mechanism to keep from repeatedly sending the same e-mail, or restarting Asterisk once a minute if for some reason the iptables rule doesn’t “take” at first.  Should you actually try to use this as it sits, read the comments in the source code carefully (they’re important), don’t forget to make the Perl script executable, and run it manually a few times to watch the output (uncomment the “print” line during initial testing).  After you have run it a few times, do an iptables –list and make sure everything looks okay there.  Remember that I am NOT a programmer, so check my code carefully! Only then should you even think about setting up a cron job to run it every minute.

I don’t know of any way to block access to a specific extension in Asterisk “on the fly” from an external script, but I would think that blocking the offending address using iptables would suffice.

So here’s the challenge for you programmers:  Write a FreePBX “Extension Geolocation” module, or a much better and more configurable script that accomplishes what I’ve envisioned here. Something that would run, say, once each minute and check for changes in the IP addresses of all extensions, ignoring those on the local network and those marked as (Unspecified).  When it finds a changed IP address, query a geolocation service (could be ip2location.com, but maybe you know of a better one that permits more free accesses or gives better information?) or run a geolocation api, as shown in the example above, and then check whatever criteria you have established for that extension (any of Country, Region, City, Zip Code, Time Zone, ISP, Domain, IDD Code, Area Code, or Zip Code might be good “trigger” criteria).  If anything doesn’t match, either ban the specific IP address (using iptables) or turn off access to that extension in some manner. And if you need to do that, it would be a good idea to automatically email the user and the system administrator to let them know that something is amiss!

I will note that there’s probably nothing FreePBX-specific about this idea, so while it would be nice to have a FreePBX module that manages this, a script or a program in a high-level language (maybe in any of those languages that starts with a “P” :) ) would be more universal, in that it could be utilized by Asterisk users that don’t use FreePBX.  Either way, it would be a great addition to the available security tools.

Comments (1)

Is there a severe security hole in certain versions of Trixbox?

If you use Trixbox, you may want to pay attention to this thread (ignoring the totally unhelpful comments of the moderator):

http://www.trixbox.org/forums/trixbox-forums/open-discussion/severe-security-flaw

We haven’t used Trixbox since they “forked” the version of FreePBX they used, so I have no idea how serious this issue might be. However, the first person to post in this thread wrote this:

“Recently our system was hacked. Someone called into our Voicemail pressed a few buttons and was able to obtain an outside line. They generated thousands of dollars in fraudulant charges. I worked with Fonality support but even they could not figure out how they performed this hack. …”

At this point, at least two other users in the thread say they’ve been able to replicate the problem, but I get the sense that it only affects certain versions.  I really can’t give you any advice here, and again, I’m just reporting what others have posted in this thread.  But if you are running Trixbox, you might want to keep an eye on that thread for possible further developments.

Comments off

New Products Wanted, part 1: Simple VPN devices (switches and/or routers)

Every now and again, particularly after seeing some of the junk that comes out at shows like the CES, I wonder why a particular product has never been offered.  Today, I want to throw out one such idea, hopefully the first of several (hence the “part 1″ in the title). To put this in perspective, however, I first want you to consider the common consumer-grade router that most of us have on our home networks.  Before these existed, you could have a router but you pretty much had to have a dedicated Linux box for the purpose (and in commercial installations, they still use dedicated Linux boxes running special software as routers).  But there is no way that most home users could figure out how to set up a router, therefore the dedicated router (as sold by Linksys, Netgear, D-Link and probably several other companies) was born.

There is another type of software that ought to be moved into its own box, and that is Virtual Private Network (VPN) client and server software.  Yes, I’m aware of OpenVPN, and I tried to find setup instructions that someone like me could understand, but to no avail – it looks like you need a degree in computer networking to understand how to set up this type of software.  And yet, built into hardware devices, it could be immensely useful in certain circumstances.  Let’s consider the following diagram:

Diagram showing position of "client side" and "server side" VPN devices

In this particular case we have a SIP-based VoIP adapter at a remote location.  Anyone who has worked with Asterisk behind the wrong kind of firewall knows the issues involved with using SIP and not having things set up just so (one-way audio, anyone)? But also, we may for whatever reason want that “remote” VoiP adapter to appear as if it were on the local network (maybe we have an ISP playing games with SIP packets?).  So we plug the VoIP adapter into our “VPN Client-Side Device” and on the other end, we have a companion “VPN Server-Side Device” which in this case makes two connections to the router – one to receive the “tunneled” data and the second to send the unencrypted data back onto the local network.  The green arrows represent the “tunnel”, the orange arrows show where the data from the VoIP adapter enters and exits the tunnel. Please note this is entirely a wired connection, we aren’t using wireless anywhere here.  Also note that as far as the VoIP adapter is concerned, the only network it can “see” is the one at the other end of the tunnel – under no circumstances can it access the Internet other than by going through the tunnel.

I show this using a VoIP adapter, but I’m sure that people could think of a lot of other ways this could be used, and a lot of other devices that could be connected to the client end.

Now some will probably argue that it is inefficient to have a device that does nothing but provide the tunnel.  But that’s the point – almost anyone could set this up.  If you send the client-side device to your grandmother, she can set it up (well, maybe that’s pushing it a bit, but you get my point).  People who would never touch a Linux box or a server could use this.

Someone will doubtless say that it would be more efficient to build this device into the router itself.  Sure it would, but here is the issue with that.  If you put it in the router, then (at least on the client side) you are going to have to provide both “tunneled” and “untunneled” jacks.  And then you have to decide, will we add extra jacks for the tunnel, or will we require some kind of web-based configuration to make each jack tunneled or non-tunneled? On the server side it would be easier – since the idea is that you’re feeding the tunneled data back into the local network, that could be done within the router itself, and you’d just need a way to configure that. But, there are doubtless many people who do not want to replace their existing routers.

Maybe a better idea would be to combine the units with a switch – you’d connect the switch to your router and, on the client side, you’d have four new tunneled ports (that connect to the distant network) and four new untunneled ports (that connect to the local network) – or something like that.  On the server side, you’d plug the switch into two ports on your router and it would give you eight more jacks for your local network, so you get a net gain of six jacks (Note: There may be some networking gurus reading this saying “You don’t need to use two connections to the router, you can do it all on one” – and if that’s the case, great, just use one.  The sum of my experience with networking is plugging computers and other devices into a router, so when conceptualizing this I’m thinking you need two connections, but I may well be wrong about that.  Probably am, in fact).

Another thing to keep in mind is that on one end of the tunnel or the other, you may want to use a software client or server.  So these devices should use some open protocol – is OpenVPN the best choice? I could see a lot of situations where you’d want the dedicated hardware on the client side (so you could send a box to someone and say, “Just plug your VoIP adapter into this device, and then plug this device into your router”) but on the server side you want to run an actual OpenVPN server, or whatever. A VoIP provider with a customer that keeps experiencing one-way audio could ship one of these boxes out, and yet on the provider’s end they’d almost certainly want to use a software server.  Maybe you’re a Linux geek, and your grandfather in Poland wants to watch programs on Hulu – you could tell him to buy one of the client boxes, then set up the OpenVPN software on your server. Sure, he could set up the server software on his computer, but do you really want to try and talk him through that?

Let me go over the main “ideal” criteria I would set for these types of boxes:

  • They must be open source, and compatible with software clients and/or servers that run on all major platforms (such as OpenVPN?)
  • They must be dead simple to set up and use
  • They must be able to find each other, even if both units are behind NAT firewalls
  • They must NOT require that ports be opened in a firewall, at least on the client side
  • Should be very flexible with regard to port usage, and able to switch ports if the “usual” port is blocked
  • If they need to communicate basic information with each other (e.g. current IP address and port usage) they should be able to use an open server (perhaps a Jabber-based IM service such as Gtalk??)
  • On the client side, the connected device(s) should never under any circumstances “see” the local internet connection – only that on the other side of the tunnel

The goal is, to the greatest extent possible these should be “plug and play” devices.  I fully expect there will be some configuration needed, but the less there is, the better. Remember, these are devices for intended for Windows users that run Internet Explorer as their browser (just as an example of the experience level of users that might buy these).

This would be a natural product for Linksys, Netgear, D-Link, or some startup company for that matter.  But I have never seen such a device.  I have seen an occasional higher-end router that advertises some type of VPN capability, but they are nowhere near drop-dead simple to set up and use, and they are also not priced for the typical consumer.  I also have no idea what they are compatble with, but I’m pretty sure it’s NOT OpenVPN.

Comments on this idea are welcome.  Oh, and if you’ve ever found any really good, clear, “cookbook” type instructions on how to set up OpenVPN (or any other VPN, for that matter), please leave a link in the comments.

Comments (5)

Stop entering passwords: How to set up ssh public/private key authentication for connections to a remote server

This article has been moved.  Please click here to read it.

Comments (1)

Phones Aren’t Safe Either, Hackers Say on Threat Level

Excerpt from the Threat Level blog:

Hacking VoIP is easy, says John Kindervag, and it gets you well past the phone. Using penetration tests propounded by a tool called VoIP Hopper, he and partner Jason Ostrom got well past the phone into the corporate systems that support it from hotel rooms, corporate offices and so on.

Phones Aren’t Safe Either, Hackers Say on Threat Level

I’m just wondering how long it will be before companies that make VoIP equipment and software will start to take security seriously.  Most VoIP traffic isn’t even encrypted in any way, and if I’m understanding this blog post correctly, it appears that an insecure VoIP system may sometimes be the weak link that allows hackers to penetrate a corporate network and walk off with other types of data not even related to VoIP!  I’m not qualified to tell you how bad this really is, but if I were a corporate type responsible for the security of my company’s VoIP and corporate data network, I don’t think I’d be sleeping too well after reading this.

Comments off

Follow

Get every new post delivered to your Inbox.

Join 133 other followers

%d bloggers like this: