Threat Intelligence

50 Osquery Query Examples Every Security Team Should Run

Fifty schema checked starting points for fleet truth, software, persistence, configuration, and investigation, each tied to an operator action.

Alex Gibson, Cofounder and Principal at Artemes AI
Alex Gibson
Cofounder, Principal
Jul 24, 2026 11 min read
Five step model that turns an osquery security question into an owned response

The problem with most osquery query examples is not the SQL. It is that nobody says what to do with the rows.

A list of 50 queries can create 50 new feeds of noise. The useful version attaches a question, platform scope, cadence, baseline, and owner to every statement. Run these examples first in osqueryi, then promote only the queries that change a real decision.

That discipline matters more in 2026. Verizon reported that vulnerability exploitation became the leading breach entry point at 31 percent in its 2026 DBIR public sector analysis. Only 26 percent of critical KEV vulnerabilities were fully remediated in 2025, and median resolution reached 43 days. Better endpoint questions should shorten that delay, not add another dashboard.

Infographic

A query becomes useful at the action boundary

Five part operating model for an osquery queryA flow from security question to scoped SQL, measured schedule, baseline comparison, and owned action.QuestionWhat decision?ScopeWhich cohort?CadenceHow fresh?CompareWhat changed?ActionWho owns it?SQL without an owner is inventorySQL with a tested response becomes a security control

Which osquery query examples should every team run?

Start with fleet truth, software, persistence, configuration, and investigation pivots. Each query below uses the osquery SQLite dialect and current table names. Platform support still varies. The official osquery SQL guide says some tables require a path or another constraint. Keep those inputs narrow, and verify every statement against the schema shipped with your agent.

Fleet truth

1. Agent version and build

All
SELECT version, build_platform, build_distro FROM osquery_info;
Act: Find unsupported agents before a table or parser change reaches them.

2. Stable host identity

All
SELECT hostname, uuid, cpu_brand, physical_memory FROM system_info;
Act: Reconcile duplicate names and missing inventory records.

3. Operating system version

All
SELECT name, version, major, minor, patch, build FROM os_version;
Act: Route unsupported builds to the platform owner.

4. Recent reboots

All
SELECT days, hours, minutes, total_seconds FROM uptime WHERE total_seconds < 86400;
Act: Explain missing events and verify a remediation restart.

5. Interactive sessions

All
SELECT user, tty, host, time FROM logged_in_users WHERE user <> '';
Act: Separate active users from background service activity.

6. Local accounts

All
SELECT uid, username, directory, shell FROM users WHERE username <> '';
Act: Compare accounts with the approved identity source.

7. Newest processes

All
SELECT pid, name, path, parent, start_time FROM processes ORDER BY start_time DESC LIMIT 25;
Act: Build a short investigation timeline.

8. Processes missing from disk

All
SELECT pid, name, path, cmdline FROM processes WHERE on_disk = 0;
Act: Investigate deleted executables, while allowing for normal software upgrades.

9. Listening ports

All
SELECT pid, port, address, protocol FROM listening_ports WHERE port > 0;
Act: Find unexpected exposure and identify the owning process.

10. Remote process connections

All
SELECT p.pid, p.name, s.remote_address, s.remote_port FROM processes p JOIN process_open_sockets s USING (pid) WHERE s.remote_port > 0;
Act: Review unusual destinations by process, not IP alone.

Software and vulnerability evidence

11. Windows installed programs

Windows
SELECT name, version, install_location, install_date FROM programs WHERE name <> '';
Act: Join exact versions with vulnerability intelligence.

12. Debian packages

Linux
SELECT name, version, source, architecture FROM deb_packages WHERE name <> '';
Act: Use source package names when the advisory tracks source rather than binary packages.

13. RPM packages

Linux
SELECT name, version, release, arch FROM rpm_packages WHERE name <> '';
Act: Preserve release and architecture before comparing versions.

14. macOS applications

macOS
SELECT name, bundle_identifier, bundle_version, path FROM apps WHERE name <> '';
Act: Use the bundle identifier as the stable application key.

15. Homebrew packages

macOS
SELECT name, version, path FROM homebrew_packages WHERE name <> '';
Act: Catch developer tools that normal application inventory misses.

16. Python packages

All
SELECT name, version, path FROM python_packages WHERE name <> '';
Act: Separate package evidence by interpreter path.

17. Node packages

All
SELECT name, version, path FROM npm_packages WHERE name <> '';
Act: Find global and local packages that create supply chain exposure.

18. Chrome extensions

All
SELECT name, version, identifier, profile, path FROM chrome_extensions WHERE name <> '';
Act: Compare identifiers with the approved extension list.

19. Firefox extensions

