Dealing with automated SSH password-guessing
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 ssh2Generally, 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/secureAfter 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-resetThese 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 - 123a567890123b567890123c567890123d567890where that start seed is a 40-hex-digit string of great randomness; I generated it with:
# dd if=/dev/random bs=1k count=1|sha1sumThis 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=10and 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 | |
---|---|
Security | Tools/Password guessing prevention |
GuestArticles | Yates, Tom |
Posted Oct 24, 2016 23:31 UTC (Mon)
by Sesse (subscriber, #53779)
[Link] (5 responses)
Posted Oct 25, 2016 11:35 UTC (Tue)
by genaro (subscriber, #82632)
[Link] (4 responses)
Posted Oct 25, 2016 16:18 UTC (Tue)
by Sesse (subscriber, #53779)
[Link]
Posted Oct 26, 2016 22:07 UTC (Wed)
by NightMonkey (subscriber, #23051)
[Link] (1 responses)
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.
Posted Nov 3, 2016 3:14 UTC (Thu)
by Chipz (guest, #82248)
[Link]
Posted Oct 27, 2016 18:39 UTC (Thu)
by HenrikH (subscriber, #31152)
[Link]
So yes the number of attempts is higher on places such as Amazon EC2.
Posted Oct 25, 2016 0:16 UTC (Tue)
by jwoithe (subscriber, #10521)
[Link] (3 responses)
Posted Oct 25, 2016 3:36 UTC (Tue)
by gfa (guest, #53331)
[Link]
Posted Oct 25, 2016 10:09 UTC (Tue)
by Yorhel (subscriber, #91403)
[Link]
Posted Oct 25, 2016 16:41 UTC (Tue)
by zdzichu (subscriber, #17118)
[Link]
Posted Oct 25, 2016 0:16 UTC (Tue)
by JoeF (guest, #4486)
[Link] (5 responses)
Posted Oct 25, 2016 0:19 UTC (Tue)
by mtaht (subscriber, #11087)
[Link]
Posted Oct 25, 2016 4:03 UTC (Tue)
by josh (subscriber, #17465)
[Link]
Posted Oct 26, 2016 1:00 UTC (Wed)
by voltagex (guest, #86296)
[Link] (2 responses)
Posted Oct 26, 2016 1:41 UTC (Wed)
by Cyberax (✭ supporter ✭, #52523)
[Link]
Also, these days I'm keeping my keys on a hardware key device.
Posted Oct 26, 2016 8:00 UTC (Wed)
by itvirta (guest, #49997)
[Link]
Posted Oct 25, 2016 1:02 UTC (Tue)
by trentbuck (guest, #66356)
[Link] (3 responses)
OTOH I haven't tried it seriously since about 2011,
1. OpenSSH client sets DSCP by default (see IPQoS in ssh_config(5));
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.
Posted Oct 25, 2016 7:29 UTC (Tue)
by Cyberax (✭ supporter ✭, #52523)
[Link] (1 responses)
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.
Posted Oct 26, 2016 2:05 UTC (Wed)
by JdGordy (subscriber, #70103)
[Link]
Posted Oct 25, 2016 1:24 UTC (Tue)
by trentbuck (guest, #66356)
[Link] (9 responses)
For users that can't handle a key-based auth (e.g. internet cafe users),
OATH HOTP appears to be roughly the same as OTPW,
Enabling UsePAM in opensshd is an additional security risk.
Posted Oct 25, 2016 9:33 UTC (Tue)
by ms (subscriber, #41272)
[Link] (7 responses)
Posted Oct 26, 2016 17:15 UTC (Wed)
by drag (guest, #31333)
[Link] (6 responses)
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.
Posted Oct 27, 2016 16:51 UTC (Thu)
by mstone_ (subscriber, #66309)
[Link] (5 responses)
In general, you're far better off with an actual two factor authentication scheme than something that depends entirely on user-protected ssh keys.
Posted Oct 27, 2016 17:41 UTC (Thu)
by drag (guest, #31333)
[Link] (4 responses)
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.
Posted Oct 27, 2016 18:07 UTC (Thu)
by mstone_ (subscriber, #66309)
[Link] (3 responses)
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.
Posted Oct 27, 2016 22:13 UTC (Thu)
by nybble41 (subscriber, #55106)
[Link] (2 responses)
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.
Posted Oct 29, 2016 8:01 UTC (Sat)
by madhatter (subscriber, #4665)
[Link] (1 responses)
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.
Posted Nov 5, 2016 17:34 UTC (Sat)
by Wol (subscriber, #4433)
[Link]
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,
Posted Oct 25, 2016 10:48 UTC (Tue)
by nix (subscriber, #2304)
[Link]
# Yubikey users need to authenticate with an OTP on SSH connection.
(The changes to PAM are... less trivial, because of PAM's horrendous excuse for conditionals.)
Posted Oct 25, 2016 2:22 UTC (Tue)
by hisdad (subscriber, #5375)
[Link] (7 responses)
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
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
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
Posted Oct 25, 2016 4:05 UTC (Tue)
by josh (subscriber, #17465)
[Link] (3 responses)
...and you know you have no plans to travel internationally, and you won't forget to change that rule before traveling...
Posted Oct 25, 2016 4:24 UTC (Tue)
by pabs (subscriber, #43278)
[Link] (2 responses)
Posted Oct 26, 2016 23:20 UTC (Wed)
by misc (subscriber, #73730)
[Link] (1 responses)
Posted Oct 27, 2016 22:36 UTC (Thu)
by bronson (subscriber, #4806)
[Link]
Posted Oct 25, 2016 7:23 UTC (Tue)
by jackb (guest, #41909)
[Link] (2 responses)
KexAlgorithms curve25519-sha256@libssh.org
Posted Oct 25, 2016 17:27 UTC (Tue)
by flussence (guest, #85566)
[Link]
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. :-)
Posted Oct 26, 2016 8:11 UTC (Wed)
by Seegras (guest, #20463)
[Link]
Posted Oct 25, 2016 3:27 UTC (Tue)
by rsidd (subscriber, #2582)
[Link] (8 responses)
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.
Posted Oct 25, 2016 7:12 UTC (Tue)
by niner (subscriber, #26151)
[Link] (5 responses)
Of course that means management has to really support this security thing.
Posted Oct 25, 2016 7:52 UTC (Tue)
by andresfreund (subscriber, #69562)
[Link] (3 responses)
Posted Oct 25, 2016 7:57 UTC (Tue)
by niner (subscriber, #26151)
[Link] (2 responses)
Posted Oct 25, 2016 15:00 UTC (Tue)
by bvanheu (guest, #88814)
[Link] (1 responses)
Posted Oct 25, 2016 16:11 UTC (Tue)
by niner (subscriber, #26151)
[Link]
Posted Oct 25, 2016 20:28 UTC (Tue)
by dsommers (subscriber, #55274)
[Link]
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.
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.
Posted Oct 25, 2016 16:45 UTC (Tue)
by gerdesj (subscriber, #5446)
[Link]
Thanks for the pointer. It's sponsored by Red Hat and the code is on Github - cool.
Posted Oct 25, 2016 7:25 UTC (Tue)
by marcH (subscriber, #57642)
[Link] (9 responses)
Any idea why sshd doesn't support this on its own and it requires a firewall hack instead?
(Everything should support rate-limiting nowadays)
Posted Oct 25, 2016 8:08 UTC (Tue)
by zev (subscriber, #88455)
[Link] (7 responses)
Posted Oct 25, 2016 14:34 UTC (Tue)
by marcH (subscriber, #57642)
[Link] (5 responses)
> 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.
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.
Back to the main topic: if proven it's sad to see a fundamental security tool not considering rate limiting.
Posted Oct 26, 2016 8:08 UTC (Wed)
by NightMonkey (subscriber, #23051)
[Link] (4 responses)
Posted Oct 26, 2016 10:50 UTC (Wed)
by MarcB (subscriber, #101804)
[Link] (3 responses)
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.
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, ...
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.
Posted Oct 26, 2016 19:49 UTC (Wed)
by marcH (subscriber, #57642)
[Link] (2 responses)
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, ...
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!
Posted Oct 26, 2016 21:59 UTC (Wed)
by chirlu (guest, #89906)
[Link]
Posted Oct 27, 2016 12:57 UTC (Thu)
by philwhineray (subscriber, #6106)
[Link]
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.
Posted Oct 25, 2016 14:41 UTC (Tue)
by droundy (subscriber, #4559)
[Link]
Posted Oct 25, 2016 22:26 UTC (Tue)
by imMute (guest, #96323)
[Link]
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.
Posted Oct 25, 2016 8:48 UTC (Tue)
by bytelicker (guest, #92320)
[Link] (9 responses)
Posted Oct 25, 2016 9:55 UTC (Tue)
by rsidd (subscriber, #2582)
[Link] (2 responses)
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?
Posted Oct 26, 2016 11:11 UTC (Wed)
by bytelicker (guest, #92320)
[Link]
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.
Posted Oct 26, 2016 18:06 UTC (Wed)
by josh (subscriber, #17465)
[Link]
Posted Oct 27, 2016 2:51 UTC (Thu)
by karkhaz (subscriber, #99844)
[Link] (1 responses)
this sounds like good fun, are you hosting the patch anywhere?
Posted Oct 27, 2016 7:21 UTC (Thu)
by Cyberax (✭ supporter ✭, #52523)
[Link]
Posted Nov 6, 2016 0:47 UTC (Sun)
by JanC_ (guest, #34940)
[Link] (3 responses)
Posted Nov 6, 2016 3:35 UTC (Sun)
by raven667 (subscriber, #5198)
[Link] (2 responses)
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.
Posted Nov 7, 2016 20:23 UTC (Mon)
by JanC_ (guest, #34940)
[Link] (1 responses)
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
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.
Posted Nov 8, 2016 17:16 UTC (Tue)
by raven667 (subscriber, #5198)
[Link]
Posted Oct 25, 2016 10:09 UTC (Tue)
by colo (guest, #45564)
[Link]
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.
Posted Oct 25, 2016 10:18 UTC (Tue)
by kooky (subscriber, #92468)
[Link]
In /etc/ssh/sshd_config
PasswordAuthentication no
.....
Match group remotessh
*****
So people in the group remotessh can use passwords, nobody else can.
Posted Oct 25, 2016 10:19 UTC (Tue)
by lyda (subscriber, #7429)
[Link]
Posted Oct 25, 2016 11:32 UTC (Tue)
by genaro (subscriber, #82632)
[Link]
You can also rate limit connections with
Posted Oct 25, 2016 12:35 UTC (Tue)
by jrigg (guest, #30848)
[Link] (1 responses)
Posted Oct 25, 2016 12:40 UTC (Tue)
by jrigg (guest, #30848)
[Link]
Posted Oct 25, 2016 15:26 UTC (Tue)
by wazoox (subscriber, #69624)
[Link] (1 responses)
Posted Oct 26, 2016 6:01 UTC (Wed)
by voltagex (guest, #86296)
[Link]
Posted Oct 25, 2016 15:39 UTC (Tue)
by lkraav (subscriber, #76113)
[Link] (1 responses)
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...
Posted Oct 26, 2016 0:55 UTC (Wed)
by speedster1 (guest, #8143)
[Link]
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.
Posted Oct 26, 2016 15:33 UTC (Wed)
by storner (subscriber, #119)
[Link]
Posted Oct 26, 2016 16:40 UTC (Wed)
by pspinler (subscriber, #2922)
[Link]
Posted Oct 28, 2016 0:33 UTC (Fri)
by ykram (guest, #89515)
[Link]
Posted Oct 28, 2016 8:12 UTC (Fri)
by rwm (guest, #104883)
[Link]
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:
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.
Posted Oct 28, 2016 12:36 UTC (Fri)
by jsanders (subscriber, #69784)
[Link]
Posted Oct 29, 2016 22:20 UTC (Sat)
by Jandar (subscriber, #85683)
[Link]
Is is very useful to speed up a sequence of many connections as in
scp file remote:/dest && ssh remote script; scp remote:/result .; ...
Posted Oct 29, 2016 23:06 UTC (Sat)
by karkhaz (subscriber, #99844)
[Link]
Posted Nov 3, 2016 22:25 UTC (Thu)
by dfsmith (guest, #20302)
[Link] (1 responses)
Posted Nov 4, 2016 13:09 UTC (Fri)
by wurtel (guest, #7155)
[Link]
Posted Nov 6, 2016 6:41 UTC (Sun)
by zblaxell (subscriber, #26385)
[Link] (1 responses)
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.
Posted Nov 13, 2016 14:56 UTC (Sun)
by paulj (subscriber, #341)
[Link]
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.
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
(Also, make sure you can use some other system to remove bans made by such draconian filters. :) )
Dealing with automated SSH password-guessing
ISPs routinely QoS 22/tcp to get preferential treatment.
and since then:
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
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
See AuthenticationMethods in sshd_config(5).
I've no experience with it myself.
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.
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?
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
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
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.
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Wol
Dealing with automated SSH password-guessing
Match Group yubissh
AuthenticationMethods publickey,keyboard-interactive
2 other methods
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
and edit your firewall (Shorewall in this case)
2 other methods
2 other methods
2 other methods
2 other methods
2 other methods
Ciphers chacha20-poly1305@openssh.com
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com
2 other methods
disable old and insecure crypto algorithms
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Try abusing some Google or Amazon cloud service just a bit and see what happens.
https://lwn.net/Articles/596156/ is hopefully the most complete example.
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
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.
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 ::.
Dealing with automated SSH password-guessing
> https://developers.soundcloud.com/blog/shoot-yourself-in-...
> 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 ::.
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
* disabling the botnet
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
PasswordAuthentication yes
RSAAuthentication yes
PubkeyAuthentication yes
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
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
http://thiemonagel.de/2006/02/preventing-brute-force-atta...
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Hide it behind a VPN
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing
https://www.cvedetails.com/vulnerability-list/vendor_id-5...
Dealing with automated SSH password-guessing
ssh master mode
Dealing with automated SSH password-guessing
My "2 cents a minute"
My "2 cents a minute"
Dealing with automated SSH password-guessing
Dealing with automated SSH password-guessing