tripwire

rpm packages for tripwire are common, so tripwire is easily installed. Of course, if you want to to this some other way, feel free.

tripwire doesn't try to prevent an intrusion, but it does try to provide information that can be used to detect an intrusion quickly and to restore the system to its pristine state. It does this by comparing system files to a baseline database and report changes, additions or deletions.

When tripwire is installed, you get three executables:

and two files that need to be created.

You also get an excellent set of man pages for documentation, including twintro to get you started and twfiles, twconfig and twpolicy to describe various parts of the system in greater detail.

Tripwire Files

Tripwire operation is controlled by a set of files as described below. If an operation modifies any one of these files, a backup is automatically created with a .bak extension.

Key Files

Key files are used to protect the tripwire files from corruption by an intruder and this is accomplished by using encryption based on two keys; a site key and a local key. The site key is used to protect files that could potentially be used across several systems and therefore must to copied and is subject to more risk. This file is stored in /etc/tripwire/site.key. The local key is used to protect local files and it is stored in /etc/tripwire/$(HOSTNAME)-local.key.

Configuration File

tripwire reads the configuration information in /etc/tripwire/tw.cfg to determine what parts of the file system need to be monitored and what information needs to be collected.

Policy File

tripwire reads the policy information from /etc/tripwire/tw.pol

Database File

The tripwire database files defaults to /var/lib/$(HOSTNAME).twd, but it can be changed in the configuration file. This file contains the baseline information for a system.

Report Files

The reports generated by tripwire are stored in /var/lib/tripewire/report/$(HOSTNAME)-$(DATE).twr by default.

Configuring tripwire

Key Files

The first thing you need to do is create the key files. Typically, you would do this with a series of commands or with a single command containing all the options as shown below. Remember that tripwire typically has several ways of representing each option.

  1. twadmin --generate-keys --local-keyfile /etc/tripwire/$(HOSTNAME)-local.key

  1. twadmin --generate-keys --site-keyfile /etc/tripwire/site.key

  1. twadmin --generate-keys --local-passphrase TheseAreTheTimes

  1. twadmin --generate-keys --site-passphrase ThatTryMensSouls

or with one command and using the shorter option tags:

   twadmin --generate-keys -L /etc/tripwire/$(HOSTNAME)-local.key 
      -S /etc/tripwire/site.key  -P TheseAreTheTimes -Q ThatTryMensSouls
   

With this done, you are ready to perform the other operations that depend on the keys.

One thing worth noting is that tripwire is very consistent in its use of command options. For all commands where appropriate, the following options are valid:

Configuration File

Next you need to create a configuration file. Normally, /etc/tripwire should install a file named twcfg.txt by default. This is a default configuration file in text form that you can use, or modify. The actual configuration file is compressed and possibly encrypted and cannot be edited directly. You should not leave the text version of the configuration file for others to look at. Encrypt the file with crypt or delete it.

Creating /etc/tripwire/tw.cfg is done with twadmin like this:

for a compressed but not signed or encrypted version, or like this:

for an encoded and signed version, which is more secure. If you want to create a different configuration file, use the -c option.

Policy File

The default policy file, tw.pol, is created from twpol.txt without encryption like this:

As before, don't leave the text policy file available for others to see.

To create the file with encryption (recommended), use the following form:

Printing Files

In order to print a configuration file, use the following command:

where filename is the name of the configuration file. To print a policy file,

where polfile is the policy file, cfgfile is the configuration file and site-key-file is the file name for the site key file.

Manipulating Files

If you need to determine the encryption status of a file, you can use the following command:

If you need to encrypt or unencrypt a file, use the appropriate commands:

Configuration

A tripwire configuration file might look like this:

This is not an exhaustive list, but indicates the type of information that you might expect to see. Some of these variables are required - POLFILE, DBFILE, REPORTFILE, SITEKEYFILE and LOCALKEYFILE.

Some of these have an obvious meaning, and others are less so:

Policies

The policy file describes the system objects to be monitored and what properties should be collected and stored in the database.

Policy files can contain:

Objects names can be any valid pathname, such as /etc/passwd.

Property Masks consist of letters that represent a specific file property and either a plus sign (+) to indicate that a property should be checked, or a minus sign (-) to indicate that a property should be ignored. If no sign is given, plus is assumed, or if a series of properties are given without spaces, the last of either plus or minus is assumed. The properties are:

Tripwire has several predefined variables the represent typical properties. They are named for the types of files with which they would normally be associated.

For example,

Finally, rules have attributes specified in the form:

or for a group of rules:

The attributes are:

severity can be any value from 0 to 1,000,000, but typically 0-100 are used. recurse can be true or false or any value from -1 to 1,000,000. If true or -1, a directory tree is recursively scanned to the bottom of the tree, otherwise, it is scanned to the number of levels specified.

An example of a tripwire policy file is the default policy file installed with tripwire. The following is a series of excerpts from that file to demonstrate the types of files that would be protected and the properties scanned. In some cases, there are very long lists of files, so they are condensed.

To this, you would add files that are specific to your own system.

Tripwire Reporting

Tripwire can be run in several modes depending on what you want to do:

After getting tripwire configured, you start the process of intrusion detection by running tripwire in database initialization mode.

This creates an encrypted database. To get a non-encrypted database, give the -e option. You can also specify the various files if they are non-standard.

Once the baseline database is created, you will likely run tripwire primarily in integrity checking mode:

This produces a report of the files tested and the results with regard to the rule specifications in the policy file. To view the report,

In this case, only a few discrepencies were found, as indicated by the asterisks in column 1 in the upper part of the report. In the lower part of the report, the errors are described in more detail, showing the files and what changed - something added, something removed or something modified. In this case, some of these errors indicate that the policies may need to be modified to prevent trivial errors.

Following the report, it is common to update the database to reflect the new values. For example, if you look at the report and decide that all the errors found are reasonable, you would update the database so that you wouldn't continue to get the same errors. This can be done with:

You can also print the actual database which contains the information currently stored by tripwire. The report is usually very large and shows the file modification time and the file properties.

There are a few integrity checking options that are worthy of discussion.

Interactive Mode (-I, --interactive)

Interactive mode opens the report file in the editor specified in the configuration file and allows the user to indicate which of the discovered inconsistencies should be updated in the database. Finally, it updates the database so that it doesn't have to be done manually.

The severity level indicates which rules should be checked based on their given severity levels, defined as Low=33, Medium=66 and High=100.

The rule option allows a given rule to be tested, which is a great way to debug your policies:

And the email option allows the reports to be directly emailed to the addresses given in the policy file:

And the email option allows the reports to be directly emailed:

Policy Changes

If you change your policy file, you will need to run twadmin to update the policy file and then you need to run tripwire in Policy Update Mode to bring the database into alignment with the current policies.

Tripwire Testing

Tripwire also has a test mode that can be used to test the email notification system.

If the email system is working, the designated user will receive a tripwire email message.