Tripwire

Tripwire .It is one program of computer – based Open Source consisting of a security tool and data integrity.

Summary

[ hide ]

  • 1 General Characteristics
  • 2 Installation
  • 3 Tripwire Settings
  • 4 Configure the policy file
  • 5 Build the Tripwire database
  • 6 Verification of the filesystem
  • 7 Deleting text files
  • 8 References

General characteristics

  • Useful for monitoring and alerting of changes in the files of a filesystem.
  • It works by checking the digital signature of files and directories against a database of the same in a previous moment.
  • The database is generated by taking a snapshot at the time of its installation and is accessed through an encrypted password, so its installation on a possibly infected system would lack effectiveness and it is recommended that its installation and configuration be done before having connected the computer to the internetfor the first time .
  • It works on GNU / Linuxoperating systems .

Installation

Tripwire is normally distributed in an RPM file that is packaged in a compressed TAR format. In the latter case, use:

  • tar xvzf tripwire.tar.gz

Which should generate the file tripwire-2.3-47.i386.rpm (the exact name will depend on your version.) Now install it:

  • rpm -ivh tripwire-2.3-47.i386.rpm

Note: On various Linux distributions, including RedHat 7.2 and higher, Tripwire is already installed, which is why this step may not be necessary.

Tripwire Settings

  • Define Tripwire Keys

Tripwire uses two keys (which can be words or sentences) to store your information. One of them, the “site key” or “site key”, is used to encrypt the configuration files and policies. The other – the “local key” or “local key”, is used to encrypt the information regarding the status of the system files being monitored. You need these two keys for Tripwire administration tasks. These must be entered as soon as Tripwire has been installed using the command:

/etc/tripwire/twinstall.sh Keep them in mind, or write them down in a safe place.

Configure the policy file

The configuration of the files to be monitored by Tripwire is kept in a large file known as a “policy file”. Its manipulation is somewhat tedious given its extension. Tripwire comes with a “template” file to be modified. This file is: /etc/tripwire/twpol.txt. You can modify it directly with a text editor (although I advise you to save an unmodified copy of it.) Now we will make a practical and didactic observation: Tripwire usually takes several minutes in each of its executions, and if You have never used it, it will probably be exasperating to wait a long time without knowing if things are going well or badly. For this reason I suggest that we start with a reduced (and almost useless) version of the policy file. Once you understand the entire process, you can go back to the original file and take advantage of it. Again the warning goes: make a backup copy of the twpol.txt file. To cut the file provided, simply use a text editor (as I saw) and look for the section “File System and Disk Administraton Programs” (which in the file I have, is located from line 185.) An excerpt from that section is featured here:

rulename = “File System and Disk Administraton Programs”,

severity = $ (SIG_HI)

 

/ sbin / accton -> $ (SEC_CRIT);

/ sbin / badblocks -> $ (SEC_CRIT);

/ sbin / dosfsck -> $ (SEC_CRIT);

/ sbin / e2fsck -> $ (SEC_CRIT);

/ sbin / debugfs -> $ (SEC_CRIT);

/ sbin / dumpe2fs -> $ (SEC_CRIT);

/ sbin / dump -> $ (SEC_CRIT);

As you might imagine, this corresponds to a set of files that are monitored by Tripwire. We will narrow down the long list by clipping the file in this section. For example, making it end in / sbin / e2fsck:

rulename = “File System and Disk Administraton Programs”,

severity = $ (SIG_HI)

/ sbin / accton -> $ (SEC_CRIT);

/ sbin / badblocks -> $ (SEC_CRIT);

/ sbin / dosfsck -> $ (SEC_CRIT);

/ sbin / e2fsck -> $ (SEC_CRIT);

Build the Tripwire database

After the policy file is configured and installed, Tripwire needs to collect the current information from the files it needs to monitor. This information is stored in a special database generated by the command:

  • tripwire -mi 2> / tmp / messages

We have redirected some of the output of this command to the / tmp / messages file. It is very likely that there are files specified in the policies (twpol.txt) that do not exist or are incorrectly written (such as lettuce.) This will be recorded in / tmp / messages. Errors must be corrected in twpol.txt, which must be reinstalled, in order to rebuild the Tripwire database. This procedure will be repeated as long as there are errors in the policy file. Delete the / tmp / messages file when all errors are gone.

Filesystem verification

Now that Tripwire is properly configured with your database, it is time to verify the integrity of the filesystem. This is achieved with the command:

  • tripwire -mc

