[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ A ] [ B ] [ C ] [ D ] [ E ] [ F ] [ G ] [ H ] [ next ]

Securing Debian Manual
Chapter 4 - After Installation

Once the system is installed you can still do more to secure the system; some of the steps described in this chapter can be taken. Of course this really depends on your setup but for physical access prevention you should read Change the BIOS (again), Section 4.3,Set a LILO or GRUB password, Section 4.4,Remove root prompt on the kernel, Section 4.5, Disallow floppy booting, Section 4.6, Restricting console login access, Section 4.7, and Restricting system reboots through the console, Section 4.8.

Before connecting to any network, especially if it's a public one you should, at the very least, execute a security update (see Execute a security update, Section 4.2). Optionally, you could take a snapshot of your system (see Taking a snapshot of the system, Section 4.18).

4.1 Subscribe to the Debian Security Announce mailing List

In order to receive information on available security updates you should subscribe yourself to the debian-security-announce mailing list in order to receive the Debian Security Advisories (DSAs). See The Debian Security Team, Section 7.1 for more information on how the Debian security team works. For information on how to subscribe to the Debian mailing lists read http://lists.debian.org.

DSAs are signed with the Debian Security Team's signature which can be retrieved from http://security.debian.org.

You should consider, also, subscribing to the debian-security mailing list for general discussion on security issues in the Debian operating system. You will be able to contact other fellow system administrators in the list as well as Debian developers and upstream developers of security tools who can answer your questions and offer advice.

FIXME: add the key here too?

4.2 Execute a security update

As soon as new security bugs are detected in packages, Debian maintainers and upstream authors generally patch them within days or even hours. After the bug is fixed, a new package is provided on http://security.debian.org.

If you are installing a Debian release you must take into account that since the release was made there might have been security updates after it has been determined that a given package is vulnerable. Also, there might have been minor releases (there were seven in Debian 2.2 potato release) which include these package updates.

You need to note down the date the removable media (if you are using it) was made and check the security site in order to see if there are security updates. If there are and you cannot download the packages from the security site on another system (you are not connected to the Internet yet? are you?) before connecting to the network you could consider (if not protected by a firewall for example) adding firewall rules so that your system could only connect to security.debian.org and then run the update. A sample configuration is shown in Security update protected by a firewall, Appendix F.

Note:Since Debian woody 3.0, after installation you are given the opportunity to add security updates to the system. If you say 'yes' to this, the installation system will take the appropiate steps to add the source for security updates to your package sources and your system, if you have an Internet connection, will download and install any security updates that might have been produced after your media was created. If you are upgrading a previous version of Debian, or you asked the installation system not to do this, you should take the steps described here.

To manually update the system, put the following line in your sources.list and you will get security updates automatically, whenever you update your system.

       deb http://security.debian.org/ stable/updates main contrib non-free

Once you've done this you can either use apt or dselect to upgrade:

If you like, you can add the deb-src lines to /etc/apt/sources.list as well. See apt(8) for further details.

Note: You do not need to add the following line:

       deb http://security.debian.org/debian-non-US stable/non-US main contrib non-free

this is because security.debian.org is is hosted in a non-US location and doesn't have a seperate non-US archive.

4.3 Change the BIOS (again)

Remember Choose a BIOS password, Section 3.1? Well, then you should now, once you do not need to boot from removable media, to change the default BIOS setup so that it only boots from the hard drive. Make sure you will not lose the BIOS password, otherwise, in the event of a hard disk failure you will not be able to return to the BIOS and change the setup so you can recover it using, for example, a CD-ROM.

Another less secure but more convenient way is to change the setup to have the system boot up from the hard disk and, if it fails, try removable media. By the way, this is often done because most people don't use the BIOS password that often; it's easily forgotten.

4.4 Set a LILO or GRUB password

Anybody can easily get a root-shell and change your passwords by entering <name-of-your-bootimage> init=/bin/sh at the boot prompt. After changing the passwords and rebooting the system, the person has unlimited root-access and can do anything he/she wants to the system. After this procedure you will not have root access to your system, as you do not know the root password.

To make sure that this cannot happen, you should set a password for the boot loader. You can choose between a global password or a password for a certain image.

For LILO you need to edit the config file /etc/lilo.conf and add a password and restricted line as in the example below.


When done, rerun lilo. Omitting the restricted line causes lilo to always prompt for a password, regardless of whether LILO was passed parameters. The default permissions for /etc/lilo.conf grant read and write permissions to root, and enable read-only access for lilo.conf's group, root.

If you use GRUB instead of LILO, edit /boot/grub/menu.lst and add the following two lines at the top (substituting, of course hackme with the desired password). This prevents users from editing the boot items. timeout 3 specifies a 3 second delay before grub boots the default item.

       timeout 3
       password hackme

To further harden the integrity of the password, you may store the password in an encrypted form. The utility grub-md5-crypt generates a hashed password which is compatible with grub's encrypted password algorithm (md5). To specify in grub that an md5 format password will be used, use the following directive:

       timeout 3
       password --md5 $1$bw0ez$tljnxxKLfMzmnDVaQWgjP0

The --md5 parameter was added to instruct grub to perform the md5 authentication process. The provided password is the md5 encrypted version of hackme. Using the md5 password method is preferable to choosing its cleartext counterpart. More information about grub passwords may be found in the grub-doc package.

4.5 Remove root prompt on the kernel

Linux 2.4 kernels provide a way to access a root shell while booting which will be presented just after loading the cramfs file system. A message will appear to permit the administrator to enter an executable shell with root permissions, this shell can be used to manually load modules when autodetection fails. This behavior is the default for initrd's linuxrc. The following message will appear:

       Press ENTER to obtain a shell (waits 5 seconds)

In order to remove this behavior you need to change /etc/mkinitrd/mkinitrd.conf and set:

       # DELAY  The  number  of seconds the linuxrc script should wait to
       # allow the user to interrupt it before the system is brought up

Then regenerate your ramdisk image. You can do this for example with:

       # cd /boot
       # mkinitrd -o initrd.img-2.4.18-k7 /lib/modules/2.4.18-k7

or (preferred):

       # dpkg-reconfigure -plow kernel-image-2.4.x-yz

Note that Debian 3.0 woody allows users to install 2.4 kernels (selecting flavors), however the default kernel is 2.2 (save for some architectures for which kernel 2.2 was not ported). If you consider this a bug consider Bug 145244 before sending it.

4.6 Disallow floppy booting

The default MBR in Debian before version 2.2 did not act as a usual master boot record and left open a method to easily break into a system:

This behavior can be changed by entering:

       lilo -b /dev/hda

Now LILO is put into the MBR. This can also be achieved by adding boot=/dev/hda to lilo.conf. There is another solution which will disable the MBR prompt completely:

       install-mbr -i n /dev/hda

On the other hand, this "back door", of which many people are just not aware, may save your skin as well if you run into deep trouble with your installation for whatever reasons.

