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
  • 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,......
  • Network Security guide for the home or small business network - Part 8 - Don't be afraid to ask for help Deep breath time. We've covered a lot of good topics and it's important at this point to take a close look at what we've talked about and think. "Am I overwhelmed?" If so that's fine. Maybe you don't have enough time to think about all of this network security stuff.......
  • Ultravnc for remote computer support A little while back I talked some about TightVNC which for a long time has been my favorite implementation of a remote framebuffer, or remote desktop viewing protocol known as VNC (Virtual Network Computing.) The original VNC (now realvnc) came out of AT&T research labs in the UK and has......
Blog Traffic Exchange Related Websites
  • A Money Making Online Business For The Price Of An IPhone Starting an electronic or digitally based online business is by far one of the most rewarding online enterprises to delve into. Just think about it, what does Google sell? No products to ship, no physical inventory to sell. You don’t find their products on the shelves of your local grocery......
  • 10 Benefits of Hosting your Own Blog If you want to create an edge over many of the other bloggers on the web, then one of the best things that you can do is host your own blog. There are a number of benefits of hosting your own blog over having some other service host your blog.......
  • 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,......
PDF24    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