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:

  1. 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.
  2. As far as possible, keep SSH service open for a limited number of IPs.
  3. Never use simple passwords for the server access (like 123123, birth date, words from dictionary). It is very easy to hack such passwords.
  4. 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.
  5. 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.

ds:~# w
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:

a. /var/log/messages
b. /var/log/syslog
/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:
http://www.yolinux.com/TUTORIALS/LinuxSecurityTools.html
http://sectools.org/ids.html

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.

  1. Services ssh, sshd, sftp-server, scp were replaced. A code sending the server password to bezbol@yahoo.com 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.
  2. They installed a few utilities with unclear functions: zmuie, zap, zcut. As I understood, they are used to clear the logs etc.
  3. Zlib library was replaced.
  4. The password and shell access was set for bin user .
  5. The software for scanning networks and guessing passwords was installed.
  6. Tasks were removed from cron and the task : * * * * * /usr/games/.bash/update >/dev/null 2>&1 was launched.
  7. 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
Delete it.

3. Check the following folders:

• /usr/games
• /dev/shm
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
Restart SSHD:
/etc/init.d/sshd restart

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:
bin:x:1:1:bin:/bin:/bin/bash
shadow:
bin:$1$v8s97$1IA.ASKLjdjaosduu9.:13890:0:99999:7:::
Change this line to:
bin:x:14490:0:99999:7:::

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.

Comments 11 comments

skear profile image

skear 5 years ago from Kansas City

These are some excellent tips! Hackers are constantly trying to brute force the SSH login to my Linux server. I wrote a hub about denyhosts a while back that you might be interested in. I would like to read some more hubs about your Linux experiences.


garryjbs 5 years ago Author

Yes. We use denyhosts script our server. This is good tool.


5 years ago

I got the same hack on mine, this really helped me. Thank you so much!


Anilkumar 5 years ago

Can i know about denyhosts scripts.


Ian Purton 4 years ago

find /etc /proc -mtime 2

Is another good command to use. See the writeup here http://servermonitoringhq.com/blog/how_to_check_if...


PreetSaluja profile image

PreetSaluja 4 years ago

Thanks! Useful info. Voted up.


amithak50 profile image

amithak50 4 years ago from India

That is nice hub...Thanks for it


unfleshedone 4 years ago

Easiest way to hide from automated ssh bruteforcing bots is to change sshd port from 22 to something else. Most bots don't bother probing other ports.


Keiishi 3 years ago

Nice post :) Thanks


simon 14 months ago

The caliber of information that you're offering is merely wonderful. http://testedhacks.com


Davenull 12 months ago

DON'T send credentials via Instant Messaging at all, NEVER

Not even separately on different networks/IM software, and certainly not on proprietary software known for their security breaches and spywares, such as Skype... it's just irresponsible

Don't even use passwords for SSH, use encryption keys, block root access on SSH, use a sudoer account instead, and avoid obvious usernames such as "admin", consider that your username as a secret, just like a password, it should not be a public information...

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working