Linux Scripts

Emergency DOS or DDOS stopping script for Linux

DDOS Attack
Click to view in Original size.

If you are under a DOS or DDOS attack and running out of your mind or don’t know what to do, use this script to get ride of this panic situation.

DoS or DDoS is an attempt to make a victim website unavailable by creating hundreds to hundreds thousands of established connections that overflow victim resources and makes a website unavailable to the genuine users/visitors.

Short and useful slide that definite this script can be view on slideshare

You can run script to mitigate a low level ddos attack some how while and can stop DOS attack completely. This script is available under GPL license from the author.

How to mitigate DoS or DDoS attack?

Stop or flush other rules for now :

service apf stop
iptables -F
mv antiDDoS.txt
chmod u+x

HowTos Linux

How to track Linux Shell Users activity?

Linux Shell users loggingQuestion:

I am managing a team of Linux System Administrators, which manages a large number of servers remotely. This admins require root level privileges on servers. Now how can I keep track of each user activity for audit purpose and to keep record of each command is executed on server. Recommend open source application on Linux.

There are couple of available tools/scripts on Linux to achieve this goal. But we have found Rootsh a simple solution to this hitch.

What is rootsh?

rootsh is a shell wrapper that logs all keystrokes of a terminal with output and save it into a file whcih is randmoly generated for each user. rootsh also supports logging into syslog but it is bad idea because syslog file can easily be removed by a root user.

We will create a separate folder for logs where we will apply group level privileges & apply append attribute to restrict the group members to write/read only to this folder so our files would be secured.

How to install rootsh?

cd /tmp/

tar -zxvf rootsh-1.5.3.tar.gz

Create logs directory :

mkdir -vp /secure/admins-logs
./configure --disable-syslog --disable-linenumbering --with-logdir=/secure/admins-logs/
make && make install

Create a group for your admins so limited users can write to this folder.

groupadd admins

Creating a testadmin user and adding it to the group.

useradd testadmin
usermod -G testadmin admins

Applying appropriate permissions to logs folder & apply attributes.

chmod 770 /secure/admins-logs
chgrp admins /secure/admins-logs
chattr +a /secure/admins-logs

Edit /etc/shells – to allow our new loggable shell.

echo "/usr/local/bin/rootsh" >> /etc/shells

Enable logging for our user “testadmin”

vim /etc/passwd

search for a user testadmin and replace /bin/bash with /usr/local/bin/rootsh

Thats it! Now, try to login in with testadmin and you should see a log file created with username+timestamp e.g /secure/admins-logs/testadmin.3243423432.log

If you have any question, feel free to ask in comments.

HowTos Linux

How to use WorldCall EVDO USB on Linux?

Few days back, one of our friend from Pakistan requested us to write a recipe to Use WorldCall USB on Linux. By default Linux 2.6 Kernel support USB EVO devices but it required a little configuration in /etc/wvdial.conf.

BTW We are using BackTracK 5 Linux on our stations.

Configuring WorldCall usb on linux :

Install a PPP dialer on Ubuntu/BackTrack Linux

aptitude install wvdial


You should see following
Bus 004 Device 002: ID 16d5:6502 AnyDATA Corporation

vim /etc/wvdial.conf

copy & paste following configuration,

[Dialer Defaults]
init1 = ATZ
init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
;init3 = AT+CGDCONT=1,"IP","data:tre:se"
Modem Type = USB Modem
Dial Command = ATDT
Baud = 460800
New PPPD = yes
Modem = /dev/ttyUSB0
Stupid Mode = 1
ISDN = 0
Phone = #777
Username =
Password = wcall

Run wvdial and start surfing internet 🙂



HowTos Linux

How to install Memcache on CPanel / WHM running CEntOS


Few days back I was working for a client where I had to transfer one application to a new server. Application had memcache php extension need and the following error appeared in apache error log ;

PHP Fatal error: Class ‘Memcache’ not found in

If you are having difficulties in same situation you should stay away from recompiling your php using /scripts/easyapache – BAD IDEA.

Solution is simple, build memcache and include it in php.ini. Let see, how we do it.

Step 1 – Download memcache

mkdir repo
cd repo
tar -xvfz memcache-3.0.6.tgz

Step 2 – Compilation & installation

cd memcache-3.0.6

you should see something like this;

Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519

make install

Step 3 – Load in php.ini

Enable memcache in php.ini.

echo "" >> /usr/local/lib/php.ini
service httpd restart

HowTos Linux Troubleshootings

CPanel / WHM Troubleshootings & Short HowTos

CPanel / WHM

CPanel is a popular WHM solution. In past few days, i faced trouble while working with it. Thought to share with you if you face the same problem.


Not a HASH reference at /var/cpanel/perl/easy/Cpanel/ line 340

/scripts/checkperlmodules --full

How to Disable ConfigServer Security & Firewall

How to Disable Mandatory SSL (Web Login to WHL)
vim /var/cpanel/cpanel.config



And change the “1” to “0”, and save the file changes.
Now execute the following command to effect the changes;
/usr/local/cpanel/whostmgr/bin/whostmgr2 --updatetweaksettings

How to Install RRDTOOL
Download the required packages and execute rpm to install it.
rpm -ivh rrdtool-1.2.23-1.el5.rf.x86_64.rpm rrdtool-devel-1.2.23-1.el5.rf.x86_64.rpm perl-rrdtool-1.2.23-1.el5.rf.x86_64.rpm

[ipcheck] Problem with DNS setup on

When your server hostname doesn’t resolve to IP address and you don’t want to add ‘A’ record in your dns, you will have to disable this script to stop sending these alerts.

ls -l /scripts/ipcheck

-rwxr-xr-x 1 root root 7428 Jun 28 18:47 /scripts/ipcheck

chmod  000 /scripts/ipcheck

Make it write protected, so its permission won’t change.

chattr +i /scripts/ipcheck

ls -l /scripts/ipcheck

———- 1 root root 7428 Jun 28 18:47 /scripts/ipcheck

Linux Troubleshootings

Openx – configuration file is locked for security reasons

Openx is enterprise class ad inventory solution for your business. Normally I carry out its configuration from command line interface but this moment I decided to enable one plugin using UI (Web based Interface) but it failed and the following error appeared on screen:

It is not possible to edit all settings because the configuration file is locked for security reasons. If you want to make changes, you may need to unlock the configuration file for this installation first.


I tried to see all option but didn’t find a way to unlock the configuration file. Finally I found that its config file should be writable by your apache user.

To UnLock Configuration File :

chmod 666 /home/hackersgarage/public_html/var/

To Lock Configuration file back :

chmod 644 /home/hackersgarage/public_html/var/

It is recommended to lock it back when you are finished with your web based configuration.