Ok, so one of my websites ( on joomla) is being hacked like the 6th time...
I won't tell you any stories. Only facts:
Firstly, I found that in template index file appeared some alien code:
<div id='hideMe'> <p>Every person knows the large quan...|...ur cure Viagra <a href="xxxxx">Viagra</a> </div><script type='text/javascript'>if(document.getElementById('hideMe') != null){document.getElementById('hideMe').style.visibility = 'hidden';document.getElementById('hideMe').style.display = 'none';}</script>
Then I found in tmp folder a file named asd.php
with content: http://www.codr.cc/bb027a
I tried to decode that and got something like: http://www.codr.cc/97c183
How did this happen? How hacker got an access to create a file? All folders perms were 755 and files - 644.
Joomla doesn't have any unsafe modules, components or templates. Everything is up to date.
What else should I do to prevent future hacks?
It hasn't been hacked for the 6th time. You have been hacked by dozens of bots and your system is backdoored. You remove the infection and a bot will just restore it.
This happened because your software is out of date. It likely some plugin or even joomla its self is very old.
How to prevent this? Well you can look up system hardening guides, and there are a lot of them out there. Regardless, you need to start for scratch. Completely reinstall joomla and all of its components, scorched earth style. Make sure everything is up to date on the new system.
If you are still having problems, hire a professional.
Check which one affects you and correct the mistakes you have made.
Update
Security Checklist/You have been hacked or defaced
Joomla Security
Vulnerable Extensions List