VPS安全配置

防止CC攻击:使用开源的ddos-defender工具来实现通过netstat定时采集针对80,443,8080的连接数,单个IP连接数达到100以上,可以认为是CC攻击. 将被会主机拒绝1小时。

防主机密码破解:使用DenyHOsts工具进行针对了SSH登录日志进行扫描,普通用户登录失败3次以上,将被主机拒绝连接5分钟,root用户登录2次失败主机将拒绝连接5分钟。
 
防止端口扫描: 一旦有用户使用扫描器扫描节点的IP地址时,该用户的IP将立即被会系统加入到阻止的IP列表中,防止再次扫描。
 
   
   
   
   
  1. #!/bin/bash -x 
  2. #used for vps  
  3. #DDoS-Defender-v2.1.0.tar.gz:  for cc ddos 
  4. #DenyHosts-2.6.tar.gz:  
  5. #portsentry-1.2.tar.gz: for portsentry 
  6. #rkhunter-1.4.0.tar.gz: for chkrookit 
  7. #lynis-1.3.0.tar.gz: for chkrookit 
  8.  
  9. SRC=/usr/local/src 
  10. cd $SRC 
  11. #install msmtp client 
  12. # if your want support TLS/SSL,install openssl-devel 
  13. # yum install -y openssl-devel  // 
  14. wget http://nchc.dl.sourceforge.net/project/msmtp/msmtp/1.4.28/msmtp-1.4.28.tar.bz2 
  15. tar xjf msmtp-1.4.28.tar.bz2 
  16. cd msmtp-1.4.28 
  17. ./configure --prefix=/usr/local/msmtp && make && make install  
  18. cd /usr/local/msmtp/ 
  19. mkdir etc 
  20. echo 'account gmailhost smtp.gmail.com 
  21. from [email protected] 
  22. auth on 
  23. tls on 
  24. tls_starttls on 
  25. tls_force_sslv3 on 
  26. tls_trust_file /usr/local/msmtp/etc/gmail.crt 
  27. user [email protected] 
  28. password ******** 
  29. port 587 
  30. syslog off 
  31. logfile /tmp/msmtp.log 
  32. account default: gmail'  >  /usr/local/msmtp/etc/msmtprc 
  33. wget -O /usr/local/msmtp/etc/gmail.crt http://www.geotrust.com/resources/extended-validation-ssl/certs/Equifax%20Secure%20Certificate%20Authority.crt 
  34. ln -s /usr/local/msmtp/bin/msmtp /usr/bin/ 
  35.  echo "set sendmail=/usr/bin/msmtp" >> /etc/mail.rc  
  36.  
  37. #install DenyHOsts 
  38. cd $SRC 
  39. wget http://nchc.dl.sourceforge.net/project/denyhosts/denyhosts/2.6/DenyHosts-2.6.tar.gz 
  40. tar -xzf DenyHosts-2.6.tar.gz  
  41. cd DenyHosts-2.6 
  42. python setup.py install  
  43. cp /usr/share/denyhosts/daemon-control-dist /usr/share/denyhosts/daemon-control 
  44. cp /usr/share/denyhosts/denyhosts.cfg-dist /usr/share/denyhosts/denyhosts.cfg 
  45. chown root /usr/share/denyhosts/daemon-control 
  46. ln -s  /usr/share/denyhosts/daemon-control  /etc/init.d/denyhost 
  47. chkconfig --add denyhost 
  48. chkconfig --level  345 denyhost on 
  49.  
  50. #configure file 
  51. ln -s /usr/share/denyhosts/denyhosts.cfg  /etc/   
  52. sed -i 's/PURGE_DENY\ =/PURGE_DENY\ = 5m/g' /etc/denyhosts.cfg   
  53. sed -i 's/DENY_THRESHOLD_INVALID\ = 5/DENY_THRESHOLD_INVALID\ = 1/g' /etc/denyhosts.cfg  
  54. sed -i 's/DENY_THRESHOLD_VALID\ = 10/DENY_THRESHOLD_VALID\ = 5/g' /etc/denyhosts.cfg  
  55. sed -i 's/DENY_THRESHOLD_ROOT\ = 1/DENY_THRESHOLD_ROOT\ = 3/g'  /etc/denyhosts.cfg  
  56. sed -i 's/HOSTNAME_LOOKUP=YES/HOSTNAME_LOOKUP=NO/g' /etc/denyhosts.cfg 
  57. sed -i 's/ADMIN_EMAIL\ =/ADMIN_EMAIL\ = [email protected]/g'  /etc/denyhosts.cfg 
  58. cd .. 
  59.  
  60. #install lynis 
  61. cd $SRC 
  62. wget http://www.rootkit.nl/files/lynis-1.3.0.tar.gz 
  63. tar -xzf  lynis-1.3.0.tar.gz  
  64. mv lynis-1.3.0 /usr/local/lynis  
  65. cd .. 
  66.  
  67. #install rkhunter-1.4.0.tar.g 
  68. cd $SRC 
  69. wget http://jaist.dl.sourceforge.net/project/rkhunter/rkhunter/1.4.0/rkhunter-1.4.0.tar.gz 
  70. tar -xzf rkhunter-1.4.0.tar.gz  
  71. cd rkhunter-1.4.0 
  72. ./installer.sh --install  
  73.  
  74. #configure file 
  75. sed -i 's/DISABLE_TESTS="suspscan hidden_procs deleted_files packet_cap_apps"/DISABLE_TESTS="suspscan deleted_files"/' /etc/rkhunter.conf 
  76. sed -i 's/ALLOW_SSH_ROOT_USER=no/ALLOW_SSH_ROOT_USER=without-password/' /etc/rkhunter.conf 
  77. sed -i 's/#ATTRWHITELIST=\/bin\/ps/ATTRWHITELIST=\/bin\/ps/' /etc/rkhunter.conf 
  78. sed -i 's/#WRITEWHITELIST=\/bin\/ps/WRITEWHITELIST=\/bin\/ps/' /etc/rkhunter.conf 
  79. sed -i 's/#SCRIPTWHITELIST=\/sbin\/ifup/SCRIPTWHITELIST=\/sbin\/ifup/' /etc/rkhunter.conf 
  80. sed -i 's/#SCRIPTWHITELIST=\/sbin\/ifdown/SCRIPTWHITELIST=\/sbin\/ifdown/' /etc/rkhunter.conf 
  81. sed -i 's/#SCRIPTWHITELIST=\/usr\/bin\/groups/SCRIPTWHITELIST=\/usr\/bin\/groups/' /etc/rkhunter.conf 
  82. sed -i 's/#ALLOWHIDDENDIR=\/dev\/.udev/ALLOWHIDDENDIR=\/dev\/.udev/' /etc/rkhunter.conf 
  83. sed -i 's/#ALLOWHIDDENDIR=\/dev\/.udevdb/ALLOWHIDDENDIR=\/dev\/.udevdb/' /etc/rkhunter.conf 
  84. sed -i 's/#ALLOWHIDDENFILE=\/usr\/sbin\/.sshd.hmac/ALLOWHIDDENFILE=\/usr\/sbin\/.sshd.hmac/' /etc/rkhunter.conf 
  85. sed -i 's/#ALLOWHIDDENFILE=\/usr\/bin\/.ssh.hmac/ALLOWHIDDENFILE=\/usr\/bin\/.ssh.hmac/' /etc/rkhunter.conf 
  86. sed -i 's/#ALLOWHIDDENFILE=\/usr\/bin\/.fipscheck.hmac/ALLOWHIDDENFILE=\/usr\/bin\/.fipscheck.hmac/' /etc/rkhunter.conf 
  87. echo 'ALLOWHIDDENDIR=/dev/ida' >> /etc/rkhunter.conf 
  88. sed -i 's/#SCRIPTWHITELIST=\/sbin\/ifdown/SCRIPTWHITELIST=\/sbin\/ifdown/' /etc/rkhunter.conf 
  89. sed -i 's/#SCRIPTWHITELIST=\/usr\/bin\/groups/SCRIPTWHITELIST=\/usr\/bin\/groups/' /etc/rkhunter.conf 
  90. echo 'SCRIPTWHITELIST=/usr/bin/ldd' >> /etc/rkhunter.conf 
  91. echo 'SCRIPTWHITELIST=/usr/bin/whatis' >> /etc/rkhunter.conf 
  92. echo 'SCRIPTWHITELIST=/usr/bin/GET'  >> /etc/rkhunter.conf 
  93. echo 'SCRIPTWHITELIST=/sbin/ifup'  >> /etc/rkhunter.conf 
  94. echo 'SCRIPTWHITELIST=/sbin/ifdown'  >> /etc/rkhunter.conf 
  95. cd ..  
  96.  
  97. #install zeppoo 
  98. #cd $SRC 
  99. #wget http://cdnetworks-kr-2.dl.sourceforge.net/project/zeppoo/zeppoo-0.0.4/zeppoo-0.0.4.tar.gz/zeppoo-0.0.4.tar.gz  
  100.  
  101. #install 
  102. wget http://pkgs.repoforge.org/chkrootkit/chkrootkit-0.49-1.el5.rf.x86_64.rpm 
  103. rpm -ivh chkrootkit-0.49-1.el5.rf.x86_64.rpm 
  104.  
  105. #install portsentry 
  106. cd $SRC 
  107. wget http://flexbox.sourceforge.net/centos/5/x86_64/portsentry-1.2-1.el5.x86_64.rpm 
  108. rpm -ivh portsentry-1.2-1.el5.x86_64.rpm 
  109.  
  110. sed -i 's/RESOLVE_HOST\ = "1"/RESOLVE_HOST\ = "0"/g'  /etc/portsentry/portsentry.conf  
  111. echo 'KILL_ROUTE="/sbin/route add -host $TARGET$ gw 333.444.555.666">>  /etc/portsentry/portsentry.conf  
  112. echo 'KILL_HOSTS_DENY="ALL: $TARGET$" ' >>   /etc/portsentry/portsentry.conf  
  113.  
  114.  
  115. #install logcheck  
  116. # //rpm -ivh logcheck-1.3.13-6.el5.noarch.rpm --nodeps 

你可能感兴趣的:(ddos,denyhosts,chkroookit)