What I'd like is for people to carefully read what I'm about to say, and work out advice that they can give that will be useful, based on the way my server is secured. I say this ahead of time because I know that quite often people can skim-read and then post an answer that they think will help, but is not relevant - and that confuses things
OK so, on to the problem.
Last Monday, I noticed with some concern that someone had downloaded a tarball via some script, and had tried to open it up. They had also fetched a tcl script and some text files. However, they failed to open the tarball, and also they failed to run the script, because of my setup - they got permission denied. One action that was tried was creating a hidden folder in /tmp. This failed, but I checked for it just in case, and it wasn't there.
So, then I go looking to see who it could be. Because it was Apache doing this, I knew they were obviously using a PHP script or something to pull the file down, but I don't know who did it. I searched FTP logs, looking for something that had been uploaded that looked odd. I searched http logs also, trying to see if an unusual script had been run. I came up blank - mainly because I have so many busy sites on my server, and I cannot possibly look through every line myself, so I had to make do with trying various strings to look for (for instance, I knew the exact time of the permission denied error, so I looked for what was being accessed at the time. It didn't help.)
I figure they used fopen() to get the remote file and write it to /tmp, because I found the tarball there. I downloaded it and had a look through, and I found eggdrop. Needless to say, that didn't please me much. I also examined the tcl script and the text files, but I found nothing damning - no sign of hack attempts, and nothing to suggest anyone was doing anything beyond trying to set up an IRC server (which is NOT allowed on my systems, ever, and so I was keen to find out who).
Well, after a while of fruitless searching, I gave up, and resolved to keep my eye on the issue.
Today, I had to restart Apache, but it failed to come up. Port 443 was already in use. Strange... a quick run of netstat showed sendmail using the port. Also strange - nothing should be on that port, plus I use qmail (got a Plesk 7 system here). A kill -9 stopped the process just fine, but to my concern I then saw that eggdrop was using the port... kill -9'd it, and sendmail was back. Very peculiar. A couple of kills later, and they were both gone, and I was able to restart Apache. (And I wasn't happy that all sites had been offline for a few minutes.)
Well, the first thing I did was try to find out where eggdrop was, and also whether it was being started by cron at all. I didn't find it anywhere in any of the cron files, but I DID find that hidden directory in /tmp that failed earlier in the week... ok, so I started to get worried then.
Tarballed and downloaded the directory, then zapped it. Checked through - nothing that would give anything away. Before I killed eggdrop I had run ps -auxw to show the full startup line, and I hunted for the text file that had been passed to eggdrop with the settings, but I didn't find it.
I then spent another long period of time searching ftp and http logs, and yet again I have found nothing. So, I've wasted what was supposed to be a much-needed relaxing Sunday afternoon, on a wild eggdrop chase. And I still have no idea how it got there, who ran it, or how the heck they managed to get it to execute.
----- ----- -----
OK so now you know the problem, this is where I describe the way I have set up my system.
I'm running Plesk 7.0.1 on RHE 3.
I have a 2.4.x kernel, patched as late as I dare (I don't want to update to 2.6.x yet)
I'm running a custom-compiled version of OpenSSH, the latest one last time I checked.
SSH is running on a secret IP (ONLY used for SSH) on a secret port.
No-one on the server has SSH access, or shell usage in any form.
Root login is disabled - a secret, unassociated user has root permissions, and I use that to do root stuff. Root itself doesn't even have a shell.
I don't use passwords to log in - I use a private key.
On top of all that, I have it locked down to my static IP, and I get sent an email every time the shell is opened.
Telnet is disabled etc.
I run APF, with everything blocked except the essentials. It's carefully configured, and as far as I can tell, eggdrop was never able to make a connection. Why it suddenly grabbed port 443 when I restarted Apache, I have no idea...
My Apache is custom-compiled, the latest 2.0.49 build, plus I use a tweaked suexec and a modded PHP 4.3.7-dev. I also have Python, Ruby, and Perl enabled in my Apache setup. For way of information, my Apache is multi-threaded, using a lot of custom stuff to get it stable (works like a dream, I must add...)
My /tmp is mounted as noexec, on it's own partition (I think I followed a how-to from these very forums actually).
----- ----- -----
There's other stuff I've done too, to try and secure the whole thing. I know that no-one is ever completely secure, but I think I know enough to cover most stuff. Tonnes of stuff I don't know though... which is always the problem. One never knows what the next exploit will be.
So - any ideas HOW this happened, how I can find out who did it, and how I can stop it happening again...?
If any more info is required, please ask.
Cheers people
::] krycek [::