FIXME check whether this really is true as of 2.2 or was it 2.1? INFO: The bootdisks as of Debian 2.2 do NOT install the mbr, but only LILO.

4.7 Restricting console login access

Some security policies might force administrators to log in to the system through the console with their user/password and then become superuser (with su or sudo). This policy is implemented in Debian by editing the /etc/login.defs file or /etc/securetty when using PAM. In:

When using PAM, other changes to the login process, which might include restrictions to users and groups at given times, can be configured in /etc/pam.d/login. An interesting feature that can be disabled is the possibility to login with null (blank) passwords. This feature can be limited by removing nullok from the line:

       auth       required   pam_unix.so nullok

4.8 Restricting system reboots through the console

If your system has a keyboard attached to it anyone (yes anyone) can reboot the system through it without login to the system. This might, or might not, adhere to your security policy. If you want to restrict this, you must check the /etc/inittab so that the line that includes ctrlaltdel calls shutdown with the -a switch (remember to run init q after making any changes to this file). The default in Debian includes this switch:

       ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

Now, in order to allow some users to shutdown the system, as the manpage shutdown(8) describes, you must create the file /etc/shutdown.allow and include there the name of users which can boot the system. When the three finger salute (a.k.a. ctrl+alt+del) is given the program will check if any of the users listed in the file are logged in. If none of them is, shutdown will not reboot the system.

4.9 Mounting partitions the right way

When mounting an ext2 partition, there are several additional options you can apply to the mount call or to /etc/fstab. For instance, this is my fstab entry for the /tmp partition:

       /dev/hda7    /tmp    ext2    defaults,nosuid,noexec,nodev    0    2

You see the difference in the options sections. The option nosuid ignores the setuid and setgid bits completely, while noexec forbids execution of any program on that mount point, and nodev, ignores devices. This sounds great, but it

The noexec option prevents binaries from being executed directly, but is easily circumvented:

       alex@joker:/tmp# mount | grep tmp
       /dev/hda7 on /tmp type ext2 (rw,noexec,nosuid,nodev)
       alex@joker:/tmp# ./date
       bash: ./date: Permission denied
       alex@joker:/tmp# /lib/ld-linux.so.2 ./date
       Sun Dec  3 17:49:23 CET 2000

However, many script kiddies have exploits which try to create and execute files in /tmp. If they do not have a clue, they will fall into this pit. In other words, a user cannot be tricked into executing a trojanized binary in /tmp e.g. when he incidentally adds /tmp into his PATH.

Also be forewarned, some script might depend on /tmp being executable. Most notably, Debconf has (had?) some issues regarding this, for more information see Bug 116448.

The following is a more thorough example. A note, though: /var could be set noexec, but some software [11] keeps its programs under in /var. The same applies to the nosuid option.

     /dev/sda6       /usr            ext2    defaults,ro,nodev       0       2
     /dev/sda12      /usr/share      ext2    defaults,ro,nodev,nosuid        0       2
     /dev/sda7       /var            ext2    defaults,nodev,usrquota,grpquota          0       2
     /dev/sda8       /tmp            ext2    defaults,nodev,nosuid,noexec,usrquota,grpquota    0       2
     /dev/sda9       /var/tmp        ext2    defaults,nodev,nosuid,noexec,usrquota,grpquota    0       2
     /dev/sda10      /var/log        ext2    defaults,nodev,nosuid,noexec    0       2
     /dev/sda11      /var/account    ext2    defaults,nodev,nosuid,noexec    0       2
     /dev/sda13      /home           ext2    rw,nosuid,nodev,exec,auto,nouser,async,usrquota,grpquota                0       2
     /dev/fd0        /mnt/fd0        ext2    defaults,users,nodev,nosuid,noexec      0       0
     /dev/fd0        /mnt/floppy     vfat    defaults,users,nodev,nosuid,noexec      0       0
     /dev/hda        /mnt/cdrom      iso9660 ro,users,nodev,nosuid,noexec            0       0

4.9.1 Setting /tmp noexec