All
SELECT name, identifier, version, active, type FROM firefox_addons WHERE active = 1;
Act: Review active extensions by identifier, not display name.

20. VS Code extensions

All
SELECT name, version, path FROM vscode_extensions WHERE name <> '';
Act: Include editor plugins in developer workstation risk.

Persistence

21. Cron entries

Linux, macOS
SELECT event, minute, hour, day_of_month, month, day_of_week, command, path FROM crontab;
Act: Flag new commands and paths outside managed locations.

22. Launchd jobs

macOS
SELECT name, path, program, run_at_load, keep_alive FROM launchd;
Act: Compare program paths and persistence behavior with the baseline.

23. Startup items

macOS, Windows
SELECT name, path, type FROM startup_items WHERE path <> '';
Act: Review items outside approved software directories.

24. Scheduled tasks

Windows
SELECT name, action, path, enabled, state FROM scheduled_tasks WHERE enabled = 1;
Act: Inspect the action, account context, and task path together.

25. Windows services

Windows
SELECT name, path, start_type, status, user_account FROM services WHERE start_type <> 'DISABLED';
Act: Find writable or unusual binary paths behind active services.

26. Systemd units

Linux
SELECT id, description, load_state, active_state, sub_state FROM systemd_units WHERE active_state = 'active';
Act: Compare active units with the server role baseline.

27. Automatic execution points

Windows
SELECT name, path, source FROM autoexec WHERE path <> '';
Act: Use one combined Windows view to start persistence triage.

28. Shell command history

Linux, macOS
SELECT uid, command, time FROM shell_history WHERE command <> '' ORDER BY time DESC LIMIT 50;
Act: Use only under an approved investigation and data policy.

29. Authorized SSH keys

Linux, macOS
SELECT uid, algorithm, key_file, comment FROM authorized_keys;
Act: Match each key file and owner with the access inventory.

30. Private SSH keys

Linux, macOS
SELECT uid, path, encrypted FROM user_ssh_keys;
Act: Find unencrypted private keys without collecting key content.

Configuration and exposure

31. Disk encryption

Linux, macOS
SELECT name, uuid, encrypted, type, encryption_status FROM disk_encryption WHERE encrypted = 0;
Act: Confirm whether an exception is real before opening a ticket.

32. Secure Boot state

Linux, Windows
SELECT secure_boot, setup_mode FROM secureboot;
Act: Investigate disabled boot trust on systems that require it.

33. Mounted filesystems

Linux, macOS
SELECT device, path, type, flags FROM mounts WHERE path <> '';
Act: Find unexpected shares, removable media, and unsafe flags.

34. Loaded kernel modules

Linux
SELECT name, size, status, address FROM kernel_modules WHERE name <> '';
Act: Compare loaded modules with the approved host role.

35. Shared resources

Windows
SELECT name, path, description, type FROM shared_resources WHERE name <> '';
Act: Close shares with no owner or business purpose.

36. Interface addresses

All
SELECT interface, address, mask, type FROM interface_addresses WHERE address <> '';
Act: Find interfaces and networks missing from asset records.

37. DNS resolvers

Linux, macOS
SELECT id, type, address, netmask, options FROM dns_resolvers WHERE address <> '';
Act: Detect resolver changes that redirect name lookups.

38. ARP neighbors

All
SELECT address, mac, interface, permanent FROM arp_cache WHERE address <> '';
Act: Use neighbor evidence to scope a local network investigation.

39. Routing table

All
SELECT destination, netmask, gateway, source, interface, type FROM routes WHERE destination <> '';
Act: Review new default routes and unexpected gateways.

40. Certificate inventory

All
SELECT common_name, issuer, not_valid_after, path FROM certificates WHERE common_name <> '';
Act: Route expired and unapproved trust material to the right owner.

Investigation pivots

41. Process tree

All
SELECT p.pid, p.name, p.path, parent.pid AS parent_pid, parent.name AS parent_name FROM processes p LEFT JOIN processes parent ON p.parent = parent.pid;
Act: Judge a process by its parent and path, not its name alone.

42. Process behind a listener

All
SELECT p.pid, p.name, p.path, l.address, l.port FROM listening_ports l JOIN processes p USING (pid) WHERE l.port > 0;
Act: Assign every exposed port to a binary and service owner.

43. Hash a known path

All
SELECT f.path, h.sha256 FROM file f JOIN hash h USING (path) WHERE f.path = '/bin/ls';
Act: Compare a specific artifact with trusted intelligence.

44. macOS code signature

macOS
SELECT path, signed, identifier, team_identifier FROM signature WHERE path = '/Applications/Safari.app';
Act: Verify publisher identity for a specific application.

45. Windows Authenticode

