10 ms·
SSHGuard
- thesuperbigfrog 4y agoSimilar tool: fail2ban: https://www.fail2ban.org/wiki/index.php/Main_Page https://www.fail2ban.org/wiki/index.php/Main_Page Tools like these are essential if you have Internet-facing SSH services. If you do not need Internet-facing SSH, do not enable it. It can be an attack vector and there are hundreds of bots that will try to brute-force access within minutes of opening Internet-facing SSH daemon. Best practices for Internet-facing SSH: - run on non-standard port (not port 22) - disable passwords, use SSH passkeys instead: https://www.techrepublic.com/article/how-to-setup-ssh-key-authentication/ https://www.techrepublic.com/article/how-to-setup-ssh-key-au... - disable root SSH login - run fail2ban, sshguard, or similar "block IP addresses for suspicious activity" services - setup port knocking: https://www.tecmint.com/port-knocking-to-secure-ssh/ https://www.tecmint.com/port-knocking-to-secure-ssh/ edit: - run WireGuard VPN (https://en.wikipedia.org/wiki/WireGuard https://en.wikipedia.org/wiki/WireGuard) for defense-in-depth
- deleted 4y ago[deleted]
- deleted 4y ago[deleted]
- jamal-kumar 4y agoThe issue with fail2ban is that it's an extremely heavy python application. It takes up a boatload of resources! SSHGuard however is much lighter and even less to configure manually.
- thesuperbigfrog 4y agoI am not trying to compare fail2ban and SSHGuard. I used fail2ban in the past and it was helpful. If I was currently running an Internet-facing SSH daemon, I would give SSHGuard a try.
- seized 4y agoFrom quickly skimming the docs, Fail2Ban can do a few other things like execute a script for the action. I have it doing an API call to block the offending IP on OPNSense firewall.
- qbasic_forever 4y agoOr just run wireguard and ssh on top of that without all the fussy config and tooling to expose ssh to the internet. You could even live dangerously and just use telnet once you have wireguard going.
- GekkePrutser 4y agoI use ssh as a fallback for when my VPN fails to activate somehow.
- funstuff007 4y agoTrue, true, true. You cannot rely on the VPN always working.
- thesuperbigfrog 4y ago>> Or just run wireguard and ssh on top of that without all the fussy config and tooling to expose ssh to the internet. Nice! Wireguard was not around when I was using Internet-facing SSH in a previous job. Adding it to the recommendations.
- smackeyacky 4y agoTailscale is a good solution. I have no ports open on my internet facing router at all any more. Tailscale has proved to be as reliable as the servers themselves. I like it so much I use it to access my AWS machines as well, by running it as an exit node up there.
- remram 4y agoIs Wireguard more secure than SSH?
- fmajid 4y agoIt's not TCP based so you can't port scan it like SSH, and it will only respond on successful authentication, so a failed attempt is undistinguishable from it not being there. It is also fairly easy to DoS SSH by having too many connections in the authentication state leaving no slots open, which SSHGuard is useful to counter. Apart from that, SSH's intrinsic security is the same, but if you have password authentication enabled, you are only as strong as the weakest password.
- bobleeswagger 4y agoCrowdsec seems to be the modern Fail2Ban replacement, it works quite well and has led to some useful insights.
- justusthane 4y agoThis is advice from the 90s and is mostly security through obscurity, except for the last one. Modern advice: don’t use password auth.
- mekster 4y agoDismissing security through obscurity as pointless is an advice from the 90s. Basically security comes with layers of obscurity. Even key based auth is a random string that no one is meant to guess. If you have more obscurity, the less chance one reaches to the actual attack surface. If an attacker gains a key, without fail2ban etc, he may try bunch of user names against the key file consecutively but if a login attempt is limited to 3 times every 5 minutes, see it's better than nothing.
- tptacek 4y agoIn a sane configuration, the only thing a tool like this should be doing for you is keeping your logs clear. If you're deploying something to mitigate the risk of brute-force attacks on your server, the problem is that it's possible to brute-force your server, not that you don't have an autoblocking system enabled. These tools are popular, but I think they're kind of silly. Later I read some comments below, which compared this to Fail2ban (I had written this tool off as yet another Fail2ban-style script). But it's even scarier: it's written in C. I guess this is from like 2010? Don't run stuff like this.
- michaelmrose 4y agoDoesn't it make sense to do both given that the cost of additional mitigation is trivial?
- GekkePrutser 4y ago> If you're deploying something to mitigate the risk of brute-force attacks on your server, the problem is that it's possible to brute-force your server, not that you don't have an autoblocking system enabled. Well, even when accepting only certificates some brute force bots are dumb enough to keep trying to connect to try passwords, and this can give a lot of unnecessary CPU load due to all the initial connection crypto handshakes. Though I have to say most of the bots these days are smart enough to quit as soon as password auth is turned off. But 10 years ago most were really dumb. Using fail2ban was more of a DDOS prevention than a security thing.
- akerl_ 4y ago
- nullc 4y agoIf you disable password auth completely (you're using key auth... right???) most of the password bruteforcers will just go away.
- silisili 4y agoI just move it off port 22 first. That alone makes it go from hundreds of attempts per day to zero.
- mekster 4y agoI'd expect a (ex?) crypto developer to think security from another perspective, but what if the key is leaked? It's time another prevention system may save your day.
- perlgeek 4y agoIf your private SSH key is leaked, you can expect the attacker to come up in with a single successful login attempt, sshguard, fail2ban etc. won't help. The only help against that scenario is a true multi factor setup, or maybe a hardware-based security token that needs a second factor (fingerprint or PIN) to unlock.
- mekster 4y agoHow's that so? The attacker has no knowledge of the user name of the key, unless that is also leaked, then only white listed IP may help.
- nullc 4y agohope you don't use github (which discloses all users keys, attached to their usernames there), and/or the same username in multiple places. SSH also leaks the keys it'll accept, it doesn't use a zero knowledge proof to first determine if the client and the server have mutually acceptable keys.
- nullc 4y ago
- tyingq 4y agoI would probably use something like pam_tally or pam_shield, since it's taking counts directly from the login flow and not via log files. Mentioned in other comments, protecting from brute force isn't really the big benefit. The benefit is reducing noise in logs so that you can see more serious activity.
- deleted 4y ago[deleted]
- throwaway892238 4y agoOne to two lines of iptables limits connection attempts, making a brute force attack take thousands of years. No logging, no monitoring, no extra software. If you only use SSH keys, no brute force attack will work anyway. https://www.systutorials.com/how-to-use-iptables-to-limit-rates-new-ssh-incoming-connections-from-each-ip-on-linux/ https://www.systutorials.com/how-to-use-iptables-to-limit-ra... https://making.pusher.com/per-ip-rate-limiting-with-iptables/ https://making.pusher.com/per-ip-rate-limiting-with-iptables... https://stackoverflow.com/questions/18616246/iptables-limit-number-of-new-ssh-connections-per-minute https://stackoverflow.com/questions/18616246/iptables-limit-... https://blog.oshim.net/2009/06/iptables-to-rate-limit-incoming/ https://blog.oshim.net/2009/06/iptables-to-rate-limit-incomi... https://stackoverflow.com/questions/47775809/iptables-rate-limiting-connection-request#48194151 https://stackoverflow.com/questions/47775809/iptables-rate-l... http://blog.serverbuddies.com/using-iptables-to-rate-limit-incoming-connections/ http://blog.serverbuddies.com/using-iptables-to-rate-limit-i...
- josephcsible 4y agoThe iptables methods all have the flaw that multiple sequential short-lived successful connections will trigger a ban too. Limiting Internet-facing SSH connections to key-only is definitely a good idea, though.
- cillian64 4y agoI experienced this at a previous company. Yocto/bitbake wanted to do a lot of git clones over SSH very quickly, but a firewall interpreted this as a brute force because it couldn’t tell that each SSH connection was actually successfully authenticating.
- 5e92cb50239222b 4y agoYou can enable SSH connection persistence by adding this to ~/.ssh/config: ServerAliveInterval 60 ControlMaster auto ControlPath ~/.ssh/conn/%r@%h:%p ControlPersist 1h I use it to speed up new SSH connections after the first one is made, but it should also prevent the issue you've described.
- upofadown 4y agoDoesn't Dovecot now have a fairly capable brute force password attack prevention system? Is there any reason that someone would still use something like this anyway? Couldn't find anything about Exim or Postfix integrated brute force prevention on SMTP connections...
- klausagnoletti 4y agohttps://hub.crowdsec.net/author/crowdsecurity/collections/dovecot https://hub.crowdsec.net/author/crowdsecurity/collections/do...
- ptcrash 4y agoIs this a new iteration in fail2ban? I gave it a cursory look and I couldn’t find any new features that make it a better tool than its predecessor
- funstuff007 4y agoI get keys are better than passwords, but how do you enforce key rotation for non-technical users when they can barely manage to changer their passwords? I much prefer 2FA than keys for non-technical users.
- einichi 4y agoFor keys used in authentication, I feel like rotation largely just protects against keys being leaked. If you can enforce keys to exist only on a secure element then to me I feel like rotation is no longer needed in this particular scenario. With the exception of the key strength no longer being enough or something similar. Perhaps I'm overlooking something?
- funstuff007 4y ago> exist only on a secure element Do non-technical users know how to operate a secure element? Is that an encrypted home drive on a laptop protected by a weak password? I appreciate your input, but I still think 2FA is the most secure and usable method for non-technical people. Of course, no SMS (at least outside the US).
- xmodem 4y agoThere are a lot of commercial solutions out there, but for those of us with macs and without control of our org's IT spend, there's Secretive [1], although it lacks a way to prove that a key is hardware backed. https://github.com/maxgoedjen/secretive https://github.com/maxgoedjen/secretive
- rzzzt 4y agoClient certificates can have an expiry date, but it is a bit more fiddly than keys.
- puffoflogic 4y agoWhy do documentation links from sshguard.net redirect to wayback machine versions of sshguard.net? That is sketchy as all heck.
- LanternLight83 4y agoI'm not sure about the actual situation, but I have an option in my cloudflare dashboard to automatically save my site to the way back machine and fall back to that if the origin is ever down, so that's a totally plausible explanation
- sjellis 4y agoPSA: If you are using AWS, you should be using Session Manager for remote access to your EC2 instances if possible - it is free and trivial to enable. Azure offers Azure Bastion, which is exactly what it says. Both of these can keep hostile SSH connections completely away from your servers, and also help to aggregate access logs.
- throwawaaarrgh 4y agoiirc you cannot handle multiple separate user accounts with limited privileges on a server with AWS SSM SM, has that changed?
- unixhero 4y agoIs this better than fail2ban? I use crowdsec also nowadays, but I don't trust it like I trust fail2ban. Due to opaque answers from the engine on how it has protected my hosts. Considering going all the way Back to fail2ban again.
- klausagnoletti 4y agoHey, head of community at CrowdSec here. Could you elaborate on your situation and the 'opaque' replies from the agent you're receiving in a mail to klaus at crowdsec dot net? Very interested in understanding your issues and hopefully help you to build trust :-)
- unixhero 4y agoHi The main issue is that on my hosts where fail2ban are running, I see week on week activity and banned hosts. When I look into cscli decisions or cscli metrics, it gives me the indication that nothing is happening which I don't believe is true. Maybe it is doing the work it promises, but I can't easily see it. This could be a false negative, and that there genuinely is less malicious connection attempts. The busy fail2ban are bastion hosts on AWS, while the others are hosted on DigitalOcean. For me as a user though, I wish there was a way to see historically blocked hosts. The last time I looked half a year ago, this was not available in CrowdSec.
- klausagnoletti 4y agoHey and thanks for your reply. This is done easily in the cscli with the 'decisions' command: https://doc.crowdsec.net/docs/next/cscli/cscli_decisions https://doc.crowdsec.net/docs/next/cscli/cscli_decisions. 'sudo cscli decisions list' lists all local decisions as you request :-). If you want to look into a decision, 'explain' is your friend: https://doc.crowdsec.net/docs/next/cscli/cscli_explain https://doc.crowdsec.net/docs/next/cscli/cscli_explain or simply look in /var/log/crowdsec.log (on Linux). I hope this answers your question. If not, you're welcome to ask again or join our Discord at https://discord.gg/crowdsec https://discord.gg/crowdsec (which is by far the best way to get help fast).
- politelemon 4y agoSeveral of its documentation links are pointing at web.archive.org copies instead of itself. Bit weird. https://www.sshguard.net/docs.html https://www.sshguard.net/docs.html The setting up link points at https://web.archive.org/web/20180901061425/https://www.sshguard.net/docs/setup/ https://web.archive.org/web/20180901061425/https://www.sshgu... and the original is 404: https://www.sshguard.net/docs/setup/ https://www.sshguard.net/docs/setup/
- adv0r 4y agommm I use ubuntu and ufw... so I guess this won't work(?) why not ufw ? Isn't it widely used?
- dddw 4y agoUfw is a wrapper for iptables no?
- sjaak 4y agoCannot recommend running sshd behind spiped (tool authored by cperciva) enough: https://www.daemonology.net/blog/2012-08-30-protecting-sshd-using-spiped.html https://www.daemonology.net/blog/2012-08-30-protecting-sshd-...
- Klasiaster 4y agoWould be nice to have this as eBPF cgroup socket filter, attachable to the systemd service (or OpenSSH could load it itself). Then it's not needed to parse the text logs anymore.
- vinay_ys 4y agoIn 2022, I can't think of good reasons to run a Internet-facing ssh server. Wireguard should be your only Internet facing protocol for any private access. Once you establish a Wireguard tunnel, you can ssh to that machine if you like. And, please don't use passwords, instead use certificates. You can easily have system to create and use a short-term valid login certificates. Also, don't forget to authenticate your hosts to users with host certificates. All of the above is needed even if it is behind wireguard. That's defense in depth. Ensure there is no shared-fate between the two authentication systems. Also, consider multi-factor personal authentication – biometric+external auth (FIDO2 device with fingerprint auth) and device-auth (device-secure-enclave bound certificates) where device is unlocked by a password/pin from your memory. If you do these, you don't need silly hacks like SSHGuard.
- ratorx 4y agoSSH certificates don’t have an equivalent in Wireguard. They are a much more scalable way of provisioning authentication. Defense-in-depth is a good idea, but has its limits. I don’t think there’s too much value to layering SSH over Wireguard. Agreed on SSHGuard type things not being necessary (for authentication protocol). SSH is not special. People can attempt to bruteforce Wireguard too. In fact, the only difference seems to be SSH making the logs (more easily) accessible. The main downside to SSH is that it allows in default configuration to use insecure passwords for authentication (but this can be disabled). Wireguard is strictly better since passwords are never an option. Protocol negotiation is another downside, but I think it’s a smaller one. The SSH devs are fairly good about removing insecure schemes from the defaults.
- hun3 4y ago> I don’t think there’s too much value to layering SSH over Wireguard. Future in-the-wild vulnerabilities in the SSH protocol layer?
- ratorx 4y agoSure, but there might be Wireguard vulnerabilities as well. Why not layer SSH over Wireguard over IPSec over OpenVPN just to be safe? I think that layering may be useful given a certain threat model, but you shouldn’t just layer protocols without actually considering the probability of vulnerability and considering the other tradeoffs you are making. Otherwise the only correct answer would be to layer SSH over every independent VPN protocol. Considering the security track record of SSH, I don’t see the value to layering, when on the other side, you now need to manage multiple keys and an entirely separate protocol that isn’t as ubiquitous (yet). The time spent doing this might be better spent building robust and testable auto-update infrastructure or architecting the applications on the server to reduce the risk of contagion given an RCE vulnerability.
- exabrial 4y agoI fixed ssh knocking with having wireguard VPN in front of all of our servers. We still require authentication and all inbound connections (even from the VPN ) are untrusted. This completely silenced our logs.