osqueryiLaunches the interactive osquery shell for live ad-hoc system querying.
Exposes the operating system as a SQL database: query processes, users, ports, packages and more across Linux, macOS and Windows.
sudo apt install osqueryosqueryiLaunches the interactive osquery shell for live ad-hoc system querying.
osqueryi --helpDisplays the list of available command-line flags and options for the interactive shell.
.helpLists the available meta-commands within the interactive shell environment.
.tablesLists all available tables that can be queried on the current operating system.
.schemaDisplays the structure and column definitions for a specific table.
Example
.schema users.modeSets the output display mode to pretty-print, line, list, or csv for better readability.
Example
.mode pretty.quitExits the interactive osquery shell safely.
SELECT version FROM osquery_info;Retrieves the currently installed version of the osquery agent.
SELECT * FROM system_info;Queries core hardware and operating system details including hostname and memory.
Example
SELECT hostname, cpu_brand, physical_memory FROM system_info;SELECT * FROM uptime;Checks how long the system has been running since the last reboot.
Example
SELECT total_seconds FROM uptime;SELECT * FROM os_version;Details the specific operating system version and build number.
Example
SELECT name, major, minor, patch FROM os_version;SELECT * FROM users;Lists all local user accounts present on the system.
Example
SELECT uid, username, description FROM users;SELECT * FROM groups;Lists all local groups defined on the system.
Example
SELECT gid, groupname FROM groups;SELECT * FROM logged_in_users;Identifies users currently logged into the system and their source.
Example
SELECT user, tty, host, time FROM logged_in_users;SELECT * FROM last;Reviews the history of system logins and reboots.
Example
SELECT username, time, type FROM last;SELECT * FROM processes;Enumerates all currently running processes on the host.
Example
SELECT pid, name, path, cmdline FROM processes;SELECT * FROM process_envs;inspects the environment variables associated with a specific process ID.
Example
SELECT pid, key, value FROM process_envs WHERE pid = 1;SELECT * FROM process_open_files;Lists all file descriptors currently opened by a specific process.
Example
SELECT pid, fd, path FROM process_open_files WHERE pid = <PID>;SELECT * FROM process_memory_map;Examines the memory map of a process to see loaded shared libraries.
Example
SELECT pid, path, permissions FROM process_memory_map WHERE pid = <PID>;SELECT * FROM listening_ports;Identifies ports that are currently in a listening state on the host.
Example
SELECT port, protocol, address FROM listening_ports;SELECT * FROM process_open_sockets;Maps active network sockets to the processes that own them.
Example
SELECT pid, local_port, remote_address, remote_port FROM process_open_sockets;SELECT * FROM interface_addresses;Lists the IP addresses assigned to network interfaces.
Example
SELECT interface, address, mask FROM interface_addresses;SELECT * FROM dns_resolvers;Checks the DNS servers configured for the system.
SELECT * FROM etc_hosts;Reads the static host definitions from the hosts file.
Example
SELECT address, hostnames FROM etc_hosts;SELECT * FROM file;Retrieves metadata for a specific file on the disk.
Example
SELECT path, size, mode, uid FROM file WHERE path = '/etc/passwd';SELECT * FROM hash;Calculates the cryptographic hash (MD5, SHA1, SHA256) of a specific file.
Example
SELECT path, sha256 FROM hash WHERE path = '/bin/ls';Recursive File SearchPerforms a wildcard search for files within a specific directory.
Example
SELECT path, filename FROM file WHERE directory = '/etc/' AND filename LIKE '%.conf';SELECT * FROM deb_packages;Lists installed Debian-based packages (Ubuntu/Debian systems).
Example
SELECT name, version, status FROM deb_packages;SELECT * FROM rpm_packages;Lists installed RPM-based packages (RHEL/CentOS systems).
Example
SELECT name, version, release FROM rpm_packages;SELECT * FROM python_packages;Enumerates globally installed Python libraries.
Example
SELECT name, version FROM python_packages;SELECT * FROM startup_items;Checks for items configured to run automatically at system boot.
Example
SELECT name, path, status FROM startup_items;SELECT * FROM crontab;Audits scheduled cron jobs for all users.
Example
SELECT command, path FROM crontab;SELECT * FROM systemd_units;Inspects systemd services and their current status on Linux systems.
Example
SELECT id, active_state, load_state FROM systemd_units;SELECT * FROM kernel_modules;Lists loaded kernel modules or drivers which could indicate rootkits.
Example
SELECT name, size FROM kernel_modules;osqueryd --flagfileStarts the osquery daemon using a specific flag file for configuration.
Example
osqueryd --flagfile /etc/osquery/osquery.flagsosqueryd --config_checkValidates the syntax of the configuration file without starting the daemon.
osqueryd --verboseEnables verbose logging to standard output for debugging daemon issues.
osqueryd --pidfileSpecifies the location to write the daemon's process ID file.
Example
osqueryd --pidfile /var/run/osqueryd.pidosqueryi --jsonExecutes a query and outputs the result in strict JSON format.
Example
osqueryi --json "SELECT * FROM users"osqueryi --csvExecutes a query and outputs the result in CSV format.
Example
osqueryi --csv "SELECT * FROM users"osqueryd --logger_pluginConfigures the daemon to write logs to the local filesystem.
Example
osqueryd --logger_plugin filesystemosqueryd --logger_pathSets the specific directory where filesystem logs will be stored.
Example
osqueryd --logger_path /var/log/osqueryosqueryd --watchdog_levelSets the strictness of the watchdog process that monitors daemon resource usage.
Example
osqueryd --watchdog_level 3osqueryd --watchdog_memory_limitLimits the memory (in MB) the daemon can use before being restarted.
Example
osqueryd --watchdog_memory_limit 500osqueryd --watchdog_utilization_limitLimits the CPU utilization percentage the daemon is allowed to consume.
Example
osqueryd --watchdog_utilization_limit 20SELECT * FROM process_events;Queries the real-time event buffer for process executions (requires audit enabling).
Example
SELECT pid, path, time FROM process_events;SELECT * FROM file_events;Queries the event buffer for file system changes monitored by FIM configurations.
Example
SELECT target_path, action, time FROM file_events;SELECT * FROM socket_events;Queries the event buffer for network socket connections and binds.
Example
SELECT local_port, remote_address, action FROM socket_events;osqueryd --disable_events=falseEnsures the eventing subsystem is enabled for table based auditing.
osqueryd --events_expirySets the time in seconds before events expire from the internal buffer.
Example
osqueryd --events_expiry 3600osqueryd --tls_hostnameDefines the remote TLS server hostname for configuration and log shipping.
Example
osqueryd --tls_hostname osquery.example.comosqueryd --enroll_secret_pathPoints to the file containing the shared secret used for authenticating to the TLS server.
Example
osqueryd --enroll_secret_path /etc/osquery/enroll.secretosqueryd --config_plugin tlsInstructs the daemon to pull its configuration from the remote TLS server.
JOIN Processes and UsersCorrelates running processes with the specific user account running them.
Example
SELECT p.pid, p.name, u.username FROM processes p JOIN users u ON p.uid = u.uid;JOIN Listening Ports and ProcessesIdentifies exactly which process binary is responsible for an open port.
Example
SELECT p.name, l.port, l.protocol FROM listening_ports l JOIN processes p ON l.pid = p.pid;Verify Firewall RulesAudits the current iptables ruleset to ensure firewall policy compliance.
Example
SELECT * FROM iptables;Check Mount PointsVerifies that filesystems are mounted with correct options (e.g., noexec on tmp).
Example
SELECT device, path, type FROM mounts;Audit SSH KeysLists all public keys authorized to SSH into user accounts.
Example
SELECT * FROM authorized_keys;Detect World Writable FilesScans critical directories for files that are writable by any user.
Example
SELECT path, mode FROM file WHERE directory = '/etc/' AND mode LIKE '%777';Detect Reverse ShellsHunts for common bash reverse shell patterns in command lines.
Example
SELECT * FROM processes WHERE cmdline LIKE '%/dev/tcp/%';Detect Suspicious ParentageIdentifies web server processes spawning unexpected shells.
Example
SELECT p1.name AS parent, p2.name AS child FROM processes p1 JOIN processes p2 ON p1.pid = p2.parent WHERE p1.name = 'httpd' AND p2.name = 'bash';Detect Deleted ExecutablesFinds processes running from binaries that have been deleted from the disk.
Example
SELECT name, pid, on_disk FROM processes WHERE on_disk = 0;Detect High Port TrafficMonitors for connections to non-standard high ports often used for C2.
Example
SELECT * FROM process_open_sockets WHERE remote_port > 1024 AND state = 'ESTABLISHED';Hunt for NetcatScans active processes for the presence of the netcat utility.
Example
SELECT pid, cmdline FROM processes WHERE name = 'nc' OR name = 'netcat';Hunt for Base64 CommandsSearches user shell history for potentially obfuscated base64 commands.
Example
SELECT * FROM shell_history WHERE command LIKE '%base64%';Hash Running ProcessesCalculates the SHA256 hash of the binary for every running process.
Example
SELECT p.name, p.pid, h.sha256 FROM processes p JOIN hash h ON p.path = h.path;Dump Process List JSONExports the full process state to JSON for offline analysis during an incident.
Example
osqueryi --json "SELECT * FROM processes"Dump Open Files JSONCaptures a snapshot of all files held open by processes for forensic review.
Example
osqueryi --json "SELECT * FROM process_open_files"Identify Malware PathQuickly inspects temporary directories for dropped executable payloads.
Example
SELECT path, size FROM file WHERE directory = '/tmp' AND size > 0;Check Sudoers ChangesVerifies the metadata of the sudoers file to check for unauthorized modification.
Example
SELECT * FROM file WHERE path = '/etc/sudoers';Batch Query ExecutionFeeds a file containing multiple SQL queries directly into the osquery shell.
Example
osqueryi < query_list.sqlPack ConfigurationIntrospects the currently loaded query packs defined in the configuration.
Example
SELECT * FROM osquery_packs;Schedule IntrospectionDisplays the execution schedule and performance stats of configured queries.
Example
SELECT * FROM osquery_schedule;Flush LogsForces the daemon to flush logs to the configured backend immediately.
Example
osqueryd --forceKill DaemonTerminates the osquery daemon process (Linux/Unix).
Example
pkill osquerydRemove PidfileManually removes the pidfile if the daemon crashed or did not exit cleanly.
Example
rm /var/run/osqueryd.pidCheck Daemon StatusVerifies from the system shell that the osquery daemon is running.
Example
ps aux | grep osquerydThe Linux Audit daemon: records system calls, file access and command execution according to rules, for compliance and detection.
Microsoft Sysinternals System Monitor: logs process creation, network connections, file changes and more to the Windows (and Linux) event log.
The endpoint agent for the open-source Wazuh SIEM/XDR: log collection, file-integrity monitoring and vulnerability detection.