Archive for the Category »Server Security «

How to define iptables rules save option?

iptables creating rules after restarting the iptables. When iptables service is restarted settings from /etc/sysconfig/iptables file are applied and used with the iptables.

You can either set up iptables rule so that current stat is saved the rule upon restart or stop/start:

You need to make changes in following file as per your requirement for values received in following GREP result.

root@server[~]# grep IPTABLES_SAVE /etc/sysconfig/iptables-config
IPTABLES_SAVE_ON_STOP=”no”
IPTABLES_SAVE_ON_RESTART=”no”
IPTABLES_SAVE_COUNTER=”no”

Or overwrite current settings with iptables-save to /etc/sysconfig/iptables file:

root@server[~]# iptables-save > /etc/sysconfig/iptables

Note : Its always good if we use NO option for following options because some time due to wrong rule we face major problem to access server.

IPTABLES_SAVE_ON_STOP=”no”
IPTABLES_SAVE_ON_RESTART=”no”
IPTABLES_SAVE_COUNTER=”no”


Simple steps for SSH Server Hardening.

SSH Server Hardening in one of the security part to secure your server.Refer following steps to secure SSH.

root@serevr[~]#pico /etc/ssh/sshd_config

Uncomment  #Protocol 2, 1

Change to Protocol 2

Append these lines to the bottom:

LoginGraceTime 120
IgnoreRhosts yes
X11Forwarding no
Save file and restart the SSH service.

root@serevr[~]#/etc/rc.d/init.d/sshd restart

Note : SSH Protocol one  based servers are facing many automated root kits attacks.As a result to step up the security Protcol 2 should be enabled on server.The reason to use SSH Protocol 2 on any webserver is that it is more secure as compare to protocol 1.

Disable directory listing for folders by using .htaccess?

To disable the Directory listing for folders you need to create the .htaccess file under the each an every folder under which you want to disable the Directory listing and insert the following code in .htaccess file.

————
Options -Indexes
————-

How to generate the password from shell (SSH)?

If you use SSH, use mkpasswd command for creating passwords…

root@gunjan[~]#mkpasswd -l 10 -d 3 -C 3 -s 2
L]4P@V6ii3

Simple cgi script to check the Server uptime?

The following script you can use to check the Server uptime?

root@Gunjan [/usr/local/apache/cgi-bin]# nano loads
#!/bin/bash

echo Content-type: text/plain
echo

echo $(hostname)
echo “=>”
echo $(uptime)

Options FollowSymLinks or SymLinksIfOwnerMatch forbidden error?

If you receive following error message after browsing the domain/website

[Sat Oct 31 04:28:39 2009] [error] [client x.x.x.x] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /home/xxx/public_html/xxx/403.shtml
[Sat Oct 31 04:29:47 2009] [error] [client x.x.x.x] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /home/xxx/public_html/xxx.co.uk/Bracelets/Stencil-Heart-Bracelet.html

To avoid above error you can add following codes in .htaccess file.

root@gunjan[#]vi .htaccess

RewriteEngine On
Options +FollowSymLinks
:wq!

Install RKHunter

You can install RKHunter on Linux Server by using following steps.

1 Login to your server as root

2. cd /usr/local/src

3 Download RKHunter and extract the archive

wget http://downloads.rootkit.nl/rkhunter-1.1.4.tar.gz

Some time above URL is working fine due to that you can also use following URL to download the tar file.

http://sourceforge.net/projects/rkhunter/files/rkhunter/1.3.4/rkhunter-1.3.4.tar.gz/download?use_mirror=autoselect

tar -xzvf rkhunter-1.1.4.tar.gz

4. Install RKHunter

cd rkhunter

./installer.sh

Or

./installer.sh –layout default –install

You can also set the cron to receive the RKHunter result.

vi /etc/cron.daily/rkhunter.sh
#!/bin/bash
(/usr/local/bin/rkhunter –update && /usr/local/bin/rkhunter -c –nocolors –skip-keypress –summary 2>&1 | mail -s “RKhunter Scan Details” username@yourdomain.com)

chmod a+x /etc/cron.daily/rkhunter.sh