Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 21-30 of 43 total

Looking into DOS and DDOS Attacks

A good guide to what to do when your server is attacked.

   1  top -d2
   2  netstat -nap | grep SYN | wc -l
   3  netstat -nap | less


If there are many httpd processes showing up after step 1, you might be under attack. If you get high numbers for the second one, you are almost definitely under attack. Use the third one to see the IP addresses, and then ban them from the server:

   1  iptables -A INPUT -s ip.address -j DROP


Also try the following for fixing stuff:
   1  cd /dev/shm
   2  ls


And delete anything that's not supposed to be there.

   1  locate bindz
   2  locate botnet.txt
   3  locate dc
   4  locate ex0.pl
   5  locate kaiten
   6  locate r0nin
   7  locate udp.pl
   8  locate ...
   9  lsof | grep .,
  10  locate mybot

Ban IPs from a server

Use the code below to permanently ban an IP address from accessing your server.

   1  
   2  iptables -A INPUT -s ip.address -j DROP

How to tail logs

   1  
   2  tail -200 /var/log/exim_mainlog
   3  tail -200 /usr/local/apache/logs/error_log


To watch the log get updated in real time:

   1  tail -f /var/log/messages 

Sims 2 File Limit Fix

Type this into Terminal in Mac OSX to fix the file size limit for The Sims 2, allowing you to have more than 5000 downloads.

   1  
   2  sudo sysctl -w kern.maxfiles=22000
   3  sudo sysctl -w kern.maxfilesperproc=20000

How To Manually Update Cpanel

   1  
   2  /scripts/upcp
   3  
   4  /scripts/upcp --force

How To Restart Services

Restart Apache:
   1  service httpd restart


Restart Services:
   1  service chkservd restart


Restart Cpanel:
   1  /etc/init.d/cpanel restart


Restart Bind:
   1  service named start


Run anything in /scripts:
   1  ./scriptname

How To Locate Files

   1  
   2  lsof | grep searchterm

How To Fix Bandwidth Updating

If bandwidth stats aren't updating:

   1  
   2  /scripts/runweblogs username
   3  /scripts/runlogsnow

How To Fix 403 Errors for public_html

If all the public_html folders got their permissions wrong:
   1  
   2  chmod 755 /home/*/public_html

How To Empty /var

If /var is too full:

   1  cd /var
   2  du -sh *


If the log directory is the problem:

   1  rm -f /var/log/*.1
   2  rm -f /var/log/*.2
   3  rm -f /var/log/*.3
   4  rm -f /var/log/*.4


(The /var/log directory contains archived files that always end with a number: exim_mainlog.1. Any file ending with a number can be safely deleted.)

If the problem is with the exim_mainlog being too large, try rotating the logs:

   1  /usr/sbin/logrotate -vf /etc/logrotate.conf


If you get an error about a duplicate log entry:

   1  cd /etc/logrotate.d
   2  rm -rf httpd.rpmorig.log


And try the rotate again.

If the problem is in spool:

   1  cd /var/spool/exim/msglog
   2  rm -rf *
« Newer Snippets
Older Snippets »
Showing 21-30 of 43 total