|
User Guide - Table of Contents |
Spot The Difference is a file integrity checker. Its goal is to detect signs of intrusion by looking for suspicious changes in system files. Crackers, in fact, to do their evil or just to make sure they can work their way back into the system, often change some configuration files, executables and/or log files (usually with rootkits); thus leaving signs of the break-in.
An integrity checker works in two phases:
Information about what files to check, which checks to perform and the connection to the database is set out in the configuration file.
The database created during the update phase can't be modified (you can't add, remove or change records to it). You can, of course, create a new database that reflects the new state of the filesystem.
Spot The Difference is fully developed in python; so you need to have python (at least 2.3.x). If you don't already have it, you can download it here. Using dbm database files to store files information doesn't require the installation of any additional python module. If you wish to use another database (MySQL, PostgreSQL and SQLite are supported), you might need to install database-specific modules.
Python database modules used by Spot The Difference are:
To install Spot The Difference on a Unix/Linux system follow these few steps:
# tar -zxvf stdiff-0.2.1.tar.gz |
# cd ./stdiff-0.2.1 |
# python setup.py install |
This will copy all modules in the third-party modules directory and the scripts in the local executables directory (usually /usr/local/bin on UN*X systems). A sample configuration (stdiff.conf.sample) file will be copied to /etc.
To install Spot The Difference on a Windows system, just run the graphical installer (stdiff-0.2.1.win32.exe); you will be asked a couple of questions:
After a couple of 'next', the installer will copy the scripts in the python scripts directory (<python_dir>\Scripts\) and the modules in the third-party modules directory (<python_dir>\Lib\site-packages\). A sample configuration file (stdiff.conf.sample) will be copied to <python_dir>\etc\.
The next step after installation is to create the database that will hold files information. Spot The Difference supports most of the open source databases (MySQL, PostgreSQL, SQLite and dbm files). If you want to use dbm or SQLite files, you don't need to create the database now: it will be automatically created at runtime.
The advantage of dbm files is their simplicity and portability. You can find a lot of software on the internet for viewing and managing their content. and you don't need to install any additional software or python module.
Also SQLite databases are stored in files and thus don't require setting up a database server. They are much faster than dbm files, but require the installation of an additional python module.
If you wish to use Spot The Difference with MySQL or PostgreSQL databases, you will need to create the database and the table that will hold files information. To do this, simply run the script
stdiff_install_db db_type |
Using a database server, like MySQL or PostgreSQL, allows you to hold data from multiple monitored machines in a single repository . All machines can query/update a single, centralized, database. The security of the database server machine becomes, of course, fundamental. To view the content of the database you can use the database server tools.
Since the configuration file must contain the password to access to the database, it is recommended to create/update the database with a privileged user and then do the later checks with an unprivileged user, with only SELECT granted.
dbm (Data Base Management) files are binary databases of key-value pairs. They are local files and their integrity must be preserved setting them as read-only (read-only NFS, read-only medium, chflags) after their creation.
"SQLite is a small C library that implements a self-contained, embeddable, zero-configuration SQL database engine". SQLite databases are local files and, like dbm files, their integrity must be preserved setting them as read-only (read-only NFS, read-only medium, chflags) after their creation.
MySQL is "the world's most popular open source database". After the installation, the command:
stdiff_install_db mysql |
You can also create the database and the table yourself. Though you can't change fields names, data types are customizable. These are the default values:
Field | Type | Description |
---|---|---|
path | VARCHAR(255) BINARY PRIMARY KEY | Full path of the file or directory (255 characters max) |
md5 | CHAR(32) | md5 file checksum (16 bytes) |
sha | CHAR(40) | sha1 file checksum (20 bytes) |
st_mode | SMALLINT UNSIGNED | File permissions in decimal format |
st_ino | MEDIUMINT UNSIGNED | File inode number (3 bytes: 16777215 max) |
st_dev | SMALLINT UNSIGNED | File device (2 bytes: 65535 max) |
st_nlink | SMALLINT UNSIGNED | Number of links (2 bytes: 65535 max) |
st_uid | INT UNSIGNED | User ID (2 bytes: 4294967295 max) |
st_gid | INT UNSIGNED | Group ID (2 bytes: 4294967295 max) |
st_size | BIGINT UNSIGNED | File size (8 bytes: 18446744073 GBytes max) |
st_atime | INT UNSIGNED | Access time (timestamp: 4 bytes) |
st_mtime | INT UNSIGNED | Modification time (timestamp: 4 bytes) |
st_ctime | INT UNSIGNED | Change time (timestamp: 4 bytes) |
"PostgreSQL is an object-relational database management system (ORDBMS) based on POSTGRES, Version 4.2, developed at the University of California at Berkeley Computer Science Department". After the installation, the command
stdiff_install_db pgsql |
You can also create the database and the table yourself. Though you can't change fields names, data types are customizable. These are the default values:
Field | Type | Description |
---|---|---|
path | VARCHAR(255) PRIMARY KEY | Full path of the file or directory (255 characters max) |
md5 | CHAR(32) | md5 file checksum (16 bytes) |
sha | CHAR(40) | sha1 file checksum (20 bytes) |
st_mode | INT | File permissions in decimal format |
st_ino | INT | File inode number (4 bytes) |
st_dev | INT | File device (4 bytes) |
st_nlink | INT | Number of links (4 bytes) |
st_uid | INT | User ID (4 bytes) |
st_gid | INT | Group ID (4 bytes) |
st_size | BIGINT | File size (8 bytes) |
st_atime | INT | Access time (timestamp: 4 bytes) |
st_mtime | INT | Modification time (timestamp: 4 bytes) |
st_ctime | INT | Change time (timestamp: 4 bytes) |
The next step after the creation of the database, is to edit the configuration file, which defines the run-time behaviour of Spot The Difference. It includes information about connecting to the database, files to check and which checks to perform on those files.
It is made up of:
Variables provide all the information needed for Spot The Difference to connect to the database. Firstly, you have to set the value of the db_type variable to the database type to use (legal values are: dbm, sqlite, mysql and pgsql). For example:
db_type = mysql |
The other variables that can be set are login variables (user and passwd), server variables (host, port or unix_socket) and database variables (db and table). Not all database types require the setting of all these variables (e.g. dbm and SQLite database files don't require login or host and port specification). See below for database-specific variables.
If you wish to receive the final report by e-mail (-e option), you have to set a couple of additional variables:
mail_server = mailserver.my.domain:2500 |
mail_recipients = foo@my.domain bar@my.domain |
For a dbm file, you only need to specify its absolute path; it must be assigned to the db variable. E.g.:
db = /root/stdiff/stdiff.dbm |
If you use a SQLite database file, you need to specify its absolute path (in the db variable) and the name of the table (in the table variable) in which to insert files information. E.g.:
db = /root/stdiff/stdiff.sql table = my_hostname |
To connect to a MySQL server, you have to set:
NOTE: you can't set both port and unix_socket variables. Spot The difference wouldn't know how to connect.
Configuration file entries for a MySQL server connection would look like this:
user = my_user passwd = my_password host = localhost unix_socket = /var/run/mysql/mysql.sock db = Spot table = my_hostname |
To connect to the database through a TCP port instead of a socket, the fourth entry would have been:
port = 3306 |
To connect to a PostgreSQL server, you have to set:
NOTE: if you connect through a UNIX socket, you don't need to set the port variable.
Configuration file entries for a PostgreSQL server connection (through a UNIX socket) would look like this:
user = my_user passwd = my_password host = /tmp db = Spot table = my_hostname |
To connect to a remote database, you should assign its name or address to the host variable and set the port variable:
host = 1.2.3.4 port = 3306 |
Rules specify the paths (files and directories) to check and the checks to perform. Each rule takes one line and consists of one or two whitespace separated fields:
There are four types of rules, identified by their prefix:
/etc 5iplzc |
/etc 51plzc !/etc/motd !/etc/X11 |
/etc 5iplzc $/etc/inetd.conf 5siplzc $/etc/ssh 5siplzc |
/etc 5iplxc =/etc/X11 |
As stated previously, some rules must contain the list of checks to perform on a specific pathname. Below is a list of available file checks; each one is identified by a single character:
5 md5 checksum s sha1 checksum p permessions i inode number d device l number of links u user ID g group ID z size a Most recent access time m Time of the most recent modification of the content of the file c Time of the last modification of inode 'metadata' (on UNIX) or creation date (on Windows)
You must specify all the checks you want to be performed (there is no special 'all' string) with no whitespace between. The following rule:
/etc 5sugmc |
For critical files, it is recommended to calculate both md5 and sha1 checksums, since it's theoretically possible to modify a file and pad it to leave its checksum unchanged. Don't forget, however, that some rootkits serve up the original file (hidden somewhere) when you open it for reading and the compromised file when you execute it. So pay close attention to new, unexpected files.
Well, so far we have created the database and edited the configuration file. What we need to do now is to update the database and then schedule a periodic check of the filesystem. The syntax of Spot The Difference is:
stdiff.py [-h] [-v|-q] [-C config_file] [-c|-u] [-o output_file] [-e]
Almost all parameters are optional. It is necessary, however, to specify wether a filesystem check (-c) or a database update (-u) is required . The options are as follows:
Below are some examples. To update the database, preserving all the default settings, simply run:
# stdiff.py -u |
If you want to override the default settings, the command:
# stdiff.py -u -o /root/stdiff/stdiff.out -C /root/stdiff/stdiff.conf -v |
Once you have populated the database, you should schedule periodic checks of the filesystem. The command:
# stdiff.py -C /root/stdiff/stdiff.conf -c -o /root/stdiff/stdiff.out -e |
After the creation/update of the database, a detailed report is generated. It contains statistics on the update process:
After a filesystem check, the generated report provides all the above data plus a detailed list of:
Thanks to Jens Engel for pointing out an unhandled exception when a broken symlink was found. Release 0.2.1 has fixed this issue and now, when updating the database, stdiff will report broken links in the final report:
Could not open these files: [...] /usr/bin/brokenlink No such file or directory: '/usr/bin/brokenlink' |
!/usr/bin/brokenlink |
Spot The Difference has been tested on *BSD, Linux and Windows sytems. Please send bug reports and comments by email.
Copyright (c) 2004, Daniele Mazzocchio
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.