Last updated at Fri, 08 Dec 2017 20:27:40 GMT
Synopsis
Tripwire is a most popular host-based intrusion detection system that continuously tracks your critical system files and reports under control if they have been destroyed. Tripwire agents monitor Linux systems to detect and report any unauthorized changes to files and directories including permissions, internal file changes, and timestamp details.
Tripwire works by scanning the file system and stores information on each file scanned in a database. If changes are found between the stored values in the database and the current state, it will send an alert to you.
In this tutorial, we will learn how to install and configure Tripwire on CentOS 7 server.
System Requirements
- Newly deployed CentOS 7 server.
- A static IP address is configured on your server.
Update the System
First, it is recommended to update your system with the latest stable version.
You can update system by running the following command:
apt-get update -y
apt-get upgrade -y
After updating system, You will also need to install EPEL repository to your system. You can install it by running the following command:
yum install epel-release -y
Next, restart your system and log in with root user.
Install Tripwire
You can easily install Tripwire from CentOS official repository by running the following command:
yum install tripwire -y
Once the installation is complete, you should see the following output:
Downloading packages:
tripwire-2.4.3.4-1.el7.x86_64.rpm | 1.0 MB 00:00:12
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : tripwire-2.4.3.4-1.el7.x86_64 1/1
Verifying : tripwire-2.4.3.4-1.el7.x86_64 1/1
Installed:
tripwire.x86_64 0:2.4.3.4-1.el7
Complete!
Create Keys for Tripwire
Tripwire uses two keys to secure its configuration files site key and local key. Site key is used to secure the configuration files, while local key is used on each machine to run the binaries.
You can create Tripwire local and site key files by running the following command:
tripwire-setup-keyfiles
You will be asked to provide passphrases for local and site key as shown below:
----------------------------------------------
The Tripwire site and local passphrases are used to sign a variety of
files, such as the configuration, policy, and database files.
Passphrases should be at least 8 characters in length and contain both
letters and numbers.
See the Tripwire manual for more information.
----------------------------------------------
Creating key files...
(When selecting a passphrase, keep in mind that good passphrases typically
have upper and lower case letters, digits and punctuation marks, and are
at least 8 characters in length.)
Enter the site keyfile passphrase:
Verify the site keyfile passphrase:
Generating key (this may take several minutes)...Key generation complete.
(When selecting a passphrase, keep in mind that good passphrases typically
have upper and lower case letters, digits and punctuation marks, and are
at least 8 characters in length.)
Enter the local keyfile passphrase:
Verify the local keyfile passphrase:
Generating key (this may take several minutes)...Key generation complete.
----------------------------------------------
Signing configuration file...
Please enter your site passphrase:
Wrote configuration file: /etc/tripwire/tw.cfg
A clear-text version of the Tripwire configuration file:
/etc/tripwire/twcfg.txt
has been preserved for your inspection. It is recommended that you
move this file to a secure location and/or encrypt it in place (using a
tool such as GPG, for example) after you have examined it.
----------------------------------------------
Signing policy file...
Please enter your site passphrase:
Wrote policy file: /etc/tripwire/tw.pol
A clear-text version of the Tripwire policy file:
/etc/tripwire/twpol.txt
has been preserved for your inspection. This implements a minimal
policy, intended only to test essential Tripwire functionality. You
should edit the policy file to describe your system, and then use
twadmin to generate a new signed copy of the Tripwire policy.
Once you have a satisfactory Tripwire policy file, you should move the
clear-text version to a secure location and/or encrypt it in place
(using a tool such as GPG, for example).
Now run "tripwire --init" to enter Database Initialization Mode. This
reads the policy file, generates a database based on its contents, and
then cryptographically signs the resulting database. Options can be
entered on the command line to specify which policy, configuration, and
key files are used to create the database. The filename for the
database can be specified as well. If no options are specified, the
default values from the current configuration file are used.
Next, run “tripwire –init” to enter Database Initialization Mode. This reads the policy file, generates a database based on its contents, and then cryptographically signs the resulting database.
tripwire --init
You should see some error called “No such file or Directory” and “file system error”. The files/directories might not be existed in your system, so ignore it. Once tripwire database initialization is finished, you should see the following output:
Wrote database file: /var/lib/tripwire/centOS-7.twd
The database was successfully generated.
Configure Policy File
Before configuring policy file, generate a list of files that are setting off tripwire with the following command:
sh -c 'tripwire --check | grep Filename > test_results'
Tripwire will identify file changes in the critical system files specified in the policy file.
Now, open the policy file /etc/tripwire/twpol.txt
:
nano /etc/tripwire/twpol.txt
Note down the each file name in the test_results
file which we have generate above and comment out all of the lines that you find that match:
Save and close the file when you are finished.
Next, you will also need to recreate the encrypted policy file that tripwire actually reads:
To do so, run the following command:
twadmin -m P /etc/tripwire/twpol.txt
Once you are done, reinitialize the database to implement your policy with the following command:
tripwire --init
All the errors and warnings that you have received earlier should be gone now.
Next, verify the tripwire for any syntax error with the following command:
tripwire --check
Test Tripwire
Now, Tripwire is configured. It’s time to test Tripwire. Let’s create some files to see how Tripwire IDS works.
touch hiteshjethva
touch hiteshjethva1
touch hiteshjethva12
touch hiteshjethva123
Now run the Tripwire interactive command:
tripwire --check --interactive
Tripwire will collect all the files/directories changes/modifications and automatically open the result in the vi editor as shown below:
Open Source Tripwire(R) 2.4.3.4 Integrity Check Report
Report generated by: root
Report created on: Sun May 21 11:16:25 2017
Database last updated on: Never
===============================================================================
Report Summary:
===============================================================================
Host name: centOS-7
Host IP address: 127.0.0.1
Host ID: None
Policy file used: /etc/tripwire/tw.pol
Configuration file used: /etc/tripwire/tw.cfg
Database file used: /var/lib/tripwire/centOS-7.twd
Command line used: tripwire --check --interactive
-------------------------------------------------------------------------------
Remove the "x" from the adjacent box to prevent updating the database
with the new values for this object.
Modified:
[x] "/etc/tripwire/tw.pol"
-------------------------------------------------------------------------------
Rule Name: Root config files (/root)
Severity Level: 100
-------------------------------------------------------------------------------
Remove the "x" from the adjacent box to prevent updating the database with the new values for this object.
Added:
[x] "/root/test_results"
[x] "/root/hiteshjethva"
[x] "/root/hiteshjethva1"
[x] "/root/hiteshjethva12"
[x] "/root/hiteshjethva123"
Modified:
[x] "/root"
===============================================================================
In the above file, you should see the list of files which we have just added. If this is a valid, you can accept the changes by updating the Tripwire database. Or just remove the x mark and update database.
Now, type q: and enter the local passphrase to save the file.
Tripwire stored it’s report file under /var/lib/tripwire/report/
directory with extension .twr
. If you want to view this type of files using test editor. First, you have to convert the files to txt file. You can do this with the following command:
twprint --print-report --twrfile /var/lib/tripwire/report/centOS-7-20170521-111625.twr > report.txt
Now you can easily open it using your favorite editor.
Automate Tripwire Report
If you want to set up a cron job to execute a tripwire check every morning 11:00 AM. You can do this by editing crontab file.
Run the following command to create a cron job:
crontab -e
Add the following line:
00 11 * * * /usr/sbin/tripwire --check
Conclusion
Congratulations! you have successfully installed Tripwire on CentOS 7 server. I hope you can now easily install and configure your Tripwire IDS.