Support

Admin Tools

#10183 site hacking inspite of admin tools Pro

Posted in ‘Admin Tools for Joomla! 4 & 5’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

Joomla! version
n/a
PHP version
n/a
Admin Tools version
n/a

Latest post by nicholas on Friday, 06 January 2012 15:22 CST

easytherm
Mandatory information about my setup:

Have I read the related troubleshooter articles above before posting (which pages?)? Yes
Have I searched the forum before posting? yes
Have I read the documentation before posting (which pages?)? full admin tool user's guide, maybe I missed something
Joomla! version: (1.7.3)
PHP version: (5.2.6)
MySQL version: (5.0.77 )
Host: (www.easygiga.com)
Admin Tools version: (Admin Tools Professional 2.1.14)


Description of my issue:

I subscribed and installed admin tools pro due to a very strange problem:

When I launch my website it starts for a couple of seconds in a strange format, then changes over to my normal template (see attached file). This problem arises with every browser (mozilla, chrome etc..) not only with IE

When I restore a clean project (using akeeba backup / kickstart), the site keeps running fine for maybe 1 or 2 days, then switchs back to this situation. Of course I make no website modification in with this state.

As far as I remember, the problem was not present before I looked at my site with google analytics, but I'm not 100% sure

I suspected I'm hacked so yesterday evening, waiting for the 2011 to 2012 minight, I subscribed and installed Admin Tools Professional 2.1.14. on a fresh website restore.
I reinstalled I followed the steps explained in chapter 4 "quicksetup" including WAF settings and .htaccess generation.

