|
|
Subscribe / Log in / New account

Dealing with automated SSH password-guessing

October 24, 2016

This article was contributed by Tom Yates

Just about everyone who runs a Unix server on the internet uses SSH for remote access, and almost everyone who does that will be familiar with the log footprints of automated password-guessing bots. Although decently-secure passwords do much to harden a server against such attacks, the costs of dealing with the continual stream of failed logins can be considerable. There are ways to mitigate these costs.

We've probably all seen thousands of lines like this in our system logs:

    Oct 21 22:49:13 wibbly sshd[20474]: Failed password for user from 192.168.1.42 port 52498 ssh2
Generally, these are the signatures of self-propagating password-guessing bots that try to crack passwords by brute-force; if they succeed, they copy themselves onto the destination system and start scanning for remote systems to password-guess from there. They also often signal home to some control organization that an account has been cracked. There are a lot of bots out there: for this article, I spun up a completely fresh VPS with one of my providers, and the first such log entries appeared 71 minutes after the machine first booted.

Let's take it for granted that all LWN readers have sensible policies regarding password complexity that are rigorously and automatically enforced on all our users, and so we're unlikely to fall victim to these bots. Nevertheless both SSH connection setup and teardown, and the business of validating a password, are computationally expensive. If the internet has free rein to ask you to do this, the CPU costs in particular can be significant. I found that until I took measures in mitigation, my sshd was constantly using about 20% of a CPU to evaluate and reject login attempts.

Change the port number

It's a really simple fix, but changing the port number away from the default of 22 can be surprisingly effective. My wife and I both run VPSes with the same provider, both of which have been up and running for several years, identical in most respects save that she runs her sshd on a non-standard port number in the mid-hundreds. In the last four complete weeks of logs, my VPS saw a total of slightly over 23,000 rejections; hers saw three.

It's not an infallible technique on its own; recently, someone found her alternate port, and tried several hundred different user/password combinations before getting bored and moving on. It can also work badly with some clients that can't easily be configured to use a non-standard port number.

