Don't miss
Showing posts with label HowTo. Show all posts
Showing posts with label HowTo. Show all posts

Monday, February 4, 2013

Linux :: How to harden SSH security on CentOS


Secure Shell for Linux has been one of the most attacked on servers, we find many cases where the bruteforce finally compromises the server for root access. One of the most common queries that come on to desk is how to harden out SSH - here are few tips that should help - I wont recommend enabling every bit of it, but will include the list which is most required and ones that are optional.

The configurations of SSH is available either on /usr/local/ssh/sshd_config or /etc/ssh/sshd_config - so that is where we start. So we need a connection on KVM or SSH on to the server and knowledge of popular editors like pico or vim to start with it.

Most Important Changes

These are the list of configurations that you should never do away with, so start with the first:
1. Block SSH Version1:
SSH protocol version 1 (SSH-1) has man-in-the-middle attacks problems and security vulnerabilities. SSH-1 is obsolete and should be avoided at all cost. Open sshd_config file and make sure the following line exists:
Protocol 2

2. SSH Port
From what I have seen, most of the bruteforce happens on to the port 22, considering the fact that most of the server owners doesn't care to change the SSH port. So this is the second most important thing to be done- change the SSH port to a number different from 22 - which is the default port id:
Port 1111
be sure to remove the comment mark preceding the Port entry and also ensure that you update your firewall or firewall wrapper configuration for the new port to be accessible. Another option of securing sites will be to disable access from all public entries and allow access to port 22 via LAN or WAN connection - this is possible only for local servers or locations where you have static IP range - the iptables entries will need to be updated as :
pico /etc/sysconfig/iptables 

(or find the locations of iptables by running /etc/init.d/iptables save)and add the following entries:

-A RH-Firewall-1-INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -s 202.54.1.5/29 -m state --state NEW -p tcp --dport 22 -j ACCEPT
if you do not want to alter the firewall configuration, you can restrict access on to the server from specific network by removing the command on 'ListenAddress' keyword:
ListenAddress 192.168.1.5
ListenAddress 202.54.1.5
where the first entry should be updated by your LAN IP and the second by your WAN IP address.
3. Protect SSH with Firewall
Apart from the iptables rules said above, it will be wise to install a bruteforce prevention firewall wrapper like CSF or similar where you can define the count of failures on to SSH and block the originating IP address. I am recommending CSF since its getting updates on a regular basis and has a simple configuration that can be used to carry out much complex operations.

4. Disable Root Login
Disabling root login is another good option which should protect the server even if your workstation is compromised with key loggers. The root password, even if it is correct, wont be accepted by the system which inturn will need a non-root user to login to the server first and then use the 'su -' command to gain root access. You can achieve this by updating the configuration entry:
PermitRootLogin no
to take this option to the next level, you can also define the set of users which do have access on to the ssh server, thereby minimizing the chances of compromise, you can do this by adding in the entry:
AllowUsers root raj rahul
or
AllowGroup sshusers
which should help you from not defining each individual user - and add the new users to the group if you want them to have SSH access

5. Defining Idle Timeout for users:
Another important setting that shouldn't be ignored is having an idle timeout set for your logins so that the active sessions doesn't allow hackers to change settings. We can get this done by updating:
ClientAliveInterval 300
ClientAliveCountMax 0
HostbasedAuthentication no
this is required by most of the systems unless you have a more secure network behind a hardware firewall. The above timeout is for 5 minutes and post this period all active sessions will be terminated.
6. Ensure that the defaults are not modified:
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
UsePam yes
ensure that these settings are not altered as you wouldn't want the rhosts entry and empty passwords to be active on for SSH logins.

7. Issue a notice on each login:
Issuing a well defined banner on each SSH login should be good as well, add in the guidelines and also define the penalty of breaching into the system - that should help at times:
Banner /etc/issue
and a sample entry would look:
----------------------------------------------------------------------------------------------
You are accessing a XYZ Government (XYZG) Information System (IS) that is provided for authorized use only.
By using this IS (which includes any device attached to this IS), you consent to the following conditions:
+ The XYZG routinely intercepts and monitors communications on this IS for purposes including, but not limited to,
penetration testing, COMSEC monitoring, network operations and defense, personnel misconduct (PM),
law enforcement (LE), and counterintelligence (CI) investigations.
+ At any time, the XYZG may inspect and seize data stored on this IS.
+ Communications using, or data stored on, this IS are not private, are subject to routine monitoring,
interception, and search, and may be disclosed or used for any XYZG authorized purpose.
+ This IS includes security measures (e.g., authentication and access controls) to protect XYZG interests--not
for your personal benefit or privacy.
+ Notwithstanding the above, using this IS does not constitute consent to PM, LE or CI investigative searching
or monitoring of the content of privileged communications, or work product, related to personal representation
or services by attorneys, psychotherapists, or clergy, and their assistants. Such communications and work
product are private and confidential. See User Agreement for details.
----------------------------------------------------------------------------------------------
courtesy:cyberciti.biz

Optional Settings for Added Security

