![]() |
Now serving 103 guides. |
|
Hardening FreeBSD General Information After a fresh install, it is important to harden the security on a server before it hits your network for use. Not only making configuration changes aid in the security of your box, but there are some practical rules to abide by. These are some hardening tips to make your FreeBSD box more secure and will apply to both the 5.x and 4.x branches, but I will assume you are running 5.x. If a 4.x change is different, I will note it.Note: Please do not apply these changes carelessly on a production server. Make sure you test, test, test on a separate box to note the effects of the changes. Requirements
Hardening Filesystem Structure On a default install, you will find two places for temporary files -- /tmp and /var/tmp. Different packages and daemons use the different directories and there really isn't any need to use two different partitions for temporary files. Here we will replace /var/tmp with a link to /tmp.
Disable Local root Access The first rule to securing your box is to never treat the root account as a regular user. Never conduct mundane business while you are logged in as root. As the superuser, there are no restrictions as to what root can do, so always log in with a normal user and su to root only when needed.With that in mind, it may be tempting to log on locally as root so let's prevent root from directly logging on to your system console. Open /etc/ttys with your editor and change every occurence of "secure" to "insecure" as this will prevent root from logging in locally. *Note: changing the console entry will result in being prompted for the root password when booting into single-user mode; thus, making the recovery of the root password more difficult.
SSH Logins By default, FreeBSD prevents root from logging in via ssh, but it gives anyone else with a valid user account access. If you are not running a shell server, it is a good idea to restrict ssh access to only members of the wheel group -- or you can create a separate group if you want some people to log in but not be able to su to root, say a group named "sshlogins." Let's add the following to the end of the sshd configuration file:
An optional security measure to take is add a banner for users to see before they log on. If you like the idea, follow these steps:
Password Rules By default, FreeBSD uses md5 for password hashing and encryption. It's not bad, but blowfish is much better suited for passwords and we need to update some files to reflect blowfish. *Note: Passwords will not be converted to blowfish until they have been changed.
/etc/login.conf and change the password format in the default class to blf. We should also modify the default password policy to put a minimum password length requirement and mix upper and lower case. Let's also cause passwords to expire after 90 days and to automatically log users out if they are idle for 30 minutes. It's also a good idea to set the default umask to prevent global access. The umask is the inverse to the chmod. So in this case when new files and directories are created, they will get the permissions of 0750.
Restrict User Access Scheduling jobs is a powerful feature in *nix, but at the same time, it can pose a security concern for your system if you allow users to schedule jobs -- especially if they are set up incorrectly. The potential harm could be looping a process endlessly, running malicious code (though this wouldn't pose too big of a problem if it's not run as root), or incorrect schedules. It is recommended to restrict cron and at to only root.
Note: Applying these changes to the log files will also mean logs can no longer be rotated.
System Configuration for Daemon Startup Now it is time to enable or disable certain services by editing/etc/rc.conf. Here we will disable sendmail as it is an insecure MTA. If you want to run a mail server, I recommend using qmail.
Set Kernel States There are some kernel states we need to change and we'll add them to/etc/sysctl.conf to make them permanent. The first one is to prevent users from seeing information about processes that are being run under another UID.
Note: 4.x users use the following instead:
Note: This setting is only for 5.3 and beyond. If you are running any older version of FreeBSD, you will need to compile your kernel with this option.
Kernel Entries There are a couple of security settings we can fix at the kernel level. One security hole we need to plug is disabling ctrl+alt+del so somebody can't walk up to your box and reboot your server with the three-finger solute. Add the following lines to the options:Note: The RANDOM_IP_ID option is only for versions of FreeBSD that are older than 5.3.
Once you finish customizing your kernel, install it and then reboot. Once it comes back up, log in and update your ports tree so you can upgrade your ports. Optional Settings For a Stealthier System The following options may be used, but are only recommended for system that are gateways, log servers, or dedicated firewalls. You may apply these to normal servers if you would like, but they may decrease performance -- especially on web servers.We can configure FreeBSD to drop SYN/FIN packets:
Author: Jon LaBass Find this guide useful?
Support the author: 10 Comments Posted by infovein420 on August 27, 2005 at 8:40:38 pm EEST
This sshd_config line should have the comma removed. Only a space is required for more than 1 parameter.
AllowGroups wheel, sshlogins to AllowGroups wheel sshlogins Leaving the comma will cause authentication problems for a client. --- Scott Posted by Jon on August 27, 2005 at 8:40:38 pm EEST
Thanks Scott. But, leaving the comma doesn't cause authentication problems as I just tested it on FreeBSD 5.3. However, I read the manpages and it does say to separate using spaces. I've updated the guide to reflect that.
Posted by rickster on August 27, 2005 at 8:40:38 pm EEST
how to undo this change
chmod o= /var/log chflags sappnd /var/log chflags sappnd /var/log/* Posted by Jon on August 27, 2005 at 8:40:38 pm EEST
You can undo the chflags by lowering your kernel securelevel and rebooting.
To do this, first edit /etc/rc.conf and change kern_securelevel equal to -1. Then # reboot # chflags nosappend /var/log # chflags nosappend /var/log/* The default permissions on /var/log is 755 so the following will restore it. # chmod o=rx /var/log Just reboot again after changing the kernel securelevel to whatever you want. Posted by z0rmus on August 27, 2005 at 8:40:38 pm EEST
About the section "Password Rules":
"The minpasswordlen and minpasswordcase facilities for enforcing restrictions on password quality, which used to be supported by login.conf, have been superseded by the pam_passwdqc(8) PAM module." "PAM configuration for the 'passwd' service passwd(1) does not use the auth, account or session services." So you must to change in /etc/pam.d/passwd the statement password to: # password password requisite pam_passwdqc.so enforce=users ------------- Sandro Herman Posted by X-Istence on August 27, 2005 at 8:40:38 pm EEST
To do this, first edit /etc/rc.conf and change kern_securelevel equal to -1
That would defeat the purpose of kern_securelevel being set in the first place, as any attacked could remove that, reboot the server, edit the log files, set it again, and reboot again. That is also one of the reasons why if you do set securelevel in either rc.conf or sysctl.conf you also chflags them to not be able to touch them in secure level. Posted by shadowbq on August 10, 2006 at 6:28:39 pm EEST
When running X11, by default it wants to rotates the X11 logs
you have to manually unset the chflags on /var/log/Xorg.0.log /var/log/Xorg.0.log.old If you dont the Xorg/X11 server will not start. Posted by staffan on February 15, 2007 at 4:27:50 pm EET
I have followed the instructions in this guide and now I can't start X11 (startx or GDM gnome). I removed the restrictions on the /var/log, but still no luck...
Does anyone has any tip on how to make it work again? or why it may not work. //Staffan Öhrberg Posted by staffan on February 15, 2007 at 5:24:59 pm EET
I can run X11 when kern_securelevel=-1, but this is not secure, right?
//Staffan Posted by Jon on May 24, 2007 at 8:00:41 pm EEST
Setting the kern_securelevel is really more effective for production servers that are Internet-facing. Therefore, there really isn't a reason to set the securelevel when running X11.
|
Copyright 2003 - 2008 BSD Guides. All rights reserved. |
About | Terms of Use | Privacy | Contact |

