Previous | Next

Objectives| Introduction| Physical Threats| Logical Threats| Passwords| Search Paths| File Permissions| Log Files and User Activity| Network Security| Public Domain Security Tools| Conclusions| Review Questions

Section 14


SECURITY


Objectives


This section aims to introduce you to the basics of security under the UNIX operating system. You will be introduced to

Introduction


A machine running the UNIX operating system can be made into a very secure system if the right amount of effort is expended. However a very secure system is usually too inconvenient for normal users to use. In implementing a security scheme the Systems Administrator must weigh the following costs A system can be made as secure as is necessary but in doing so you might lose all ability to make use of the machine. A machine in a room with no door and no outside connection is very secure, no-one can use it. The Systems Administrator must balance the needs for convenience against the need for security.

To implement security on a system you should first identify the possible threats to the system. There are three major types of threats to a computer system

Having identified the threats to the machine a security plan must be implemented. A security plan should have two components

Physical Threats


Physical threats include Not all attacks on computer systems rely on intimate knowledge of computer hardware and software. The quickest way of denying service is to steal or destroy the physical hardware. Mechanisms should be in place to prevent access to the physical hardware of a system.

One part of modern computer systems that is often overlooked in a security plan is the cabling. The simplest way to bring a site's computer network to the ground is to take a shovel and dig up a few fibre optic cables. This does not always happen on purpose. CQU's network has been taken down a number of times by people (accidentally) digging up fibre.


Acts of Nature


While every effort can be taken to minimise damage from acts of nature there is always the possibility that an event will occur that can destroy a system. This is one possibility that must be served by the site's recovery plan.

The old maxim don't put all your eggs in one basket is very applicable. Copies of backup tapes should be kept at another site. A number of sites in earthquake prone California send copies of backup tapes to other States to make sure that tapes are out of the earthquake zone.


Logical Threats


Logical threats typically take the form of Computer systems today are complex congregations of interacting programs. The complexity of these programs and their interactions means that security holes crop up every now and then. It is these holes that bad guys use to break into systems.

It is important that a Systems Administrator keeps up to date with possible security holes in the systems being managed. Possible source of information about security holes are

	Name		Method

	bacteria	programs that reproduce rapidly and eventually
			  overwhelm the system
	viruses		programs that hide themselves inside other programs
			  and cause bad side-effects when the enclosing
			  program is executed
	worms		programs that use networks to move from system to
			  system perhaps leaving behind viruses and bacteria
	Trojan horses	programs that appear to provide the functionality
			  of another program but really do something else
	back doors	undocumented methods of access within programs

		Table 14.1. Nasty Program Categories.

Computer Emergency Response Teams


The main aims of a Computer Emergency Response Team (CERT) are The first CERT was formed by the Defence Advanced Research Projects Agency (DARPA) in response to the Internet worm incident in late 1988. Some of the services provided by CERT include One of the major services provided by CERT are CERT advisories. A CERT advisory provides information on how to patch a known computer security problem or a warning about ongoing attacks.

Much of the information in this section is taken from the FAQ (frequently asked questions) list available from CERT's anonymous FTP site.

	Information Source		Description

	comp.security.announce		newsgroup to which CERT advisories
					  are posted
	cert.org			anonymous FTP site for CERT
	cert-advisory-request@cert.org	mailing list for CERT advisories
	cert-tools-request@cert.org	mailing list about security tools

		Table 14.2. Various Information sources provided by CERT.

Passwords


Passwords are the first line of defence in the security of a computer system. They are also usually the single biggest security hole. The main reason is that users do dumb things with passwords including These methods are the easiest way of breaking into accounts on most computer sites, especially Universities.

There have been a number of experiments that attempt to discover how many users actually choose dumb passwords. All of these experiments have found an alarmingly high percentage of users choose stupid passwords. One experiment found that approximately 10 to 20% of passwords could be guessed using a password list containing variations on login names, user's first and last names and a list of 1800 common first names

Every year the program Crack (more on this program later in the section) is run using the password file of the machine used by students of the Systems Administration subject offered by Central Queensland University. Every year between 10 to 20% of the passwords are discovered by Crack.

There are a number of schemes a Systems Administrator can use to help make passwords more secure including


Threats to /etc/passwd


The /etc/passwd file is the cornerstone of the password security system. The Systems Administrator should perform a number of checks on the contents of the /etc/passwd file. These checks are performed to make sure someone has not compromised security and left a gaping hole. The checks include looking for Exercise 14-1. Write a shell procedure passwdck that performs all of the checks listed above.

Passwords are only the first line of defence for a system. It must be assumed that someone will be able to break this line of security. The following section examines what steps can be undertaken to improve the internal security of the system.

Search Paths


When you enter a command the shell will search through all the directories listed in the PATH variable for an executable file with a filename that matches the command name. It is almost standard for users to include the current directory (signified by .) in their search path.