8. Using Key based login
This is usually a recommended option which allows each user to create a sign in key and if it matches with the key on the server, the access is granted in. We had skipped this option earlier as it becomes tough when you are not on the machine or laptop that you are used to working from and will be troublesome if you have to get to the system from a new machine.

You can refer : http://www.cyberciti.biz/faq/ssh-passwordless-login-with-keychain-for-scripts/ for setting up the key authentication.

Another interesting addition will be : Using Google Authenticators So the settings you will need to update is to enable key based authentication are:
PasswordAuthentication no
ServerKeyBits 2048
RSAAuthentication yes
PubkeyAuthentication yes
That should help you get running.

9. Disabling SSH open Server
So if it is just for SSH that you need the server running for and to avoid users from sending out or receiving files over SSH, you can disable SSH server entity which is enabled by default, you can do that by running the commands:
chkconfig sshd off
 yum erase openssh-server
 service iptables restart
 service ip6tables restart


10. Use Log-level info
Read your logs using logwatch or logcheck. This should help you keep constant check on the SSH activity and modify the security rules based on incoming traffic. Make sure LogLevel is set to INFO or DEBUG in sshd_config:
LogLevel INFO
Additionally, you can recompile the source code of SSH to enable the following options which should help you gain added security:
#  Turn on privilege separation
UsePrivilegeSeparation yes
# Prevent the use of insecure home directory and key file permissions
StrictModes yes
# Turn on  reverse name checking
VerifyReverseMapping yes
# Do you need port forwarding?
AllowTcpForwarding no
X11Forwarding no
#  Specifies whether password authentication is allowed.  The default is yes.
PasswordAuthentication no
Once the modifications are complete, save the configuration and run the following command to ensure the compatibility of changes:
`which sshd` -t
if the syntax returns no error, then feel free to restart the services:
service sshd restart
Hope this did help!


Updated at: Monday, February 04, 2013

Friday, December 14, 2012

Petcare : How to Make Kennel Best For Your Pet




Many vets believe that a kennel is the primary part where the dog gets its shape. The health and fitness of the dog is very much dependent on the kennel and its cleanliness. Usually there is little care taken for the kennel but if you will check few points mentioned below, it can make a great difference on how your pet behaves or how its health goes on.



A Sample of a shelter that you can provide to your loved one.


* Kennel should be built at a location which is elevated, well drained and sunny place.

* It should be well build , well ventilated.

* Kennel should be warm in winter and cool in summer.

* Damp and water logged areas should be discarded

* Kennel should have windows to facilitate sun rays into the kennel.

* It should provide for enough free space for free movement, turn around and jump about.

* Ideally the kennel should be near the owners house, this will provide a better care for the pet and also relieve it from the boredom inside the kennel.

* There should be a provision of "run" inside the kennel which does help the dog to get its exercise during its stay in kennel. A run is the additional play area secured by fences which allows the dog to run and jump.

* Ideally the Kennel should be made on concrete for better cleaning but use of a wooden kennel will help get warmth during cold seasons.

* Kennel should be kept clean, neat, dry and tidy. It should be washed with detergent frequently and also use disinfectants or antiseptics to keep it disease free. Use of potassium permanganate is also recommended. Fly repellent sprays and insecticides is also recommended, but ensure that the pet is out of the Kennel to avoid inhalation of insecticides.

Hope these tips help!



Updated at: Friday, December 14, 2012

Tuesday, December 11, 2012

HowTo : Cpanel not displaying active databases


Once in a while Cpanel does act bad and decides to play a hide n seek game, and as seekers we have to find the hidden stuff. Going back to technical jargon, you might find one day that all your databases listed under Cpanel is missing. So if you have root access to your server, then here is a cool way how you can fix it up in a matter of seconds. Ready?

Here we go

As always run the command :
-bash-3.2# /scripts/upcp --force &&
 /scripts/checkperlmodules --force && 
/usr/local/cpanel/bin/setupdbmap --force


usually these should fix the issue without even you knowing what was causing it, but if you are curious, try running:

cat /usr/local/cpanel/logs/error_log|grep mysql|less

or
tail -f /usr/local/cpanel/logs/error_log|grep mysql
check for the recent errors you see on the page, do you see any authentication errors from root user? If yes, then try running command:
-bash-3.2# mysql


normally if you are signed in as root then you shouldn't have any trouble reaching mysql prompt from there. But if you do then you will have to try the following steps:

Login to WHM as root >> MySQL Root Password

And reset the password, once you have the new password, check back on the ssh screen and run the command:

-bash-3.2# mysql_fix_privilege_tables --verbose --password=newpassword


Once this is done, try logging on to Cpanel for the account and add a database, and check back on the listing, you should find your databases back on the list.

UPDATE : If the error persists, then please try running
-bash-3.2# /scripts/update_db_cache
-bash-3.2# vi /etc/my.cnf
and add the entry:
innodb_force_recovery = 4

and restart mysql.

References:

CPanel Docs, Cpanel Forums


Updated at: Tuesday, December 11, 2012