mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-08 18:33:54 +00:00
a140333441
This commit contains the features specified in #1390 as well as a refactoring of the general osquery configuration code. The API for the config plugins hasn't changed, although now there's a `genPack` method that config plugins can implement. If a plugin doesn't implement `genPack`, then the map<string, string> format cannot be used. The default config plugin, the filesystem plugin, now implements `genPack`, so existing query packs code will continue to work as it always has. Now many other config plugins can implement custom pack handling for what makes sense in their context. `genPacks` is not a pure virtual, so it doesn't have to be implemented in your plugin if you don't want to use it. Also, more importantly, all config plugins can use the standard inline pack format if they want to use query packs. Which is awesome. For more information, refer to #1390, the documentation and the doxygen comments included with this pull requests, as well as the following example config which is now supported, regardless of what config plugin you're using: ```json { "options": { "enable_monitor": "true" }, "packs": { "core_os_monitoring": { "version": "1.4.5", "discovery": [ "select pid from processes where name like '%osqueryd%';" ], "queries": { "kernel_modules": { "query": "SELECT name, size FROM kernel_modules;", "interval": 600 }, "system_controls": { "query": "SELECT * FROM system_controls;", "interval": 600, "snapshot": true, }, "usb_devices": { "query": "SELECT * FROM usb_devices;", "interval": 600 } } }, "osquery_internal_info": { "version": "1.4.5", "discovery": [ "select pid from processes where name like '%osqueryd%';" ], "queries": { "info": { "query": "select i.*, p.resident_size, p.user_time, p.system_time, time.minutes as counter from osquery_info i, processes p, time where p.pid = i.pid;", "interval": 60, "snapshot": true }, "registry": { "query": "SELECT * FROM osquery_registry;", "interval": 600, "snapshot": true }, "schedule": { "query": "select name, interval, executions, output_size, wall_time, (user_time/executions) as avg_user_time, (system_time/executions) as avg_system_time, average_memory from osquery_schedule;", "interval": 60, "snapshot": true } } } } } ``` The `osquery_packs` table was modified to remove the superfluous columns which could already have been found in `osquery_schedule`. Two more columns were added in their place, representing stats about pack's discovery query execution history. Notably, the internal API for the `osquery::Config` class has changed rather dramatically as apart of the refactoring. We think this is an improvement. While strictly adhering to the osquery config plugin interface will have avoided any compatibility errors, advanced users may notice compilation errors if they access config data directly. All internal users of the config have obviously been updated. Yet another reason to merge your code into mainline; we update it for you when we refactor!
95 lines
2.8 KiB
C++
95 lines
2.8 KiB
C++
/*
|
|
* Copyright (c) 2014, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
*/
|
|
|
|
#include "osquery/events/kernel.h"
|
|
|
|
#include <osquery/config.h>
|
|
#include <osquery/logger.h>
|
|
#include <osquery/filesystem.h>
|
|
|
|
namespace osquery {
|
|
|
|
class FileAccessEventSubscriber
|
|
: public EventSubscriber<KernelEventPublisher> {
|
|
public:
|
|
Status init();
|
|
|
|
Status Callback(const TypedKernelEventContextRef<osquery_file_event_t> &ec,
|
|
const void *user_data);
|
|
};
|
|
|
|
REGISTER(FileAccessEventSubscriber, "event_subscriber", "file_access_events");
|
|
|
|
Status FileAccessEventSubscriber::init() {
|
|
Config::getInstance().files(
|
|
[this](const std::string &, const std::vector<std::string> &files) {
|
|
for (const auto &file : files) {
|
|
auto sc = createSubscriptionContext();
|
|
sc->event_type = OSQUERY_FILE_EVENT;
|
|
osquery_file_event_subscription_t sub = {
|
|
.actions = (osquery_file_action_t)(
|
|
OSQUERY_FILE_ACTION_OPEN | OSQUERY_FILE_ACTION_CLOSE |
|
|
OSQUERY_FILE_ACTION_CLOSE_MODIFIED)};
|
|
auto path = file;
|
|
replaceGlobWildcards(path);
|
|
path = path.substr(0, path.find("*"));
|
|
strncpy(sub.path, path.c_str(), MAXPATHLEN);
|
|
sc->udata = ⊂
|
|
VLOG(1) << "Added kernel listener to: " << path;
|
|
|
|
subscribe(&FileAccessEventSubscriber::Callback, sc, NULL);
|
|
}
|
|
});
|
|
|
|
return Status(0, "OK");
|
|
}
|
|
|
|
Status FileAccessEventSubscriber::Callback(
|
|
const TypedKernelEventContextRef<osquery_file_event_t> &ec,
|
|
const void *user_data) {
|
|
Row r;
|
|
switch (ec->event.action) {
|
|
case OSQUERY_FILE_ACTION_OPEN:
|
|
r["action"] = "OPEN";
|
|
break;
|
|
case OSQUERY_FILE_ACTION_CLOSE:
|
|
r["action"] = "CLOSE";
|
|
break;
|
|
case OSQUERY_FILE_ACTION_CLOSE_MODIFIED:
|
|
r["action"] = "CLOSE MODIFIED";
|
|
break;
|
|
default:
|
|
r["action"] = "UNKNOWN";
|
|
break;
|
|
}
|
|
r["pid"] = BIGINT(ec->event.pid);
|
|
r["parent"] = BIGINT(ec->event.ppid);
|
|
r["uid"] = BIGINT(ec->event.uid);
|
|
r["euid"] = BIGINT(ec->event.euid);
|
|
r["gid"] = BIGINT(ec->event.gid);
|
|
r["egid"] = BIGINT(ec->event.egid);
|
|
r["owner_uid"] = BIGINT(ec->event.owner_uid);
|
|
r["owner_gid"] = BIGINT(ec->event.owner_gid);
|
|
r["create_time"] = BIGINT(ec->event.create_time);
|
|
r["access_time"] = BIGINT(ec->event.access_time);
|
|
r["modify_time"] = BIGINT(ec->event.modify_time);
|
|
r["change_time"] = BIGINT(ec->event.change_time);
|
|
r["mode"] = BIGINT(ec->event.mode);
|
|
r["path"] = ec->event.path;
|
|
r["uptime"] = BIGINT(ec->uptime);
|
|
|
|
add(r, ec->time);
|
|
|
|
return Status(0, "OK");
|
|
}
|
|
|
|
|
|
} // namespace osquery
|