- Computers & Software»
- Operating Systems
Few signs that your Linux server has been hacked
First of all, I want you to know that the article doesn’t pretend to be the Guidelines for the Linux protection. It’s just my experience of using Linux as a server.
One of my clients asked me to help because his sever has been hacked. I was able to catch the moment of the hack and capture the software used for the attack. I analyzed the software and discovered what was done and what system services were replaced. But I will begin from the simple tips that let you prevent hacking your system:
- Never send server access information (IP, Login, Password) via Email, Skype or other instant message clients. If you need to send the information, divide it into a few parts. For instance, send IP and user name via email and password – via Skype.
- As far as possible, keep SSH service open for a limited number of IPs.
- Never use simple passwords for the server access (like 123123, birth date, words from dictionary). It is very easy to hack such passwords.
- Never use a similar password for all servers and services. If one of your servers will be hacked, then hackers will find other servers with the same password.
- Never use the same password when registering on different sites. Inexperienced users often use email at Gmail, Yahoo, Hotmail and other services to get register on different sites. They specify password for the email. If the site is hacked, or this site is fraud site, you will lose your password. Remember that hackers will use every password for scanning servers and services.
The most hacks are made with the help of special programs. I.e. there is no a human who hacks your site. Robots do everything.
How to determine that your Linux server has been hacked
A few ways to find out that your Linux server has been hacked:
1. w or who command doesn’t work.
12:21:39 up 96 days, 13:49, 1 user, load average: 0.59, 0.85, 0.63
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
Hackers often removes /var/log/wtmp file so you can’t see who works on the PC.
2. Logs don’t work:
/etc/syslog.conf file was replaced.
3. /etc/passwd and /etc/shadow file are changed – check the dates. Check shady accounts. Hackers can open shell access to a bin user and set their own password.
4. Check crontab for unclear tasks.
This software can help you get out of the rain:
I discovered that the server has been hacked by the above symptoms. We were the lucky men as we discovered the hack very fast.
Now I will describe what happened with our server in details.
- Services ssh, sshd, sftp-server, scp were replaced. A code sending the server password to firstname.lastname@example.org was added. I.e. once the user logs in to the server the password is sent to the hackers via email.If you logged to other servers from the hacked one using ssh, scp, sftp, the password gets to the hackers.
- They installed a few utilities with unclear functions: zmuie, zap, zcut. As I understood, they are used to clear the logs etc.
- Zlib library was replaced.
- The password and shell access was set for bin user .
- The software for scanning networks and guessing passwords was installed.
- Tasks were removed from cron and the task : * * * * * /usr/games/.bash/update >/dev/null 2>&1 was launched.
- Files /etc/shadow and /etc/passwd were stolen.
Our action when your server has been hacked:
1. Close SSH for all IPs except yours one ASAP. Don’t change the password, this is useless. New password will immediately be sent to the hackers.
2. Check crontab. Check change date for cron files
The following process was created on your server in /etc/cron.daily/dnsquery file:
* * * /usr/games/.bash/update >/dev/null 2>&1
3. Check the following folders:
I found services launched by the hackers in these folders.
Analyze these files. Find out what the hacker launched. On our server, the unclear demon was started:
ps ax|grep slogd
and bash – the process found in /usr/games/.bash/bash
Kill all shady processes.
Check the update date of ssh, sshd, sftp-server utilities and /etc/passwd, /etc/shadow files. These dates will help you to specify time of the attack.
4. Check mail.log. Try to understand if the server sends some emails when you log on using ssh.
5. Try to update sshd. You can do this with the following command on CentOS:
yum update openssh.
If you can’t update, try to download and re-install openssh packages.
yum reinstall openssh-XXXXXX.rpm
6. In our case, we re-installed zlib
rpm -ivh --force zlib-devel-XXXXX.rpm zlib-XXXXX.rpm
yum reinstall zlib-devel-XXXXX.rpm zlib-XXXXX.rpm
7. Remove the files:
rm -f /usr/bin/zap
rm -f /bin/zcut
rm -f /usr/bin/zmuie
8. Check /etc/passwd and /etc/shadow
On our server, the password was set and the bash was open for bin user:
Change this line to:
9. yum reinstall utils-linux-XXXXX.rpm
Keep in mind that 100% guarantee way to get rid the effects of the hackers attack is reinstall the system. But the above actions will help you to save time and create backups of your files, databases etc.
Did you meet the similar problems? I’m waiting for your comments.