Live data from Hacker News

Ask HN: How do you handle server security/intrusion monitoring?

news.ycombinator.com

11–20 of 21 posts

Re: Ask HN: How do you handle server security/intrusion monitoring?

#11
Monitoring intrusion attempts is almost always a waste of time; secure the server instead.

Set up the server in a secure way, with many layers of defense. Any applications that accept data from the internet should be very robust. After that, add mitigating stuff like SQL permissions, a chroot jail for the web server, running as a totally unprivileged user (i.e. not nobody), and so on and so forth. Pick a secure kernel, too, and make sure that your software is compiled with exploit mitigation techniques (e.g. ASLR, W^X). Throw out anything that needs patching more often than once a year (once every ten years is a better goal). Don't pick a weak password and leave SSH password logins enabled.

If you are interested in detecting intrusions, a first layer may be a list of checksums of crucial files. This is built-in to my favourite OS, OpenBSD, but others can use Tripwire, AIDE or any of the other programs. Note that an attacker with root privileges can typically bypass this.

EDIT: Look at mod_security, too, if you use Apache and cannot trust the web developer (which may be you). Just accept that it will, in the end, not save you.

EDIT2: And don't store passwords in plain text. Or MD5.

Re: Ask HN: How do you handle server security/intrusion monitoring?

#12
post #3

A really skilled intruder won't leave any obvious clues behind if he gets in. You are likely to encounter this only if someone is deliberately targeting your server for some reason. That said, most intrusion attempts are unsophisticated, analogous to a person walking around a parking lot trying car doors to see if any are unlocked. Tools I've used (it's been a while so some of these may be dated) include logwatch to…

Tripwire is useful for post-facto detection - at least as long as the attacker doesn't get root - but logwatch defaults to letting stuff through, which means that any change in log formatting by any program means that your "security" suddenly fails.

Re: Ask HN: How do you handle server security/intrusion monitoring?

#13
sudo apt-get install rkhunter chkrootkit logcheck monit

rkhunter and chkrootkit will both look for insecure configuration, permissions, and known root kits. rkhunter will also maintain a database of the signatures of your system binaries. I assume there are overlaps between the two. I don't really care, I run both.

logcheck will watch your logs and email you when something shows up in a log that doesn't match a configurable set of regular expressions. When I add a new piece of software to a system, logcheck goes berserk. I go through the emails I receive and add in new regex's to ignore the harmless notifications until they finally taper out and disappear, only leaving me with the true exceptions.

Look over the documentation for all three of these, and make sure that they're actually running. Personally, I don't want an email unless something is wrong. If I get an email every day, I'll start to ignore it. I don't think I'd notice if an email I was ignoring didn't show up, so I optimize for no output unless it's something I should read. I chase down the cause of every exception in my logs. No excuses. If it isn't an exception, I add a regex to logcheck.

I run monit because it is pretty easy to set up, and it sends me an email when a server process gets changed or restarted. It lets me enforce limits on a server process, so I can potentially get warning of an attack as it happening. I suspect monit is nowhere near the most sophisticated tool for this purpose, but it meets my needs very well.

As for other basic security stuff... Don't use port 22 for ssh, use something much higher so that you won't get the continuous pounding on the front door that an ssh server on port 22 receives. Disable root login, as well as password login. Use certificates to log in to your machine. Configure servers to listen to 127.0.0.1 whenever you can. Install a software firewall to only allow access to http and ssh anyway.

Unless you've done something stupid with your web app, you've made it incredibly difficult to impossible for script kiddies. If you piss off an elite black-hat, it's probably safe to assume they can own you, and you likely won't know it. So make good backups, with regular offline backups that can't get destroyed by a hacker with a particularly malicious bent.

Re: Ask HN: How do you handle server security/intrusion monitoring?

#14

Monitoring intrusion attempts is almost always a waste of time; secure the server instead. Set up the server in a secure way, with many layers of defense. Any applications that accept data from the internet should be very robust. After that, add mitigating stuff like SQL permissions, a chroot jail for the web server, running as a totally unprivileged user (i.e. not nobody), and so on and so forth. Pick a secure kerne…

Is per-user salted MD5 not secure? I'm using SHA1 nowadays, but I have an old app using MD5.

Re: Ask HN: How do you handle server security/intrusion monitoring?

#15
post #8

Earlier quoted context omitted.

There isn't one single solution to cover all angles. So yes, logs are useful but won't protect you either. And yes, they could help you to discover intrusion. Regarding authentication, you could use public/private key auth for ssh. This is stronger than passwords. You could also use two factors authentication (look for yubikey for an example) And yes, such a tool exist: for instance tripwire.

Good tip on the pub/priv key auth for ssh. Also on tripwire. Thanks! Custom logs generated by your own app for things like login attempts, etc, are definitely useful for detecting issues. I was referring more to things like apache connection logs, and other logs generated by other programs - I would imagine that there's a huge range of things to look for.

When I say logs, I mean all sort of logs (network, system, app...). So that include auth logs, apache logs and so on.

Re: Ask HN: How do you handle server security/intrusion monitoring?

#16
post #14

Monitoring intrusion attempts is almost always a waste of time; secure the server instead. Set up the server in a secure way, with many layers of defense. Any applications that accept data from the internet should be very robust. After that, add mitigating stuff like SQL permissions, a chroot jail for the web server, running as a totally unprivileged user (i.e. not nobody), and so on and so forth. Pick a secure kerne…

Is per-user salted MD5 not secure? I'm using SHA1 nowadays, but I have an old app using MD5.

There are no currently known cryptographic weaknesses in this application of MD5, and using salts is adequate protection against rainbow tables. But a weakish password can still be guessed far too quickly.

Using a proper key derivation function like OpenBSD's pessimised Blowfish (with a suitable numbers of rounds), John the Ripper tries about 60 passwords per second on my hardware. Against salted MD5, 3000. (Also see PBKDF2, which is also a good solution.)

SHA1 isn't really that much better here, sadly - the problem is not cryptographic weaknesses, it's weak passwords and a function that can be evaluated too quickly.

Re: Ask HN: How do you handle server security/intrusion monitoring?

#17
1 - use a minimal server base install. start with a linux/bsd install that has as little running as possible for your needs. I've found both ubuntu-server and FreeBSD work for me.

2 - Install things that you understand. I don't install large meta-packages. I also install most things from source: nginx, ruby, gems, postgresql. All these things make/install without much effort. When compiling, only include options you need.

3 - Lock down SSH. Login only with SSH keys, protocol 2. Also, change your sshd port to something less likely to be scanned. This way, your SSH log files won't have too much garbage in them and you actually can check them with little effort. You can find lots of tutorials on locking down ssh.

4 - Document _everything_. If all else fails, your docs enable you to recreate your server environment within a few hours.

If you do all this correct, when you upgrade your server, e.g.: apt-get upgrade, you will only be upgrading basic distro stuff, mostly security updates.

oh yeah, _little_things_ like making sure your ruby/blub app processes are connecting to your db with an "app" id instead of an "admin" one is a choice decision ;).

