Vandals banging on the door of ssh….



Sometimes I wish I wasn’t curious about things…. The other night I was working on something on the testbox in the back room and saw the switch lights flickering fairly actively between the server and the internet gateway. At first I thought maybe it was some mail coming in, but it was awfully persistent. So, I started nosing around. I saw that sshd was showing up in the process list and on checking /var/log/messages…. found hundreds of ongoing attempts to break in through the ssh server. (sigh….) Now, there was a time when I’ve kind of snickered when I’ve seen these futile attempts, because I have a VERY short list of allowed ssh users. (AllowUsers username can be set in /etc/ssh/sshd_config) But, this was fairly persistent and there was more variety to the usernames than I’m used to seeing.


What’s more is that I saw one specific IP hammering away for a span of ten-twenty or even thirty minutes it seemed. Of course, it got me to thinking if there were any ways I could tighten my sshd security. I already make use of the AllowUsers setting and don’t DREAM of allowing Root login… so PermitRootLogin no good. I use UsePrivilegeSeparation yes which should help if the sshd process is crashed out by a buffer overflow I suppose…. I’ve set Protocol 2 to avoid the legacy (breakable) version 1 encryption…. what more could I do?

Well – one thing I was curious about is whether the attacker could see WHY an attempted login failed (banned user?) The answer is no – I’ve tried with ssh debugging enabled (as IF they’re doing that when they try 300 connections in a couple minutes….) So that makes me feel a bit better. What ways are there to throttle connections or blacklist their IP???

One setting I found was MaxStartups 2 With MaxStartups you can limit the number of unauthenticated simultaneous logins… no this doesn’t mean you can’t have more than 2 users logged in, but they have to authenticate before more can try. Well – at least that way we won’t have a bunch of memory tied up with unauthenticated sshd’s waiting for input. For that matter LoginGraceTime 600 might be a bit high and could be ratcheted down lower. (The given setting gives you 10 minutes to type in your username/password.)

But there’s another interesting tool to help work against these brute force attacks. sshutout. It essentially runs and monitors the appropriate system log where ssh login attempts are kept. If it detects an “attack signature” in those logs it dynamically manages firewall rules to ignore the attacking host.

Now there are other approaches (just use key based authentication?) as well. One thing I noticed was that my ssh server running on a non-standard port saw NO activity while the port 22 sshd was just getting hammered.

There is another good iptables based suggestion at this page… This… should allow only 3 connections per minute from a host to the ssh port and ban the host for a minute if that’s exceeded.

iptables -A INPUT -p tcp –dport 22 -m state –state NEW -m recent –set
–name SSH -j ACCEPT
iptables -A INPUT -p tcp –dport 22 -m recent –update –seconds 60 –hitcount 4 –rttl
–name SSH -j LOG –log-prefix “SSH_brute_force ”
iptables -A INPUT -p tcp –dport 22 -m recent –update –seconds 60
–hitcount 4 –rttl –name SSH -j DROP

(Should be entered as three seperate lines – the forward leaning slash breaks up a long line.) I’ve tested that and can vouch for it. There is also a suggestion there for creating a custom whitelist chain first (if you have “safe” hosts that you want to keep from getting caught in the spiderweb of the above chain.)

Recent may not be available for all distros. (Kernel patch). Also, this would affect ALL SSH logins legit or not. So if you try to connect multiple times from one machine it’ll make you wait too.

hosts.deny is an option as well for some, but requires that sshd be compiled with tcp wrappers support. Unfortunately on my chosen machine that’s not (currently) the case… that can be checked by the output of
ldd /usr/sbin/sshd | grep libwrap … if there’s nothing thne no wrappers support. IF YOU DO have libwrap support in sshd then hosts.deny will work and something like denyhosts can update hosts.deny for you based on log entries. There are a couple other usefull suggestions at this site.

__UPDATE__ I’m wrong – a blank output from ldd /usr/sbin/sshd | grep libwrap does NOT necessarily mean that tcpwrappers won’t work (hosts.allow hosts.deny) Another way to test would be to deny localhost and try ssh’ing to the localhost ssh server. (If you have ALL: ALL in hosts.allow it doesn’t matter WHAT you have in deny – allow is checked first.)

There’s also daemonshield which looks promising as a way of dynamically creating iptables rules to temporarily drop packets from the script kiddies banging on the door. (NOT just for SSH).

Hope that helps give some ideas on blunting the attacks when the vandals are at the gate….

__UDPATE__ denyhosts really looks the most straightforward and best solution if you JUST want to protect sshd from the bruteforce login attacks.

Related Posts

Blog Traffic Exchange Related Posts
  • Network Security guide for the home or small business network - Part 11 - Why? Alright, so you're still reading this series and you're thinking. Look, I'm not protecting national security secrets. All I'm doing is (running a business|emailing my grandkids|using the web for research). True, good point. You're not at the defense department. OK. Let's say you just use your computer for email and......
  • Evolution email error MAIL FROM command failed: Unknown Some time back, I was teetering on the brink.... I've used Evolution as my linux mail client for ages (since I switched), because it had the calender integrated etc... However, Kontact has REALLY looked nice for some time, but I didn't have time to mess with changing. Then one day,......
  • Firewall musings... Yesterday I had a bit of a realization. I had just been looking at a wireless router/firewall setup and was thinking about the firewalling rules (which seemed to be geared at the WIRELESS lan... i.e. blocking that activity on the Wireless segment.) You know, traditionally firewalls have had the attitude......
Blog Traffic Exchange Related Websites
  • A Few Suggestions About Ways It's Possible For You To Improve Customer Service Frequently when thinking about home business ideas you might want to create a website. When building your own website there are a few things to think about. If you know nothing about site design, you'll need to pay someone to design it exactly how you desire. Make sure you utilise......
  • What You Need From a WordPress Hosting Company Wordpress has taken over the world of websites and blogs, creating a simple and easy way for individuals get information out into the world of the Internet. The system gives users an incredibly easy platform to create the blogs, information, and news sites that they need to be successful. The......
  • Using Managed Dedicated Web Hosting Managed dedicated web hosting is for an individual or organization that wants storage and bandwidth with out the restrictions that you get by choosing a free of charge web hosting service.  Should you have a website which you would like to have much more bells and whistles programmed into it,......
www.pdf24.org    Send article as PDF   

Similar Posts


See what happened this day in history from either BBC Wikipedia
Search:
Keywords:
Amazon Logo

Comments are closed.


Switch to our mobile site