Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Security IT

The Optimum Attack Rate For SSH Bruteforce? Once Every Ten Seconds 167

badger.foo writes "Remember the glacially slow Hail Mary Cloud SSH bruteforcers? They're doing speedup tweaks and are preparing a comeback, some preliminary data reported by Peter Hansteen appear to indicate. The optimum rate of connections seems to be 1 per ten seconds, smack in the middle of the 'probably human' interval."
This discussion has been archived. No new comments can be posted.

The Optimum Attack Rate For SSH Bruteforce? Once Every Ten Seconds

Comments Filter:
  • by halber_mensch ( 851834 ) on Friday April 06, 2012 @01:23PM (#39600015)
    RSA keypair auth, disable password auth, bruteforcers irrelevant.
    • by aztracker1 ( 702135 ) on Friday April 06, 2012 @01:26PM (#39600083) Homepage
      RSA key/pair is something you have... you still need something you are, and something you know... Once someone has your key, it's no more secure than your password. A trojan can read local files, just as easily, if not more so than snoop for a password.
      • by 0racle ( 667029 ) on Friday April 06, 2012 @01:35PM (#39600193)
        If you have a trojan keylogger, you probably don't have to worry about SSH bruteforcing.
      • by nine-times ( 778537 ) <nine.times@gmail.com> on Friday April 06, 2012 @02:00PM (#39600521) Homepage

        Once someone has your key, it's no more secure than your password.

        Whether the token is something you know, something you are, or something you have, it *all* becomes useless once someone else has it. That's not really the issue here. The issue is brute-force attacks on SSH, and using a key makes them significantly more difficult than passwords.

        Stealing someone's key/password is not a brute-force attack.

        • by Brucelet ( 1857158 ) on Friday April 06, 2012 @03:09PM (#39601319)
          It is if I break into your house and brute-force you to hand it over
        • Someone cannot have something you are without you being aware of it.

          • by nine-times ( 778537 ) <nine.times@gmail.com> on Friday April 06, 2012 @03:54PM (#39601803) Homepage

            That's nice in theory and all, but it depends on what that "something you are" is. Essentially we're talking about biometrics, so what are we measuring? Is it a thumbprint scan? Those have been defeated in the past by taking a thumbprint and replicating it by some means. Is it a DNA scan? Then they might just need to get ahold of your DNA.

            Really, the "something you are" is still "something you have", but you "have" it attached to your body. That doesn't necessarily mean it can't be stolen or replicated somehow. Similarly, the "something you know" can also be considered to be "something you have", but you "have" it in your mind. In some circumstances, it can still be figured out or retrieved, or you might be tricked into providing it.

            Real security isn't quite as simple as you make it sound.

            • Gun one place, bolt and ammo somewhere else. You know where but somebody who breaks in at night doesn't.
              Biometrics or whatever don't matter, the important thing is to make sure an attacker can't get everything they need to get in from one place. A key on a USB stick or the local machines disk and the passphrase/password in your head is not one place. If an attacker aims to trick you into providing access then they have have to trick you twice, or steal and trick you.
            • by dargaud ( 518470 )

              Really, the "something you are" is still "something you have", but you "have" it attached to your body.

              Not necessarily. Something you are is nine-times. The gard at the entrance knows you as nine-times. For hime you _are_ nine-times. Maybe you get fired from work and your badge (something you have) is revoked and your system password (something you know) is removed. But they forget to notify the guard and the next day you manage to walk in as usual, because he knows you. Of course the opposite situation is possible too: the boss throws you out and tells the guard not to let you in, even though your cards pas

          • It's all too easy to socially engineer people into doing things without them being aware of it. "Hey, could you test this biometric scanner for me? It keeps saying 'swipe finger evenly' but I think it's just broken."
      • by mlts ( 1038732 ) *

        If the computer with the key is compromised, the game is over. The password can be slurped, the key snarfed, and even the session hijacked.

        It is all about limiting exposure. Going to public keys closes a potential common method of access, brute force guessing.

        No security method is 100%, but in a lot of cases, something is better than nothing, and having at least root locked out from password guessing is a must for Internet facing systems.

        • by artg ( 24127 )
          You're assuming the loss is via a compromised computer. For me, the most likely loss of the key is laptop theft. So I want to ensure that isn't going to give an automatic login to the home machine. i'd prefer to have both key pair and password, but failing that I think password is preferable to key pair.
      • by sexconker ( 1179573 ) on Friday April 06, 2012 @02:13PM (#39600691)

        RSA key/pair is something you have... you still need something you are, and something you know... Once someone has your key, it's no more secure than your password. A trojan can read local files, just as easily, if not more so than snoop for a password.

        When you send bits out, everything in those bits is "something you know".

        You don't need to have the keyfob, you just need to know what it will output at any given time, or what a prior output was (as long as you use it within the time window for which it is valid - typically 30 seconds to 2 minutes). Yes, it's mathematically hard to get the key by brute forcing, but it's not impossible. When you log in with one of those, you're not proving that you have the thing, you're proving that you know what it output at a given time.

        Imagine if PS4 games had built in RSA shits right onto game discs. (Or the Vita game cards if you can't imagine a thing battery, cpu, and display on a disc.)
        Touch an area on the surface of the game disc (or card) and get a password on a little display. You have to put that password in within X time to access the game. This isn't secure because even if Bob holds onto the disc physically, Alica can call him up and ask him to read the code.

        Sony wants the disc to be in Bob's physical possession (and no one else's) at any given time, but they cannot rely on this type of security to ensure that. For all they know Bob is visiting Alice and brought his new game over.

        • Are you thinking of RSA SecurID? That is something quite different.

          If you want to log in to my SSH server, then in practice you need a private counterpart to a public key which you have added to your authorized_keys file.

      • Encrypt your private key with a passphrase that you know, which is a property of something you are (your brain). Nothing will protect you from local malware that can intercept your keystrokes. Even if you use a secure keyfob for your private key the trojan could just take over your session and execute commands on your behalf once you're securely connected.
      • by gweihir ( 88907 )

        Sorry, but fail. 2-factor only works when both factors are independent. That is not the case here, as they are always used together. About the only way to compromise the RSA key is to compromise the SSH source host. But as soon as you have that, you also have the password on the first login, hence both are not independent.

    • by the eric conspiracy ( 20178 ) on Friday April 06, 2012 @01:27PM (#39600105)

      Anyone see these guys on a port other than 22?

      • by TheLink ( 130905 ) on Friday April 06, 2012 @01:53PM (#39600435) Journal
        Yeah to me that's the best approach - use a different port. Simple and effective enough. You could resort to port knocking or similar (use some other method[1] to selectively allow access to the ssh server). But just running the ssh server on a different port allows you to avoid nearly all automated attempts, so when you actually see brute forcing on your ssh server, it's more likely to be a serious targeted attack (hence you can set up an automated response/alert without getting too many false positives).

        [1] For example, if you already have to expose https to the world you could have a web app that triggers the opening of ssh access for the web client's current IP.
        • by multimediavt ( 965608 ) on Friday April 06, 2012 @03:03PM (#39601253)
          I made it just a different port on my router at home; still points to port 22 on the internal address forward. That way I can just turn sshd on (after configuring max tries to '3') and not worry about port fiddling on the machine. Works. Haven't seen many attempts at it since I did that years ago.
          • by cynyr ( 703126 )

            I'm running fail2ban myself. 3 wrong guesses and get banned for 30 minutes. Not really an issue for me, I did leave pasword auth on for users, but not root you need a key to ssh to root. None of my users can su either, and sudo isn't even installed.

          • by TheLink ( 130905 )
            On a firewall server I used to run, I had an sshd server bound to 127.x.y.z:P. Then I set firewall rules to forward external access to external_IP:high_port to 127.x.y.z:P.

            This way externals cannot access the ssh server if the firewall service is disabled or has no rules.
      • by drosboro ( 1046516 ) on Friday April 06, 2012 @01:53PM (#39600441)

        Good point. My standard setup is to move SSHD to a non-standard port, and to turn off PasswordAuthentication completely in favour of RSA key-pairs.

        Just checking my SSHD logs, it looks like I've had exactly one rejected attempt on a busy public-facing web server (which may in fact have been me, connecting from a machine that I hadn't set up a key for) in the past month... so in my experience, no, they're not trying too hard off of port 22.

        • by jandrese ( 485 )
          Wouldn't it be easier to just choose good passwords? The downside of port knocking is when you are using ssh because all of the other ports are blocked (including 80, thanks to your ISP).

          This is probably not a solution if you have a bunch of users, but for a home machine it's not that hard to create a password that will never be guessed by some bot trying one dictionary word every 10 seconds.
        • by JWSmythe ( 446288 ) <jwsmythe@noSPam.jwsmythe.com> on Friday April 06, 2012 @02:20PM (#39600787) Homepage Journal

                I double that up. sshd to a nonstandard port, and firewall rules to only allow access in from very specific IPs and networks.

              You really shouldn't be able to ssh in from just anywhere. Even if that means throwing a copy of OpenVPN up at a static location, to ssh to the second.

              I can get to most of my stuff directly from home. At a hotel, airport, or coffee shop, I am on a hostile network, and shouldn't even be able to see that the port is open.

              But, most people scanning for machines with SSH on them to hit are blindly scanning port 22. It's people interested in your specific network will scan every port on every machine. Someone determined to hit your machine specifically will try every trick they can, and having SSH on port 2222, 9222, or 64222 won't help, if you have a weak password or an exploitable version.

          • by cynyr ( 703126 )

            And it is rather easy to ask nmap to do a simple sneaky-ish scan of a machine looking for SSH, and the pound away at that port.

      • Agreed! - this seems like the simplest tweak to bypass brute-force attacks -- After all why attack a server that isn't listening on port 22 when so many are?
      • Anyone see these guys on a port other than 22?

        +1. Moving to a different service port dropped my failed login attempt logs down to nothing (at least, for now). Prior to that, my logs still weren't too big because I block IPs after #MAX_ATTEMPTS within a 24 hour window. However, the attempts were coming in at a rate of 10 minutes apart. Still, they got blocked. It's just that the hacking community seems to be well aware of trying to keep the number of attempts / unit time down to avoid detection.

      • I put my sshd on port [redacted] instead of 22 and, looking through logs now, I see no attempts at all for the last year.

        Only two attempts in the past 2 years total.

        They're not brute forcing SSH logins by finding SSH servers through fingerprinting yet. They're still only using conventional ports.

      • by dbIII ( 701233 )
        I used to, then I just dropped packets from any port that doesn't belong.
        I haven't seen anyone mention Fail2ban or any other automatic firewall block rule generation script yet. The concept is flawed in that attackers can spoof addresses and manipulate your firewall, but the execution gets around that by blocking for only a limited time and hoping the attackers go after somebody else (and that somebody that was locked out by making a mistake with their passphrase a few times can try again later).
    • by v1 ( 525388 )

      RSA keypair auth, disable password auth, bruteforcers irrelevant.

      I'd also recommend changing the ssh listener port to something else, to keep the secure.log a little cleaner and easier to spot possible issues in.

      443 is a fun one, few if any of the ssh bots even consider that one.

      • 443 is a fun one, few if any of the ssh bots even consider that one.

        The other advantage to 443 is that pretty much no ISP/WiFi provider/whatever will block access to that port, and since they expect to see encrypted traffic, they probably won't mess with the connection at all.

    • by miknix ( 1047580 )

      Meh, just add proper rules to iptables and you will be fine:
      http://www.ducea.com/2006/06/28/using-iptables-to-block-brute-force-attacks/ [ducea.com]

      sshguard is pretty good too:
      http://www.sshguard.net/ [sshguard.net]

    • by Trogre ( 513942 )

      Cool, so once the hackers compromise one of your computers they can get to all of them.

      Nice.

  • So, set your fail2ban or denyhosts configuration to 11 seconds intervals, and problem solved?
    • 5 fails in a row...ever.
      • Additionally... automatically block any single attempt to login as root, admin, www, ftp, etc..
        • by mlts ( 1038732 ) *

          What would be interesting is that if someone tries to log in as root with a password (as opposed to using a public key), rather than outright deny access, just make sure all access is denied from that IP or IP range, even if a future attempt at logging on would have normally been successful. This keeps the attacker busy thinking they can gain something.

          Or, if someone is really clever, spawn a fake shell which drops to a prompt, then 1-2 seconds later, have it look like it got logged out.

          Something like that

          • just make sure all access is denied from that IP or IP range

            Which is exactly what denyhosts and fail2ban do.
            On failure, echo $IP:ALL >> /etc/hosts.deny
            • Think more honeypottish. The defender's best tactic against an attacker is to deny the attacker knowledge of whether or not their break-in was actually successful: the more complex and bewildering you can make the fake prompt, the better. No one will try to brute-force a machine they think they already have access to.
              • by mlts ( 1038732 ) *

                Exactly. If an attacker is running their stuff on some botnet clients, and gets reports that machines on a network all are accessible, it will waste their time and resources in having to vet each and every machine that reported a successful login.

                It isn't a true honeypot because the machines are not giving much of an environment for an intruder to play around in, but more of a way to fool the brute forcing scripts in giving them a bunch of false positives.

  • by khasim ( 1285 ) <brandioch.conner@gmail.com> on Friday April 06, 2012 @01:24PM (#39600055)

    I'm going to guess it was a dictionary attack because otherwise it is even dumber.

    That's 6 attempts per minute.
    360 per hour
    8640 per day
    60,480 per week
    3,144,960 per year.

    So unless you're allowing usernames such as "root" or "admin" or "administrator" AND using dictionary passwords wouldn't this fail? And be obvious in the logs?

    • by PRMan ( 959735 )
      Also, you use logarithmically-increasing delays to both the username and the IP address (and to a lesser extent, range) that tries this. They won't be trying much for long. And no, I don't want people on zombie botnets coming to my site.
    • Re: (Score:3, Funny)

      So unless you're allowing usernames such as "root" or "admin" or "administrator" AND using dictionary passwords wouldn't this fail? And be obvious in the logs?

      You're thinking... this makes you a bad reference model for the average user.

    • Re: (Score:2, Interesting)

      So unless you're allowing usernames such as "root" or "admin" or "administrator" AND using dictionary passwords wouldn't this fail? And be obvious in the logs?

      Yes, it would be obvious in the logs. However, most of the common hacks are now scripted and distributed. They'll use a dictionary attack that is spread over some number (dozens or more) of distinct botnet systems, making it very inconvenient for you the admin to try to block all those addresses.

      Although of course as you point out, it should fail if they are going for root or equivalent. That said from my experience the botnets usually seem to do a white pages type list of common usernames and then

      • by khasim ( 1285 ) <brandioch.conner@gmail.com> on Friday April 06, 2012 @02:04PM (#39600571)

        They'll use a dictionary attack that is spread over some number (dozens or more) of distinct botnet systems, making it very inconvenient for you the admin to try to block all those addresses.

        Who cares about blocking them? They're not getting in anyway. Blocking is just additional work that may cause problems.

        That said from my experience the botnets usually seem to do a white pages type list of common usernames and then try either blank or extremely common user names to try to get in by.

        That's the reason that they're not going to get in. They're using usernames that don't exist (unless the sysadmin is an idiot in which case you have the regular idiot problems and it's probably been cracked already through one of those).

        So you may also want to ensure that if you have users who use very common (English) first names as their login names, they are using strong passwords.

        If you're using JUST first names or last names as usernames then you have a bigger problem.

        Instead use something like one of the following:
        FIrstnameLastname
        Firstname.Lastname
        FirstnameMiddleinitialLastname

        You should be able to easily distinguish the potential threats from the random script-kiddies. That being a REAL username on your system with hundreds of login attempts.

        And then you deal with that issue by changing the username. Then investigate how that username leaked.

        • That's the reason that they're not going to get in. They're using usernames that don't exist (unless the sysadmin is an idiot in which case you have the regular idiot problems and it's probably been cracked already through one of those).

          Do you have your system set up so that email names are not user names?

          • by khasim ( 1285 ) <brandioch.conner@gmail.com> on Friday April 06, 2012 @04:01PM (#39601879)

            Do you have your system set up so that email names are not user names?

            At home? Yes.

            I think I seen where you're going with that and I don't think you understand. Collecting email login names is easy.

            But being able to login to an outward-facing server (email or ftp or ssh or whatever) should be limited to a certain amount of failed logins (no matter from which IP address) per time period.

            The crackers would have to go through an ADDITIONAL step to try to match email login names with ssh login names and an ADDITIONAL ADDITIONAL step to match that name to a different type of server (such as ssh).

            Let me see if I can illustrate this.

            1. Attacking ssh on server A.B.C.D with username aaron - if there's any chance that the cracker can do it then the sysadmin failed. Even more so with "root" or "admin" or such.

            2. Collecting username aaron.aaronson via email spammer and then trying to attack ssh on server mail.example.com - more work for the cracker than scenario #1 but still the same as #1. If there is any chance that the cracker can succeed then the sysadmin has failed. SSH should only be allowed on the mail server from the inside interface.

            3. Collecting username aaron.aaronson via email spammer and then trying to attack ssh on servers in the block A.B.C.D through A.B.C.Z (and one of those is your SSH server). And the cracker is using multiple machines to make multiple attempts (one per machine) within time period X. - Again, if it works then the sysadmin has failed. Too many attempts in time period X should lock out the account for a set number of minutes. No matter how many IP addresses are involved.
            -continued-
            And that depends upon aaron.aaronson being a LEGITIMATE USERNAME ON THAT SYSTEM. Once the sysadmin sees that attack in the logs then the logins to that should be changed (ssh.aaron.aaronson or such) to break that attack if they were not already such. Or change them AGAIN (aaron.aaronson.ssh) and be aware that something leaked somewhere.

            4. See #3 except the logins are from multiple machines but only 1 login attempt in time period X so it never triggers the account lockout. Again, change the login names (ssh.aaron.aaronson) to break that attack (and did they leak?).

            In summary, getting your system cracked via SSH means that your sysadmin failed so many times.

            • And that depends upon aaron.aaronson being a LEGITIMATE USERNAME ON THAT SYSTEM. Once the sysadmin sees that attack in the logs then the logins to that should be changed (ssh.aaron.aaronson or such) to break that attack if they were not already such. Or change them AGAIN (aaron.aaronson.ssh) and be aware that something leaked somewhere.

              But you are being reactive. Wouldn't it be better to have the ssh user name different from the email name, and really different, so that it is difficult to deduce one from th

              • by khasim ( 1285 )

                But you are being reactive. Wouldn't it be better to have the ssh user name different from the email name, and really different, so that it is difficult to deduce one from the other?

                Being completely non-related to your login ID is okay. I won't hurt anything by having it like that.

                But it also won't add any additional security if you follow the other steps I've outlined.

                It all comes down to the cracker being able to match (pretty much in order):
                1. your SSH server
                AND
                2. legit username on that server
                AND
                3. match

            • by dbIII ( 701233 )

              In summary, getting your system cracked via SSH means that your sysadmin failed so many times.

              I had that once - handed over a machine and then had to rush in to reinstall the hacked mess on night a couple of years later. The problems were:
              Everybody with an email account had shell access.
              Usernames were common first names.
              One user had a password of "coffee".
              A dire mistake or deliberate action was made with "chmod" giving all users full read, write and execute access to nearly everything on the system. Areas

    • That's 6 attempts per minute.

      per zombie in the botnet. Each zombie IP gets banned individually, and the slow attack attempts prevents a DDoS.

  • Key AND Password (Score:5, Interesting)

    by XanC ( 644172 ) on Friday April 06, 2012 @01:29PM (#39600125)

    So what I've never understood is why it's not possible (as far as I know) for a server to require BOTH a key AND a password. Sure, I can put a password on my key, but that isn't the same at all. Is this possible yet?

    • If you are worried about that setup VPN with only access to ssh. Use a password for one and a key for the other. Otherwise, just keep your keys password protected and in a safe place. You can also restrict ssh/vpn to your IP address or a known range to limit the attack surface to locations you might actually be using to login. Add in fail2ban and a honeypot... wait why I am I telling you all this? If you are that worried just unplug it from the internet, don't use removable media and you will be fine!
    • by allo ( 1728082 )

      maybe with pam.

      at least you can for example use password AND one-time-password with pam, which applies for ssh, too.
      with OTP its more often used as password replacement (login from places where you do not trust the computer), but you can configure it as two-factor auth as well.

      • by heypete ( 60671 )

        Indeed.

        Google Authenticator (which is an implementation of TOTP, and doesn't send anything back to Google itself) can tie in with SSH/PAM [google.com] quite easily.

        • Re:Key AND Password (Score:4, Interesting)

          by allo ( 1728082 ) on Friday April 06, 2012 @02:14PM (#39600707)

          yeah, or i once had a sshd with https://en.wikipedia.org/wiki/OPIE_Authentication_System [wikipedia.org] running. Nice thing, you generate a bunch of passwords and print it. Then you can login from everywhere without looking out for keyloggers.

        • by mlts ( 1038732 ) *

          Maybe even going back to the age-old S/KEY or OPIE protocol that has been part of BSD for 20+ years? This has fallen into disuse because it was mainly designed to foil packet sniffers, but might be a good way of doing things. Maybe modify the algorithm a little bit so it uses a modern hash, and perhaps add a random 4-5 digit number somewhere in addition to dictionary chosen words. That way, trying to brute force a pass phrase that will easily be more than 20+ characters will be almost impossible, especia

        • I use Google Authenticator on my home server (and on Google itself). It's a great solution to this problem and works very well. Some ssh clients (notably on iOS) can't handle the two-factor authentication, but I just set those up with private key authentication.
      • I use Mobile OTP (http://motp.sourceforge.net/) for two-factor auth at work. Once I figured out the PAM side of things, it was quite straight-forward. I installed it on my server at home as well, but I'm a little more relaxed about it -- I allow ssh from a few "trusted" boxes via ssh-keys, otherwise it requires password+OTP token authentication. Now, I just have to worry about keeping those "trusted" boxes safe. (I do have a password on the ssh keys, but wonder if I have a long-running login session wit

    • by Qzukk ( 229616 )

      Non-Open-SSH has been able to require multiple authentication stages for some time now. Every now and then someone updates a patch for OpenSSH to do the same [mindrot.org].

    • Why would you want that? If you fear somebody else getting hold of your key, put a password on it; if you fear your key is too short, make it longer.

    • Perhaps that program could be "login" or something similar. Also, that give you the ability to use different command and different behaviors on a key-by-key basis for the account.

  • Or never... (Score:5, Informative)

    by damn_registrars ( 1103043 ) <damn.registrars@gmail.com> on Friday April 06, 2012 @01:30PM (#39600135) Homepage Journal
    Most of the bruteforce attacks I see on my home server are trying to get in as root. I don't allow remote root logins anyways (and even say so on the ssh greeting) so they'll never get in, even if they do manage to guess the password.

    Hence their most optimal rate for my system would be never, because they won't get in that way. Not that my system is impenetrable - I'm sure an intelligent hacker could compromise it - but they will never get in trying to ssh in as root.

    If they're doing white pages username + dictionary password - or white pages username + blank password (I've seen both, from botnet attacks), they still won't get in on my system as none of the common user names are used there.
  • by ledow ( 319597 ) on Friday April 06, 2012 @01:41PM (#39600279) Homepage

    I have a portknocking setup. All your packets bounce when you touch my port 22 until you have touched a "magic sequence" of port numbers first. That sequence can be cryptographically strong, time-dependent, etc. but even a simple one-port knock is enough to stop all this random SSH spam and has been for years.

    And if you do "get lucky" and find the right ports and then detect that port 22 is open and then start a brute-force on that? Public-key-only authentication and no root logins allowed.

    Impact on me? Another line in a shell script that I use to connect (and hell, even Android has free port-knocking apps, not to mention them being standard-enough to be in Ubuntu/Debian). Impact on server? Greatly reduced number of fake connections bouncing off iptables and a tiny little daemon that does nothing but listen on the ports I need (and can ONLY open the SSH port even if compromised). Impact on brute-forcers? They might as well give up and go home.

    Even those remote companies that we do allow to port-forward direct to their device on my work network (e.g. telecoms providers, etc.) understand it and "knock" before they come in (which tells us exactly when they are about to log in), while everyone else in the world sees closed ports.

    Why everyone doesn't use it, I have no idea. Even our VPN users have an automated script that just knocks to open the VPN ports (and only the VPN ports) before they connect. Transparent to them, invisible to everyone else, no different if "compromised".

    • Re: (Score:2, Interesting)

      by Anonymous Coward

      Why go through all that just to leave your SSH server on port 22?

    • Is there a package that includes this functionality or is it all custom done?

      • Re:Details? (Score:5, Informative)

        by ledow ( 319597 ) on Friday April 06, 2012 @02:08PM (#39600639) Homepage

        knockd on Linux. Apt-get should find it for you. It will execute a specified shell script when it receives a specified knock (default one is specified). That shell script can be passed the IP that knocked (so you can include it in an iptables opening within the script).

        There are also implementations for Windows, should you need that.

    • This is interesting. It's the first time I've heard of such a setup. How exactly do you have this setup in iptables? Is it just a chain that you jump to on the first port and return from on the last knocked port?
    • TCP port numbers are unencrypted so a serious attacker will be able to find out your sequence anyway. All you're doing is wasting your own time by making legitimate connections take longer.

      • by ledow ( 319597 )

        There are cryptographically secure versions. But you've missed the point.

        This stops random port-spam, random brute-force attacks, and casual access. If you want something secure, you should SECURE it (e.g. by restricting access to the bare minimum necessary and provide only public-key authentication ONLY). You can do that AND add port-knocking, if you want.

        But the spam on port 22 on an unsecured machine will flood your logs the second you put it on the net. Port-knocking stops that without having to tou

    • I had not heard of this--super interesting.

      Question though: how is it fundamentally different from simply having a slightly strongly stronger public-key-only authentication?  Just the fact that that sshd doesn't get involved?
    • All your packets bounce when you touch my port 22 until you have touched a "magic sequence" of port numbers first

      Using the old "ex-wife" model of security, eh?

    • by Trogre ( 513942 )

      Just curious, is there a reason you don't require both key pairs AND a password?

  • iptables with the recent module...ssh brute force attacks a thing of the past. Actually, same with RDP and just about any other service you can identify via iptables.

    Rate limit those suckers to something useful ( for ssh, I configured 2 attempts in 5 minutes, everything else is dropped ), call it done.

    iptables -I INPUT -i eth0 -p tcp --dport 22 -m state --state ESTABLISHED -j ACCEPT
    iptables -I INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -m recent --name sshattack --set
    iptables -I INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -m recent --name sshattack --update --seconds 300 --hitcount 3 -j DROP
    iptables -I INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -j ACCEPT

    ( Disclaimer: the above is from memory. I am positive there are better ways and more things you can do with it )

    • by Culture20 ( 968837 ) on Friday April 06, 2012 @02:20PM (#39600803)
      That's only useful if there's one attacker IP. TFA is talking about a botnet doing the attacking. Hundreds, if not thousands of IPs per minute. The only way to "protect" against that with iptables is to have iptables block all incoming on port 22 from any address. But then you're left with a DDoS where your ssh port is down nearly all the time. Same deal with locking accounts; if hundreds of attempts occur per minute, a lot of accounts can be locked out as a DDoS, intentionally or not.
  • 1 attempt per 10 seconds, so 360 attempts per hour, 8640 per 24 hours, 3,153,600 per year or 31 million passwords per 10 years.

    Well, if your password is not in some rainbow table and it's at least moderately strong, then you should be fine.

  • Comment removed (Score:5, Informative)

    by account_deleted ( 4530225 ) on Friday April 06, 2012 @02:09PM (#39600645)
    Comment removed based on user account deletion
  • by psydeshow ( 154300 ) on Friday April 06, 2012 @02:30PM (#39600893) Homepage

    I've been blocking these "attacks" using a script+firewall for many years now. And I still think that, really, OpenSSH should have a configuration switch to block them internally. But BSD folks don't see it as a real threat, and they don't want to risk having actual users to get locked out of their servers. Fair enough, I guess.

    So we're left with mitigation strategies. At 6 connections per minute, it's more a a nuisance than an attack, but I've seen rates as high as 200 connections per minute in the past, and there is no reason it couldn't go higher on an out-of-the-box OpenSSH configuration.

    Some solutions, as others have pointed out:
      - Have ssh listen on a port other than 22
      - Turn on OpenSSH's internal rate limiting (MaxStartups config)
      - Use key-based authentication
      - Roll your own script to grep the log for failed connections, and firewall any IP addresses with 10 or more failures

    A real brute-force attack would do a portscan first so putting ssh on a high port isn't much of a solution. Key-based auth is a nearly perfect solution, except that there are situations in which it is undesirable/awkward to use keys. The others just slow down the attack, which prevents the force part of brute-force.

    • by subreality ( 157447 ) on Friday April 06, 2012 @05:46PM (#39602823)

      Why roll your own firewalling script? fail2ban works great.

      In my experience fail2ban alone gets the attack rate down so low that they'll never succeed. They can scale the attack with more IPs, but large botnets aren't free and the price is apparently high enough for them to never bother any of my exposed machines.

  • An alternate method is to add the PAM pam_access module to /etc/pam.d/sshd. You set up /etc/security/access.conf to allow logins from console, secure tty, and local LAN and deny all others. Each user's ~/.ssh/authorized_keys file has his/her public key from the systems they want to login from (e.g. each user sets up a separate key pair for each system they have and adds the public key from each key pair to authorized_keys)

    ---

    When an attempt is made to login, sshd first checks authorized_keys and if the

  • But I was always too chicken to set it up to try every failed username/password combination against the host attempting to log in and executing a 'sudo shutdown -h now' if it succeeded. I can't imagine the botnet operators change the vulnerable passwords; that might alert the owner that something was up.
    • by shitzu ( 931108 )

      Here's an idea - route port 22 back to the connecting host. Then it will do a recursive bruteforce.

      • Might even work because the connecting host was prolly brute forced earlier. What you want to do if you get in is disable the machine somehow.

         

"It takes all sorts of in & out-door schooling to get adapted to my kind of fooling" - R. Frost

Working...