7 ms·
In 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
by tptacek 4y ago
In 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 agoIt seems improbable that the baseline load of a couple concurrent SSH attempts is higher than the load of running an extra Python daemon that's constantly checking your log files.
- loeg 4y agosshguard is C, and the log file for sshd won't have very much output if there are only a couple concurrent SSH attempts. Don't use this, but not because of concerns about performance overhead.
- akerl_ 4y agoFrom the comment I replied to: > Using fail2ban was more of a DDOS prevention than a security thing.
- GekkePrutser 4y agoWhen I still ran my own server it was a pretty heavy load, like 30% or so. Much more than a minor nuisance. But it was a SPARC server with 1 core at a few hundred MHz and no crypto acceleration. As you can tell this is a while ago :) So yeah I guess these days it's much less of an issue. But the number of possible attempts will have increased too of course.
- akerl_ 4y agoI figured I might as well go pull up some numbers from my personal systems. I've got 3 internet-facing VMs that expose SSH to the world. For the past 30 days, I've seen a combined total of 86k SSH attempts. I've not bothered to filter out my own legitimate sessions, given that they're in the ballpark of ~3 connections a day tops. Total load on each of these systems has stayed below 0.5, and that's including the other actual work the servers do. I don't have a great way to pull out sshd specifically, but it's safe to say that these servers haven't had their operations affected at all by the nefarious attempts. For what it's worth, the one thing I'm doing that could potentially impact the resource consumption is hardcoding cipher/keyexchange/MAC selections. Given that I control 100% of the legitimate clients for these SSH daemons, I've hardcoded the settings as follows: Ciphers chacha20-poly1305@openssh.com KexAlgorithms curve25519-sha256@libssh.org MACs hmac-sha2-512-etm@openssh.com HostKey /etc/ssh/ssh_host_ed25519_key Over 95% of the spam connection attempts get dropped before my server ever does any crypto, because the connecting system doesn't support that KeyExchange choice.
- hsbauauvhabzb 4y agoI’d say that fail2ban is a Band-Aid too, if brute forcing passwords is an issue your problem is that you’re not using key based auth. If someone wants to go to the trouble to break crypto, it would be cheaper to infiltrate the ssh project and implement back doors after a few years of building trust. If that’s your threat model, double wrap your protocols (WireGuard jumphost > ssh type stuff)
- hnarn 4y agoAs you correctly point out, password authentication should not be used for SSH to begin with, but more importantly fail2ban is not a piece of software written to stop brute force password attacks, it’s a very general tool for triggering network blocking actions based on specific patterns found in logs. My only point being that there are some great use cases for fail2ban, and while this isn’t one of them it’s important to remember that this does not make fail2ban a misdirected or useless security initiative by default, in case anyone gets that impression from reading these comments.
- hsbauauvhabzb 4y agoIt doesnt stop determined attackers who have access to a botnet, but it does stop low sophistication attacks. If brute forcing anything is a concern then addressing that concern should come first, focusing effort on fail2ban is a cost that is probably better spent elsewhere.
- vbezhenar 4y agoI agree. I never understood why people use all this stuff. If you use strong enough passwords, it's impossible to be brute-forced, simple as that. If you can't control people on your servers and afraid of weak passwords, just disable password authentication and that's about it. Now the issue of logs is real. I tried to configure debian to remove noise from the logs and I couldn't. May be someone with more knowledge would suggest how to do so. Because I'd like to see successful authentications in the logs and only those. So that could be a valid reason to change port, etc. But that's only because logs are lacking proper configurability.
- mtlmtlmtlmtl 4y agoHave you looked into logrotate?
- n4bz0r 4y ago> I tried to configure debian to remove noise from the logs and I couldn't. Not very elegant (as in, not with built-in tools), but using Logstash would be one way of achieving that. There probably is a better (simpler) way, though. https://www.elastic.co/guide/en/logstash/current/pipeline.html https://www.elastic.co/guide/en/logstash/current/pipeline.ht... Edit: After some research, rsyslog seems like a more appropriate candidate. But the docs don't seem too novice-friendly and the configuration is quite obscure. Tradeoffs. https://en.m.wikipedia.org/wiki/Rsyslog https://en.m.wikipedia.org/wiki/Rsyslog
- deathanatos 4y agoI primarily use it for logs. However, I've worked at a lot of startups, and no matter how much you try to discipline people, someone thinks their circumstance is special (and it somehow requires a password-based login), or someone is just lazy and sets a password for unfathomable reasons. So, for those people, I run fail2ban to allow it to act as a rate-limiter. But tptacek is right, in any sane situation, you don't really need it. But sometimes the situation isn't sane. > just disable password authentication and that's about it. a.) for what ever reason, I've had third-parties insist on passwords. (In healthcare¹, too. Ugh.) b.) For quite a while, Azure's "AADLogin" used keyboard-interactive, which meant that you couldn't disable it. Thankfully, that got fixed in a recent version. ¹In addition to fail2ban, we also did firewalls at the cloud level. The password was a good (secure) one, but I'd sleep easier with a key-based login.
- akulbe 4y agoHi Tom - I don't know if you've already written about this elsewhere, but what would be some sane defaults for SSH? Do you think using key-based auth and disabling password authentication is enough? or are there other things you would recommend? OT - nice Fibonacci in your profile :D
- antihero 4y agoI’ve always used this: https://www.sshaudit.com/hardening_guides.html https://www.sshaudit.com/hardening_guides.html If there’s something better please correct me!
- akulbe 4y agoI wasn't familiar with this. I find it interesting that one of the suggestions is to disable the ECDSA host key. I thought ECDSA was one of the "good" algorithms?
- EnigmaCurry 4y agoIts suspected from the snowden docs that this is one of the ones intentionally weakened by NIST. Here's the long answer: https://blog.cr.yp.to/20140323-ecdsa.html https://blog.cr.yp.to/20140323-ecdsa.html
- tptacek 4y agoNobody serious thinks the P-curves, which is what we're talking about, were weakened by NIST. I don't think anybody at all thinks the DSA algorithm was "intentionally weakened", but lots of people, reasonably, believe it was incompetently designed. Ed2519 has the virtue of both a better curve and a better signing algorithm, which is why it's used in preference to ECDSA. If you're using 25519, don't bother keeping the rest of the algorithms enabled. I think these hardening guides are mostly pretty silly too, for whatever that's worth. The important thing is making sure nobody can log into anything with a password. The rest is just liturgical.
- 4y ago
- Wobble4978 4y agoI have it installed, but I'm not sure I understand why its as you say. Why are you scared of C? Also, should I remove sshguard? I dont want my server going down. Btw, it has been updated after 2010. Are you talking about 2010 release ?
- Jorengarenar 4y ago> But it's even scarier: it's written in C. Why would being written in C make it scarier?
- mattarm 4y agoTwo terms: undefined behavior and memory safety. Try searching the web for those terms.
- Jorengarenar 4y agoThe question wasn't about common mistakes C programmers make
- ergonaught 4y agoI mean, yeah, these things are kind of silly. So is, "But it's even scarier: it's written in C. I guess this is from like 2010? Don't run stuff like this."
- tptacek 4y agoFail2ban is written in Python and managed to have a vulnerability.
- Jorengarenar 4y agoSince when being written in Python automatically makes a program less vulnerability prone than usual?
- tptacek 4y agoIt depends I guess on where you start the count; some people would say Elias' "Smashing The Stack", I'd say Lopatic's HP-UX exploit, some people would go all the way back to RTM's worm.
- _flux 4y agoWell it does make the developer try harder to have a vulnerability. You can't just forget to bound check an array indexing, you need to actually take instructions from the Internet (e.g. eval, import, or exec in case of fail2ban), but of course the way this happens is usually very indirect (e.g. race condition). No programming language can stop a determined developer from creating a vulnerability, but some languages make the task easier than others.
- rurban 4y agoIt's mostly shell scripts, with a few C handlers. Very minimal.
- loeg 4y agoPossibly the best tool in this space is blacklistd / blocklistd, which just exposes some reporting APIs and hooks them directly in sshd, rather than trying to parse failed logins out of logs. That said, meh. https://github.com/zoulasc/blocklist https://github.com/zoulasc/blocklist
- deathanatos 4y agoEdit: Yeah, there's no race condition; the client sends the offending socket to blocklistd over the blocklistd socket. (Originally…) I'm a bit curious; it also seems to imply that it logs the fd number, and then blocklistd queries the kernel to obtain the remote's address. That seems like a race condition: 1. blocklist call is made 2. daemon closes the socket (connection has failed, after all) 3. next client connects 4. lookup is made by blocklistd, and the wrong peer is potentially incriminated (Actually, perhaps it's sending the fd over the socket. I forget you can do that, and the README is hard for me to follow. The "like syslog" also implied that it's logging over syslog to me, but that's not what the code does.)
- cookiengineer 4y agoRemember when fail2ban had an RCE to execute things on a server via root user and it was as simple as parsing an email string because it was executing the mail binary on the other end? [1] That's pretty much the reason why I started to write my own guard tools. I don't need people from China or Russia logging in to my server. I don't understand why tools like this are never built in an ASN aware manner, blocking mechanisms would be so much easier. [1] https://research.securitum.com/fail2ban-remote-code-execution/ https://research.securitum.com/fail2ban-remote-code-executio...
- intelVISA 4y ago> write my own guard tools. if (notMe) panic(); Though I agree, security is a mindset not a tool you can simply download or run.
- UI_at_80x24 4y agoI _WANT_ to harvest IP's of PC's trying to SSH into any of my servers. I want them because then I can block ALL traffic coming from their IP's. At my last gig, I had thousands of domains and hundreds of servers running on every major (and a shitload of minor) service provider. I custom scripted all these servers to compile all the IP's that attempted a connection, send those lists back to HQ, and then distribute back to each node a block-list table that I could dynamically apply to each edge device. One compromised computer even trying to login was completely blocked from 5000+ domains within 15 minutes. I'm not worried about my ssh login being brute-forced, but if your computer is compromised I want nothing to do with you.
- tptacek 4y agoThere is a whole Internet worth of random IPv4 addresses being variously used to variously attack various computers. Your blocklist doesn't even approximate it. What's the point of trying to track and block 0.000000001% of the machines that might be used to attack you?
- 9dev 4y agoWhat’s worse, those IPs are probably (at least in part) dynamic, from VPS servers in data centres, or using residential Proxies or compromised machines behind a NAT. A soon as those addresses change or get assigned another customer, you’re blocking potentially legitimate traffic…
- maltris 4y agoI dont see anything wrong in collecting and blocking them for some time, not infinitely of course. Blocking at the firewall effectively means blocking further communication and requests that cost you bandwidth and computing time. Why not save that for the legitimate visitors?
- swinglock 4y agoBecause you block legitimate visitors. After we ran out of IPv4 space and started to use CGNAT instead of IPv6, the internet has become a bastardized version of itself.
- schipplock 4y agoBut it's even scarier: it's written in C. I don't want to defend this tool, but OpenSSH is written in C as well :).
- 0___0 4y agoTwo Cs don't make it Rust
- jbotz 4y agoOpenSSH doesn't try to parse untrusted text input that can be fairly easily manipulated by an attacker (i.e. in this case the logs). That's something that should be scary in any language, but C is definitely one of the worst choices possible for this particular task.
- nix23 4y ago>These tools are popular, but I think they're kind of silly. Really? And how do you block someone who slowly try's (every 2-4 minutes) to bruteforce your smtp? Yes your openSSH has some slowdown mechanisms builtin, but your Imap-Server? Smtp-Server? Your openTTD-Server? However i think using the logs is the wrong approach hence my use of blacklistd* whenever possible. * https://www.freebsd.org/cgi/man.cgi?query=blacklistd&sektion=8&format=html https://www.freebsd.org/cgi/man.cgi?query=blacklistd&sektion... * https://man.netbsd.org/NetBSD-7.0/blacklistd.8 https://man.netbsd.org/NetBSD-7.0/blacklistd.8
- xwolfi 4y agoDefense in depth, cost little to add one more layer.
- amelius 4y agoSecurity always works in layers, it should never be just one line of defense ... Even obscurity has its place (e.g. using a different SSH port)