Re: Ask HN: How do you handle server security/intrusion monitoring?

#18
FreeBSD handbook goes over some practices, treat security like layers of an onion peel.

http://www.freebsd.org/doc/en/books/handbook/security-intro....

Some things we found useful

* don't have ssh bind to a public interface on. You need to VPN in first and then ssh to the private IP. we only have 80 and 443 open on public interfaces

* portaudit is awesome. it keeps you up to date if there is an exploit for software that you run, not just "is there an update". portaudit will tell you if there is an unpatched vulnerability out there so you can make a decision on what to do.

* paranoia - don't trust anything. we run WP on a DMZed box that doesn't have access to anything. we mod_proxy all requests to this box from our edge servers. jails are also great for this, give everything the least amount of permissions necessary to run

* monitor your servers, any weird cpu usage or bw. cacti is quite nice

You can also block all outbound traffic on your serves that isn't responding to a requests.

Re: Ask HN: How do you handle server security/intrusion monitoring?

#20
post #19

Using OSSEC (open source). Seriously, it puts rkhunter, logcheck and all these old tools in their toes.. Check http://www.ossec.net It monitors your logs, file changes, etc all by default, simple to install, etc.. I love it.

+1 for OSSEC. It is my preferred one for sure. I use that to monitor my Apache logs, Wordpress, SSH and a few more.
Post reply on HN