If the current directory is included in the search path it should be the last one.

If the current directory is the first directory in the path then whenever the user executes a command the shell will look first in the current directory. This is a security hole. One practice of bad guys is to place programs with names that match standard commands (like passwd and su) everywhere in the directory hierarchy.

They do this to take advantage of situations like the following

The shell will find the passwd program written and placed in the /usr directory by the bad guy. Bingo, the vandal has a password.

The current directory SHOULD NOT be in the search path for the root user.

Some Systems Administrators are so worried about this situation that they will always enter the full path of every command executed as root.

For example:

	Instead of typing
	bash$ su
	They will enter
	bash$ /bin/su

File Permissions


If a bad person has actually managed to crack someone's password and break into their account the next step they will want to take is obtain an account with more access (root if possible). The major hurdle they must overcome is UNIX file permissions.

A system's file permissions should be set up in such a way that will prevent users from accessing areas that they should not. The Systems Administrator is responsible for first setting up the file permissions correctly and then maintaining them.

The issues involved with file permissions include

		#!/bin/sh
		while [ 0 ]
		do
		  mkdir .temp  #start with a dot so it is normally hidden
		  cd .temp
		  cp /bin/* .
  		done
One way to prevent this type of thing from happening is to use disk quotas (see the next Section 15) to limit the amount of disk space any user can use.


Permission Settings


The Systems Administrator must ensure It is important that a system have the correct permission settings on all files especially important system files and the device files. If the system files, such as /etc/passwd, have incorrect permissions bad guys can do a number of nasty things to a system.

The device files are equally important. Having world read and write on device files for disk drives is a security hole. Since the disk can be read from the device file a bad person does not have to go through the file system (the file system enforces the file permissions system). With a little knowledge about the file system structure they can write a program to read (or delete) any file on the disk.

Permission settings are not always set correctly by the manufacturer. One version of a well-known workstation was distributed with sound capabilities, including a microphone. The problem was that the permissions, as set in the factory, for the microphone device file included world read. This meant that if the microphone was turned on anyone on the system could listen to what was being said in the vicinity of the microphone.

Once the permissions are set correctly they must be continually checked to ensure that they are not changed. This can be accomplished by a simple shell script that

A script of this description will report changes in Exercise 14-2. Write a shell script fs_check that performs the roles outlined above.


Setuid Programs and Shell Scripts


Create a text file called i_am.cc that contains the following C program
#include <stdio.h>
#include <unistd.h>

void main()
{
  int real_uid, effective_uid;
  int real_gid, effective_gid;

  real_uid = getuid();
  effective_uid = geteuid();
  real_gid = getgid();
  effective_gid = getegid();

  printf( "The real uid is %d\n", real_uid );
  printf("The effective uid is %d\n", effective_uid );
  printf("The real gid is %d\n", real_gid );
  printf("The effective gid is %d\n", effective_gid );
}
Compile the program by using the following command
	cc i_am.cc -o i_am
This will produce an executable program called i_am. Run the program.

Every time you execute a program the operating system creates a process. Associated with every process is a great deal of information including

The real user and group identifiers are used to store the user and group ids of the user who executed the command. The effective user and group id are used to determine what access the process has, what files and directories it can read, write and delete.

Normally the effective ids will be the same as the real ids. However the set user identifier (set-uid) and the set group identifier permissions (set-gid) can be used to change the effective identifiers.

The process will be executing a program. The code for that program will be contained in a file somewhere. When the set-uid and set-gid bits are set the effective ids are changed to the uid and gid of the file's owners (instead of those of the user running the program).

The passwd command is a prime example of the use of set uid permissions. passwd allows any user to modify either the /etc/passwd file or the shadow password file. How is this possible if only the root user has write permission on these files? passwd is a set-uid program.

Exercise 14.3. Examine the permissions of the passwd program. What is different?

Exercise 14.4. Examine the manual page for chmod to discover how a file is made setuid and setgid.

Exercise 14.5. Change the ownership of the executable file i_am so it is owned by the root user and is setuid root. Run the program and see how this changes the output.

Exercise 14.6. Make the i_am program setgid root.

Never ever write a setuid shell script. In fact, some operating systems will not allow setuid shell scripts. The reason is that there are well-known ways of using setuid shell scripts to obtain extra privileges for nasty purposes.

Once bad people get root access on a machine they want to keep it. One method of doing this is to write a program or script that is setuid root and secret it away in some part of the file system. The next time they login all they have to do is run the program and they have root access again (even if the root password has been changed).

You should check regularly for the addition of any setuid and setgid programs anywhere in the file system.

Exercise 14-7. Incorporate into the script fs_check the ability to keep a track of current setuid and setgid programs.


Log Files and User Activity


Having all the above precautions in place is only the first step in maintaining security. In addition the Systems Administrator should perform regular checks on Just to make certain nothing untoward is going on.


What are the Users up to?


A Systems Administrator should have some idea about what is considered normal behaviour for the system they maintain. A Systems Administrator should know the characteristics of their system including what is the normal load, the normal disk usage, when do certain users normally logon and what the users normally do.

This knowledge can help identify when something unusual is going on. There are a variety of system commands and systems that allow the Systems Administrator to keep an eye on the system. These commands are summarised in Table 14.3.

	Command	Purpose						Availability

	ps	List information about current processes	all systems
	top	Similar to ps but provides additional features	BSD systems
								  plus others
	w and	Display information about what users are	all systems
	 who	  logged on
	whodo	Displays information that combines w and ps	SysV
		  with some extras

		Table 14.3. System Observation Commands.
BSD and SysV each have different options for the ps command. Tables 14.4 and 14.5 list some of the more useful ps options for observing the current state of the system.
	Switch	Purpose

	-a	display processes owned by other users
	-x	include process with no controlling terminal
	-S	display accumulated CPU time for the process
	-g	display all processes
	-c	display the real command name

		Table 14.4. BSD ps Switches.


	Switch	Purpose

	-e	display every process now running
	-f	generate a full listing

		Table 14.5. SysV ps Switches.
For example:
	The whodo command produces output like the following
	bash$ whodo
	Thu Sep 22 10:44:53 1994
	UNIX_System_V

	pts/1		david	 10:41
	   pts/1	     4926	0:00 bash
	   pts/1	     4944 	0:00 elm

	pts/2		phil	9:36
	   pts/2	     4806	0:00 bash
	   pts/2	     4946	0:00 whodo


What have the Users done?


Most UNIX systems have a number of accounting functions (discussed in detail in Section 15) that maintain logs of what has been done to and with the system. The type of information normally kept includes Table 14.6 summarises some of the commands that can be used to view this information.
	Command		Purpose					Availability

	sa	displays, summarises process accounting information	BSD
       lastcomm	displays information about the last commands that have	BSD
		  been executed
	ac	displays information about login, logout		BSD
	last	displays last login times for users			all
	pac	various information about printer use			BSD
	quot	amount of disk space used by individual users		all
	syslog	a logging function that records certain events, errors	BSD, some SysV
		  and warnings
	du	amount of disk space used				all
	df	amount of disk space free				all

		Table 14.6. Commands for examining Accounting Information.
These commands and systems are discussed in more detail in the next section.

Network Security


Connecting a computer to a network is probably the worst thing you can do from a security point of view. Connection to a network adds a new pile of security holes that have to be plugged and adds a whole new population of bad guys who will try to break your system.

The following is a brief introduction to network security. It is a topic too large to cover properly in an introductory Systems Administration course.

In this networking age it will be a rare computer site that is not networked in some way. The following are some of the schemes that are used to make networking more secure

Instead of running the appropriate network daemon inetd will instead run the TCPWrapper daemon. This daemon performs a variety of security checks and some logging functions before running the network daemon that inetd would have run in the original system (Diagram 14.2).

Image

Diagram 14.2. How network daemons are started with TCPWrappers.


Public Domain Security Tools


There are a number of public domain packages that can assist the Systems Administrator in maintaining the security of a machine. Table 14.7 lists some of the more popular, the purpose of the packages and the Internet addresses they can be obtained from.
Name	Purpose				Location

COPS	checks the status of a UNIX	ftp://archie.au/security/cert/cops
	  system, checks permissions,	ftp://cert.sei.cmu.edu/pub/cops
	  for Trojan horses
Kerberos network encryption system	ftp://brolga.cc.uq.oz.au/pub/athena/kerberos
					ftp://aeneas.mit.edu/pub/ATHENA/kerberos
Crack	cracks insecure passwords	ftp://archie.au/security/cert/tools/crack 
					ftp://cert.sei.cmu.edu/pub/tools/crack
Tripwire checks for security of and	ftp://archie.au/security/tools/tripwire
	  changes to the file system	ftp://cert.sei.cmu.edu/pub/tools/tripwire

	Table 14.7. Public Domain Security Packages.

Conclusions


A UNIX machine can be made secure if care and effort is expended. How secure your system is to become must be balanced with other factors including ease of use.

Passwords are the first line of defence and often the weakest. Users must be encouraged to use secure, hard to guess passwords. The internal security supplied by file permissions is the second line of defence. To maintain the security of a machine the Systems Administrator should regularly


Review Questions


14.1. List the issues that are important for system security.

14.2. List ways in which password security can be enhanced.

14.3. List possible problems with the internal security of a system.

14.4. How would you go about breaking into a system?


Previous | Next

David Jones (author)
Chris Hanson (html 10/09/96)