Skip to content

Response, New York. Noah Park: Check Point Patches Actively Exploited Management Server Path Traversal. Detection, Dallas. Ava Okello: Report Finds Nearly Half of Deployed Detections Need Attention Before SOCs Can Trust Them.

SOCtember

Always First. Fast SOC News.

osquery documentation, Logging, Differential logs section explaining that results are changes between the last query execution and the current one.
Screenshot: osquery documentation, Logging osquery, Differential logs, the osquery project (fair use).

Tools

Did You Know: An osquery Scheduled Query Logs Only What Changed Since Its Last Run, and a Process That Starts and Exits Between Runs Is Never Seen at All

osquery's scheduled queries do not report the state of a host each time they run. By default they log only the rows added or removed since the previous run, and a query against the processes table sees only what is running at that instant. A short-lived attacker process can come and go without leaving a single row unless evented tables are switched on.

James Whitford, ToolsAustin3 min read

AUSTIN - Many SOC teams run osquery across their fleets and send its scheduled query results to a SIEM, where analysts search them as if they were a regular inventory of every host. The documentation describes something narrower. Results of scheduled queries go to the results log. "These are differential changes between the last (most recent) query execution and the current execution." Each log line says which rows a query added or removed. The first time a query runs there is no previous run, so the first batch consists entirely of added rows. After that, only changes are written.

osquery documentation showing added and removed result lines for a processes query and noting that no results are logged if no processes start or stop.
Screenshot: osquery documentation, Logging osquery, Event format, the osquery project (fair use).

The documentation's own example is a query that selects name, path and pid from the processes table. One run logs a removed line for an osqueryd process and an added line for a new osqueryd process with a different pid, which tells the reader the binary was stopped and started again. osquery keeps a cache of the previous results and logs only when the cache changes. "If no new processes are started or stopped, the query won't log any results." For an analyst, that means silence from a host is not an empty answer. A service that has been running since before the first scheduled run appears once, in that first batch of added rows, and a search over the last hour will not find it.

osquery documentation, Snapshot logs section describing point-in-time results written to a dedicated snapshots log.
Screenshot: osquery documentation, Logging osquery, Snapshot logs, the osquery project (fair use).

When a team needs the full picture on every run, osquery offers snapshot mode. Setting "snapshot": true on a scheduled query logs an exact point in time set of results, with no differentials. The documentation warns that this "will be a lot of data amortized across your fleet," and with the filesystem logger, snapshot results are written to a dedicated sink, /var/log/osquery/osqueryd.snapshots.log, not the regular results log. A log shipper that collects only the results file will miss them.

osquery documentation, Eventing Framework, explaining that query-time retrieval is lossy and a short-lived process will never appear in the processes table.
Screenshot: osquery documentation, Eventing Framework, the osquery project (fair use).

The second gap is timing. Most osquery tables are generated when a query asks for data, so the processes table shows only what exists at that moment. The documentation is blunt: "From an operating systems perspective, query-time synchronous data retrieval is lossy." Its example is a process like ps that runs for a fraction of a moment, which no SELECT against the processes table will ever include. A tool that starts and exits between two scheduled runs leaves nothing behind in that table. Schedules also drift: by default a 10 percent splay is applied to each query's interval, and the configuration guide notes that intervals count the time the daemon itself has been running, so a query with a 24-hour interval on a laptop that is suspended at night could take a few days to run.

osquery documentation, Process Auditing, listing the evented tables for process and socket events and their sources on Linux and macOS.
Screenshot: osquery documentation, Process and socket auditing with osquery, the osquery project (fair use).

The fix is osquery's evented tables, whose names end in _events. They buffer operating system events as they happen and report them at query time. On Linux and macOS, process_events, bpf_process_events and es_process_events record process executions from Audit, BPF, OpenBSM or EndpointSecurity, and socket_events and bpf_socket_events cover network connections. They require additional configuration, and the documentation cautions that they "may introduce additional CPU overhead and greatly increase the number of log events generated by osquery." Buffers are finite too: the events_max flag defaults to the 50000 most recent events waiting to be drained by a query.

For a SOC team, the checks are short. Know which scheduled queries are differential and which are snapshots, and make sure the snapshots log is collected. Do not read the absence of a row as proof that a process or connection never existed. Turn on the evented tables for process and socket activity on the hosts that matter, test the overhead, and size events_max against how often the scheduled query drains it. And when a host has been asleep or offline, check when its queries last actually ran before trusting what they say.

About the Author

James Whitford

James Whitford covers SOC tooling, SIEM, SOAR, and detection platforms for SOCtember from Austin.

Related stories

Tools desk