Skip to content

Commit

Permalink
Filebeat: osquery module (#5971)
Browse files Browse the repository at this point in the history
* Filebeat Osquery module

This adds a Filebeat module for centralising osquery logs.

osqueryd writes the results in JSON, which makes it fairly easy to ingest to the Elastic stack. The module uses the JSON decoding support in Filebeat, and then renames the fields to match the Beats naming conventions (most fields prefixed with osquery.result). There is an option (use_namespace: false) to leave the fields as they were in the original JSON, but changing that settings makes the sample dashboards unusable.

This module comes with two dashboards, one for the compliance pack in osquery, the other for the ossec-rootkit pack.

* Set read_timestamp

* Clarified the unix_timestamp column

* make update

* Rename Kafka module `beat.read_time` to `read_timestamp`, which is documented
  • Loading branch information
tsg authored and kvch committed Jan 10, 2018
1 parent b9d1db8 commit 94ad82c
Show file tree
Hide file tree
Showing 24 changed files with 2,948 additions and 3 deletions.
59 changes: 59 additions & 0 deletions filebeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ grouped in the following categories:
* <<exported-fields-logstash>>
* <<exported-fields-mysql>>
* <<exported-fields-nginx>>
* <<exported-fields-osquery>>
* <<exported-fields-postgresql>>
* <<exported-fields-redis>>
* <<exported-fields-system>>
Expand Down Expand Up @@ -1535,6 +1536,64 @@ type: text
The error message
[[exported-fields-osquery]]
== Osquery fields
Fields exported by the `osquery` module
[float]
== osquery fields
[float]
== result fields
Common fields exported by the result metricset.
[float]
=== `osquery.result.name`
type: keyword
The name of the query that generated this event.
[float]
=== `osquery.result.action`
type: keyword
For incremental data, marks whether the entry was added or removed. It can be one of "added", "removed", or "snapshot".
[float]
=== `osquery.result.host_identifier`
type: keyword
The identifier for the host on which the osquery agent is running. Normally the hostname.
[float]
=== `osquery.result.unix_time`
type: long
Unix timestamp of the event, in seconds since the epoch. Used for computing the `@timestamp` column.
[float]
=== `osquery.result.calendar_time`
String representation of the collection time, as formatted by osquery.
[[exported-fields-postgresql]]
== PostgreSQL fields
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions filebeat/docs/modules/osquery.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
////
This file is generated! See scripts/docs_collector.py
////

[[filebeat-module-osquery]]
:modulename: osquery

== Osquery module

The +{modulename}+ module collects and decodes the result logs written by
https://osquery.readthedocs.io/en/latest/introduction/using-osqueryd/[osqueryd]
in the JSON format. To set up osqueryd follow the osquery installation
instructions for your operating system and configure the `filesystem` logging
driver (the default). Make sure UTC timestamps are enabled.

include::../include/what-happens.asciidoc[]


[float]
=== Compatibility

The +{modulename}+ module was tested with logs from osquery version 2.10.2.
Since the results are written in the JSON format, it is likely that this module
works with any version of osquery.

This module is available on Linux, macOS, and Windows.

[float]
=== Example dashboard

This module comes with a sample dashboard for visualizing the data collected by
the "compliance" pack. To collect this data, enable the `id-compliance` pack in
the osquery configuration file.

[role="screenshot"]
image::./images/kibana-osquery-compatibility.png[]

include::../include/configuring-intro.asciidoc[]

The following example shows how to set paths in the +modules.d/{modulename}.yml+
file to override the default paths for the syslog and authorization logs:

["source","yaml",subs="attributes"]
-----
- module: osquery
result:
enabled: true
var.paths: ["/path/to/osqueryd.results.log*"]
-----


To specify the same settings at the command line, you use:

["source","sh",subs="attributes"]
-----
./{beatname_lc} --modules {modulename} -M "osquery.result.var.paths=[/path/to/osqueryd.results.log*]"
-----

include::../include/config-option-intro.asciidoc[]

[float]
==== `result` fileset settings

include::../include/var-paths.asciidoc[]

*`var.use_namespace`*::

If true, all fields exported by this module are prefixed with `osquery.result`.
Set to false to copy the fields in the root of the document. If enabled, this
setting also disables the renaming of some fields (e.g. `hostIdentifier` to
`host_identifier`). Note that if you set this to false, the sample dashboards
coming with this module won't work correctly. The default is true.


[float]
=== Fields

For a description of each field in the module, see the
<<exported-fields-osquery,exported fields>> section.

2 changes: 2 additions & 0 deletions filebeat/docs/modules_list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This file is generated! See scripts/docs_collector.py
* <<filebeat-module-logstash>>
* <<filebeat-module-mysql>>
* <<filebeat-module-nginx>>
* <<filebeat-module-osquery>>
* <<filebeat-module-postgresql>>
* <<filebeat-module-redis>>
* <<filebeat-module-system>>
Expand All @@ -26,6 +27,7 @@ include::modules/kafka.asciidoc[]
include::modules/logstash.asciidoc[]
include::modules/mysql.asciidoc[]
include::modules/nginx.asciidoc[]
include::modules/osquery.asciidoc[]
include::modules/postgresql.asciidoc[]
include::modules/redis.asciidoc[]
include::modules/system.asciidoc[]
Expand Down
14 changes: 14 additions & 0 deletions filebeat/filebeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,20 @@ filebeat.modules:
# can be added under this section.
#prospector:

#------------------------------- Osquery Module ------------------------------
- module: osquery
result:
enabled: true

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

# If true, all fields created by this module are prefixed with
# `osquery.result`. Set to false to copy the fields in the root
# of the document. The default is true.
#var.use_namespace: true

#----------------------------- PostgreSQL Module -----------------------------
#- module: postgresql
# Logs
Expand Down
2 changes: 1 addition & 1 deletion filebeat/module/kafka/log/ingest/pipeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
{
"rename": {
"field": "@timestamp",
"target_field": "beat.read_time"
"target_field": "read_timestamp"
}
},
{
Expand Down
12 changes: 12 additions & 0 deletions filebeat/module/osquery/_meta/config.reference.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- module: osquery
result:
enabled: true

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

# If true, all fields created by this module are prefixed with
# `osquery.result`. Set to false to copy the fields in the root
# of the document. The default is true.
#var.use_namespace: true
12 changes: 12 additions & 0 deletions filebeat/module/osquery/_meta/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- module: osquery
result:
enabled: true

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

# If true, all fields created by this module are prefixed with
# `osquery.result`. Set to false to copy the fields in the root
# of the document. The default is true.
#var.use_namespace: true
67 changes: 67 additions & 0 deletions filebeat/module/osquery/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
:modulename: osquery

== Osquery module

The +{modulename}+ module collects and decodes the result logs written by
https://osquery.readthedocs.io/en/latest/introduction/using-osqueryd/[osqueryd]
in the JSON format. To set up osqueryd follow the osquery installation
instructions for your operating system and configure the `filesystem` logging
driver (the default). Make sure UTC timestamps are enabled.

include::../include/what-happens.asciidoc[]


[float]
=== Compatibility

The +{modulename}+ module was tested with logs from osquery version 2.10.2.
Since the results are written in the JSON format, it is likely that this module
works with any version of osquery.

This module is available on Linux, macOS, and Windows.

[float]
=== Example dashboard

This module comes with a sample dashboard for visualizing the data collected by
the "compliance" pack. To collect this data, enable the `id-compliance` pack in
the osquery configuration file.

[role="screenshot"]
image::./images/kibana-osquery-compatibility.png[]

include::../include/configuring-intro.asciidoc[]

The following example shows how to set paths in the +modules.d/{modulename}.yml+
file to override the default paths for the syslog and authorization logs:

["source","yaml",subs="attributes"]
-----
- module: osquery
result:
enabled: true
var.paths: ["/path/to/osqueryd.results.log*"]
-----


To specify the same settings at the command line, you use:

["source","sh",subs="attributes"]
-----
./{beatname_lc} --modules {modulename} -M "osquery.result.var.paths=[/path/to/osqueryd.results.log*]"
-----

include::../include/config-option-intro.asciidoc[]

[float]
==== `result` fileset settings

include::../include/var-paths.asciidoc[]

*`var.use_namespace`*::

If true, all fields exported by this module are prefixed with `osquery.result`.
Set to false to copy the fields in the root of the document. If enabled, this
setting also disables the renaming of some fields (e.g. `hostIdentifier` to
`host_identifier`). Note that if you set this to false, the sample dashboards
coming with this module won't work correctly. The default is true.
9 changes: 9 additions & 0 deletions filebeat/module/osquery/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- key: osquery
title: "Osquery"
description: >
Fields exported by the `osquery` module
fields:
- name: osquery
type: group
description: >
fields:
Loading

6 comments on commit 94ad82c

@jjqq2013
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can i port osquery module back to filebeat5.4.0 by copy these yml?

@ruflin
Copy link
Contributor

@ruflin ruflin commented on 94ad82c Feb 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjqq2013 You caj try but I would not be surprised if it does not work because of some changes we made in the binary and the module side in 6.0. It should be quick to try it out.

@jjqq2013
Copy link

@jjqq2013 jjqq2013 commented on 94ad82c Feb 28, 2018 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjqq2013
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works!

Optionally, I copied osquery mapping json from 6.2.2 to filebeat.template.json

          "osquery": {
            "properties": {
              "result": {
                "properties": {
                  "action": {
                    "ignore_above": 1024,
                    "type": "keyword"
                  },
                  "calendar_time": {
                    "ignore_above": 1024,
                    "type": "keyword"
                  },
                  "columns": {
                    "properties": {
                      "arch": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "blocks": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "blocks_available": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "blocks_free": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "blocks_size": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "device": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "device_alias": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "flags": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "inodes": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "inodes_free": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "name": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "path": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "pid": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "release": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "revision": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "sha1": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "size": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "source": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "type": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      },
                      "version": {
                        "ignore_above": 1024,
                        "type": "keyword"
                      }
                    }
                  },
                  "counter": {
                    "ignore_above": 1024,
                    "type": "keyword"
                  },
                  "epoch": {
                    "ignore_above": 1024,
                    "type": "keyword"
                  },
                  "host_identifier": {
                    "ignore_above": 1024,
                    "type": "keyword"
                  },
                  "name": {
                    "ignore_above": 1024,
                    "type": "keyword"
                  },
                  "unix_time": {
                    "type": "long"
                  }
                }
              }
            }
          }

and change template.overwrite to true in output.elasticsearch section, so the complete filebeat.yml is

filebeat.modules:
- module: osquery
  result:
    enabled: true
    var.paths: ["/var/log/osquery/osqueryd.results.log*", "/var/log/osquery/osqueryd.snapshots.log*"]
filebeat.prospectors:
- input_type: log
  paths:
    - /var/log/*.log
  enabled: false   #I do not harvest these files, so set to false
output.elasticsearch:
  enabled: true
  hosts: ["my_elasticsearch_server:9200"]
  template.overwrite: true   ##
logging.to_files: true
logging.files:

@ruflin
Copy link
Contributor

@ruflin ruflin commented on 94ad82c Mar 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjqq2013 Cool to hear that you got it working and also sharing it here. Making newer modules working with older filebeat versions out of the box would be pretty nice, but we are not there yet. Hopefully upgrading filebeat is also not that bad ;-)

@jjqq2013
Copy link

@jjqq2013 jjqq2013 commented on 94ad82c Mar 4, 2018 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.