2021-08-23 01:13:54 +02:00
|
|
|
# Osquery
|
|
|
|
|
|
|
|
* [Documentation](https://osquery.readthedocs.io/en/stable/)
|
2022-11-08 00:48:19 +01:00
|
|
|
* [Schema Docs](https://osquery.io/schema/5.5.1/)
|
2021-08-23 01:13:54 +02:00
|
|
|
|
|
|
|
## Usage
|
2022-11-08 00:48:19 +01:00
|
|
|
|
|
|
|
* `osqueryi .help` is the overiew
|
2021-08-23 01:13:54 +02:00
|
|
|
|
|
|
|
### List available tables
|
2022-11-08 00:48:19 +01:00
|
|
|
|
|
|
|
List an overview of all available topics which can be queried.
|
2021-08-23 01:13:54 +02:00
|
|
|
```sh
|
|
|
|
.tables
|
|
|
|
```
|
|
|
|
* Specify via `.tables <tablename>`
|
|
|
|
|
|
|
|
### Show schema
|
2022-11-08 00:48:19 +01:00
|
|
|
|
2021-08-23 01:13:54 +02:00
|
|
|
```sh
|
|
|
|
.schema <table_name>
|
|
|
|
```
|
|
|
|
* Show schema for foreign operating systems via `--enable_foreign`
|
|
|
|
|
|
|
|
### Queries
|
|
|
|
|
2022-11-08 00:48:19 +01:00
|
|
|
* Select
|
2021-08-23 01:13:54 +02:00
|
|
|
```sql
|
|
|
|
select * from <table>;
|
|
|
|
select * <attr>,<attr> from <table>;
|
|
|
|
```
|
|
|
|
|
|
|
|
* UPDATE and DELETE is possible on run-time tables
|
|
|
|
|
|
|
|
* JOIN
|
|
|
|
```sql
|
|
|
|
SELECT pid, name, path FROM osquery_info JOIN processes USING (pid);
|
|
|
|
```
|
|
|
|
|
2022-11-08 00:48:19 +01:00
|
|
|
* Where
|
|
|
|
```sql
|
|
|
|
select * from programs where name = 'paint';
|
|
|
|
```
|
|
|
|
|
2021-08-23 01:13:54 +02:00
|
|
|
* Where clause operators
|
|
|
|
* `=` [equal]
|
|
|
|
* `<>` [not equal]
|
|
|
|
* `>, >=` [greater than, greater than or equal to]
|
|
|
|
* `<, <=` [less than or less than or equal to]
|
|
|
|
* `BETWEEN` [between a range]
|
|
|
|
* `LIKE` [pattern wildcard searches]
|
|
|
|
* `%` [wildcard, multiple characters]
|
|
|
|
* `_` [wildcard, one character]
|
|
|
|
|
|
|
|
* Matching wildcard rules
|
|
|
|
* `%`: Match all files and folders for one level.
|
|
|
|
* `%%`: Match all files and folders recursively.
|
|
|
|
* `%abc`: Match all within-level ending in "abc".
|
|
|
|
* `abc%`: Match all within-level starting with "abc".
|
|
|
|
|
2022-11-08 00:48:19 +01:00
|
|
|
* Table 'userassist' stores executed processes
|
|
|
|
|
|
|
|
## Modes
|
|
|
|
|
|
|
|
There are multiple modes to select from to show the data
|
|
|
|
|
|
|
|
```sh
|
|
|
|
osqueryi
|
|
|
|
osqueryi> .mode .help
|
|
|
|
```
|
|
|
|
|
2021-08-23 01:13:54 +02:00
|
|
|
## Remote Queries via Frontend
|
2022-11-08 00:48:19 +01:00
|
|
|
|
2021-08-23 01:13:54 +02:00
|
|
|
* [Repo](https://github.com/fleetdm/fleet.git)
|
|
|
|
|
|
|
|
## Extensions
|
2022-11-08 00:48:19 +01:00
|
|
|
|
2021-08-23 01:13:54 +02:00
|
|
|
* [osquery-extensions](https://github.com/trailofbits/osquery-extensions)
|
|
|
|
* [osq-ext-bin](https://github.com/polylogyx/osq-ext-bin)
|
|
|
|
|
|
|
|
### Yara
|
2022-11-08 00:48:19 +01:00
|
|
|
|
2021-08-23 01:13:54 +02:00
|
|
|
```sql
|
|
|
|
select * from yara where sigfile='<sigfile>' and path like '/home/%%';
|
|
|
|
```
|
|
|
|
* [Docs](https://osquery.readthedocs.io/en/stable/deployment/yara/)
|
|
|
|
|
|
|
|
|