October 28, 2019 ( last updated : October 27, 2019 )
File Integrity Monitoring (FIM)
File Integrity Monitoring
osquery
https://github.com/gridgentoo/osquery
Osquery created by Facebook. Osquery is an open source operating system instrumentation, monitoring, and analytics. Created by Facebook, it exposes an operating system as a high-performance relational database that can be queried using SQL-based queries.
Maintaining real-time insight into the current state of your infrastructure is important. At Facebook, we’ve been working on a framework called osquery which attempts to approach the concept of low-level operating system monitoring a little differently.
Introducing osquery. Osquery created by Facebook.
Osquery exposes an operating system as a high-performance relational database. This design allows you to write SQL-based queries efficiently and easily to explore operating systems. With osquery, SQL tables represent the current state of operating system attributes, such as:
SQL tables are implemented via an easily extendable API. Several tables already exist and more are being written. To best understand the expressiveness that is afforded to you by osquery, consider the following examples.
This first example illustrates how you might use osquery to interact with the processes that are running on the current system. Specifically, this query returns all of the processes which are currently executing. The where clause of the query only returns processes where the original binary used to launch the process no longer exists on the filesystem. This is a common tactic used by malicious actors, so this should not return any results on your system, assuming your system isn’t compromised.
Interacting with operating system state via SQL is fun and easy. One of the aspects of SQL that makes it so applicable to operating system analytics is the ability to join different tables together. Consider the following example, which uses data from both the “listening_ports” table and the “processes” table. This query finds all processes that are listening on network ports. Then, using the processes table from the last example, we can join the two tables together since they both expose the pid of the processes in question. This allows you to use generic tables to add context as you explore operating system state.
There are many tables included with osquery and we’re creating more every day. Tables are easy to write, so we often encourage new contributors to develop a few tables as an introduction to the osquery codebase. For detailed documentation on how to create a table, see the guide on the wiki.
See the usage guide on the wiki. Osquery created by Facebook.
Osquery provides its own repository for all platform installation, and the first step we are going to do is installing the osquery package FROM the official osquery repository.
Install osquery on Linux Server On Ubuntu
Add the osquery repository and install the package.
Install osquery on Linux Server On On CentOS
Add the osquery key to the system.
Add and enable the osquery repository, and install the package.
Wait for all packages to be installed.
Note:
If you get the error about the yum-config-manager command.
Install the 'yum-utils' package.
On Ubuntu
Install the rsyslog package using the apt command below.
On CentOS
Install the rsyslog package using the yum command below.
After the installation is complete, go to the '/etc/rsyslog.d' directory and create a new configuration file osquery.conf.
Paste the following configuration there.
Save and exit.
osquery default configuration is 'osquery.conf', usually located in the '/etc/osquery' directory. There are samples of the osquery configuration '/usr/share/osquery/osquery.conf' and sample of osquery packs configuration.
In this step, we will learn about the osquery configuration components, create the custom osquery configuration, and then deploy the osqueryd as a service.
osquery configuration formatted as a JSON file contains osquery configuration specifications described below.
Go to the '/etc/osquery' directory and create a new custom configuration 'osquery.conf'.
Paste the following configurations there.
Save and exit.
Note:
Now start the osqueryd daemon service and enable it to launch every time at system boot.
And restart the rsyslog service.
Basic configuration osquery has been completed.
Osquery provides File Integrity Monitoring on Linux and MacOS Darwin using the inotify and FSEvents. Simply, it monitors and detects any changes of files on the defined directory using the 'file_path'and then store all activity to the file_events table.
In this step, we will configure osquery to monitor important directories such as home, ssh directory, etc, tmp, and the www web root directory using custom FIM packs.
Go to the '/usr/share/osquery/packs' directory and create a new packs configuration file 'fim.conf'.
Paste configurations below.
Save and exit.
Now back to the '/etc/osquery' configuration directory and edit the 'osquery.conf' file.
Add the File Integrity Monitoring packs configuration inside the 'packs' section.
Save and exit, then restart the osqueryd service.
Note:
Keep checking the JSON configuration file using the JSON linter 'http://jsonlint.com/' and make sure there is no error.
We will test the File Integrity Monitoring packs by creating a new file on the defined directory 'home'and 'www'.
Go to the '/var/www/' directory and create a new file named 'howtoforge.md'.
Go to the '/home/youruser/' directory and create a new file named 'fb-labs.md'.Now we will check all logs monitoring using the real-time interactive mode osqueryi and the logs of the osquery results.
osqueryi
Run the osqueryi command below.
Now check all logs about file changes in the 'file_events' table.
For global changes.
For 'home' directory.
For the 'www' web root directory.
osqueryd results log
Go to the '/var/log/osquery' directory and you will get the 'osqueryd.results.log' file.
Filter the osquery logs using the 'grep' command.
You will see info about those file has been created.
The installation and configuration of the File Integrity Monitoring (FIM) on Linux Server Ubuntu and CentOS using osquery has been completed successfully.
Reference
Originally published October 28, 2019
Latest update October 27, 2019
Related posts :