I'm not sure if anyone actually answered this or not, I stopped reading when the flaming started.
Turning off compilers
Code:
chmod 700 /usr/bin/*cc*
Mounting /tmp noexec
Code:
Move to directory with 500MB free
cd /home
Stop everything
service chkservd stop
service httpd stop
service mysql stop
Use dd to write 500MB of zero'd out data to it:
dd if=/dev/zero of=tmpfs bs=1k count=512000
Then, force mke2fs to format it:
mke2fs -j -F tmpfs
Okay, so now we have a formatted filesystem inside this file.
Mount it someplace temporarily:
mkdir /newtmp
mount -t ext3 -o loop /home/tmpfs /newtmp
and copy over files and rm /tmp
cd /tmp
cp -ra * /newtmp
rm -rf *
Unmount new tmp:
umount /home/tmpfs
Add the following to /etc/fstab:
vi /etc/fstab
/home/tmpfs /tmp ext3 loop,noexec 0 0
Remount:
mount -a
Change permissions on the directory:
chmod 777 /tmp
chmod +t /tmp
Start everything
service chkservd start
service httpd start
service mysql start
-Note, I had to readd the mysql.sock symlink after I did this
cd /tmp
ln -s /var/lib/mysql/mysql.sock
If /var/tmp isn't symlinked to /tmp do
cd /var
rm -rf tmp/
ln -s /tmp tmp
DONE
As for a firewall, we used iptables, here's what our iptables policy script looks like
Code:
IPTABLES="/sbin/iptables"
#Flush everything, start from scratch
$IPTABLES -F
#Set default policies to DROP
$IPTABLES -P INPUT DROP
$IPTABLES -P FORWARD DROP
#Allow all lo traffic
$IPTABLES -A INPUT -i lo -s 0.0.0.0/0 -d 0.0.0.0/0 -j ACCEPT
#Allow all connections related and established connections
$IPTABLES -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
$IPTABLES -A INPUT -s 24.155.39.207 -j DROP
#Set default OUTPUT policy to ACCEPT
$IPTABLES -P OUTPUT ACCEPT
# Open ports for server/services
$IPTABLES -A INPUT -p tcp --dport 20 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 21 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 22 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 25 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 37 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 43 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 53 -j ACCEPT
$IPTABLES -A INPUT -p udp --dport 53 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 80 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 110 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 113 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 143 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 443 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 465 -j ACCEPT
$IPTABLES -A INPUT -p udp --dport 465 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 873 -j ACCEPT
$IPTABLES -A INPUT -p udp --dport 873 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 993 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 995 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 2082 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 2083 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 2086 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 2087 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 2089 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 2095 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 3306 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 6666 -j ACCEPT
#Enable Blogger support (non-standards compliant piece of dogshit that it is)
$IPTABLES -A INPUT -s 66.102.15.83 -j ACCEPT
$IPTABLES -A INPUT -s 216.34.7.186 -j ACCEPT
#Add passive-mode people here
$IPTABLES -A INPUT -s 24.1.79.131 -j ACCEPT
#Logging
$IPTABLES -A INPUT -j LOG --log-prefix "INPUTDEFAULT: "
#Save rules
iptables-save > /etc/sysconfig/iptables
#Restart for rules to take effect
service iptables restart
I'd also reccomend installing and using phpSuExec, which if you use cPanel, can be turned on using /scripts/easyapache
Hope this helps and good luck in fighting off the hackers.