43 ms·
The answer isn't quite "don't bother" but it's definitely not "install these tools and get started". Most of the things you can easily set up to watch for secu
by tptacek 9y ago
The answer isn't quite "don't bother" but it's definitely not "install these tools and get started".
Most of the things you can easily set up to watch for security events are looking for problems you simply shouldn't have.
For instance: you can set up fail2ban, sure. But what's it doing for you? If you have password SSH authentication enabled anywhere, you're already playing to lose, and logging and reactive blocking isn't really going to help you. Don't scan your logs for this problem; scan your configurations and make sure the brute-force attack simply can't work.
The same goes for most of the stuff shrink-wrap tools look for in web logs. OSSEC isn't bad, but the things you're going to light up on with OSSEC out of the box all mean something went so wrong that you got owned up.
Same with URL regexes. You can set up log detection for people hitting your admin interfaces. But then you have to ask: why is your admin interface available on routable IPs to begin with?
What you want is an effectively endless sink for developer logs (Splunk is fine but expensive, ELK is fine but complicated to manage), and you want to add structured instrumenting logs to your applications in all the security-sensitive places, like authorization checks (which should rarely fail), and especially a very solid, very long-term audit trail of admin-like actions, so you have some prayer of tracking insider misuse. You could instrument your SQL queries and catch any query failures --- which should also be rare. That kind of stuff. I don't think there's a good shrink-wrap package that does that.
But really: focus on removing attack surface, rather than continuously monitoring it.
- koolba 9y ago> But really: focus on removing attack surface, rather than continuously monitoring it. You buried the lede on this one.
- monkpit 9y agoI think you meant “Splunk” :)
- tptacek 9y agothx
- peterwwillis 9y agoOr, you know, install these tools and get started: Scanners: - Nikto (https://cirt.net/nikto2) - A comparison of tools from 2017 (http://sectoolmarket.com/price-and-feature-comparison-of-web-application-scanners-unified-list.html) Web Application Firewalls: - ModSecurity (https://geekflare.com/install-modsecurity-on-nginx/) - Enable OWASP rules in ModSecurity (https://geekflare.com/modsecurity-owasp-core-rule-set-nginx/) - Vulture (https://www.vultureproject.org/) - Pay $500 to have SpiderLabs configure ModSecurity for you (https://ssl.trustwave.com/web-application-firewall) - Nginx (https://www.nginx.com/products/nginx-waf/) - Azure (https://azure.microsoft.com/en-us/blog/azure-web-application-firewall-waf-generally-available/) - AWS (https://aws.amazon.com/waf/) - Symantec (https://www.symantec.com/products/web-application-firewall-reverse-proxy) - Incapsula (https://www.incapsula.com/website-security/web-application-firewall.html) - Smoothwall (holy cow, they're still around? https://us.smoothwall.com/utm/) - Shadow daemon (probably defunct, https://shadowd.zecure.org/overview/introduction/) - IronBee (same, https://github.com/ironbee/ironbee) Hardening guides: - Apache (https://www.tecmint.com/apache-security-tips/) - Nginx (https://geekflare.com/nginx-webserver-security-hardening-guide/)
- tptacek 9y agoDon't do most of this.
- andyfleming 9y agoCare to elaborate?
- tptacek 9y agoYou almost certainly don't want to set up a WAF. Don't use any of those scanners, all of which look almost exclusively for vulnerabilities you don't have. Do look into getting a Burp license for every developer on your team. By all means, harden Nginx. Don't pay SpiderLabs to do it for you.
- 9y ago
- wongma 9y agoIs there a course (or set of courses), books or other learning material you recommend for web developers to get to a competent level in terms of building, deploying and maintaining secure applications (including infrastructure)? Edit: updated to be more clear
- tachion 9y agoGet more into DevOps/SRE/Ops/SysAdmin/WordOfTheWeek where building secure infrastructure is part of their job. Writing secure applications is one thing, deploying them on secure infrastructure is another.
- wongma 9y agoThanks for the tips! Yeah, I should have been more explicit. When I say build secure applications, I imply the full stack including infrastructure. I updated my comment accordingly.
- thedonkeycometh 9y agoAlways keep up to date with OWASP
- yani 9y agoIt is a good advice but the OP is asking for web log files not ssh and any other logs. You cannot remove the attack surface when the app/service is served via http
- dx034 9y agoIf you use a service such as Cloudflare, you can restrict the ip range, ensuring that all requests go through that service (which probably has more experience with malicious requests than the website owner).
- t3h2mas 9y agoYou cannot remove the attack surface when the app/service is served via http Remove? Probably not. There are many options for minimizing the attack surface with http.
- ivanr 9y agoI came here to add an important detail about WAFs that's missing in this thread. For context, I am the original author of ModSecurity (but haven't worked on it since at least 2009). I wrote ModSecurity for three use cases that still make a lot of sense sense; they are: 1) full HTTP transaction logging (meaning request and response bodies), 2) rule-based analysis of HTTP traffic (largely to trigger logging and otherwise highlight anomalies) and 3) virtual patching. The first two use cases are all about traffic visibility, which has been, and remains a big problem. If we're talking about improving security, the third use case—virtual patching—is the exciting part. The story goes something like this: you discover a vulnerability in your code but you can't fix it immediately, for whatever reason (take your pick). In practice, it may be weeks until the problem is fixed. However, if you have ModSecurity installed, you can write a virtual patch for your problem, often to fix it 100% reliably. However, it's very important to understand that virtual patching doesn't mean just slapping together some rule that appears to be doing the job. Blacklisting doesn't work. To properly virtual-patch, you have to fully understand the vulnerability and the entry point to the application. You have to carefully whitelist all parameters in that particular location. In other words, you have to almost replicate the work that should have been done by the developer. Even in this context, it's not all rosy. Virtual patching requires a great deal of expertise to do properly. It's almost always better to spend your time fixing the actual problem. Sometimes, however, that's not possible to do in a reasonable time frame, and that's when a WAF (according to my definition), can be a life saver.
- tptacek 9y agoThanks for this. I admire ModSecurity! But the subtext of my comment is the needs of typical HN people, most of whom manage applications they wrote, for small companies. Overwhelmingly, those people should spend any time they would spend on things like ModSecurity instead shoring up the security of their code.
- FuckOffNeemo 9y agoTLDR: Ivan, thank you for everything you've provided to the IT community. - - - - There's few people I am more pleased to see commenting here on a topic like Sec more than yourself Ivan, your work's exceptional. And the tools you've provided like Hardenize and SSL Labs have saved me countless hours. Your books have been an immense source of knowledge for me (and I'm relatively a newcomer by my colleagues standards). Really pleased to see you here on HN. Though, I'm not entirely surprised. The best of the best seem to haunt this place.
- Neil44 9y agoI use some custom fail2ban rules on my web servers, for example too many hits on url X in a 10 minute window = firewalled for a day. Helps stop brute forcing on web apps e.g. Wordpress and can cut down massively on the traffic the server is having to deal with. I Also have some mod_rewrite rules in to 403 some URL’s that bots currently hit, mostly because I don’t want to spend 200ms of PHP time for the bot to discover that it’s exploit didn’t work. I accept that when you’re hosting websites for a load of other people you’re gonna need backups too, that’s the bottom line.
- busterarm 9y agoI don't even give them the courtesy of a 403. That's more information than they deserve. HAproxy severely throttles their requests, at no cost to my web servers, and eventually stops responding entirely. Converting our WordPress sites to static sites greatly simplified and improved our infrastructure.
- hueving 9y ago>But then you have to ask: why is your admin interface available on routable IPs to begin with? You have railed against network isolation as defense in other threads. Locally-scoped IPs, VPNs, and ACLs are all about network isolation. Care to shed some light on the inconsistency?
- tptacek 9y agoI did?
- iuguy 9y agoThe parent posted what is pretty much the right answer, but to add: * Your logs should be there to help you find out what happened in the event of a compromise, not to detect it in progress. What OP should be monitoring is the activity that occurs on the system - logins, processes spawned (e.g. php or mysql suddenly spawning shells for no reason), changes to content, resource volume spikes and as the parent said, configuration changes. Much of this can be done with a variety of tools but there isn't really a one-size fits all approach. I'd start with resource spikes as it's easiest and work up to an OSSEC configuration reflecting the actual environment. Also by way of middle ground on the log front, Graylog2 is a happy medium between Splunk and ELK, but it's better to log fewer (but more useful) things than a load of noise.
- viraptor 9y ago> What OP should be monitoring is the activity that occurs on the system - logins, processes spawned (e.g. php or mysql suddenly spawning shells for no reason), In my experience, monitoring this takes about as much effort as adding a new apparmor / selinux / firejail / ... rule which would block it in the first place. I mean, with processes spawned we're almost at auditd level already.
- unethical_ban 9y ago>logs are not there.... to detect an attack in progress I vehemently disagree with this assertion. I also disagree with tptacek's asseration that any admin interface should be inaccessble from the public Internet. That's just not how a lot of small businesses, non-profits, etc. operate. 2FA? Sure. Geo-fencing? Keeps out noise. Basic auth / some front-end to minimize app-specific attack surface? Perhaps. Saying "you shouldn't look at logs to detect anomalous activity before the fact" is awful. So is "If you have and admin availability publicly, you're screwed". My saying is "Security is a spectrum". A bank should not have their firewall admin interface publicly available. A community newsletter blog would probably be alright.
- tptacek 9y agoI don't know what the maturity cutoff you're using here is, but I'll draw my line at "deploying on AWS". If you're on AWS, you have really no business exposing an admin interface on a routable address. Deploy it on an internal address and have admins use a VPN to reach it. There are organizations on AWS that have publicly-routable admin interfaces. They should all be working on plans to migrate away from that, and, in the meantime, they should be extra careful about authentication and monitoring. If you're too small to have a non-routable admin interface, you are definitely too small to pay for security products.
- perlgeek 9y agoThis applies if you are developing your own software. If you do security for an enterprise with dozens or hundreds of apps that you don't develop yourself, you might not have the luxury of only trying to reduce attack surface, or instrumenting 3rd-party supplied code.
- tptacek 9y agoYes, that's true.
- ctack 9y agoThanks for this. Just removed ssh login from a server.
- jalk 9y agoThe suggestion was to only allow logins with ssh keys - not disable ssh logins entirely.
- tptacek 9y agoIn an ideal world, literally no SSH at all. That's doable in container cattle fleet networks. In a realistically achievable world for virtually every startup, no routable SSH. No security rule allows 22/tcp from a routable address into a VPC. You want to SSH into a host, you VPN to your network first. This is how most organizations with security teams set up SSH. If you can't get there, at least get to jump box SSH --- 22/tcp is allowed to exactly one isolated host from the outside world (some people filter source addresses to their jump boxes, I don't bother); to get to real hosts, you bounce through that one. A network where you can randomly connect to the sshd on real servers is one most security professionals will assume isn't being run competently.
- ctack 9y agoJa, should have been more clear. Removed password login while maintaining existing keys.
- dalore 9y agoYeah I find young naive devops people implementing security watching and stuff like fail2ban but in the long run it reduces productivity. Stuff like fail2ban can block legitimate traffic (it blocked me on many occasion trying to work from home). When I was young I too used to try implement detection and banning but realised it's a waste of time. Key only access to ssh and make sure you at least subscribe to security updates for all packages is enough. For our own app we went the ELK route due to the number of log messages coming from our own application. But yes as you said it's a pain to manage. Also creating kibana graphs/views/desktop for each type of log is also painful. A good service I believe would be someone to offer a turnkey/shrink wrapped managed ELK for self hosting. Not only managing the system side of it, but also offering services to help create custom kibana graphs.
- danieltillett 9y agoJust set a short ban time in fail2ban. I have it set to 5 minutes. The aim is just to slow down the kiddies so that my logs don’t fill with a zillion pointless attempts.
- spurgu 9y agoAnd/or just reconnect through another server or VPN.
- danieltillett 9y agoYes, but my aim is more to create a molasses pit to slow down the log fill rate rather than to ban anyone for long. If I manage to lock myself out I just get up and get a drink of water. Using a short ban time keeps the load of running fail2ban to a minimum. I at one point was banning the kiddies/bots for a week and 40% of the server load was chewed up just running fail2ban.
- gog 9y agoFail2ban has issues when you have a lot of IPs blocked in memory. The solution I came up with to this problem is to use a custom ban action that adds an IP to the blocked ipset list with a given TTL, but set fail2ban to think that the IP has to be only banned for 5 seconds or so. The result is that ipset purges the IP from the list after the TTL expires, but fail2bans working set is a 5 second rolling windows of blocked IPs. This works great and it's being used in production for a couple of years.
- danieltillett 9y agoRemoving attack surface make it viable to continuously monitor. I don’t think it is an either/or. Just out of curiosity has anyone with a cryptographically strong ssh password ever been hacked via the password authentication path unless they gave this password to someone else?
- tptacek 9y agoI don't know what "cryptographically strong" means in the context of a password, but I do know people with strong SSH passwords that got owned up, yes. Don't use "cryptographically strong" passwords with SSH. Use keys, disable passwords.
- danieltillett 9y agoI mean a password with enough entropy that also hasn't been used before and is not shared with anyone. Do you know how they were owned? Is there a write up anywhere as this is a super interesting topic.
- IncRnd 9y agoFor passwords "cryptographically strong" normally means a password with appropriate complexity and sometimes unpredictability requirements, since entropy is almost nonexistent in passwords.
- namibj 9y agoSomething out of pwgen or diceware would do though. If your application has length requirements that preclude the latter, make sure they are liable if you loose something due to preventing you from using a secure password. (No one can remember a short secure Password for more than a small handful of applications.)
- weavie 9y ago> but I do know people with strong SSH passwords that got owned up By having their password brute forced, or some other means?
- mta13 9y agoGood answer, I only came to add that OSQuery should be included in your tool box. Much easier to query for indicators of a problem, especially at scale, than it is to grep through logs and reconstruct an event. This is still a detective tool that would not likely catch an incident in real time, so the preventative measures listed are still best practice, but it should be included as a tool to fall back on.
- eeZah7Ux 9y agoSecurity monitoring is useful and part of a defense-in-depth strategy. So is fail2ban and many other things.
- tptacek 9y ago"Defense in depth" is just a way security product salespeople get customers to buy more stuff. If you remove attack surface altogether, you don't need more depth of defense.
- eeZah7Ux 9y ago> "Defense in depth" is just a way security product salespeople get customers to buy more stuff. "just" that? That's a very bold statement that most of the security community would disagree with. An example: you don't monitor network traffic on the border because you trust your server not to be compromised. Then one gets compromised and the incident goes undetected due to lack of monitoring. > If you remove attack surface altogether That's a big if. Services can have a complex life, with software and configuration changing often. Unless you pull the plug you attack surface is never going to be zero and, on top of that, there so guarantee that it stays small. Hence organizations usually have different people taking care of different layers.
- jimktrains2 9y ago> What you want is an effectively endless sink for developer logs (Splunk is fine but expensive, ELK is fine but complicated to manage I'm pretty happy with sumo. A couple things I wish they'd change, but their core competency is searching logs and metrics and they do that really well. It is paid (there is a free tier but we outgrew it quickly) bit it's well worth it IMHO. > But really: focus on removing attack surface, rather than continuously monitoring it. So much this. Logs are great for telling you something bad has already happened and what that was, both security and faults. Reducing the attack service will get you more mileage from a security pov (again, in my opinion). Logs need to he there and some basic trawling of them is also necessary, but is purely reäctive.
- drbawb 9y ago>focus on removing attack surface, rather than continuously monitoring it. Amen to that. I stopped caring about these sorts of entries in my HTTP logs when I realized these automated attacks target software packages written for language runtimes I don't even have installed. I'm sure not losing any sleep at night that someone is trying to hit phpMyAdmin or wp-admin on my server that doesn't even have a PHP interpreter.
- squarefoot 9y agoA while ago I was looking for a very lightweight system to set up a small CMS with no bells & whistles (Pico, Grav etc), but all of them seem to require PHP. Are there any alternatives around which could also dodge most common attacks by not having installed most common interpreters?
- tracker1 9y agoLook into static site generators... you basically write your site offline, and run a script to deploy it to a static web server (or mostly static). In the end, a web server that doesn't run any code outside delivering content is the most secure web server. It'll be fast, and (usually) near zero attack surface.
- rambossa 9y agothis is essential, love the analogy here: https://youtu.be/NUXpz0Dni50?t=14m13s https://youtu.be/NUXpz0Dni50?t=14m13s