Monitoring Mac Laptops With Apache NiFi and osquery
Monitoring Mac Laptops With Apache NiFi and osquery
Either download or brew cask install. https://osquery.readthedocs.io/en/2.11.2/installation/install-osx/
I setup a simple configuration here: (https://github.com/tspannhw/nifi-osquery)
{
"options": {
"config_plugin": "filesystem",
"logger_plugin": "filesystem",
"logger_path": "/var/log/osquery",
"disable_logging": "false",
"disable_events": "false",
"database_path": "/var/osquery/osquery.db",
"utc": "true"
},
"schedule": {
"system_info": {
"query": "SELECT hostname, cpu_brand, physical_memory FROM system_info;",
"interval": 3600
}
},
"decorators": {
"load": [
"SELECT uuid AS host_uuid FROM system_info;",
"SELECT user AS username FROM logged_in_users ORDER BY time DESC LIMIT 1;"
]
},
"packs": {
"osquery-monitoring": "/var/osquery/packs/osquery-monitoring.conf",
"incident-response": "/var/osquery/packs/incident-response.conf",
"it-compliance": "/var/osquery/packs/it-compliance.conf",
"osx-attacks": "/var/osquery/packs/osx-attacks.conf",
"vuln-management": "/var/osquery/packs/vuln-management.conf",
"hardware-monitoring": "/var/osquery/packs/hardware-monitoring.conf",
"ossec-rootkit": "/var/osquery/packs/ossec-rootkit.conf"
}
}
We then turn JSON osquery records into records that can be used for routing, queries, aggregates and ultimately pushing it to Impala/Kudu for rich Cloudera Visual Apps and to Kafka as Schema Aware AVRO to use in Kafka Connect as well as a live continuous query feed to Flink SQL streaming analytic applications.
We could also have osquery push directly to Kafka, but since I am often disconnected from a Kafka server, in offline mode or just want a local buffer for these events lets use Apache NiFi which can run as a single 2GB node on my machine. I can also do local processing of the data and some local alerting if needed.
Once you have the data from one or million machines you can do log aggregation, anomaly detection, predictive maintenance or whatever else you might need to do. Sending this data to Cloudera Data Platform in AWS or Azure and having CML and Visual Apps to store, analyze, report, query, build apps, build pipelines and ultimately build production machine learning flows on really makes this a simple example of how to take any data and bring it into a full data platform.
References:
- https://community.cloudera.com/t5/Community-Articles/Ingesting-osquery-Into-Apache-Phoenix-using-Apache-NiFi/ta-p/249308
- Source code: https://github.com/tspannhw/nifi-osquery/
- https://osquery.readthedocs.io/en/stable/deployment/log-aggregation/
- https://osquery.readthedocs.io/en/stable/deployment/anomaly-detection/
- https://osquery.io/downloads/official/4.5.1
- https://osquery.readthedocs.io/en/stable/installation/install-macos/
- https://osquery.readthedocs.io/en/stable/installation/install-macos/
- https://osquery.readthedocs.io/en/stable/deployment/logging/
- https://holdmybeersecurity.com/2019/04/25/detecting-malicious-downloads-with-osquery-rsyslog-kafka-python3-and-virustotal/