I immediately made a backup to get a reference point.
During the night I got about 20 security exceptions coming from admin tools pro, but the website ran fine. At 15h00, I checked and the problem was here again. I suspected index.php and configuration.php have changed. Their timestamp is 14h55 (I wasn't doing anything at that time). Their permissions are 644

Just to be sure, I ran a site backup in this situation and compared this (bad) backup with the last (good) one using sitediff. The result shows me 2160 (!) modified files, mostly php files, please see sitediff output.

Do you have any suggestion?


best regards and happy new year

Jacques Charpié


nicholas
Akeeba Staff
Manager
Please note that Admin Tools Professional can only protect you against hacking attempts which go through your site's index*.php files. When you use the .htaccess Maker, it will also create a .htaccess which prevents direct access to .php files on your site, unless you allow specific files to be directly accessible.

From that point, your site can be hacked with one of the following ways (these are the most common ways, not an exclusive list):
- Bad ownership/permissions. Please note that permissions alone mean NOTHING AT ALL. For more information, you can consult Akeeba Backup User's Guide, the Security chapter. If you have bad ownership/permissions, it is possible that another hacked account on the same server can overwrite your files, i.e. hack your site.
- Direct access to vulnerable .php files. If you have not used .htaccess Maker or if you have added exceptions for some .php files and these are vulnerable, an attacker can very easily access them over the web to hack your site. Since the access to these files does not pass through Joomla!'s index*.php files, Admin Tools is not running and can not protect you.
- Stolen FTP access. It's not that hard. Malware on your or your client's (if you're managing a client's site) computer can steal your FTP login information. This gives the attacker a "free pass" to hack your site.
- Exploited yesterday, ready to be hacked tomorrow as Brian Teeman has shown. In this very common scenario, the attacker has infiltrated your site a while ago, then hacks it at his convenience in a later date.
- Some attacks may pass through Admin Tools Professional, albeit it take a lot of skill and a scandalously badly coded extension for this to happen. For example, if you have an extension which allows an attacker to execute PHP code passed in a POST request without a PHP tag (e.g. the developer is using PHP's eval() with unvalidated input data) there's no way Admin Tools can protect you. I have not seen such extensions in the wild, only custom extensions written by underskilled (or, should I say, unskilled), idiotic freelancers of the 1$/hour rent-a-coder variety.

So, what can you do? Start by reading my Unhacking your site walkthrough. It will help you not only fix the hack, but also secure your site.

The next step you can do is to wait just a few days for me to publish the new alpha release of Admin Tools. I have just (as in, ten days ago) completed writing a handy new tool which allows you to run a security assessment of your site's files. It does throw a lot of false positives in the first run, but it will narrow down the list of possibly suspicious files to about 100 of them. The documentation explains how you can check those files against the "official" files of Joomla! itself or the extension they belong to to make sure they are not suspicious. If you find a compromised file, you will immediately know how you're being hacked.

If, despite the above, you still get hacked, you are on a host with one or more hacked sites and screwed up ownership/permissions which allow the hacker to hack your site through the "back door", i.e. by directly modifying your site's files from the other hacked site on the same server. Besides fixing your ownership and permissions (as explained in the Unhacking Your Site walkthrough) the only other workaround is to actually move to a different host.

I know this is a LOT of information to take in. Let me give you a sound advice. Don't panic. The situation can't get much worse than it is right now and doing things hastily will end up to offering no solution, only wasting your time. Start by meticulously following the unhacking instructions and you'll see that things will start making sense. It will take you 1-2 days, but in the end you'll end up with a much more secure site.

Good luck and, should you get stuck, please post back so that I can help you!

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

easytherm
Nicholas

Thank you for your advises,

Today, I spent a couple of hours reading the documentations, checking my logs and my configuration.

I observed this:

in my apache access log there are no “insert”, “update” or “replace” statements, but "GET" and "POST" statement. Maybe I miss something.


In my project, when hacked, all *.php files have got exactly the same code insertion, something like this
All files got about the same timestanp, and were modified up to 4 subdirectories from the root directory. Lower files (5 subdirectories away or more) were not modified.
WAF was set with "all" options suggested in your quick setup, as well as .htaccess with the default setup you propose. I also used the "fix permission" button just to be sure.

On my host, I configured some month ago a subdomain with a copy of my website, in order to be able to test mdifications before putting them in the main website. This morning, I erased this website, just to be sure I'm not opening a backdoor by myself and a restored my site and configured it with admin tools pro.

I will see within a couple of hours or days if I get hacked again.
Anyway I wait for your new relase of admin tool, in order to check my files if they are corrupted.

My host proposed me to switch to another server with a more recent php version (5.2.17 instead of currently 5.2.6). Can this be a way to improve my situation?

best regards

Jacques

nicholas
Akeeba Staff
Manager
Hi,

I think you are confusing the action verbs' context. The first verb (GET, POST) is the HTTP command. these are the two most common, accounting for 99.9% of all requests you'll see in the log. Some more exotic HTTP verbs are HEAD, TRACE, PUT and DELETE, but I don't think you're going to see them in your logs. Now, the INSERT/UPDATE/DELETE verbs are SQL commands and would only appear in the URL (not the column before the URL!) if an attacker tried to launch a SQL injection (a.k.a. SQLi) attack on your site. If you don't see any of them, the attacker is not using an SQL injection attack.

The next bit you mention is a case-breaker:
All files got about the same timestanp, and were modified up to 4 subdirectories from the root directory
Let me analyse this. Something scans and modifies all PHP files, 4 levels deep, within a few seconds. This means that there is a PHP file which performs that malicious act. In your previous email you also told me that this always happens around 3 p.m. every day. You know what that sounds like? A CRON job. Check the CRON jobs on your site. If you see anything you didn't put in there yourself, remove it (after noting down the file which was being called), then remove the file which was being called. Also change all of your passwords, including your hosting account password. Better be safe than sorry.

You should also follow all of the other security advice in the unhacking guide, including the tip to restore your site using Kickstart's FTP mode to make sure your files are not writable by another hacked site on the same server.

The PHP version seems to be quite irrelevant with this hack. I think that there is a hacking script somewhere in your site which is being run every so often, re-hacking your site all over again. This is what you have to locate and remove.

If you can't make heads and tails of that, please send me a Personal Message. I can give you contact details for Joomla! professionals who can do the whole unhacking deal for you, albeit for a fee. They will also help you secure your site.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

easytherm
Nicholas

maybe I go a step forward. I checked my host's crontab. There is still only the one task I configured to be executed at 2h30 AM to backup my site after midnight.

I checked the content of that file backup.php. It has not changed until setup and seems correct to me:

*************** with my values


define('SITEURL', '******************'); // Base URL of your site
define('SECRETKEY', '******************'); // Your secret key
define('PROFILE',1); // The profile's ID

// ====================== DO NOT MODIFY BELOW THIS LINE ======================
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,
SITEURL.'/index.php?option=com_akeeba&view=backup&key='.
SECRETKEY.'&profile='.PROFILE);
curl_setopt($curl_handle,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($curl_handle,CURLOPT_MAXREDIRS,10000); # Fix by Nicholas
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer))
echo "Sorry, the backup didn't work.";
else
echo $buffer;
?>

So ther is no correlation with the hacking event and my current crontab setting.

I will now check at what time the next hack will arrive. This may give me more information.

By the way, I restored my site with Kickstart's FTP mode disabled (which facilitates new component installation). I understand this may be a mistake.

In the next hour, I change all my passwords (hosting, ftp, joomla superuser, and mysql)

easytherm
By the way, I realize that all passwords are in clear in configuration.php:

mysql
ftp
smtp (email)

configuration.php owner has permission 444 but owner is apache. Is that correct?

