An attacker got root on your system. You can't trust ANYTHING on the system, at all. The scope of what can be done by a rootkit is vast.
If you have backups of your content somewhere, then use them. Otherwise, you can hope the attacker didn't mess up your data. Dump your SQL tables and copy that along with your other stuff (jpgs, pdfs, html, but NOT any scripts / php / anything else that will be executed). Copy it to another system, or dowload it to your home computer if it's small enough for you to be able to upload it again.
Do whatever you can to verify that what you copied is still ok. (like check that the jpgs are still all valid jpgs, just in case. Maybe run a virus scanner on them?)
Blow away the compromised install. If your server is hosted on a typical hosting service, then hopefully they have things set up so you have a control panel that can't be messed up even by root on the host. So you can hope that the attacker didn't manage to touch anything outside of the machine they compromised. (If you had passwordless access to anything else set up on that machine, though, check them.)
Do whatever you have to do to make a fresh install. Might as well move to Ubuntu 14.04 LTS, since you have to reinstall anyway.
Do NOT copy any code from the compromised system to the new system. All data that came from the compromised system should be treated like a potential plague carrier.
Unix filesystem semantics require write permission on the directory for you to remove files. (filenames are links from a name to an inode. The system call to make hardlinks (other names for a file) is link(2)
, and the call to remove a file is unlink(2)
.)
If the sticky bit is set on a directory (chmod +t
), unlink(2)
and rename(2)
also require that the caller own the file to be unlinked or renamed. (regardless of write permission on the file). It's standard for /tmp
and /var/tmp
to be 1777
(world writeable with sticky bit set).
rm
, the shell command, is required by POSIX to prompt before unlinking read-only files, but it has to check for that case. It doesn't have to actually do anything more than unlink(2)
like it would for any other file. So don't be fooled into thinking that this has any effect at all on an adversary.
None of this is very relevant to defending against attacks, because the most likely case is gaining control of your web server process, or something else that is running with a user-id that does have write access to a lot of things.
The more you can limit what can be written by processes that have to deal with data from the Internet, the less chance there is for an attacker to escalate from getting control of your httpd to modifying your data or getting control of your whole machine.
This is why you shouldn't run apache as root.