Windows
SELECT path, subject_name, issuer_name, serial_number, result FROM authenticode WHERE path = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe';
Act: Check a named binary before trusting its location.

46. Files in a constrained directory

All
SELECT path, uid, gid, mode, size, mtime FROM file WHERE directory = '/tmp';
Act: Keep file queries bounded to a path with a clear purpose.

47. Recent process events

Linux, macOS with events
SELECT pid, path, cmdline, parent, time FROM process_events WHERE time > strftime('%s', 'now') - 300;
Act: Review short lived processes that a snapshot misses.

48. Recent socket events

Linux, macOS with events
SELECT pid, remote_address, remote_port, time FROM socket_events WHERE time > strftime('%s', 'now') - 300;
Act: Tie brief outbound connections to a process and time.

49. Recent file events

Linux, macOS with events
SELECT target_path, action, uid, time FROM file_events WHERE time > strftime('%s', 'now') - 300;
Act: Confirm what changed inside a monitored path.

50. Recent logins

Linux, macOS
SELECT username, tty, host, time FROM last WHERE time > strftime('%s', 'now') - 86400;
Act: Review account, source, and time against expected access.

How do you turn examples into a production pack?

Do not schedule all 50. Choose one decision for one cohort. Add an explicit column list, platform selector, minimum version, interval, and description. Decide whether you need differential results or full snapshots. Differential mode records added and removed rows. Snapshot mode sends the full answer each time.

The official schedule specification sets snapshot to false and removed row logging to true by default. It permits intervals up to 604,800 seconds and deterministic sharding from 1 to 100 percent. Those controls are your rollout mechanism. Start at one percent, measure, then expand.

Simple math is unforgiving. Fifty hourly queries across 5,000 endpoints create six million executions a day. Even when each query takes only 40 milliseconds, that is 66.7 hours of combined endpoint compute every day, before result storage and analyst review. Ten focused queries at the right cadence beat a giant pack nobody owns.

Schema versions move too. Osquery 5.23.0, released April 25, 2026, added Windows process handle visibility, Linux Secure Boot certificates, process memory YARA scanning, and broader modern package manager coverage. The official 5.23.0 release notes are a reminder that a pack must declare its minimum agent version and test result shape during upgrades.

How should query results be triaged?

Compare results with approved state before opening work. An unknown service is not automatically malicious. A process missing from disk can be a normal upgrade. An open port may belong to an approved developer tool. Add asset role, owner, exposure, change record, and recent activity before assigning severity.

This is where deep endpoint context with AI driven analysis helps Artemes AI separate a real finding from a version or configuration match. A rules based program should demand the same evidence. Every ticket should say what changed, why it matters on this host, who owns it, and how to verify the fix.

For investigation queries, preserve the raw result and collection time. For compliance queries, preserve the expected value, exception, approver, and expiry. For vulnerability queries, preserve package source, version, reachability evidence, and remediation command. One row can support different decisions, but the evidence packet cannot be vague.

Frequently asked questions

Can I paste these queries directly into osqueryi?

Yes, after checking that the table exists on your platform. Event table examples also require collection to be enabled and configured before they return data.

Why do some osquery queries return no rows?

No rows can be a valid answer, an unsupported table, missing permissions, an unmet required constraint, or a collection failure. Check .schema, status logs, and the agent version.

Should every query run on a schedule?

Keep expensive or sensitive pivots for live investigations. Schedule only the evidence whose freshness changes an ongoing decision.

How often should security queries run?

Match the interval to the shortest useful response window. Process events may need minutes. Installed software may need hours. Hardware inventory may need a day. Measure cost on each host cohort.

The takeaway

Pick ten examples, test them on one host per operating system, and write the action beside each result. Remove any query that has no owner. Canary the remaining pack at one percent, measure cost and row volume for a week, then expand. The goal is not 50 scheduled statements. It is a smaller set of questions that consistently ends in owned action.

Continue with the definitive osquery handbook, the SQL writing guide, and the query pack deployment guide. The older threat hunting guide shows how to turn a query into a comparison with a hypothesis.

Artemes AI

Put more evidence behind vulnerability decisions

Artemes AI combines endpoint telemetry, sourced vulnerability intelligence, and analysis with practitioner review so teams can examine the evidence, missing context, and recommended next step together. We are accepting early access requests now.

Alex Gibson, Cofounder and Principal at Artemes AI

Alex Gibson

Cofounder, Principal

Alex writes about configuration drift, operational security evidence, endpoint telemetry, triage supported by AI, and the practical work of turning signals into better remediation decisions.

Osquery
Blue Team
Threat Modeling
Found this useful? Share it.

Get articles like this in your inbox.

Security research and occasional Artemes AI product updates.