Be careful if setting /tmp noexec when you want to install new software, since some programs might use it for installation. Apt is one such program (see http://bugs.debian.org/116448) if not configured properly APT::ExtractTemplates::TempDir (see apt-extracttemplates(1)). You can set this variable in /etc/apt/apt.conf to another directory with exec privileges other than /tmp.

Regarding noexec, please be aware that it might not offer you that much security. Consider this:

       $ cp /bin/date /tmp
       $ /tmp/date
       (does not execute due to noexec)
       $/lib/ld-linux.so.2 /tmp/date
       (works since date is not executed directly)

4.9.2 Setting /usr read-only

If you set /usr read-only you will not be able to install new packages on your Debian GNU/Linux system. You will have to first remount it read-write, install the packages and then remount it read-only. The latest apt version (in Debian 3.0 'woody') can be configured to run commands before and after installing packages, so you might want to configure it properly.

To do this modify /etc/apt/apt.conf and add:

           Pre-Invoke  { "mount /usr -o remount,rw" };
           Post-Invoke { "mount /usr -o remount,ro" };

Note that the Post-Invoke may fail with a "/usr busy" error message. This happens mainly when you are using files during the update that got updated. Annoying but not really a big deal. Just make sure these are no longer used and run the Post-Invoke manually.

4.10 Providing secure user access

4.10.1 User authentication: PAM

PAM (Pluggable Authentication Modules) allows system administrators to choose how applications authenticate users. Note that PAM can do nothing unless an application is compiled with support for PAM. Most of the applications that are shipped with Debian 2.2 have this support built in. Furthermore, Debian did not have PAM support before 2.2. The current default configuration for any PAM-enabled service is to emulate UNIX authentication (read /usr/share/doc/libpam0g/Debian-PAM-MiniPolicy.gz for more information on how PAM services should work in Debian).

Each application with PAM support provides a configuration file in /etc/pam.d/ which can be used to modify its behavior:

The following description is far from complete, for more information you might want to read the The Linux-PAM System Administrator's Guide (at the primary PAM distribution site), this document is also provided in the libpam-doc.

PAM offers you the possibility to go through several authentication steps at once, without the user's knowledge. You could authenticate against a Berkeley database and against the normal passwd file, and the user only logs in if he authenticates correct in both. You can restrict a lot with PAM, just as you can open your system doors very wide. So be careful. A typical configuration line has a control field as its second element. Generally it should be set to requisite, which returns a login failure if one module fails.

The first thing I like to do, is to add MD5 support to PAM applications, since this helps protect against dictionary cracks (passwords can be longer if using MD5). The following two lines should be added to all files in /etc/pam.d/ that grant access to the machine, like login and ssh.

       # Be sure to install libpam-cracklib first or you will not be able to log in
       password   required     pam_cracklib.so retry=3 minlen=12 difok=3
       password   required     pam_unix.so use_authtok nullok md5

So, what does this incantation do? The first line loads the cracklib PAM module, which provides password strength-checking, prompts for a new password with a minimum length of 12 characters, a difference of at least 3 characters from the old password, and allows 3 retries. The second line introduces the standard authentication module with MD5 passwords and allows a zero length password. The use_authtok directive is necessary to hand over the password from the previous module. The package depends in a wordlist (such as wenglish, wspanish, wbritish...), make sure that you install the one appropiate to your language (otherwise it might not be useful at all). [12]

To make sure that the user root can only log into the system from local terminals, the following line should be enabled in /etc/pam.d/login:

       auth     requisite  pam_securetty.so

Then you should add the terminals from which the user root can log into the system, in /etc/security/access.conf. Last but not least the following line should be enabled if you want to set up user limits.

       session  required   pam_limits.so

This restricts the system resources that users are allowed (see below in Limiting resource usage: the limits.conf file, Section 4.10.2 ). For example, you could restrict the number of concurrent logins (of a given group of users, or system-wide) you may have, the number of processes, the memory size...

Now edit /etc/pam.d/passwd and change the first line. You should add the option "md5" to use MD5 passwords, change the minimum length of password from 4 to 6 (or more) and set a maximum length, if you desire. The resulting line will look something like:

       password   required   pam_unix.so nullok obscure min=6 max=11 md5

If you want to protect su, so that only some people can use it to become root on your system, you need to add a new group "wheel" to your system (that is the cleanest way, since no file has such a group permission yet). Add root and the other users that should be able to su to the root user to this group. Then add the following line to /etc/pam.d/su:

       auth        requisite   pam_wheel.so group=wheel debug

This makes sure that only people from the group "wheel" can use su to become root. Other users will not be able to become root. In fact they will get a denied message if they try to become root.

If you want only certain users to authenticate at a PAM service, this is quite easy to achieve by using files where the users who are allowed to login (or not) are stored. Imagine you only want to allow user 'ref' to log in via ssh. So you put him into /etc/sshusers-allowed and write the following into /etc/pam.d/ssh:

       auth        required    pam_listfile.so item=user sense=allow file=/etc/sshusers-allowed onerr=fail

Last, but not least, create /etc/pam.d/other and enter the following lines:

       auth     required       pam_securetty.so
       auth     required       pam_unix_auth.so
       auth     required       pam_warn.so
       auth     required       pam_deny.so
       account  required       pam_unix_acct.so
       account  required       pam_warn.so
       account  required       pam_deny.so
       password required       pam_unix_passwd.so
       password required       pam_warn.so
       password required       pam_deny.so
       session  required       pam_unix_session.so
       session  required       pam_warn.so
       session  required       pam_deny.so

These lines will provide a good default configuration for all applications that support PAM (access is denied by default).

4.10.2 Limiting resource usage: the limits.conf file

You should really take a serious look into this file. Here you can define user resource limits. If you use PAM, the file /etc/limits.conf is ignored and you should use /etc/security/limits.conf instead.

If you do not restrict resource usage, any user with a valid shell in your system (or even an intruder who compromised the system through a service) can use up as much CPU, memory, stack, etc. as the system can provide. This resource exhaustion problem can only be fixed by the use of PAM. Note that there is a way to add resource limits to some shells (for example, bash has ulimit, see bash(1)), but since not all of them provide the same limits and since the user can change shells (see chsh(1)) it is better to place the limits on the PAM modules.

For more information read:

FIXME: Get a good limits.conf up here

4.10.3 User Login actions: edit /etc/login.defs

The next step is to edit the basic configuration and action upon user login.

       FAIL_DELAY          10

This variable should be set to a higher value to make it harder to use the terminal to log in using brute force. If a wrong password is typed in, the possible attacker (or normal user!) has to wait for 10 seconds to get a new login prompt, which is quite time consuming when you test passwords (manually). Pay attention to the fact that this setting is useless if using a program other than getty, such as mingetty for example.

       FAILLOG_ENAB        yes

If you enable this variable, failed logins will be logged. It is important to keep track of them to catch someone who tries a brute force attack.

       LOG_UNKFAIL_ENAB    yes

If you set the variable FAILLOG_ENAB to yes, then you should also set this variable to yes. This will record unknown usernames if the login failed. If you do this, make sure the logs have the proper permissions (640 for example, with an appropriate group setting such as adm), because users often accidentally enter their password as the username and you do not want others to see it.

       SYSLOG_SU_ENAB      yes

This one enables logging of su attempts to syslog. Quite important on serious machines but note that this can create privacy issues as well.

       SYSLOG_SG_ENAB      yes

The same as SYSLOG_SU_ENAB but applies to the sg program.

       MD5_CRYPT_ENAB      yes

As stated above, MD5 sum passwords greatly reduce the problem of dictionary attacks, since you can use longer passwords. If you are using slink, read the docs about MD5 before enabling this option. Otherwise this is set in PAM.

       PASS_MAX_LEN        50

If MD5 passwords are activated in your PAM configuration, then this variable should be set to the same value as used there.

4.10.4 Restricting ftp: editing /etc/ftpusers

The /etc/ftpusers file contains a list of users who are not allowed to log into the host using ftp. Only use this file if you really want to allow ftp (which is not recommended in general, because it uses cleartext passwords). If your daemon supports PAM, you can also use that to allow and deny users for certain services.

FIXME (BUG): Is it a bug that the default ftpusers in Debian does not include all the administrative users (in base-passwd).

4.10.5 Using su

If you really need users to become the super user on your system, e.g. for installing packages or adding users, you can use the command su to change your identity. You should try to avoid any login as user root and instead use su. Actually, the best solution is to remove su and switch to sudo, as it has more features than su. However, su is more common as it is used on many other Unices.

4.10.6 Using sudo

sudo allows the user to execute defined commands under another user's identity, even as root. If the user is added to /etc/sudoers and authenticates himself correctly, he is able to run commands which have been defined in /etc/sudoers. Violations, such as incorrect passwords or trying to run a program you don't have permission for, are logged and mailed to root.

4.10.7 Disallow remote adminitrative access

You should modify /etc/security/access.conf also so that remote administrative login is disallowed. This way the users need to use su (or sudo) so that there is always an audit trace whenever a local user wants to use administrative powers.

You need to add the following line to /etc/security/access.conf, the default Debian configuration file has a sample line commented out:

        -:wheel:ALL EXCEPT LOCAL

4.10.8 Restricting users's access

Sometimes you might think you need to have users created in your local system in order to provide a given service (pop3 mail service or ftp). Before doing so, first remember that the PAM implementation in Debian GNU/Linux allows you to validate users with a wide variety of external directory services (radius, ldap, etc.) provided by the libpam packages.

If users need to be created and the system can be accessed remotely take into account that users will be able to log in to the system. You can fix this by giving users a null (/dev/null) shell (it would need to be listed in /etc/shells). If you want to allow users to access the system but limit their movements, you can use the /bin/rbash, equivalent to adding the -r option in bash (RESTRICTED SHELL see bash(1)). Please note that even with restricted shell, a user that access an interactive program (that might allow execution of a subshell) could be able to bypass the limits of the shell.

Debian currently provides in the unstable release (and might be included in the next stable releases) the pam_chroot module (in the libpam-chroot). An alternative to it is to chroot the service that provides remote logging (ssh, telnet). [13]

If you wish to restrict when users can access the system you will have to customize /etc/security/access.conf for your needs.

Information on how to chroot users accessing the system through the ssh service is described in Chroot environment for SSH, Appendix G.

4.10.9 Hand-made user auditing

If you are paranoid you might want to add a system-wide /etc/profile that sets the environment in a way such that they cannot remove audit capabilities from the shell (commands are dumped to $HISTFILE. The /etc/profile could be set as follows:

       readonly HISTFILE
       readonly HISTSIZE
       readonly HISTFILESIZE

For this to work the user can only append information to .bash_history. You need also to set the append-only option using chattr program for .bash_history for all users. [14].

Note that you could do that per user's .profile. But then you would need to setup permissions properly: having the user's home directories not belong to the users but enable them to read the configuration .profile and write on the .bash_history. It would be good to set the inmutable flag (also using chattr) for .profile too if you do it this way.

If you are completely paranoid and want to audit every user's command, you could take bash source code, edit it and have it send all that the user typed into another file. Or have ttysnoop constantly monitor any new ttys [15] and dump the output into a file. Other useful program is snoopy (see also the project page) which is a user-transparent program that hooks in as a library providing a wrapper around execve() calls, any command executed is logged to syslogd using the authpriv facility (usually stored at /var/log/auth.log).

Note that you cannot use the script command for this since it will not work as a shell (even if you add it to /etc/shells).

4.10.10 Complete user audit

The previous example is a simple way to configure user auditing which might be not useful for complex systems. If this is your case, you need to look at acct, the accounting utilities. These will log all the commands run by users or processes in the system, at the expense of disk space.

When activating accounting, all the information on processes and users is kept under /var/account/, more specifically in the pacct. The accounting package includes some tools (sa and ac) to analyse this data.

4.10.11 Reviewing user profiles

If you want to see what users are usually doing, when they are connecting you can use the wtmp database that includes all login information. This file can be processed with several utilities, amongst them sac which can output a profile on each user showing in which timeframe they usually log on to the system.

In case you have accounting activated, you can also use the tools provided by it in order to determine when the users access the system and what they execute.

4.10.12 Setting users umasks

Depending on your user policy you might want to change how information is shared between users, that is, what the default permissions of new files created by users are. This change is set by defining a proper umask setting for all users. You can change the UMASK setting in /etc/limits.conf, /etc/profile, /etc/csh.cshrc, /etc/csh.login, /etc/zshrc and probably some others (depending on the shells you have installed on your system). Of all of these the last one that gets loaded takes precedence. The order is: PAM's limits.conf, the default system configuration for the user's shell, the user's shell (his ~/.profile, ~/.bash_profile...)

Debian's default umask setting is 022 this means that files (and directories) can be read and accessed by the user's group and by any other users in the system. If this is too permissive for your system you will have to change the umask setting for all the shells (and for PAM). Don't forget to modify the files under /etc/skel/ since these will be new user's defaults when created with the adduser command.

Note, however that users can modify their own umask setting if they want too, making it more permissive or more restricted.

4.10.13 Limiting what users can see/access

FIXME: Content needed. Tell of consequences of changing packages permissions when upgrading (and admin this paranoid should chroot his users BTW).

If you need to grant users access to the system with a shell think about it very carefully. A user can, by default unless in a severely restricted environment (like a chroot jail), retrieve quite a lot of information from your system including:

What can a user see in your system? Probably quite a lot of things, try this (take a deep breath):

       find / -type f -a -perm +006 2>/dev/null  
       find / -type d -a -perm +007 2>/dev/null

The output is the list of files that a user can see and the directories to which he has access. Limiting access to other user's information

If you still grant shell access to users you might want to limit what information they can view from other users. Users with shell access have a tendency to create quite a number of files under their $HOMEs: mailboxes, personal documents, configuration of X/GNOME/KDE applications...

In Debian each user is created with one associated group, and no two users belong to the same group. This is the default behavior: when the userX is created a group with name userX is created and the user is assigned to it. This avoids the concept of a users group which might make it more difficult for users to hide information from other users.

However, users' $HOME directories are created with 0755 permissions (group-readable and world-readable). The group permissions is not an issue since only the user belongs to the group, however the world permissions might (or might not) be an issue depending on your local policy.

You can change this behaviour so that user creation provides different $HOME permissions. To change the behaviour for new users when they get created, change DIR_MODE in the configuration file /etc/adduser.conf to 0750 (no world-readable access).

Users can still share information, but not directly in their $HOME directories unless they change its permissions.

Note that this will prevent users from being able to set up personal pages (~userX) if a web server is present, since the web server will not be able to read the $HOME directory and thus, the public_html directory under it. If you want to permit users to publish HTML pages in their ~userX/public_html then change DIR_MODE to 0751. This will allow the webserver to access that directory (which should be mode 0755) and provide the content published by users.

4.10.14 Generating user passwords

There are many cases when an administrator needs to create many user accounts and provide passwords for all of them. Of course, the administrator could easily just set the password to be the same as the user's account name, but that would not be very sensitive security-wise. A better approach is to use a password generating program. Debian provides makepasswd, apg and pwgen packages which provide programs (the name is the same as the package) that can be used for this purpose. Makepasswd will generate true random passwords with an emphasis on security over pronounceability while pwgen will try to make meaningless but pronounceable passwords (of course this might depend on your mother language). Apg has algorithms to provide for both (there is a client/server version for this program but it is not included in the Debian package).

Passwd does not allow non-interactive assignation of passwords (since it uses direct tty access). If you want to change passwords when creating a large number of users you can create them using adduser with the --disabled-login option and then use chpasswd [16] (in the passwd package so you already have it installed). If you want to use a file with all the information to make users as a batch process you might be better off using newusers.

4.10.15 Checking user passwords

User passwords can sometimes become the weakest link in the security of a given system. This is due to some users choosing weak passwords for their accounts (and the more of them that have access to it the greater the chances of this happening). Even if you established checks with the cracklib PAM module and password limits as described in User authentication: PAM, Section 4.10.1 users will still be able to use weak passwords. Since user access might include remote shell access (over ssh, hopefully) it's important that a remote attacker is not able to guess user passwords (after he has been able to do user enumeration by other means).

A system administrator must, given a big number of users, check if the passwords they have are consistent with the local security policy. How to check? Try to crack them as an attacker would if he had access to the hashed passwords (the /etc/shadow file).

An administrator can use john or crack (both are brute force password crackers) together with an appropriate wordlist [17] to check users' passwords and take appropriate action when a weak password is detected.

4.10.16 Logging off idle users

Idle users are usually a security problem, a user might be idle maybe because he's out to lunch or because a remote connection was broken and not re-established. For whatever the reason, idle users might lead to a compromise:

Some remote systems have even been compromised through an idle (detached) screen.

Automatic disconnection of idle users is usually a part of the local security policy that must be enforced. There are several ways to do this:

The timeoutd or autolog daemons are the preferred method since, after all, users can change their default shell or can, after running their default shell, switch to another (uncontrolled) shell.

4.11 Using tcpwrappers

TCP wrappers were developed when there were no real packet filters available and access control was needed. The TCP wrappers allow you to allow or deny a service for a host or a domain and define a default allow or deny rule. If you want more information take a look at hosts_access(5).

Many services installed in Debian are either:

On the one hand, for services configured in /etc/inetd.conf (this includes telnet, ftp, netbios, swat and finger) you will see that the configuration file executes /usr/sbin/tcpd first. On the other hand, even if a service is not launched by the inetd superdaemon, support for the tcp wrappers rules can be compiled into it. Services compiled with tcp wrappers in Debian include ssh, portmap, in.talk, rpc.statd, rpc.mountd, gdm, oaf (the GNOME activator daemon), nessus and many others.

To see which packages use tcpwrappers try:

       $ apt-cache showpkg libwrap0 | egrep '^[[:space:]]' | sort -u | \
             sed 's/,libwrap0$//;s/^[[:space:]]\+//'

Take this into account when running tcpchk. You can add services that are linked to the wrapper library into the hosts.deny and hosts.allow files but tcpchk will warn that it is not able to find those services since it looks for them in /etc/inetd.conf (the manpage is not totally accurate here).

Now, here comes a small trick, and probably the smallest intrusion detection system available. In general, you should have a decent firewall policy as a first line, and tcp wrappers as the second line of defense. One little trick is to set up a SPAWN [18] command in /etc/hosts.deny that sends mail to root whenever a denied service triggers wrappers:

       ALL: ALL: SPAWN ( \
         echo -e "\n\
         TCP Wrappers\: Connection refused\n\
         By\: $(uname -n)\n\
         Process\: %d (pid %p)\n\
         User\: %u\n\
         Host\: %c\n\
         Date\: $(date)\n\
       " | /usr/bin/mail -s "Connection to %d blocked" root) &

Beware: The above printed example is open to a DoS attack by making many connections in a short period of time. Many emails mean a lot of file I/O by sending only a few packets.

4.12 The importance of logs and alerts

It is easy to see that the treatment of logs and alerts is an important issue in a secure system. Suppose a system is perfectly configured and 99% secure. If the 1% attack occurs, and there are no security measures in place to, first, detect this and, second, raise alarms, the system is not secure at all.

Debian GNU/Linux provides some tools to perform log analysis, most notably swatch, [19] logcheck or log-analysis (all will need some customisation to remove unnecessary things from the report). It might also be useful, if the system is nearby, to have the system logs printed on a virtual console. This is useful since you can (from a distance) see if the system is behaving properly. Debian's /etc/syslog.conf comes with a commented default configuration; to enable it uncomment the lines and restart syslogd ( /etc/init.d/syslogd restart):

             *.=notice;*.=warn       /dev/tty8

There is a lot regarding log analysis that cannot be fully covered here, a good resource for information is Counterpane's Log Analysis Resources. In any case, even automated tools are no match for the best analysis tool: your brain.

4.12.1 Using and customising logcheck

The logcheck package in Debian is divided into two packages logcheck (the main program) and logcheck-database (a database of regular expressions for the program). The Debian default (in /etc/cron.d/logcheck) is that logcheck is run daily at 2 AM and once after each reboot.

This tool can be quite useful if properly customised to alert the administrator to unusual events in the system. Logcheck can be fully customised so that it can send mails from events recovered from the logs that are worthy of attention. The default installation includes profiles for ignored events and policy violations for three different setups (workstation, server and paranoid). The Debian package includes a configuration file /etc/logcheck/logcheck.conf, sourced by the program, that defines which user the checks are sent to. It also provides a way for packages that provide services to implement new policies in the directories: /etc/logcheck/hacking.d/_packagename_, /etc/logcheck/violations.d/_packagename_, /etc/logcheck/violations.ignore.d/_packagename_, /etc/logcheck/ignore.d.paranoid/_packagename_, /etc/logcheck/ignore.d.server/_packagename_, and /etc/logcheck/ignore.d.workstation/_packagename_. However, not many packages currently do so. If you have a policy that can be useful for other users, please send it as a bug report for the appropriate package (as a wishlist bug). For more information read /usr/share/doc/logcheck/README.Debian

The best way to configure logcheck is to install it (it will ask for the user to which reports should be mailed and generate /etc/logcheck/logcheck.logfiles from syslog entries). If you wish to add new log files just add them to /etc/logcheck/logcheck.logfiles. The package dependency will also force the installation of logcheck-database; during installation it will ask which security level is desired: workstation, server or paranoid. This will make /etc/logcheck/ignore.d point to the appropriate directories (through symbolic links). To change this run dpkg-reconfigure -plow logcheck-database. Then create the /etc/ignore.d/local, this file will hold all the rules to exclude messages that should not be reported. Leave it empty for the moment (a simple cp /dev/null /etc/ignore.d/local will work).

Once this is done you might want to check the mails that are sent, for the first few days/weeks/months. If you find you are sent messages you do not wish to receive, just add the regular expressions (see regex(7)) that correspond to these messages to the /etc/ignore.d/local. It's an ongoing tuning process; once the messages that are sent are always relevant you can consider the tuning finished. Note that if logcheck does not find anything relevant in your system it will not mail you even if it does run (so you might get a mail only once a week, if you are lucky).

4.12.2 Configuring where alerts are sent

Debian comes with a standard syslog configuration (in /etc/syslog.conf) that logs messages to the appropriate files depending on the system facility. You should be familiar with this; have a look at the syslog.conf file and the documentation if not. If you intend to maintain a secure system you should be aware of where log messages are sent so they do not go unnoticed.

For example, sending messages to the console also is an interesting setup useful for many production-level systems. But for many such systems it is also important to add a new machine that will serve as loghost (i.e. it receives logs from all other systems).

Root's mail should be considered also, many security controls (like snort) send alerts to root's mailbox. This mailbox usually points to the first user created in the system (check /etc/aliases). Take care to send root's mail to some place where it will be read (either locally or remotely).

There are other role accounts and aliases on your system. On a small system, it's probably simplest to make sure that all such aliases point to the root account, and that mail to root is forwarded to the system administrator's personal mailbox.

FIXME: it would be interesting to tell how a Debian system can send/receive SNMP traps related to security problems (jfs). Check: snmptraglogd, snmp and snmpd.

4.12.3 Using a loghost

A loghost is a host which collects syslog data remotely over the network. If one of your machines is cracked, the intruder is not able to cover his tracks, unless he hacks the loghost as well. So, the loghost should be especially secure. Making a machine a loghost is simple. Just start the syslogd with syslogd -r and a new loghost is born. In order to do this permanently in Debian, edit /etc/init.d/sysklogd and change the line




Next, configure the other machines to send data to the loghost. Add an entry like the following to /etc/syslog.conf:

       facility.level            @your_loghost

See the documentation for what to use in place of facility and level (they should not be entered verbatim like this). If you want to log everything remotely, just write:

       *.*                       @your_loghost

into your syslog.conf. Logging remotely as well as locally is the best solution (the attacker might presume to have covered his tracks after deleting the local log files). See the syslog(3), syslogd(8) and syslog.conf(5) manpages for additional information.

4.12.4 Log file permissions

It is not only important to decide how alerts are used, but also who has read/modify access to the log files (if not using a remote loghost). Security alerts which the attacker can change or disable are not worth much in the event of an intrusion. Also, you have to take into account that log files might reveal quite a lot of information about your system to an intruder if he has access to them.

Some log file permissions are not perfect after the installation (but of course this really depends on your local security policy). First /var/log/lastlog and /var/log/faillog do not need to be readable by normal users. In the lastlog file you can see who logged in recently, and in the faillog you see a summary of failed logins. The author recommends chmod 660 for both. Take a brief look at your log files and decide very carefully which log files to make readable/writeable for a user with a UID other than 0 and a group other than 'adm' or 'root'. You can easily check this in your system with:

       #  find /var/log -type f -exec ls -l {} \; | cut -c 17-35 |sort -u
       (see to what users do files in /var/log belong)
       #  find /var/log -type f -exec ls -l {} \; | cut -c 26-34 |sort -u
       (see to what groups do files in /var/log belong)
       # find /var/log -perm +004
       (files which are readable by any user)
       #  find /var/log \! -group root \! -group adm -exec ls -ld {} \;
       (files which belong to groups not root or adm)

To customize how log files are created you will probably have to customize the program that generates them. If the log file gets rotated, however, you can customize the behavior of creation and rotation.

4.13 Adding kernel patches

Debian GNU/Linux provides some of the patches for the Linux kernel that enhance its security. These include:

FIXME: add more content, explain how these specific patches can be installed in Debian using the kernel-2.x.x-patch-XXX packages.

FIXME: Divide patches that apply only to 2.2 kernels, patches that apply to 2.4 kernels and those that work with both.

However, some patches have not been provided in Debian yet. If you feel that some of these should be included please ask for it at the Work Needing and Prospective Packages. Some of these are:

4.14 Protecting against buffer overflows

Buffer overflow is the name of a common attack to software [21] which makes use of insufficient boundary checking (a programming error) in order to execute machine code through a program's inputs. These attacks, against server software which listen to connections remotely and against local software which grant higher privileges to users (setuid or setgid) can result in the compromise of any given system.

There are mainly four methods to protect against buffer overflows:

Debian GNU/Linux, as of the 3.0 release, provides software to introduce all of these methods expect for the protection on source code compilation (but this has been requested in Bug #213994)

Notice that even if Debian provided a compiler which featured stack/buffer overflow protection all packages would need to be recompiled in order to introduce this feature. This is, in fact, what Adamantix does (among other features). The effect of this new feature on the stability of software is yet to be determined (some programs or some processor architecures might break due to it).

In any case, be aware, that even these workarounds might not prevent buffer overflows since there are ways to circumvent these, as described in phrack's magazine issue 58 or in CORE's Advisory Multiple vulnerabilities in stack smashing protection technologies.

4.14.1 Kernel patch protection for buffer overflows

Kernel patches related to buffer overflows include the Openwall patch provides protection against buffer overflows in 2.2 linux kernels. For 2.4 kernels, you need to use the Grsecurity patch (in the kernel-patch-2.4-grsecurity) which includes the Openwall patch and many more features (including ACLs and network randomness to make it more difficult to remote OS fingerprinting), or the Linux Security Modules (in the kernel-patch-2.4-lsm and kernel-patch-2.5-lsm packages). For more information on using these patches read the the section Adding kernel patches, Section 4.13.

4.14.2 Libsafe protection

Protecting a Debian GNU/Linux system with libsafe is rather easy. Just install the package and say Yes to have the library preloaded globally. Be careful, however, since this might break software (notably, programs linked with the old libc5, so make sure to read the reported bug reports first and test the most critical programs in your system first with the libsafe wrapper program.

Important Note: Libsafe protection might not be effective currently as describe in 173227. Consider testing it thoroughly before using it in a production environment and don't depend exclusively on it to protect your system.

4.14.3 Testing programs for overflows

The use of tools to detect buffer overflows requires, in any case, of programming experience in order to fix (and recompile) the code. Debian provides, for example: bfbtester (a buffer overflow tester that brute-forces binaries through command line and environment overflows) and njamd.

4.15 Secure file transfers

During normal system administration one usually needs to transfer files in and out from the installed system. Copying files in a secure manner from a host to another can be achieved by using the sshd server package. Another possibility is the use of ftpd-ssl, a ftp server which uses the Secure Socket Layer to encrypt the transmissions.

Any of these methods needs, of course, special clients. Debian provides clients, for example the ssh provides scp. It works like rcp but is encrypted completely, so the bad guys cannot even find out WHAT you copy. There is also a ftp-ssl client package for the equivalent server. You can find clients for these software even for other operating systems (non-UNIX), putty and winscp provide secure copy implementations for any version of Microsoft's operating system.

Note that using scp provides access to the users to all the file system unless chroot'ed as described in Chrooting ssh, Section 5.1.1. FTP access can be chroot'ed, probably easier depending on you chosen daemon, as described in Securing FTP, Section 5.3. If you are worried about users browsing your local files and want to have encrypted communication you can either use an ftp daemon with SSL support or combine cleartext ftp and a VPN setup (see Virtual Private Networks, Section 8.5).

4.16 File System limits and control

4.16.1 Using quotas

Having a good quota policy is important, as it keeps users from filling up the hard disk(s).

You can use two different quota systems: user quota and group quota. As you probably figured out, user quota limits the amount of space a user can take up, group quota does the equivalent for groups. Keep this in mind when you're working out quota sizes.

There are a few important points to think about in setting up a quota system:

Every partition or directory which users have full write access should be quota enabled. Calculate and assign a workable quota size for those partitions and directories which combines usability and security.

So, now you want to use quotas. First of all you need to check whether you enabled quota support in your kernel. If not, you will need to recompile it. After this, control whether the package quota is installed. If not you will need this one as well.

Enabling quota for the respective file systems is as easy as modifying the defaults setting to defaults,usrquota in your /etc/fstab file. If you need group quota, substitute usrquota to grpquota. You can also use them both. Then create empty quota.user and quota.group files in the roots of the file systems you want to use quotas on (e.g. touch /home/quota.user /home/quota.group for a /home file system).

Restart quota by doing /etc/init.d/quota stop;/etc/init.d/quota start. Now quota should be running, and quota sizes can be set.

Editing quotas for a specific user (say 'ref') can be done by edquota -u ref. Group quotas can be modified with edquota -g <group>. Then set the soft and hard quota and/or inode quotas as needed.

For more information about quotas, read the quota man page, and the quota mini-howto(/usr/share/doc/HOWTO/en-html/mini/Quota.html).

You might or might not like lshell, since it violates the FHS. Also take into account that pam_limits.so might provide the same functionality and lshell is currently orphaned

4.16.2 The ext2 filesystem specific attributes (chattr/lsattr)

In addition to the usual Unix permissions, the ext2 and ext3 filesystems offer a set of specific attributes that give you more control over the files on your system. Unlike the basic permissions, these attributes are not displayed by the usual ls -l command or changed using chmod, and you need two other utilities, lsattr and chattr (in package e2fsprogs) to manage them. Note that this means that these attributes will usually not be saved when you backup your system, so if you change any of them, it may be worth saving the successive chattr commands in a script so that you can set them again later if you have to restore a backup.

Among all available attributes, the two that are most important for increasing security are referenced by the letters 'i' and 'a', and they can only be set (or removed) by the superuser:

These attributes can also be set for directories, in which case everyone is denied the right to modify the contents of a directory list (eg. rename or remove a file, ...). When applied to a directory, the append attribute only allows file creation.

It is easy to see how the 'a' attribute improves security, by giving to programs that are not running as the superuser the ability to add data to a file without modifying its previous content. On the other hand, the 'i' attribute seems less interesting: after all, the superuser can already use the basic Unix permissions to restrict access to a file, and an intruder that would get access to the superuser account could always use the chattr program to remove the attribute. Such an intruder may first be confused when he sees that he is not able to remove a file, but you should not assume that he is blind - after all, he got into your system ! Some manuals (including a previous version of this document) suggest to simply remove the chattr and lsattr programs from the system to increase security, but this kind of strategy, also known as "security by obscurity", is to be absolutely avoided, since it provides a false sense of security.

A secure way to solve this problem is to use the capabilities of the Linux kernel, as described in Proactive defense, Section The capability of interest here is called CAP_LINUX_IMMUTABLE: if you remove it from the capabilities bounding set (using for example the command lcap CAP_LINUX_IMMUTABLE) it won't be possible to change any 'a' or 'i' attribute on your system anymore, even by the superuser ! A complete strategy could be as follows:

  1. Set the attributes 'a' and 'i' on any file you want;
  1. Add the command lcap CAP_LINUX_IMMUTABLE (as well as lcap CAP_SYS_MODULE, as suggested in Proactive defense, Section to one of the startup scripts;
  1. Set the 'i' attribute on this script and other startup files, as well as on the lcap binary itself;
  1. Execute the above command manually (or reboot your system to make sure everything works as planned).

Now that the capability has been removed from the system, an intruder can not change any attribute on the protected files, and thus can not change or remove the files. If he forces the machine to reboot (which is the only way to restore the capabilities bounding set), it will easily be detected, and the capability will be removed again as soon as the system restarts anyway. The only way to change a protected file would be to boot the system in single-user mode or using another bootdisk, two operations that require physical access to the machine !

4.16.3 Checking file system integrity

Are you sure /bin/login on your hard drive is still the binary you installed there some months ago? What if it is a hacked version, which stores the entered password in a hidden file or mails it in cleartext version all over the Internet?

The only method to have some kind of protection is to check your files every hour/day/month (I prefer daily) by comparing the actual and the old md5sum of this file. Two files cannot have the same md5sum (the MD5 digest is 128 bits, so the chance that two different files will have the same md5sum is roughly one in 3.4e3803), so you're on the safe site here, unless someone has also hacked the algorithm that creates md5sums on that machine. This is, well, extremely difficult and very unlikely. You really should consider this auditing of your binaries as very important, since it is an easy way to recognize changes at your binaries. Common tools used for this are sXid, AIDE (Advanced Intrusion Detection Environment), TripWire (non-free; the new version will be GPL), integrit and samhain.

Installing debsums will help to check the file system integrity, by comparing the md5sums of every file against the md5sums used in the Debian package archive. But beware, those files can easily be changed.

Furthermore you can replace locate with slocate. slocate is a security enhanced version of GNU locate. When using slocate, the user only sees the files he really has access to and you can exclude any files or directories on the system.

FIXME: put references to the snapshot taken after installation.

FIXME: Add a note regarding packages not providing debsums for all apps installed (not mandatory).

4.16.4 Setting up setuid check

Debian provides a cron job that runs daily in /etc/cron.daily/standard. This cron job will run the /usr/sbin/checksecurity script that will store information of this changes.

In order for this check to be made you must set CHECKSECURITY_DISABLE="FALSE" in /etc/checksecurity.conf. Note, this is the default, so unless you have changed something, this option will already be set to "FALSE".

The default behavior does not send this information to the superuser but, instead keeps daily copies of the changes in /var/log/setuid.changes. You should set the CHECKSECURITY_EMAIL (in /etc/checksecurity.conf) to 'root' to have this information mailed to him. . See checksecurity(8) for more configuration info.

4.17 Securing network access

FIXME. More (Debian-specific) content needed

4.17.1 Configuring kernel network features

FIXME: Content missing

Many features of the kernel can be modified while running by echoing something into the /proc file system or by using sysctl. By entering /sbin/sysctl -A you can see what you can configure and what the options are, and it can be modified running /sbin/sysctl -w variable=value (see sysctl(8)). Only in rare cases do you need to edit something here, but you can increase security that way as well. For example:

     net/ipv4/icmp_echo_ignore_broadcasts = 1

This is a Windows emulator because it acts like Windows on broadcast ping if this option is set to 1. That is, ICMP_ECHO request sent to the broadcast address will be ignored. Otherwise, it does nothing.

If you want to block any ICMP echo requests on your system, enable this configuration option:

     net/ipv4/icmp_echo_ignore_all = 0

To log packets with impossible addresses (due to wrong routes) on your network use:

     /proc/sys/net/ipv4/conf/all/log_martians = 1

For more information on what things can be done with /proc/sys/net/ipv4/* read /usr/src/linux/Documentation/filesystems/proc.txt. All the options are describe thoroughly under /usr/src/linux/Documentation/networking/ip-sysctl.txt [22].

4.17.2 Configuring Syncookies

This option is a double-edged sword. On the one hand it protects your system against syn flooding; on the other hand it violates defined standards (RFCs).

     net/ipv4/tcp_syncookies = 1

If you want to change this option you each time the kernel is working you need to change it in /etc/network/options by setting syncookies=yes. This will take effect whener /etc/init.d/networking is run (which is done at boot time) whileas this will only work with the current running kernel:

     echo 1 > /proc/sys/net/ipv4/tcp_syncookies

This option will only be available if the kernel is compiled with the CONFIG_SYNCOOKIES. All Debian kernels are compiled with this option builtin but you can verify it running:

     $ sysctl -A |grep syncookies
     net/ipv4/tcp_syncookies = 1

For more information on TCP syncookies read http://cr.yp.to/syncookies.html.

4.17.3 Securing the network on boot-time

When setting configuration options for the kernel networking you need configure it so that it's loaded every time the system is restarted. The following example enables many of the previous options as well as other useful options.

FIXME Instead of providing this script provide a sample configuration for sysctl.conf (see: sysctl.conf(5)). Also send this as a wishlist bug to the procps package.

Create the script in /etc/network/interface-secure (the name is given as an example) and call it from /etc/network/interfaces like this:

     auto eth0
     iface eth0 inet static
             address xxx.xxx.xxx.xxx
             netmask 255.255.255.xxx
             broadcast xxx.xxx.xxx.xxx
             gateway xxx.xxx.xxx.xxx
             pre-up /etc/network/interface-secure
     # Script-name: /etc/network/interface-secure
     # Modifies some default behaviour in order to secure against 
     # some TCP/IP spoofing & attacks
     # Contributed by Dariusz Puchalak  
     echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts 
                                                # broadcast echo protection enabled
     echo 0 > /proc/sys/net/ipv4/ip_forward     # ip forwarding disabled
     echo 1 > /proc/sys/net/ipv4/tcp_syncookies # TCP syn cookie protection enabled
     echo 1 >/proc/sys/net/ipv4/conf/all/log_martians # Log strange packets
     # (this includes spoofed Packets, source routed Packets, redirect Packets)
                              # but be careful with this on heavy loaded web servers
     echo 1 > /proc/sys/net/ipv4/ip_always_defrag 
                                                #  defragging protection always enabled
     echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses 
                                                # bad error message protection enabled
     # now ip spoofing protection
     echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
     # and finally some more things:
     # Disable ICMP Redirect Acceptance
     echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
     echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
     # Disable Source Routed Packets
     echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
     echo 1 > /proc/sys/net/ipv4/conf/all/log_martians

You can also create a init.d script and have it run on bootup (using update-rc.d to create the appropriate rc.d links).

4.17.4 Configuring firewall features

In order to have firewall capabilities, either to protect the local system or others behind it, the kernel needs to be compiled with firewall capabilities. The standard Debian 2.2 kernel (also 2.2) provides the packet filter ipchains firewall, Debian 3.0 standard kernel (kernel 2.4) provides the stateful packet filter iptables (netfilter) firewall. Older Debian distributions would need the appropriate kernel patch (Debian 2.1 uses kernel 2.0.34).

In any case, it is pretty easy to use a kernel different from the one provided by Debian. You can find pre-compiled kernels as packages you can easily install in the Debian system. You can also download the kernel sources using the kernel-source-X and build custom kernel packages using make-kpkg.

Setting up firewalls in Debian is discussed more thoroughly in Adding firewall capabilities, Section 5.14.

4.17.5 Disabling weak-end hosts issues

Systems with more than one interface on different networks can have services configured so that they will bind only to a given IP address. This usually prevents services when requested through a given address. However, this does not mean (although it's a common misconception even I had) that the service is bound to a given hardware address (interface card). [23]

This is not an ARP issue and it's not an RFC violation (it's called weak end host in RFC1122, section Remember, IP addresses have nothing to do with physical interfaces.

On 2.2 (and previous) kernels this can be fixed with:

     # echo 1 > /proc/sys/net/ipv4/conf/all/hidden
     # echo 1 > /proc/sys/net/ipv4/conf/eth0/hidden
     # echo 1 > /proc/sys/net/ipv4/conf/eth1/hidden

On later kernels this can be fixed either with:

Along this text there will be many ocasions in which it is shown how to configure some services (sshd server, apache, printer service...) in order to have them listening on any given address, the reader should take into account that, without the fixes given here, the fix would not prevent accesses from within the same (local) network. [26]

FIXME: comments on bugtraq indicate there is a Linux specific method to bind to a given interface.

FIXME: Submit a bug against netbase so that the routing fix is standard behaviour in Debian?

4.17.6 Protecting against ARP attacks

When you don't trust the other boxes on your LAN (which should always be the case, because it's the safest attitude) you should protect yourself from the various existing ARP attacks.

As you know the ARP protocol is used to link IP addresses to MAC addresses. (see RFC826 for all the details). Every time you send a packet to an IP address an arp resolution is done (first by looking into the local ARP cache then if the IP isn't present in the cache by broadcasting an arp query) to find the target's hardware address. All the ARP attacks aim to fool your box into thinking that box B's IP address is associated to the intruder's box's MAC address; Then every packet that you want to send to the IP associated to box B will be send to the intruder's box...

Those Attacks (Cache poisonning, ARP spoofing...) allow the attacker to sniff the traffic even on switched networks, to easily hijack connections, to disconnect any host from the network... Arp attacks are powerful and simple to implement, several tools exists : arpspoof (present in package dsniff), arpmim, arpoison...

However, there is always a solution:

4.18 Taking a snapshot of the system

Before putting the system into production system you culd take a snapshot of the whole system. This snapshot could be used in the event of a compromise (see After the compromise (incident response), Chapter 10). You should remake this upgrade whenever the system is upgraded, specially if you upgrade to a new Debian release.

For this you can use a writable removable-media that can be set up read-only, this could be a floppy disk (read protected after use) or a CD on a CD-ROM unit (you could use a rewriteable CD-ROM so you could even keep backups of md5sums in different dates).

The following script creates such a snapshot:

     /bin/mount /dev/fd0 /mnt/floppy
     /bin/cp /usr/bin/md5sum /mnt/floppy
     echo "Calculating md5 database"
     for dir in /bin/ /sbin/ /usr/bin/ /usr/sbin/ /lib/ /usr/lib/
        find $dir -type f | xargs /usr/bin/md5sum >>/mnt/floppy/md5checksums-lib.txt
     /bin/umount /dev/fd0
     echo "post installation md5 database calculated"

Note that the md5sum binary is placed on the floppy drive so it can be used later on to check the binaries of the system (just in case it gets trojaned).

The snapshot does not include the files under /var/lib/dpkg/info which includes the md5 hashes of installed packages (in files ended with .md5sums). You could copy this information along too, however you should notice:

Once the snapshot is done you should make sure to set the medium read-only. You can then store it for backup or place it in the drive and use it to drive a cron check nightly comparing the original md5sums against those on the snapshot.

4.19 Other recommendations

4.19.1 Do not use software depending on svgalib

SVGAlib is very nice for console lovers like me, but in the past it has been proven several times that it is very insecure. Exploits against zgv were released, and it was simple to become root. Try to prevent using SVGAlib programs wherever possible.

[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ A ] [ B ] [ C ] [ D ] [ E ] [ F ] [ G ] [ H ] [ next ]

Securing Debian Manual

2.99 18 April 2004Wed, 3 Mar 2004 09:18:54 +0100

Javier Fernández-Sanguino Peña jfs@computer.org