OSQuery Project

Project Partners: Elizabeth Chadbourne, Lily Pouliot, and Connor Schnackenberg

What is OSQuery?

OSQuery is an Open Source tool that you can use to query your device for information as if it were a database. It has installation guides for Windows, macOS, and Linux. At a high level OSQuery can be used to monitor devices and generate logs for state changes, which can easily be integrated into existing logging solutions. It uses SQL language and interface to collect information on your devices.

For our purposes, OSQuery can be integrated into the Wazuh logging solution we already have in place, making it easy to find all logs and alerts in a single dashboard.

Installation Instructions for Rocky Linux:

The following instructions detail how to install OSQuery on Rocky Linux.

Step 1: Check your Linux Distribution

cat /etc/os-release

Look at this section:

We know from here that we need to use RPM (red hat) and x86 for the download in the next few steps.

Step 2: Create Firewall rule to allow for software Installation

Use the commands below on your firewall to allow traffic temporarily, so you are able to install software on your rocky machine.

# allow all traffic temporarily

configure 
set firewall name DMZ-to-WAN default-action accept
set firewall name WAN-to-DMZ default-action accept
commit
save

Step 3: Download the correct OSQuery File

If wget is not installed use the following command:

Go to this link: https://osquery.io/downloads/official/5.15.0arrow-up-right

  • Copy the link address

  • Do the following commands in your Rocky machine

    • We are using the RPM(x86_64) version for this lab

The file should now be in your home directory. You will need to install it with the following command:

Delete Firewall Rule used to Install Traffic:

Alternative Methods for Installation:

Follow the instructions for alternative installation for RPM distributions

If the use of “yum-config-manager” comes back with a “not found” error, install it:

OSQuery Integration With Wazuh:

Step 1: Build the osquery.conf file

Input the following into the file:

Step 2: Enable and start the OSQuery Daemon

Step 3: Edit the default Wazuh configuration file

Add the following to the bottom of the Wazuh configuration file:

Your file should now look like this:

Step 4: Restart the Wazuh Agent

Step 5: Update Wazuh Dashboard

  • Go to Wazuh Interface

  • Click Wazuh Logo

    • >Settings

    • >Modules

    • > Scroll down to threat detection and response

    • > Enable Osquery

Step 6: Test Querying to Wazuh

  • Go to your Wazah interface

  • Click Wazuh Logo

    • > Modules

    • > Threat Detection and Response

    • > OSquery

Follow the steps below to find your logs:

  • Go to your Wazuh Interface

    • > Wazuh Logo

    • > Security Events

Additional Features of OSQuery Application Client:

SQL-Based Queries

One of the major features of osquery is the support of SQL syntax to fetch information from endpoint devices. They can be codified and reviewed to meet specific requirements, allowing the users to reuse queries and scale them to fetch data from multiple devices. This can be executed without the need to reach out to all operating systems and devices that are present.

Everything in SQL:arrow-up-right When using SQL with osequery, select only ! All mutation-based verbs exist, like INSERT, UPDATE, DELETE, and ALTER, but they do nothing, unless creating run-time tables or VIEWs, or using an extension. Mutation-based verbs are allowed in extensions, if the extension supports them. When working with several tables, they require a predicate for one of the columns and will not work without it.

Instructions to add SQL-Based Queries

To begin using SQL with osequery, osqueryi must be powered up as the user or superuser.

The following shows the output of running the help command after running osqueryi

Meta Commands

.tables and .schema will list all of the tables and their schema. The schema meta-command takes an argument that helps limit the output to a partial string match. Below shows the output of the .schema process, where the complete schema can be found linked herearrow-up-right, showing all supported platforms. To see schema in your shell for tables foreign to your OS, like kernel modules on macOS, use the --enable_foreign command line flag.

Making a simple query:

SQL supports refinements to queries like select, which can be combined with OS-level data like browser plugins to give more insight.

Meta table:

looking at the “meta” table that provides details to osquery about itself, which can be prefixed with osquery_ This will always show the current PID of the running osquery process.

Reminder: .mode will change the outlook of the display mode. There are five modes

Pros and Cons of OSQuery:

Pros:

  • Relatively easy to install OSQuery on the machine

    • Many methods to use if one doesn’t work

  • Very simple to integrate with our existing Wazuh logging

  • Lots of documentation - Both for installation and Wazuh integration

  • Allows querying system information using SQL queries

  • Provides real-time monitoring

  • Supports extensions and plugins

Cons:

  • Resource intensive; depending on the query complexity and frequency OSQuery can consume lots of system resources.

  • Learning curve; takes time to research and get used to the commands and how it works, not necessarily intuitive.

Demonstration Video:

https://youtu.be/BWFDSwwlmG0arrow-up-right

Sources:

Osqueryd (Daemon) - Osquery. https://osquery.readthedocs.io/en/stable/introduction/using-osqueryd/. Accessed 5 Mar. 2025.

Osqueryi (Shell) - Osquery. https://osquery.readthedocs.io/en/stable/introduction/using-osqueryi/. Accessed 5 Mar. 2025.

Welcome to Osquery - Osquery. https://osquery.readthedocs.io/en/stable/. Accessed 5 Mar. 2025.

Last updated