

> order by p.start_time An UNIX timestamp can be formatted to a human-readable date with the datetime function: datetime(start_time, 'unixepoch') Repeat Actions With Scheduled Queries " osqueryd is the host monitoring daemon that allows you to schedule queries and record OS state changes. > where p.uid = u.uid and u.username = 'gvincent' Osquery> select u.username, p.pid, p.start_time, p.name, p.path, p.state It is a joint query between the users and processes tables using the uid: Relation between the users and processes tables osquery>. We want to list the processes owned by a specific user. Now we have made our first query we can further. Is_hidden = 0 List running processes by users Osquery> select * from users where username = 'gvincent' The current print is the pretty mode by default but it can be changed: osquery>. | uid | gid | uid_signed | gid_signed | username | description | directory | shell | uuid | is_hidden | schema usersĬREATE TABLE users(`uid` BIGINT, `gid` BIGINT, `uid_signed` BIGINT, `gid_signed` BIGINT, `username` TEXT, `description` TEXT, `directory` TEXT, `shell` TEXT, `uuid` TEXT, `type` TEXT HIDDEN, `is_hidden` INTEGER, `pid_with_namespace` INTEGER HIDDEN, PRIMARY KEY (`uid`, `username`, `uuid`, `pid_with_namespace`)) WITHOUT ROWID osquery> select * from users where username = 'gvincent' It is possible to get the table schema: osquery>. We are going to list all the existing users in the users table. tables Create First OS Queries With SQL Retrieve user information helpcommand or in the documentation: osquery>. You can retrieve the list of tables with the. timer ON|OFF Turn the CPU timer measurement on or off width + Set column widths for "column" mode types Show result of getQuer圜olumns for the given query show Show the current values for various settings socket Show the local osquery extensions socket path separator STR Change separator used by output mode nullvalue STR Use STRING in place of NULL values Pretty Pretty printed SQL results (default)

mode MODE Set output mode where MODE is one of: headers ON|OFF Turn display of headers on or off features List osquery's features and their statuses disconnect Disconnect from a connected extension socket connect PATH Connect to an osquery extension socket You are connected to a transient 'in-memory' virtual database. Osquery provides an SQL interpreter with the osqueryi command: $ osqueryi Then let's start the osquery daemon: $ sudo osqueryctl startįor Linux systems you can start osqueryd using systemd: sudo systemctl start osqueryd Play With the Osquery Interpreter The example configuration file needs to be copied: $ sudo cp -p /var/osquery/ /var/osquery/nf The detailed installation below is for MacOSX but you can find another installation guide here.
#Osquery architecture install#
It is possible to install osquery on many OS: Operating Systems supported by Osqueryĭepending on the operating system you are using you can have extra information. In addition, we will extend osquery information by adding a new table in the endpoint. We will use Golang to execute queries programmatically. The communication interface is not limited only to the interpreter. Logs may be forwarded to a centralized logging system. It is useful to make system audits and record events in logs. Then we will figure out the scheduled queries using the osqueryd daemon. After installing it, we will get started to make some queries from a simple to a complex one. In this article, we will explore the osquery possibilities. Osquery performs real-time calls to the OS to serve you data: Osquery concept schema

Afterward, you can retrieve information from them with SQL queries. Tables represent OS abstract concepts such as users or processes for example.

Osquery exposes the OS as a high-performance relational database. This is the concept that the osquery project pushes by providing a low-level and powerful endpoint that can be used for system analysis or monitoring The osquery project logo How Does Osquery Work Finally, an operating system can be considered roughly and simplified as a database and the command line as a query to access what we want. The command line allows us to retrieve information about the current state of the system. Stop chaining commands start making SQL queries to fetch OS informationĪs dev or ops, we interact every day with operating systems ( OS) that may differ.