But changing the port number is probably the lightest-weight mitigation technique in this article; it is a simple matter of changing a line in /etc/ssh/sshd_config (or your distribution's configuration file) from Port 22 to Port 567, for example. You will need to pick a port without a current listener to avoid clashes; netstat can be helpful for this. Moreover, you will need to add permission to your firewall rules for the new port number before you restart the service, then take out the old port 22 permission after the restart and confirmation that everything works. I advise against just changing the existing firewall permission from port 22 to the new port; it's easy to get the sequencing wrong, and lock yourself out of your remote server that way.

Fail2ban

Fail2ban is an elegant piece of software that watches log files for evidence of abuse of network services, then adjusts firewall rules in realtime to ban access from the offending IP addresses to the service in question. It's pretty easy to find; CentOS users will find it in the EPEL repository, Ubuntu seems to have it in the standard repositories, and it shouldn't be hard to find for most other major distributions.

The project has a good page of HOWTOs, which include an excellent guide to using it on SSH. Although I disagree with banning IP addresses for a whole day — I think it's much too easy to lock oneself out of one's own systems — I found it otherwise easy to follow, and it works. On my CentOS system, I configured in the EPEL repository, did a "yum install fail2ban", and put the following into /etc/fail2ban/jail.local:

    [ssh-iptables]
    bantime = 600
    enabled = true
    filter = sshd
    action = iptables[name=SSH, port=ssh, protocol=tcp]
    maxretry = 5
    logpath=/var/log/secure
After that, doing a "service fail2ban start" was enough to lock out a test client system after five failed SSH attempts.

iptables rate limiting

One of the shortcomings of Fail2ban is a strong IPv4 focus. The huge size of the IPv6 address space makes scanning for SSH servers much more expensive, but my servers are already seeing non-service-specific IPv6 port scans most days, and the problem will only grow. As the Internet of Things comes along, and more houses have routed IPv6, there will be a lot more SSH servers to find. It's one thing having my colocated server being password-guessed by random servers in North Korea; it is quite another having all my kitchen appliances being password-guessed by half a million badly-configured light bulbs. So I do my rate-limiting with iptables (and ip6tables). The following lines of iptables commands log and reject the fourth and subsequent new connections in a rolling 60-second window:
    iptables -A INPUT -p tcp -m state --state NEW --dport 22 -m recent \
             --name sshrate --set
    iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent \
             --name sshrate --rcheck --seconds 60 --hitcount 4 -j LOG \
	     --log-prefix "SSH REJECT: "
    iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent \
             --name sshrate --rcheck --seconds 60 --hitcount 4 -j REJECT \
	     --reject-with tcp-reset
These lines need to come near the beginning of your iptables rules; specifically, before any blanket ACCEPT for any ESTABLISHED connections, and before any general permit for port 22 (or your sshd port of choice). You can use identical rules for ip6tables, and if your router is running Linux, you can add them to the FORWARD chain as well, protecting all the devices inside your network.

This is an extremely inexpensive way of rejecting over-frequent attempts to authenticate via SSH. Looking at the last complete week of logs on my colocated server, iptables refused over 153,000 connection attempts. Only 9,800 connection attempts were permitted to talk to sshd, and refused for having invalid passwords. 94% of malicious traffic was rejected quite cheaply, by iptables.

Although the ban period is only 60 seconds, if the banned address keeps trying to connect during the period of the ban — as bots tend to do — the ban continually renews itself. Only when the connection attempts stop can the 60-second window clear out and allow new connection attempts to succeed. Thus, this approach tends to impact bots more than humans, which is good. On the odd occasions I'm using a tool that needs to make large numbers of frequent connections, I can always make a manual SSH connection in SSH master mode, then tell the tool to use SSH slave mode and feed it the relevant ControlPath.

Public-key authentication

Another simple but powerful approach is to disallow password-based authentication in favor of public-key-based authentication. Changing the PasswordAuthentication parameter from yes to no in the sshd configuration file, will cause sshd to refuse attempts to authenticate via password. Your system still pays the setup and teardown cost of each SSH connection, but it doesn't have the expense of validating a password each time.

I can't quantify the utility of this approach, because my users wouldn't put up with it, but with Amazon EC2, nearly all new instances come out-of-the-box configured to refuse password-based authentication. I suspect this has done a great deal to decrease the number of systems on the internet that are vulnerable to automated password-guessing.

Two-factor authentication

As mentioned above, my users needed the ability to authenticate via password from time to time; for example, sometimes they needed to log in from a work site, where they were unwilling to leave a trusted key pair installed for a long time.

Two-factor authentication (2FA) is an excellent way to handle this; the recent rise in popularity of Google Authenticator has done much to introduce people to the idea, and to demystify it. Since Google Authenticator is simply a slightly idiosyncratic implementation of OATH Open Authentication, much can be done with this infrastructure without coupling oneself permanently to Google. Note that, as described below, this does not affect public-key-based SSH access; that can continue without the need for a 2FA exchange. Only password-based access requires 2FA, thus completely frustrating the bots.

On my CentOS 6 system, I had to do:

    # yum install pam_oath
    # ln -s /usr/lib64/security/pam_oath.so /lib64/security/  
Then I created a the /etc/users.oath file with mode 600 and owner root:root, and populated it with lines like:
    #type   username        pin     start seed
    HOTP   yatest             -        123a567890123b567890123c567890123d567890
where that start seed is a 40-hex-digit string of great randomness; I generated it with:
    # dd if=/dev/random bs=1k count=1|sha1sum
This seed should also be fed to an OATH HOTP software token. Google Authenticator, which is one such, suffers from the idiosyncrasy that it wants its seed in base-32 encoding, rather than hex. You can convert it yourself, or use a friendlier software OATH token generator, such as Android Token. Once this is done, the token will produce a stream of seemingly-random six-digit numbers that will be exactly what your server is expecting.

Then, in the file /etc/pam.d/sshd, immediately before the first line containing password-auth I added the line:

    auth required pam_oath.so usersfile=/etc/users.oath window=10
and in /etc/ssh/sshd_config ensured I had the lines:
    UsePAM yes
    PasswordAuthentication no
    ChallengeResponseAuthentication yes 

Once I had restarted sshd, I found that when SSHing in, I was asked first for the OATH six-digit number from the token, secondly for my password, and then granted access.

As an aside, do not succumb to the temptation to produce more than one or two token numbers right away. The function of HOTP OATH is to produce a sequence of numbers that are completely predictable if you know the secret seed (but not predictable if you only know previous numbers in the sequence). The window=10 parameter in the /etc/pam.d/sshd entry means that the server should accept not only the next expected number in the sequence, but any of the nine numbers after that as well. If you keep pressing the button on your software token, and run through (say) the next 20 numbers, you will get further through the sequence than the server expects you to be. Once server and token get out of sync, best practice is to reset both server and token, and to change the shared secret.

Note that you should keep a live SSH session, authenticated as root, throughout this process, so you don't accidentally lock yourself out of your own system. Better still, be within six feet of the system console when trying it for the first time.

In conclusion, if you don't like this incessant password-guessing stressing your system, you have options. Work out which one(s) best fit your needs, and give them a go.

Index entries for this article
SecurityTools/Password guessing prevention
GuestArticlesYates, Tom


to post comments

Dealing with automated SSH password-guessing

Posted Oct 24, 2016 23:31 UTC (Mon) by Sesse (subscriber, #53779) [Link] (5 responses)

20% CPU for dealing with failed SSH attempts? I've seen nowhere near that on even a Raspberry Pi; that would entail several connection attempts per second at the very least. What kind of machine is this where the CPU usage from this is a real problem?

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 11:35 UTC (Tue) by genaro (subscriber, #82632) [Link] (4 responses)

The author says he runs a VPS. I'd wager that bots are aware of the provider's netblock(s) and see it as a target rich environment.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 16:18 UTC (Tue) by Sesse (subscriber, #53779) [Link]

But by the same story, it requires 71 minutes for the first attempt to come, so presumably that's the average time. That means they'd need to hammer (eating a full core) for almost 15 minutes at a time for it to average 20%. That doesn't look like any pattern I've seen on e.g. AWS.

Dealing with automated SSH password-guessing

Posted Oct 26, 2016 22:07 UTC (Wed) by NightMonkey (subscriber, #23051) [Link] (1 responses)

Indeed. Netblock-to-Netblock variances in bot traffic can be substantial. The new assignee of the address or netblock gets the sad benefit of inheriting whatever the previous assignees 'attack surface' drew in.

Also, just one more vote here for moving away from known and common ports for administrative services. I think I said this on LWN many years ago, but it still is true for me that moving ports means that I can pay much greater attention to *directed* attacks on *my resources*, rather than just see a sea of dumb "wardialing" bots.

Dealing with automated SSH password-guessing

Posted Nov 3, 2016 3:14 UTC (Thu) by Chipz (guest, #82248) [Link]

Personally, I have been surprised at how many (seemingly undirected) SSH attacks I receive on non-standard ports. Perhaps if SSH had some kind of "--dont-reveal-service" flag, it might help

Dealing with automated SSH password-guessing

Posted Oct 27, 2016 18:39 UTC (Thu) by HenrikH (subscriber, #31152) [Link]

We run a number of servers on Amazon EC2 (in their Ireland region) and I see roughly 3000 failed login attempts per machine over ssh (thankfully we have been using public-keys since we begun to use Linux back in the day). For the physical servers that we have I see roughly 200 tries per server for the servers located in Stockholm and roughly 600 for the servers located in London.

So yes the number of attempts is higher on places such as Amazon EC2.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 0:16 UTC (Tue) by jwoithe (subscriber, #10521) [Link] (3 responses)

Another alternative along similar lines to fail2ban is sshguard. It has fewer dependencies than fail2ban and a number of firewall backends which can make it easier to integrate into arbitrary systems.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 3:36 UTC (Tue) by gfa (guest, #53331) [Link]

sshguard does work with ipv6, fail2ban doesn't

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 10:09 UTC (Tue) by Yorhel (subscriber, #91403) [Link]

In addition to the IPv6 support that was already mentioned, sshguard also starts with a much lower ban time (a few minutes by default, I think it was) and increases exponentially. So you don't have to worry too much about locking yourself out after a few failed login attempts.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 16:41 UTC (Tue) by zdzichu (subscriber, #17118) [Link]

sshguard looks cool. It would be even cooler if someone resurrected it's review request (https://bugzilla.redhat.com/show_bug.cgi?id=1260845). I'd like to play with sshguard when it's in Fedora,

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 0:16 UTC (Tue) by JoeF (guest, #4486) [Link] (5 responses)

I use Fail2Ban, but more aggressive. My systems are set up for public key authentication, so any attempt to log in with password is reason for an immediate block.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 0:19 UTC (Tue) by mtaht (subscriber, #11087) [Link]

I use xinetd's sensors feature a lot - detects telnet and ftp attempts and shuts down all access to the system that way. Have always meant to better integrate those ideas with ssh/failtoban, as well as come up with a decent rbl like reporting mechanism to a trusted, more central authority.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 4:03 UTC (Tue) by josh (subscriber, #17465) [Link]

Potentially a good idea, but occasionally you might be on a new system where you haven't copied your SSH key yet. So, I'd suggest *not* applying that level of aggression to connections that disconnect without actually trying a password.

Dealing with automated SSH password-guessing

Posted Oct 26, 2016 1:00 UTC (Wed) by voltagex (guest, #86296) [Link] (2 responses)

What happens if you forget to load your key on your desktop / laptop agent?

Dealing with automated SSH password-guessing

Posted Oct 26, 2016 1:41 UTC (Wed) by Cyberax (✭ supporter ✭, #52523) [Link]

Don't forget to do this. Duh.

Also, these days I'm keeping my keys on a hardware key device.

Dealing with automated SSH password-guessing

Posted Oct 26, 2016 8:00 UTC (Wed) by itvirta (guest, #49997) [Link]

Disable password authentication altogether on the client side (for that host) so you still won't accidentally present a password.
(Also, make sure you can use some other system to remove bans made by such draconian filters. :) )

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 1:02 UTC (Tue) by trentbuck (guest, #66356) [Link] (3 responses)

IME running SSH on a nonstandard port has one major downside:
ISPs routinely QoS 22/tcp to get preferential treatment.

OTOH I haven't tried it seriously since about 2011,
and since then:

1. OpenSSH client sets DSCP by default (see IPQoS in ssh_config(5));
2. mosh appeared <https://en.wikipedia.org/wiki/Mosh_(software)>; &
3. ISPs probably stopped applying internal netadmin preferences to customer links.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 6:23 UTC (Tue) by gdt (subscriber, #6284) [Link] (2 responses)

ISPs routinely QoS 22/tcp to get preferential treatment

It would be a rare ISP which does this. Remember that most SSH traffic a ISP sees is network abuse. It would also preference SFTP, which isn't desirable.

The SSH programs will typically continue to set the DSCP if you use a different port number. The DSCP isn't set on bulk file transfers, and so is a better choice for ISPs to use to mark the traffic than the TCP port number. That DSCP may or may not have a preferential per-hop behaviour within the ISP, depending on policy and equipment.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 7:29 UTC (Tue) by Cyberax (✭ supporter ✭, #52523) [Link] (1 responses)

ISPs absolutely do this (I worked at one). Mostly because their sysadmins love responsive SSH as much as the next guy.

And the total amount of SSH traffic is tiny compared to HTTP traffic, even with all the password guessing and SCP stuff. So there's no real downside for ISPs.

Dealing with automated SSH password-guessing

Posted Oct 26, 2016 2:05 UTC (Wed) by JdGordy (subscriber, #70103) [Link]

meanwhile, here in .au we have ISPs which just outright block incoming 80, 22 and 25 (and others), some without a way to get them unblocked without paying.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 1:24 UTC (Tue) by trentbuck (guest, #66356) [Link] (9 responses)

Regarding multifactor authentication ("2FA"), this is built into OpenSSH 6.2+.
See AuthenticationMethods in sshd_config(5).
I've no experience with it myself.

For users that can't handle a key-based auth (e.g. internet cafe users),
I have had good success with libpam_otpw.so on Debian.
This is effectively still a "something you have",
but it lives on a printout in their wallet,
instead of in ~/.ssh/id_ecdsa on their laptop.

OATH HOTP appears to be roughly the same as OTPW,
except more modern and phone-friendly.
But if you're going to put OTP tokens on your phone,
why not just put a regular id_ecdsa on your phone?

Enabling UsePAM in opensshd is an additional security risk.
Some distros enable it by default.
IIRC Dropbear doesn't support PAM at all;
not sure about GNU LSH or proprietary implementations (e.g. Cisco IOS).

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 9:33 UTC (Tue) by ms (subscriber, #41272) [Link] (7 responses)

I thought that one way to do the 2FA stuff with SSH would be to use FreeIPA. I believe they do support eg yubikeys. I am waiting for the version in Debian to get sorted out before trying it out though. I also what to be able to enforce that requirement for IMAP which appears to require GSSAPI which apparently should be possible with FreeIPA but I guess I'll find out what a can of worms that is in a few months time...

Dealing with automated SSH password-guessing

Posted Oct 26, 2016 17:15 UTC (Wed) by drag (guest, #31333) [Link] (6 responses)

For basic 2FA all you need is to do is use ssh key pairs.

1st factor: The private key. (something you have)

2nd factor: The password to encrypted the private key. (something you know)

Bingo! 2FA for cheap. It doesn't get any more complicated then that.

FreeIPA would be VERY overkill if that is all you want.

What FreeIPA can get you is kerberos support for your enterprise, management of sudo rules, ldap, manage selinux rules, it's own RBAC for network services, and all that fun stuff. For securing OpenSSH you can use kerberos or have FreeIPA manage the SSH keys. It can manage your user's public key for them and also manage your host SSH keys (all stored in LDAP). That way it makes the 'unknown host key' feature for ssh work better.

For fanciness you can do OTP with FreeIPA. You can use the embedded OTP and radius server that ships with FreeIPA or you can use a external OTP service via a radius server. The most basic FreeIPA OTP usage is to lock down the user's web interface so they will need to use their token + password to do self-management things like changing passwords for kerberos or for uploading their ssh public key.

All of this is not terribly useful if your goal is to eliminate internet failed logins.

I, personally, think that it's mostly silly. I am able to ignore failed login attempts with gratuitious use of 'grep -v' when looking at logs. The only login attempts that you should care about is ones that succeed. :P

Although if you are getting hit so hard that it's actually impacting your server then that is a real problem.

Dealing with automated SSH password-guessing

Posted Oct 27, 2016 16:51 UTC (Thu) by mstone_ (subscriber, #66309) [Link] (5 responses)

An ssh key pair is not two factors--it's something you have, and something you can brute force if you have the thing. It's incredibly common for people to just point to ssh keys and shrug off everything else because they're magical security voodoo, but the end result in most environments is that you're entirely dependent on users to protect their keys well, and (unlike passwords) you have zero ability to enforce any kind of security policy on the secret key. If you could trust users to always do all the right things, passwords wouldn't be such a problem...

In general, you're far better off with an actual two factor authentication scheme than something that depends entirely on user-protected ssh keys.

Dealing with automated SSH password-guessing

Posted Oct 27, 2016 17:41 UTC (Thu) by drag (guest, #31333) [Link] (4 responses)

> An ssh key pair is not two factors--it's something you have, and something you can brute force if you have the thing.

Because somebody can brute force 1FA like http-auth does that make it 0FA?

If you just have the password to the private key it's worthless without the key. If all you have is the encrypted private key and not the password it's useless. You need to have both for it to be any good. That's two factors. :)

Sure it's not a perfect solution, but there are no perfect solutions.

> It's incredibly common for people to just point to ssh keys and shrug off everything else because they're magical security voodoo,

If you think that you must have a really low opinion of everybody else. There are lots of good reasons why you would want to use ssh keys even when you have something like kerberos available.

The real problem with ssh keys isn't that they are insecure, but that it's difficult to revoke keys that have become compromised or are out dated. If you use defaults that ship with distributions then you get stuck having to use something like ansible to go and look for rouge authorized_key files, which sucks.

There are ways to mitigate this problem, however. For example you can configure your sshd servers to have public keys in a central location on each server and use puppet/ansible to manage those keys. If you are using something like FreeIPA you can manage ssh public keys via LDAP.

For many situations were you are dealing with administrators or personal systems then ssh keys can be extremely robust and continue to function correctly despite having huge portions of infrastructure broken or missing.

Having something that works when everything else doesn't is very advantageous. Being resistant to 'denial of service' is itself a important security consideration. So adding central management of auth has it's own downsides.

> but the end result in most environments is that you're entirely dependent on users to protect their keys well,

Name me ONE authentication system that doesn't depend on clients being secure. Kerberos isn't going to do it. OpenLDAP auth isn't going to do it. OTP isn't going to accomplish that either.

If you can solve this problem you will be responsible for a revolution in computer security.

> If you could trust users to always do all the right things, passwords wouldn't be such a problem...

The problem with passwords isn't that end users are stupid. There are is nothing you can do to fix that.

The problem with passwords is that they make VERY difficult for end users to do the right thing. Doing pure password approach is just bad design, pure and simple. To manage passwords correctly you need to have unique passwords for everything and you need to enter them every time. That never happens. Even you don't do it right and you know it.

And doing kerberos or otp poorly makes this worse. There is no such thing as a magic bullet here.

Dealing with automated SSH password-guessing

Posted Oct 27, 2016 18:07 UTC (Thu) by mstone_ (subscriber, #66309) [Link] (3 responses)

> If you just have the password to the private key it's worthless without the key. If all you have is the encrypted private key and not the password it's useless.

The password to unlock the secret key is in the secret key--it's offline crackable. There's also no way for you to enforce that your users even have a password. This isn't a word game, it's intrinsic to the understanding of authentication factors.

> The real problem with ssh keys isn't that they are insecure, but that it's difficult to revoke keys that have become compromised or are out dated.

Key revocation is a specific case of the general problem of ssh key management, and that's exactly the problem I'm talking about.

> Name me ONE authentication system that doesn't depend on clients being secure

You're engaging in hyperbole. A very real problem of ssh key security is that users quite often copy their keys around. You're not only relying on their client to be secure, you're also relying on every shared system that they have ever left a copy of the key on to be secure. Many places have found out the hard way that's a lot of trust.

The only one talking about magic bullets is you. Real security comes from understanding the trade offs that come with any implementation, and in my experience too many people toss around "ssh keys" as though there are no trade offs--which means that they certainly aren't doing anything to mitigate the risks.

Dealing with automated SSH password-guessing

Posted Oct 27, 2016 22:13 UTC (Thu) by nybble41 (subscriber, #55106) [Link] (2 responses)

One solution to all of this is to use a hardware token for your SSH keys. I have a Yubikey 4 which serves this purpose, for example, though it does require some configuration on the client (PKCS11Provider in ssh_config or ~/.ssh/config) to enable integration with the OpenSC library. I believe one can accomplish a similar result by configuring GPG to act as an SSH agent.

The problem with password + key as 2FA is that the password and the key are both "something you know"; even if you only "know" the key in the sense that your computer remembers it for you, it's still just data which you have access to. 2FA requires two _dissimilar_ factors. Moving the SSH keys into a secure hardware token changes them from "something you know" (the key) to "something you have" (the hardware); combine this with a password or PIN to unlock the token and you have effective 2FA.

Administrators can enforce that only hardware token keys are acceptable for public-key authentication by configuring the tokens themselves and using a centrally-controlled authorized_keys database consisting exclusively of hardware token public keys.

Dealing with automated SSH password-guessing

Posted Oct 29, 2016 8:01 UTC (Sat) by madhatter (subscriber, #4665) [Link] (1 responses)

I agree with most of the comments above, particularly those around the impossibility of verifying that your remote users have not stripped their passwords from their stored keys. But nybble41, above, really puts his finger on my objections to drag's suggestion, with his mention of hardware tokens.

When used in the context of 2FA, something you have doesn't refer to knowledge; it refers to physical objects, because although digital knowledge can be easily copied, copying physical objects with all their internal state is still comparitively difficult, and the difference in these difficulties is what makes a physical object secure in a completely different way to something you know.

Using two physical objects wouldn't be true 2FA either, because although they are difficult to copy, they are comparitively easy to steal, when compared to the other two classes of authentication token (something you know, something you are). It is important that the two things in 2FA be from different classes of token.

I also use a yubikey to generate my HOTPs (and TOTPs, with the assistance of NFC and an Android phone to provide a timestamp for sealing). Some more details can be found here.

Dealing with automated SSH password-guessing

Posted Nov 5, 2016 17:34 UTC (Sat) by Wol (subscriber, #4433) [Link]

Dunno whether they have this elsewhere, but a lot of banks in the UK use 2FA. For example, I have a card-reader for my Barclays account (I gather the same reader will work for any bank - I know it's interchangeable with NatWest).

When I want to log in to my bank, I put my bank card into the reader, type in my PIN, and then use the resultant OTP to log in to the bank.

Likewise, whenever I want to make a payment or stuff like that to someone the bank doesn't already know about, I have to use a *different* OTP to authorise that payment. Quite often I have to sign the payment.

Cheers,
Wol

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 10:48 UTC (Tue) by nix (subscriber, #2304) [Link]

I use AuthenticationMethods to require public key *and* OTP authentication when a user has both. It's trivial:

# Yubikey users need to authenticate with an OTP on SSH connection.
Match Group yubissh
AuthenticationMethods publickey,keyboard-interactive

(The changes to PAM are... less trivial, because of PAM's horrendous excuse for conditionals.)

2 other methods

Posted Oct 25, 2016 2:22 UTC (Tue) by hisdad (subscriber, #5375) [Link] (7 responses)

1st, make sure you have a current putty, then add this to sshd_config

KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-ripemd160-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,umac-128@openssh.com

A surprising number of bots can't negotiate these.

Unable to negotiate with 116.31.116.44 port 31730: no matching key exchange method found. Their offer: diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1 [preauth]

Secondly, if you, like me, don't care about the rest of the world (they are all foreigners)

install the geoblocking part of xtables http://xtables-addons.sourceforge.net/geoip.php
and edit your firewall (Shorewall in this case)

SSH(ACCEPT):info loc:^[NZ] $FW - - - - s:4/min:2

Which works just fine here in NZ. It is also rate limiting.

Take care you don't lock yourself out.

--Dad

2 other methods

Posted Oct 25, 2016 4:05 UTC (Tue) by josh (subscriber, #17465) [Link] (3 responses)

> Secondly, if you, like me, don't care about the rest of the world

...and you know you have no plans to travel internationally, and you won't forget to change that rule before traveling...

2 other methods

Posted Oct 25, 2016 4:24 UTC (Tue) by pabs (subscriber, #43278) [Link] (2 responses)

Not a problem, just use a Tor exit node from your home country to get back in and whitelist your new country again.

2 other methods

Posted Oct 26, 2016 23:20 UTC (Wed) by misc (subscriber, #73730) [Link] (1 responses)

Then I guess you could directly use a onion service in the first place to serve ssh.

2 other methods

Posted Oct 27, 2016 22:36 UTC (Thu) by bronson (subscriber, #4806) [Link]

Suffering ssh over tor briefly is OK. Using laggy ssh over tor all day sounds like hell.

2 other methods

Posted Oct 25, 2016 7:23 UTC (Tue) by jackb (guest, #41909) [Link] (2 responses)

You're still being too lenient.

KexAlgorithms curve25519-sha256@libssh.org
Ciphers chacha20-poly1305@openssh.com
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com

2 other methods

Posted Oct 25, 2016 17:27 UTC (Tue) by flussence (guest, #85566) [Link]

Mine simply has:

MACs umac-64-etm@openssh.com

The other two lines are already default as a side effect of my openssh being built without openssl support, which removes support for everything else entirely. I haven't found anything important actually needs the old algos, even my phone can do 25519 these days. :-)

disable old and insecure crypto algorithms

Posted Oct 26, 2016 8:11 UTC (Wed) by Seegras (guest, #20463) [Link]

This actually helps a lot and is probably the easiest and most convenient thing to do.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 3:27 UTC (Tue) by rsidd (subscriber, #2582) [Link] (8 responses)

>I can't quantify the utility of [disabling password-based authentication], because my users wouldn't put up with it

But why should your users get to decide? Make them put up with it! It's what we do at my workplace, only key-based-login for the outward-facing hosts. For even a modest-sized organization it is impossible to ensure that every user has an unguessable password.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 7:12 UTC (Tue) by niner (subscriber, #26151) [Link] (5 responses)

It's actually quite trivial to ensure every user has an unguessable password: don't let them pick it. When all passwords are generated automatically, you know they're good. If you're nice, you let the users generate a new one as often as they like, i.e. until they find one they can remember.

Of course that means management has to really support this security thing.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 7:52 UTC (Tue) by andresfreund (subscriber, #69562) [Link] (3 responses)

Meh. That just ensures that passwords are guaranteed to be on yellow stickies besides monitors, below keyboards and such.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 7:57 UTC (Tue) by niner (subscriber, #26151) [Link] (2 responses)

With physical access an attacker has already almost won anyway... But yes, no solution is perfect. Though I can't say that I've seen stickers around here where we do have this policy.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 15:00 UTC (Tue) by bvanheu (guest, #88814) [Link] (1 responses)

do you always leave your computer unlocked?

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 16:11 UTC (Tue) by niner (subscriber, #26151) [Link]

I'm sorry, I don't understand where you infer that from or what you're getting at?

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 20:28 UTC (Tue) by dsommers (subscriber, #55274) [Link]

Or add proper centralized authentication. FreeIPA is a breeze to setup and doesn't require too much resources even, allows you to have a centralized password management with password policies (including password strength and rotation) and you can store SSH keys centralized if you want.

Couple FreeIPA with kdcproxy (which is shipped in FreeIPA) and you get Kerberos/GSSAPI authentication over HTTPS + FreeIPA gives you Kerberos with 2FA (useful to enable Kerberos tickets when being on the road). Which again can be integrated with the local login on Fedora/RHEL/SL/CentOS as well, including local caching of authentication data for times when you're offline. At this point, you can disable password authentication on enrolled SSH hosts and allow GSSAPI instead. End result is a setup which gives you Single Sign-On as well. You type your password once when you login (or unlock your screen locally), and Kerberos/GSSAPI takes care of the rest.

Not to mention that this setup can be integrated with other solutions as well, extending the SSO capabilities. The Ipsilon project is also worth looking at, which integrates FreeIPA with SAML and several of other authentication schemes used by many third-party solutions.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 9:33 UTC (Tue) by farnz (subscriber, #17727) [Link] (1 responses)

If you're a workplace, you can go one better - set up 2FA with mobile apps to provide OTPs (HOTP and TOTP are standards for this, and there's a FreeOTP application for iOS and Android phones). You can improve slightly by adding a device like the Nitrokey to your supported hardware set, so that I don't need to pull out my phone - just plug in a magic USB device, and tap it whenever I want to log in.

Then, the password is only needed to protect you in the window between user losing their OTP device and user reporting it lost (so that you can invalidate it on the backend), and thus its weakness is less of an issue - to break in, I need to somehow obtain your OTP device and guess your weak password before the OTP device is reported lost and disabled in your backend OTP service.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 16:45 UTC (Tue) by gerdesj (subscriber, #5446) [Link]

"and there's a FreeOTP application for iOS and Android phones"

Thanks for the pointer. It's sponsored by Red Hat and the code is on Github - cool.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 7:25 UTC (Tue) by marcH (subscriber, #57642) [Link] (9 responses)

> So I do my rate-limiting with iptables (and ip6tables).

Any idea why sshd doesn't support this on its own and it requires a firewall hack instead?

(Everything should support rate-limiting nowadays)

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 8:08 UTC (Tue) by zev (subscriber, #88455) [Link] (7 responses)

To take the opposite perspective, why should we build the same functionality into O(n) things (applications) instead of O(1) things?

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 14:34 UTC (Tue) by marcH (subscriber, #57642) [Link] (5 responses)

> > (Everything should support rate-limiting nowadays)

> O(n) things (applications) instead of O(1) things?

Not "instead": everywhere.

1. In an ideal world, all applications should provide (optional) application-specific rate limiting knobs to the sysadmin. Typically: *per-user* quotas. Common code - to measure network traffic for instance - can be in shared libraries.
Try abusing some Google or Amazon cloud service just a bit and see what happens.

2. If desired again by the sysadmin, rate limits can also be set at the network level; but in an application independent / port independent / simpler manner.

The hack/"optimization" above is having application-specific rate-limiting implemented at the network level. One symptom it is a hack is seeing the port number duplicated in both layers.

This firewall discussion happened already many times - on this site and others.
https://lwn.net/Articles/596156/ is hopefully the most complete example.

Back to the main topic: if proven it's sad to see a fundamental security tool not considering rate limiting.

Dealing with automated SSH password-guessing

Posted Oct 26, 2016 8:08 UTC (Wed) by NightMonkey (subscriber, #23051) [Link] (4 responses)

That is certainly not the *NIX way. :)

Dealing with automated SSH password-guessing

Posted Oct 26, 2016 10:50 UTC (Wed) by MarcB (subscriber, #101804) [Link] (3 responses)

It's not about Unix ways, it's about fundamental networking principles, notably the end-to-end principle.

The way firewalling has evolved in the last decades has gone horribly wrong. More and more functionality that does not belong there has been moved into the firewall and kernel or even into external firewall boxes. Commercial vendors at least got an "excuse" for that: They need to compete in the feature space to impress decision makers. The technical staff will then turn most of the features off anyway, at least after the first disaster.
Open source developers somehow also felt the need to get into this race. Additionally, in Linux, pushing everything into the kernel seemed - and still seems - acceptable. The BSDs also do that, but to a lesser degree. They got more functionality in userspace daemons.

At this point, it is possible to trigger a DoS on a very busy Linux system simply by running iptables -L (which is naively assumed to never change any state), because that can cause connection tracking to be enabled, then the tracking tables to overflow and packets to be dropped. This has once caused a VoIP outage for millions of users (there is also a public story about a similar accident: https://developers.soundcloud.com/blog/shoot-yourself-in-...).

Of course, there should be a central switch for administrators to restrict reachable ports, and also depending on the source. But this could also be achieved by a shared library that reads configuration from a well-known place and is used by any application binding to an IP socket. This library could then be extended at will with logging, rate-limiting, tar-pitting, ...
This would also make administration much easier and unified. Currently, some applications can bind to given interface names. Others to IP addresses. Others only to 0.0.0.0 or ::.

There even is something like this: tcpwrapper. I used to consider this pointless, because the kernel could already to that via ipchains/iptables. But now I think this is the right approach and should be massively extended. Ideally, it would never be required to use Netfilter on a non-router.

Dealing with automated SSH password-guessing

Posted Oct 26, 2016 19:49 UTC (Wed) by marcH (subscriber, #57642) [Link] (2 responses)

> At this point, it is possible to trigger a DoS on a very busy Linux system simply by running iptables -L (which is naively assumed to never change any state), because that can cause connection tracking to be enabled, then the tracking tables to overflow and packets to be dropped.
> https://developers.soundcloud.com/blog/shoot-yourself-in-...

Amazing.

> Of course, there should be a central switch for administrators to restrict reachable ports, and also depending on the source. But this could also be achieved by a shared library that reads configuration from a well-known place and is used by any application binding to an IP socket. This library could then be extended at will with logging, rate-limiting, tar-pitting, ...
> This would also make administration much easier and unified. Currently, some applications can bind to given interface names. Others to IP addresses. Others only to 0.0.0.0 or ::.

Another funny side-effect of having application-level configuration set in the wrong place: the ridiculously massive duplication between "iptables -L" and "ip6tables -L". Just run these two commands on most Linux systems and see for yourself. Who knows: maybe some day someone will get tired of this duplication and will start some user space tool to manage it... that would be a first step towards the aforementioned library!

Dealing with automated SSH password-guessing

Posted Oct 26, 2016 21:59 UTC (Wed) by chirlu (guest, #89906) [Link]

I have a single rule file that is used both for IPv4 and IPv6 and loaded via iptables-restore (from the iptables-persistent package, formerly netfilter-persistent). In the few cases where different rules are needed, they can be marked with the -4 and -6 options.

Dealing with automated SSH password-guessing

Posted Oct 27, 2016 12:57 UTC (Thu) by philwhineray (subscriber, #6106) [Link]

> Who knows: maybe some day someone will get tired of this duplication and will start some user space tool to manage it...

So then, just a quick plug for FireHOL, which produces IPv4 and IPv6 rules from a single config, with the option to mark rules as just for one or the other.

http://firehol.org/tutorial/firehol-ipv6/

It doesn't really help when it comes to inspecting the loaded rules, though.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 14:41 UTC (Tue) by droundy (subscriber, #4559) [Link]

That would be because openssh knows the difference between failed connections and successful ones. Rate limiting all connections requires implementing a workaround in openssh.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 22:26 UTC (Tue) by imMute (guest, #96323) [Link]

One of the things that the iptables method can get you is blocking the offender for ALL traffic, not just SSH traffic. Bonus points for making the "and if you keep trying the ban will be extended" to include ANY traffic from the offender, not just SSH traffic.

I went as far as dropping ICMP on the floor once the SSH trapdoor is hit. Once that trapdoor is hit, my VPS basically stops replying _completely_. Yes, that probably breaks some things, but for an endpoint trying to bruteforce my SSH server, I don't really care.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 8:48 UTC (Tue) by bytelicker (guest, #92320) [Link] (9 responses)

I also use public key authentication. Patched my SSH daemon to log and save all password-based login attempts; both username and password. It keeps giving. I have a pretty modest dictionary now. Been running with this patch for some years now. It's fun!

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 9:55 UTC (Tue) by rsidd (subscriber, #2582) [Link] (2 responses)

So what do you do with this dictionary?

I have always wondered, if you ran a site that required an email-address as login (or for other reasons) and a password, and you were feeling malicious, you could collect quite a few gmail passwords -- either because of the user's bad finger memory, or because it's the same password! A good site should not store the password you type, just hash it and compare it with their hash, but how many sites do that? Several, I'm sure, store the passwords in plain text (eg, er, most GNU Mailman lists...)

How big is this problem in real life?

Dealing with automated SSH password-guessing

Posted Oct 26, 2016 11:11 UTC (Wed) by bytelicker (guest, #92320) [Link]

I completely agree with what you write. No site or service should collect passwords in either cleartext or whatever.

I set this up because I am the only valid person SSH'ing to my server and for fun! I was stunned at how many login attempts my SSH daemon got. I'm not using the dictionary for anything but I certainly could. The dictionary contains around ~24 million records as of today.

Dealing with automated SSH password-guessing

Posted Oct 26, 2016 18:06 UTC (Wed) by josh (subscriber, #17465) [Link]

Dealing with automated SSH password-guessing

Posted Oct 27, 2016 2:51 UTC (Thu) by karkhaz (subscriber, #99844) [Link] (1 responses)

> Patched my SSH daemon to log and save all password-based login attempts

this sounds like good fun, are you hosting the patch anywhere?

Dealing with automated SSH password-guessing

Posted Oct 27, 2016 7:21 UTC (Thu) by Cyberax (✭ supporter ✭, #52523) [Link]

Dealing with automated SSH password-guessing

Posted Nov 6, 2016 0:47 UTC (Sun) by JanC_ (guest, #34940) [Link] (3 responses)

You could also try connecting back to them with the same user/password combinations...

Dealing with automated SSH password-guessing

Posted Nov 6, 2016 3:35 UTC (Sun) by raven667 (subscriber, #5198) [Link] (2 responses)

> You could also try connecting back to them with the same user/password combinations...

That's actually a terrible idea, you don't own the computers that are scanning you, they are probably themselves just infected with a botnet, but even if it was the attacker, you have no right to log into their computers, as they have no right to log into yours. I don't think everyone going all vigilante justice on everyone else results in a stable system.

Dealing with automated SSH password-guessing

Posted Nov 7, 2016 20:23 UTC (Mon) by JanC_ (guest, #34940) [Link] (1 responses)

I agree that vigilante justice is not the way to go, and that's also not what I was proposing.

Still, trying this “reverse login” might be useful for more ethical purposes (even if it would possibly be illegal still), e.g.:

* researching which devices use what default/backdoor passwords
* disabling the botnet

Also: if that other system is owned by another person, then is it illegal or legal that you try to help them and/or the community? If you see a child/dog in a closed car suffering under a heavy sun, and the owners doesn't seem to be around, then is it illegal or legal (or even legally required) to break into that car because you aren't the owner? If you see a car that rolled halfway on the road because somebody forgot to pull their handbrake, then is it illegal or legal to enter that car, push it off the street, and pull the handbrake?

Sounds like an interesting question for someone who actually has a clue about the law/jurisprudence on such things.

Dealing with automated SSH password-guessing

Posted Nov 8, 2016 17:16 UTC (Tue) by raven667 (subscriber, #5198) [Link]

I don't see how those examples are relevant, that's more of a Samaritan example on which there is existing law, a closer match would be if someone broke into your house and stole your TV, could you (as a private citizen) follow them home and break into their house and rifle through it. What if the house you followed them to was not their home but just another victim, could you rifle through their house as well? Is it different if the police do the same thing?

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 10:09 UTC (Tue) by colo (guest, #45564) [Link]

There's at least one genuine FOSS software TOTP/HOTP token available for Android phone: https://f-droid.org/repository/browse/?fdid=org.fedorahos...

That app is also available for iOS devices, and can even ingest the token's secret from a QR-code. Our company-internal self-service portal for authn-related stuff that I write uses a small Javascript-library (https://jeromeetienne.github.io/jquery-qrcode/) to make it extra-convenient for users to set up their token.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 10:18 UTC (Tue) by kooky (subscriber, #92468) [Link]

If you use keys to login, then you can also enable password authentication on a per user basis.

In /etc/ssh/sshd_config

PasswordAuthentication no

.....

Match group remotessh
PasswordAuthentication yes
RSAAuthentication yes
PubkeyAuthentication yes

*****

So people in the group remotessh can use passwords, nobody else can.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 10:19 UTC (Tue) by lyda (subscriber, #7429) [Link]

Looking on Ubuntu I see libpam-google-authenticator and libpam-oath. Both are pretty much the same, though google-authenticator uses a file in the user's home dir which is nicer on a shared system. Be nice if the oath toolkit had a method for users to change their key.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 11:32 UTC (Tue) by genaro (subscriber, #82632) [Link]

You can also rate limit connections with ufw. Something like ufw limit 22/tcp will deny connections if an IP address attempts to initiate 6 or more connections within 30 seconds. It's less tune-able than iptables but still an option.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 12:35 UTC (Tue) by jrigg (guest, #30848) [Link] (1 responses)

You can also use iptables rules to temporarily blacklist IP addresses which are the source of multiple login attempts, eg.:
http://thiemonagel.de/2006/02/preventing-brute-force-atta...

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 12:40 UTC (Tue) by jrigg (guest, #30848) [Link]

Ignore my previous comment; it's described in the article. Must read more carefully next time.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 15:26 UTC (Tue) by wazoox (subscriber, #69624) [Link] (1 responses)

I'm using a non standard high port, and it recently failed me because I was connecting from a network that doesn't allow any outside connection but towards 80 or 443 ports. Then I discovered SSLH ( available in Debian based distros, else https://github.com/yrutschle/sslh ): it's a proxy that listen to port 443, identifies SSL or SSH traffic and redirect it towards the right service. Sounds really clever, I plan to use it instead of port 54022 :)

Dealing with automated SSH password-guessing

Posted Oct 26, 2016 6:01 UTC (Wed) by voltagex (guest, #86296) [Link]

I may move from sslh to haproxy - but sslh has served me well for many years. Just make sure you read the forking configuration stuff. I'm fairly sure I exhausted the RAM on an original Raspberry Pi with the default config.

Dealing with automated SSH password-guessing

Posted Oct 25, 2016 15:39 UTC (Tue) by lkraav (subscriber, #76113) [Link] (1 responses)

I'm also finding rate-limiting / tarpitting at least incrementally a more effective strategy compared to just timed bans. `iptables-xt_recent` was a pleasant discovery, is working very well, and the basic setup example already ships with `fail2ban`.

https://github.com/fail2ban/fail2ban/blob/master/config/a...

Key for me was to disable `fail2ban` unban action altogether. This enabled `xt_recent` timeout configuration to fully control ban renewal and most attackers stay in the ban table indefinitely, or until they leave it alone. Very few bots, if any ever, have been configured to try 1 attack / 24h to evade rate limiting...

Dealing with automated SSH password-guessing

Posted Oct 26, 2016 0:55 UTC (Wed) by speedster1 (guest, #8143) [Link]

> Very few bots, if any ever, have been configured to try 1 attack / 24h to evade rate limiting...

Even if they were, it would take a significant number of bot hosts to cause trouble at that rate. Probably have to be a special target of interest rather than a random victim to receive that much attention.

Hide it behind a VPN

Posted Oct 26, 2016 15:33 UTC (Wed) by storner (subscriber, #119) [Link]

Installing OpenVPN is (close to) trivial, and there are clients for at least Linux, Windows and Android (don't have a Mac). And the VPN gives you more flexibility by letting you use other network services on the server without tunneling through an SSH connection.

Dealing with automated SSH password-guessing

Posted Oct 26, 2016 16:40 UTC (Wed) by pspinler (subscriber, #2922) [Link]

Or a port knocker. I use knockd to only open my firewall to the originating host when it recognizes a particular knock sequence. At a pinch I can send the approptiate knock sequence from the command line using e.g. nc or even telnet.

Dealing with automated SSH password-guessing

Posted Oct 28, 2016 0:33 UTC (Fri) by ykram (guest, #89515) [Link]

Inspecting packets to see if the SSH agent string contains libssh and blocking them afterwards has helped in my environment. Furthermore, I've taken to blocking entire subnets associated with China, Russia and Vietnam which has helped stop probably close to 95% of these.

Dealing with automated SSH password-guessing

Posted Oct 28, 2016 8:12 UTC (Fri) by rwm (guest, #104883) [Link]

My two cents:

I've never been a fan of fail2ban style systems, you're increasing your systems complexity and making your firewall rules depend on the actions of malicious parties. It seems like a good way to open your systems up to a DoS attack, after having a quick look at fail2ban's history they've already had some of those types of vulnerability crop up:
https://www.cvedetails.com/vulnerability-list/vendor_id-5...

Disable password auth and you're secure enough for most purposes. Enable a second factor in the form of TOTP or some substitute, and you're secure enough for all other purposes that involve a machine directly connected to the Internet.

Complexity is the enemy.

Dealing with automated SSH password-guessing

Posted Oct 28, 2016 12:36 UTC (Fri) by jsanders (subscriber, #69784) [Link]

pam-abl is another way for blocking ssh attacks. It seems better than fail2ban, as it doesn't need to parse log files or mess around with firewalls. See http://pam-abl.sourceforge.net/

ssh master mode

Posted Oct 29, 2016 22:20 UTC (Sat) by Jandar (subscriber, #85683) [Link]

There is an ssh-option for opportunistic multiplexing: ControlMaster=auto. With this a master connection is established if there isn't one and hold open for ControlPersist seconds.

Is is very useful to speed up a sequence of many connections as in

scp file remote:/dest && ssh remote script; scp remote:/result .; ...

Dealing with automated SSH password-guessing

Posted Oct 29, 2016 23:06 UTC (Sat) by karkhaz (subscriber, #99844) [Link]

This article is obviously aimed at sysadmins with lots of users to tolerate, but for personal systems I cannot recommend a port-knocking strategy using something like knockd [1] highly enough. (That implementation is by the creator of Arch Linux, but coding one up yourself is also good fun). That instantly reduces the number of attempts on your system to zero, permanently.

[1] http://www.zeroflux.org/projects/knock

My "2 cents a minute"

Posted Nov 3, 2016 22:25 UTC (Thu) by dfsmith (guest, #20302) [Link] (1 responses)

My server also runs an Asterisk PBX (phone exchange). So to get ssh access, I call a number on my phone and enter a code. The server then opens an ssh port for 3 minutes, and verbally reads out the port number to connect to. It sounds complex, but it wasn't that difficult and has been working for years.

My "2 cents a minute"

Posted Nov 4, 2016 13:09 UTC (Fri) by wurtel (guest, #7155) [Link]

So long you don't need access because Asterisk has stopped working for some unknown reason...

Dealing with automated SSH password-guessing

Posted Nov 6, 2016 6:41 UTC (Sun) by zblaxell (subscriber, #26385) [Link] (1 responses)

We use a variety of non-standard, often non-TCP transports for SSH, and leave a honeypot on Internet-facing hosts listening to port 22.

The honeypot is hosted at an isolated site and pops up on public servers through NAT and VPN tunneling with draconian bandwidth limitations to keep the CPU and bandwidth costs negligible. The scanners are working for hours on thousands of SSH ports to eventually log into one artificially slow-and-laggy Raspberry Pi in a DMZ.

The best way to get the wardialling community to voluntarily blacklist you is to quietly poison their data. A big list of vulnerable hosts--the product that funds all the scanning work--is much less valuable if too many of the entries are fake, or more expensive to produce if all the successful probes from automated tools have to be verified by a human. If we simply block the SSH port or reject password authentication, the scanners will quickly move on to the next target, and we'll have wasted our opportunity to passively degrade their efficiency.

Dealing with automated SSH password-guessing

Posted Nov 13, 2016 14:56 UTC (Sun) by paulj (subscriber, #341) [Link]

Beautiful.

It'd be great to document how to do this, and maybe start a project to provide a pool of useless, slow honeypot (actually, /tarpit/ might be a better term?) servers.


Copyright © 2016, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds