Server Administration

  Home arrow Server Administration arrow Page 3 - Preventive Measures to Block SSH Attac...
SERVER ADMINISTRATION

Preventive Measures to Block SSH Attacks
By: Barzan 'Tony' Antal
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2009-10-28

    Table of Contents:
  • Preventive Measures to Block SSH Attacks
  • Preventive Measures
  • Even More Measures
  • Final Thoughts

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Preventive Measures to Block SSH Attacks - Even More Measures


    (Page 3 of 4 )

    When keeping up with the count of SSH attacks becomes hard, automated script solutions come to the rescue. DenyHosts is pretty popular and does the job. It is a Python script that runs in the background and analyzes your log files. When dubious attempts are found, such as multiple failed attempts from specific hosts,  it takes preventive actions, such as denying those hosts--specifically banning them.

    DenyHosts is really configurable; it has numerous options for setting thresholds, report generation, keeping a history, and all that. Basically, it parses the logs, and you can check them later on for offending hosts, which users are targeted/abused, etc. It is really useful even if all you do is set up DenyHosts, configure your limits, and then let it work in the background. Once limits are met, the hosts are blocked (/etc/hosts.deny).

    It is beyond this article’s scope to present an entire configuration tutorial on how to set up DenyHosts, but if that’s what you want to do, you can find plenty of information. Maybe in a future article we will actually cover our best practices. But for now, let’s move on to present even more strategies to prevent SSH attacks!

    SSHguard is another open-source project that acts similarly to DenyHosts. It also monitors the log files, and once dubious occurrences of login attempts are found, it blocks the hosts with firewall rules. It can operate with other protocol types, including SSH, but also others, such as FTP, IMAP, etc. It is compatible with most firewall suites on Linux (such as the popular Netfilter/iptables, PF, IPFilter, hosts.allow, etc.). It supports IPv6.

    The third tool that we want to mention is called Fail2ban. It does the same job as the other two presented above. Please check out its set of features for more information.

    If your server is already using a Netfilter/Iptables firewall, then you may consider the following implementation. What about limiting the count of incoming SSH connections? Things can become malicious when there are more than three attempts within a minute, for example. Since most SSH attacks happen really fast and “background” log monitoring utilities may fail to recognize them as soon as possible, this technique is a life-saver.

    iptables -I INPUT -p tcp --dport X -i eth0 -m state --state NEW -m recent --set

    iptables -I INPUT -p tcp --dport X -i eth0 -m state --state NEW -m recent --update --seconds 60 --hitcount 4 -j DROP

    Please don’t forget to edit the above iptables rule accordingly. The number X after the --dport argument specifies the destination port number, which is your SSH daemon port. Moreover, the “eth0” is the NIC through which the server is reachable. The other arguments are specified the hitcount (4) within those 60 seconds and the action (drop).

    And finally, there’s one more technique that you can research. It’s called Port Knocking. It’s one of the most advanced preventive measures that you can implement. It is not transparent at all, and sometimes can cause headaches until you can get it working. However, that one strategy really deserves an article of its own. But if you’re anxious, just Google it and you will find lots of worthwhile gems regarding SSH port-knocking.

    More Server Administration Articles
    More By Barzan 'Tony' Antal

    blog comments powered by Disqus

    SERVER ADMINISTRATION ARTICLES

    - Server Responses to Client Communication
    - Authentication in Client/Server Communication
    - Client/Server Communication
    - Understanding Awk in the UNIX Shell
    - Stream Editor in the UNIX Shell
    - Processes in the UNIX Shell
    - Migrating from Windows to Wine
    - Wine: Not Another Emulator
    - Preventive Measures to Block SSH Attacks
    - Monitoring Temperatures with Cacti
    - Cacti: RRDTool-based Graphing Solution
    - Network Magic 5.0 Review
    - Netfilter and Iptables Overview
    - Installing and Configuring Squid
    - Clickfree PC Backup Systems Compared


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap