Jump to content



Photo

Security for a home server

linux security server

  • Please log in to reply
16 replies to this topic

#1 Gullible Jones

Gullible Jones

    Neowinian

  • Joined: 02-June 11

Posted 25 April 2013 - 13:16

If I were to set up a home web server in my firewall's DMZ, what would be a reasonably secure setup I could use? Specifically if I wanted to set up a web forum?

Distros
Anything mainstream with GPG signed packages should do, I think, as long as I don't install X. Main ones I'm thinking of are

- Slackware: Very easy to set up. Not really secure by default. Comes with a compiler and headers for everything, which in this case is a security risk. No automatic updates.

- Ubuntu LTS: Probably harder setup. Using a custom kernel might be annoying. Much better default security, plus automatic updates and a larger dev team.

Kernels
Custom GrSecurity kernel seems like the way to go. GrSec is very easy to set up (and on a server I can enable mprotect() restriction, woo).

I do wonder about drivers though. Would it make sense to disable drivers that aren't used on a server, e.g. the graphics card and sound drivers? Any code is attack surface, after all...

Software Firewall
It is very easy to write iptables rules, but not so easy to decide what should and should not be logged. What's recommended for a server? I am thinking it would be good to log all connections, both accepted and denied, and label them as clearly as possible. (And put /var/log on a separate partition of course.)

Access Control
At the moment think it would be best to put the web server daemon in a chroot, instead of relying on complicated MAC systems. GrSec does a lot of chroot hardening stuff. I could be convinced otherwise though.

Intrusion Detection
UNIX IDS with an encrypted database? I think Open Source Tripwire should do. Don't want something too confusingly featureful.

Backups
This is where it starts getting beyond my experience level. What's a sane way to do backups of a website? Maybe I could use Git?

Website Security
Because I don't want my website defaced and used to spread malware, which can be done even if the machine isn't rooted... And code injection attacks can't be defeated by GrSec.

I suspect the best way to handle this would be to use a web application framework that is known to be fairly secure. Unfortunately all FOSS forum softwares I know of are based on PHP, which from what I've heard has... problems. So maybe it would make sense to build a forum using a web application framework, like Django or Ruby on Rails? How much time would that take?

What BBS software, web application frameworks, etc. are generally recognized as being fairly secure against code injection attacks?

Hardware Firewall

My current "hardware firewall" is actually an old laptop running IPFire. IPFire has a nice web interface, but I think it may not be up to snuff for this - the kernel is a (minimal) vanilla 3.x one that may be suscpetible to network attacks.

Are there better firewall distros out there? Would it make sense to build my own firewall system, again with a custom GrSec kernel and all?

Attitude
Or, "am I overthinking this?"

On the one hand, Linux on the desktop is mainly secure through lack of widespread use. Linux servers get hacked all the time.

On the other hand, I do have a life, and have stuff to do other than babysitting my own Linux systems. So anything that requires too much time maintaining it is a liability.

What security measures make sense for a home-hosted forum, and won't eat up too much time after it's all set up?

Thanks in advance...


#2 +Mindovermaster

Mindovermaster

    Neowinian Senior

  • Tech Issues Solved: 8
  • Joined: 25-January 07
  • Location: /USA/Wisconsin/
  • OS: #!Crunchbang Debian
  • Phone: HTC ONE V

Posted 25 April 2013 - 14:31

I think CentOS or Arch are better secure than Slackware or Ubuntu.

#3 articuno1au

articuno1au

    Neowinian Senior

  • Tech Issues Solved: 2
  • Joined: 20-March 11
  • Location: Brisbane, Australia

Posted 25 April 2013 - 14:40

I am inclined to say avoid Ubuntu. Debian/Arch/CentOS etc are all good choices. I'm a particular fan of Debian.

Git would be good for distributed backups >.< I run my own SVN server and push all my work onto that.

RSync would be good for rolling backups of your server, but there might be better solutions out there, I'm more of a Windows guy >.<

You are DEFINITELY over thinking this. Following best practices should keep you pretty secure. Beyond that you're entering overkill territory. The hardened kernel can't hurt :)

I don't think there is any inherent downside to using PHP if you do it properly. I'd also be inclined to say your hard firewall should be fine, just reduce the attack surface on your server if you want to be cautious >.<

#4 Brian M.

Brian M.

    Neowinian Senior

  • Tech Issues Solved: 10
  • Joined: 07-January 05
  • Location: London, UK

Posted 25 April 2013 - 14:52

The best distro to use is the one you have the most experience with. Any differences in easiest to install, etc, will be negated when things go wrong - it's easiest to fix things if you know your way around the distro ;).

Personally, all of my servers use Debian.

#5 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 25 April 2013 - 14:54

I think CentOS or Arch are better secure than Slackware or Ubuntu.


Arch and Slackware both seem like insane choices for a server distro. They each have their advantages, but fast rolling releases and extreme source-level customization are not often goals for a server. Servers often aim for security and stability above all else. CentOS is certainly a good candidate considering the excellent enterprise quality packages and security features (particularly SELinux). Ubuntu server (LTS) is also a good choice if you need commercial support, otherwise Debian is probably a better choice for a server because of its larger archive, extreme focus on stability, and faster security updates.

#6 OP Gullible Jones

Gullible Jones

    Neowinian

  • Joined: 02-June 11

Posted 25 April 2013 - 14:58

I think CentOS or Arch are better secure than Slackware or Ubuntu.


CentOS -> probably, it is enterprise stuff. OTOH I can't be bothered to mess with SELinux.

Arch -> no IMO, it's a great OS but it's basically for customized desktops.

Ubuntu, not sure how it compares with Debian; it just happens to have automatic updates, so I figured why not?

Slackware is actually pretty good about userland updates, it's just that they never update the kernel in stable - you're expected to compile your own. Also it doesn't ship with any firewall configured (but that is easy to remedy).

I am inclined to say avoid Ubuntu. Debian/Arch/CentOS etc are all good choices. I'm a particular fan of Debian.


Noted. I'm also a Debian fan, just thought some aspects of Ubuntu might be better automated.

Git would be good for distributed backups >.< I run my own SVN server and push all my work onto that.

RSync would be good for rolling backups of your server, but there might be better solutions out there, I'm more of a Windows guy >.<


Not sure about distributed. My thought was basically to have a cron job that does regular git commits of the website, and then rsyncs the whole git repo to a (relatively) safe directory; from whence I could back it up to external media.

You are DEFINITELY over thinking this. Following best practices should keep you pretty secure. Beyond that you're entering overkill territory. The hardened kernel can't hurt :)


No it can't. :) But part of the issue is that I don't have much sysadmin experience, so I'm not entirely familiar with "best practices."

I don't think there is any inherent downside to using PHP if you do it properly. I'd also be inclined to say your hard firewall should be fine, just reduce the attack surface on your server if you want to be cautious >.<


The problem as I understand it is that
- Using PHP properly is harder than it looks
- A lot of BBS softwares therefore don't use it properly

I certainly hope you're right re the hard firewall.

Edit: I need to stop with the quoting...

@Brian M - Fortunately I'm familiar with all the major distros...

@xorangekiller - Arch would be insane. Slackware, maybe. I think it would mostly depend on the average time between unmitigated vulnerabilities in the GrSecurity kernel, since recompiling the kernel regularly would be a pain.

#7 articuno1au

articuno1au

    Neowinian Senior

  • Tech Issues Solved: 2
  • Joined: 20-March 11
  • Location: Brisbane, Australia

Posted 25 April 2013 - 15:01

I'm a huge fan of Debian for servers.

EDIT::
You can have a cron job on your desktop/laptop that auto syncs Git onto your machine. Thus you have it on Git/Server/Desktop and or Laptop. That's how I ensure the safety of my SVN. I might lose the delta changes if I lose my server and backups, but I'll always have the final files :)

Best practices are pretty much common sense. Don't CHMOD 777 stuff >.>

With regards to PHP, that's a question of the forum I guess. I'm running IPB on my server (as is Neowin) and I've found it quite reliable. Only issue I have with it is the occasional spammer.

I'm also running it in an IIS instance which might make it a little harder to attack O.o

#8 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 25 April 2013 - 15:39

I'm not going to respond to every one of your points, but I have a few thoughts. Most of my experience comes from administering CentOS/RHEL and Debian servers, so I probably have somewhat of a bias in that direction.

Distros
Anything mainstream with GPG signed packages should do, I think, as long as I don't install X. Main ones I'm thinking of are

- Slackware: Very easy to set up. Not really secure by default. Comes with a compiler and headers for everything, which in this case is a security risk. No automatic updates.

- Ubuntu LTS: Probably harder setup. Using a custom kernel might be annoying. Much better default security, plus automatic updates and a larger dev team.


I responded to this point in my last post (where I quoted Mindovermaster). Summary: I would probably choose Debian in your scenario.

Kernels
Custom GrSecurity kernel seems like the way to go. GrSec is very easy to set up (and on a server I can enable mprotect() restriction, woo).

I do wonder about drivers though. Would it make sense to disable drivers that aren't used on a server, e.g. the graphics card and sound drivers? Any code is attack surface, after all...


I know of the GrSecurity kernels, but I have never used them in a production environment. They potentially provide additional security, but it's probably overkill for your simple web server. Vendors like RedHat and Debian generally do an excellent job providing security updates to their stable kernels in a timely manner. If you are actively interested in the security of your server I recommend that you subscribe to your distribution's security mailing list. You can subscribe to either RedHat's Enterprise Watch List or Debian's Security Announcements Mailing List to keep up with the latest security news for your respective distribution.

Software Firewall
It is very easy to write iptables rules, but not so easy to decide what should and should not be logged. What's recommended for a server? I am thinking it would be good to log all connections, both accepted and denied, and label them as clearly as possible. (And put /var/log on a separate partition of course.)


iptables is the standard firewall. Make sure that you set it up to deny all inbound, outbound, and forwarded connections by default (not default in RHEL or Debian) and explicitly allow services and routes if you are really paranoid about security. This will probably do you more good than trying anything with kernel hardening since the system's firewall is your first line of defense when your server is in a DMZ. (If you're running Debian you will also want to install the iptables-persistent package so that your iptables rules are applied automatically on boot. RHEL has this functionality integrated by default.)

Access Control
At the moment think it would be best to put the web server daemon in a chroot, instead of relying on complicated MAC systems. GrSec does a lot of chroot hardening stuff. I could be convinced otherwise though.


I don't think chrooting your web server is really going to help you in any significant capacity. Chroot is not designed to be a security measure! Read this post on the FreeBSD mailing list and this summary of an old kernel mailing list thread for more information on exactly why. Steve Friedl's Best Practices for chroot() Operations is an excellent guide on what to do and what to avoid when using chroots.

My recommendation for locking down your web server is to run the daemon as its own user with extremely limited privileges. If you are careful with the permissions you assign it you can effectively limit the scope of any breach that might occur. The security problems inherent in many web server installations is due to the lax security setup people apply because they want the server to "just work". The fact that you are seriously considering the security implications of running a web server already means you are unlikely to make the same mistake.

Intrusion Detection
UNIX IDS with an encrypted database? I think Open Source Tripwire should do. Don't want something too confusingly featureful.


Tripwire is a little bit of a pain to maintain (since you need to update the database when you make legitimate configuration changes), but it is an indispensable security measure for production systems in my opinion. Although they are not strictly related, I often use it in conjunction with fail2ban, which I also highly recommend.

Backups
This is where it starts getting beyond my experience level. What's a sane way to do backups of a website? Maybe I could use Git?


There are many ways to do backups, but I automated it using rsync and cron. If you ever get more than one server and want to have a single backup location, then you can setup an rsync daemon on one server and have the others backup to that one. Rsync scales very well. Theoretically you can have the same sort of setup with git, but I have never used that as a backup solution before. (It is definitely my favorite source control system though.)

Hardware Firewall

My current "hardware firewall" is actually an old laptop running IPFire. IPFire has a nice web interface, but I think it may not be up to snuff for this - the kernel is a (minimal) vanilla 3.x one that may be suscpetible to network attacks.

Are there better firewall distros out there? Would it make sense to build my own firewall system, again with a custom GrSec kernel and all?


There are a few good open-source firewall distros out there. If you strictly want a Linux based firewall, then Untangle is an excellent choice. If you don't mind a FreeBSD base, then I definitely recommend pfSense, which is currently my favorite. Both have excellent commercial support options available should you ever need it.

Attitude
Or, "am I overthinking this?"

On the one hand, Linux on the desktop is mainly secure through lack of widespread use. Linux servers get hacked all the time.

On the other hand, I do have a life, and have stuff to do other than babysitting my own Linux systems. So anything that requires too much time maintaining it is a liability.

What security measures make sense for a home-hosted forum, and won't eat up too much time after it's all set up?

Thanks in advance...


It is definitely very good that you are trying to think through the security of your web server rather than rushing something sub-par into production without much thought. I commend you for that. You are already starting far ahead of where most people would be. Overall your thoughts on security sound fairly reasonable, but don't stress yourself over trying to implement enterprise-grade security. Implement reasonable security measures - like I suggested above - as you can, and work from there as your website grows.

#9 sean.ferguson

sean.ferguson

    GNU/Linux User

  • Joined: 25-June 05
  • Location: Scotland
  • OS: GNU/Linux

Posted 25 April 2013 - 18:32

I'l just add my $0.02 -

A linux server is only as secure as you make it. My best suggestion would be if you are going to choose linux for your server environment choose Debian (if you want to try out BSD FreeBSD/OpenBSD are best choices). The reason for my choice is simple. I currently run three servers from home all run Debian, I also have a 2u colo server running Debian. In the approx. 4 years I have run these various systems I have had hundreds of thousands of attempts to break in via different methods (check your logs or have them mailed to you periodically to check for malicious activity), all these attempts have been in vain and my setup is a generally default setup with no fancy hacks/code/patches other than the many security improvement measures found all over the internet.

Debian uses tried and tested software rather than bleeding edge which means security flaws are generally patched already and those that the community are aware of are patched as soon as possible. Talking of communities Debian has an astounding community, so any questions about securing Debian in different ways there is always a Debian geek available :)

#10 n_K

n_K

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 19-March 06
  • Location: here.
  • OS: FreeDOS
  • Phone: Nokia 3315

Posted 25 April 2013 - 18:42

All my *nix servers are arch based.
Just because arch is a fast rolling release does not mean you have to update all the packages or use the versions on the web, most server orientated packages are compiled and packaged by me, including the kernel.

#11 +Mindovermaster

Mindovermaster

    Neowinian Senior

  • Tech Issues Solved: 8
  • Joined: 25-January 07
  • Location: /USA/Wisconsin/
  • OS: #!Crunchbang Debian
  • Phone: HTC ONE V

Posted 25 April 2013 - 20:22

There is a BSD version of Debian, too, can't remember link though.

#12 sean.ferguson

sean.ferguson

    GNU/Linux User

  • Joined: 25-June 05
  • Location: Scotland
  • OS: GNU/Linux

Posted 25 April 2013 - 20:25

There is a BSD version of Debian, too, can't remember link though.


I think you are thinking of kFreeBSD :) Never used it so really can't comment.

#13 +Mindovermaster

Mindovermaster

    Neowinian Senior

  • Tech Issues Solved: 8
  • Joined: 25-January 07
  • Location: /USA/Wisconsin/
  • OS: #!Crunchbang Debian
  • Phone: HTC ONE V

Posted 25 April 2013 - 20:29

Yeah, that was it: http://wiki.debian.o...NU/kFreeBSD_why

#14 cybertimber2008

cybertimber2008

    Neowinian Senior

  • Joined: 02-December 08

Posted 25 April 2013 - 22:12

Another good security tool is 'Denyhosts', and automated tool which monitors login attempts among other things and after a number of failed attempts (http, ftp, SSH, etc) it blocks the IP for a number of days. Connect it to the online database submitted by thousands of servers and you're protected from things that haven't targeted you yet.

#15 +fusi0n

fusi0n

    The Crazy One

  • Tech Issues Solved: 1
  • Joined: 08-July 04
  • OS: OSX 10.9
  • Phone: iPhone 5S 64GB

Posted 25 April 2013 - 22:27

This is an interesting thread..



Click here to login or here to register to remove this ad, it's free!