This command will be used every time we want to know that our system has not been altered. If for any reason some of the monitored files are modified (for example, due to a software update) then we must rebuild the database as seen in the previous step, so that there are no discrepancies with the current state of the filesystem in the next verifications. If we want to stop monitoring certain files or start monitoring others, then we must configure the policy file (twpol.txt) as seen above, and reinstall it. Afterwards, the filesystem database will be rebuilt. This process can unfortunately be very tedious when there are many files to monitor.

Finally, the /etc/cron.daily/tripwire file must be modified as follows:

  • / usr / sbin / tripwire -mc –email-report

The configuration file twcfg.txt contains some additional parameters for configuring the email notification system. For example, it is possible to configure whether reports should be sent even if there have been no problems (see MAILNOVIOLATIONS directive in twcfg.txt.) You can also select the messaging agent (see MAILPROGRAM directive) in order not to use sendmail and generate a connection direct SMTP to another host. See the manual for twconfig (4) and twpolicy (4) for more options and examples.

Delete text files

Tripwire saves your configuration and filesystem policy in two files encrypted with the “site key”. These are: /etc/tripwire/tw.cfg and /etc/tripwire/tw.pol, respectively. The first one was generated from /etc/tripwire/twcfg.txt when the keys were configured, and the second one has been regenerated every time you modified your /etc/tripwire/twpol.txt policy file. For security, you should not keep them in the system until they are needed again, so proceed to delete them:

  • rm /etc/tripwire/twcfg.txt /etc/tripwire/twpol.txt

When you need to make a policy modification, you can regenerate the twpol.txt file as follows:

  • twadmin -mp> /etc/tripwire/twpol.txt

And the configuration through:

  • twadmin -mf> /etc/tripwire/twcfg.txt
  • Script check_twpol.sh

As indicated, eventually you will have to use the twpol.txt file that comes with tripwire, which contains numerous references to system files. However, this file in almost all cases will need to be customized since not all systems have the same files installed. In order to speed up this process (which is tremendously tedious), I made the following script that generates a “corrected” version of twpol.txt by contrasting the original against what is in the system. This script does NOT modify the twpol.txt file, but instead leaves the “new version” in /tmp/new.twpol.txt. To run it, simply type:

  • bash check_twpol.sh

The preferred script should be downloaded and not copied manually (it should be available together with this document or on my website) in order to avoid subtle errors between spaces and tabs. Likewise, there it goes:! / Bin / bash

Generation of corrected version of policy file twpol.txt (C) 2002-4002 Diego (www.compulinux.com/diego) Please check these variables: Please cheack these veriables:

Original twpol.txt TWPOL = / etc / tripwire / twpol.txt

Where to search for new files Where to search for new files SRC_DIR = “/ sbin / etc / etc / sysconfig / bin”

The generated twpol.txt Generated twpol.txt RESULT = / tmp / new.twpol.txt if [! -f $ TWPOL]; then

echo “$ TWPOL must exist to start!”

echo “$ TWPOL must exist for running this thing!”

exit

fi echo “Removing non-existent files from twpol.txt” echo “Cutting non-existent files from twpol.txt” while reading L do Caution: a space and a tab are written between brackets (3 lines below) Beware: between brackets there is a space and a tab (following 3 lines) if echo “$ L” | grep ‘^ [] * /’> / dev / null; then

PX = $ (echo “$ L” | sed ‘s / ^ [] * \ ([^] * \). * / \ 1 /’)

PY = $ (echo “$ L” | sed ‘s / ^ [] * \ ([^] * \) \ (. * \) / \ 2 /’)

if [-e “$ PX”]; then

echo “$ PX $ PY”

else

echo “# – $ PX $ PY”

echo -n ‘.’ > / dev / tty

# echo $ PX> / dev / tty

fi

else

echo “$ L”

fi

done <$ TWPOL> $ RESULT

threw out

echo “Inserting new files to twpol.txt” echo “Inserting new files to twpol.txt”

for DIR in $ SRC_DIR

do echo “# -” echo “# -” echo “# -” echo “(” echo “rulename = \” $ DIR \ “,” echo ‘severity = $ (SIG_HI)’ echo “)” echo ” {”

echo> / dev / tty

echo “Processing $ DIR”> / dev / tty

echo “Processing $ DIR”> / dev / tty

for F in $ DIR / *

do

Warning: a space and a tab are written between brackets (next line) Beware: between brackets there is a space and a tab (next line)

if [-f $ F] &&! grep “^ [] * $ F []” $ RESULT> / dev / null; then

echo “$ F -> \ $ (SEC_CRIT);”

echo -n “.” > / dev / tty

fi

done

echo “}” done >> $ RESULT echo echo “The new twpol.txt file was generated in $ RESULT” echo “New twpol.txt file was generated as $ RESULT”

 

Leave a Comment

Scroll to Top