nicholas
Akeeba Staff
Manager
OK, it's not a CRON job, the only CRON file (the one you posted) is perfectly safe as it is. This leaves only a handful of possibilities:
- A hacking script left in a directory and being called by the attacker to re-hack your site (Using Admin Tools' .htaccess Maker with the default settings will rule that out)
- Another compromised account on your server hacking your site (you should restore using Kickstart's FTP mode and use Joomla!'s FTP feature to allow extension installation, do not use 0777 permissions)
- Stolen FTP information (this won't be a factor once you change your passwords)
I'd say we're in a good track. You've ruled out a few possibilities so far, which means that you're closing in to the solution.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

nicholas
Akeeba Staff
Manager
Yes, all passwords are stored in the configuration file as cleartext.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

easytherm
please excuse me to ask it again with other words. Are there any precautions to be taken with configuration.php due to these cleartext information? In my poor knowledge of unix, I understand that: as apache is owner of this file, a php script can read this file and disclose this information.

I suppose it has to do with .htaccess

Maybe you can just suggest me a corresponding reading

nicholas
Akeeba Staff
Manager
You are absolutely correct. Worse yet, since all of your files are owned by Apache, they can be read and written to by all users on this web server. That's why I asked you to restore your site using Kickstart's FTP mode. This will change the ownership to your site's user. From that point, it's your host's responsibility to ensure that the home directory's permissions are 0700 to prevent any unauthorised user from peeking at your files. If they can't do that, it's a good idea to move to a secure host, like CloudAccess.net, iRedHost or Rochen.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

easytherm
I immediately checked my home directory ( httpdocs on my host).
user was ftp account, which seems ok, but permissions were 777. I could set this to 0700 through my parallel plesk file manager interface.

Later this evening, I'll restore my website again using Kickstart's FTP mode.

Thanks a lot for your suggestions!

Jacques

nicholas
Akeeba Staff
Manager
You're welcome! Let me know how it works out!

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

easytherm
some news of my tests. As I told you, I changed the permission of my home directory to 0700. No problem. I tought... But my website didn't work anymore (forbidden access, message was I think error 403 or so)

I thought, it doesn't matter, I reinstall it anyway, using using Kickstart's FTP mode. Wich I just finished now.

I encountered a problem. Access to kickstart was not possible from my browser, as long as home directory permission was 700. I needed to put it to 0770 and then I could proceed.

Q1: Is this a problem what the host security concerns?


Then installation with ftp mode worked fine and website is working now.
I just saw that you published the new admin tool pro and wanted to install it. Now comes the ftp problematic again.

If I want to activate ftp I need to do it from admin - site - global configuration - server. Right? then when I save, I get the error "JFTP: :write: Bad response Could not save data. Error: Could not write to the configuration file"

I think this is due to the actual permissions on configuration.php, set through admin tools to 444.

I imagine the following has to be done. Q2: Can you confirm it makes sense:
Basically, ftp mode should stay at off, and when needed (component/module/plugin installation) switched to on then, after completion, back to off?

for changing this, configuration.php should be writable (now it is unwritable, or 444 as set by admin tool)

So I imagine the following procedure, to be repeated at every modification ( abit complicated, but makes sense to me)

set configuration.php permission to 700
change ftp mode to on
install the component/module/plugin
change ftp mode to off
revert configuration.php permission back to 444

Q3: same as Q2 is the above procedure correct?

best regards

nicholas
Akeeba Staff
Manager
Hi,

1. It actually depends on ownership. 0770 sounds a typical case. Not very secure, but unless your host is using suPHP or Apache's mod_itk this is the closes to secure you can possibly get.

2. You have to do a little trick. Set the permissions of configuration.php to 0777, go to Global Configuration, set up the FTP mode and click on Save. This will replace the configuration.php (owned by apache) with a new one (owned by your FTP user) and change its permissions back to 0444. Talking about killing two birds with one stone ;)

3. No, not really. You can have the FTP mode turned on but without a password. What I mean is that after installing the extension, go back to Global Configuration and delete the FTP password, but please leave the FTP enabled. Next time you try to install an extension, Joomla! will ask you for your FTP password. Clever, huh?

You will only need to supply your FTP password to Global Configuration before using an extension which needs to modify site files, like Admin Tools' Fix Permissions or Clean Temporary Directory tool.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

easytherm
Hello Nicholas,

Since last reinstall with kickstart ftp mode enabled, my site seems stable, no more php files modifications, inspite of many security alerts... Again, thanks a lot.

Anyway, I've asked my host to enable the suPHP function on my shared server. When done, I'll recheck with 700 permission on the home direcory.

The reason I reply one more time is the following problem, which I didn't notice first:

I installed for a couple of months extplorer and could use it to my full satisfaction, also with the free version of admin tools. Since I installed Admin tools pro I can't access to this component (see attached file). Maybe you can give me a hint, what is to be safely enabled in the WAF?

Jacques Charpié

nicholas
Akeeba Staff
Manager
That's easy! Go to Components, Admin Tools, .htaccess Maker and expand the "Server Protection" pane. Add the following line to the "Allow direct access to these files" text area:
administrator/components/com_extplorer/fetchscript.php
Then click on Save and Create .htaccess.

FYI, the exact instructions for coming to this conclusion yourself are listed in the documentation and our troubleshooting guide.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

easytherm
Thank you very much. Next time I try to figure out by myself using your documentation.

Jacques

nicholas
Akeeba Staff
Manager
You're welcome! If you get stuck and can't figure it out on your own, just post here and include a URL if it's a front-end item. It allows me to just go to that page, take a look and tell you what needs to be added.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!