-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ProcessTree: add macos-specific loader and event adapter
- Loading branch information
Showing
6 changed files
with
275 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/// Copyright 2023 Google LLC | ||
/// | ||
/// Licensed under the Apache License, Version 2.0 (the "License"); | ||
/// you may not use this file except in compliance with the License. | ||
/// You may obtain a copy of the License at | ||
/// | ||
/// https://www.apache.org/licenses/LICENSE-2.0 | ||
/// | ||
/// Unless required by applicable law or agreed to in writing, software | ||
/// distributed under the License is distributed on an "AS IS" BASIS, | ||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
/// See the License for the specific language governing permissions and | ||
/// limitations under the License. | ||
#ifndef SANTA__SANTAD_PROCESSTREE_ENDPOINTSECURITYADAPTER_H | ||
#define SANTA__SANTAD_PROCESSTREE_ENDPOINTSECURITYADAPTER_H | ||
|
||
#include <EndpointSecurity/ESTypes.h> | ||
|
||
#include "Source/santad/ProcessTree/tree.h" | ||
|
||
namespace santa::santad::process_tree { | ||
|
||
// Inform the tree of the ES event in msg. | ||
// This is idempotent on the tree, so can be called from multiple places with | ||
// the same msg. | ||
void InformFromESEvent(int client, ProcessTree &tree, const es_message_t *msg); | ||
|
||
} // namespace santa::santad::process_tree | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/// Copyright 2023 Google LLC | ||
/// | ||
/// Licensed under the Apache License, Version 2.0 (the "License"); | ||
/// you may not use this file except in compliance with the License. | ||
/// You may obtain a copy of the License at | ||
/// | ||
/// https://www.apache.org/licenses/LICENSE-2.0 | ||
/// | ||
/// Unless required by applicable law or agreed to in writing, software | ||
/// distributed under the License is distributed on an "AS IS" BASIS, | ||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
/// See the License for the specific language governing permissions and | ||
/// limitations under the License. | ||
#include <EndpointSecurity/EndpointSecurity.h> | ||
#include <Foundation/Foundation.h> | ||
#include <bsm/libbsm.h> | ||
|
||
#include "Source/santad/ProcessTree/process_tree.h" | ||
#include "Source/santad/ProcessTree/process_tree_macos.h" | ||
#include "absl/status/statusor.h" | ||
|
||
namespace santa::santad::process_tree { | ||
|
||
void InformFromESEvent(int client, ProcessTree &tree, const es_message_t *msg) { | ||
if (!tree.Step(client, msg->mach_time)) { | ||
return; | ||
}; | ||
|
||
struct pid event_pid = PidFromAuditToken(msg->process->audit_token); | ||
auto proc = tree.Get(event_pid); | ||
|
||
if (!proc) { | ||
return; | ||
} | ||
|
||
switch (msg->event_type) { | ||
case ES_EVENT_TYPE_AUTH_EXEC: | ||
case ES_EVENT_TYPE_NOTIFY_EXEC: { | ||
std::vector<std::string> args; | ||
args.reserve(es_exec_arg_count(&msg->event.exec)); | ||
for (int i = 0; i < es_exec_arg_count(&msg->event.exec); i++) { | ||
es_string_token_t arg = es_exec_arg(&msg->event.exec, i); | ||
args.push_back(std::string(arg.data, arg.length)); | ||
} | ||
|
||
es_string_token_t executable = msg->event.exec.target->executable->path; | ||
tree.HandleExec( | ||
msg->mach_time, **proc, PidFromAuditToken(msg->event.exec.target->audit_token), | ||
(struct program){.executable = std::string(executable.data, executable.length), | ||
.arguments = args}, | ||
(struct cred){ | ||
.uid = audit_token_to_euid(msg->event.exec.target->audit_token), | ||
.gid = audit_token_to_egid(msg->event.exec.target->audit_token), | ||
}); | ||
|
||
break; | ||
} | ||
case ES_EVENT_TYPE_NOTIFY_FORK: { | ||
tree.HandleFork(msg->mach_time, **proc, | ||
PidFromAuditToken(msg->event.fork.child->audit_token)); | ||
break; | ||
} | ||
case ES_EVENT_TYPE_NOTIFY_EXIT: tree.HandleExit(msg->mach_time, **proc); break; | ||
default: return; | ||
} | ||
} | ||
|
||
} // namespace santa::santad::process_tree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/// Copyright 2023 Google LLC | ||
/// | ||
/// Licensed under the Apache License, Version 2.0 (the "License"); | ||
/// you may not use this file except in compliance with the License. | ||
/// You may obtain a copy of the License at | ||
/// | ||
/// https://www.apache.org/licenses/LICENSE-2.0 | ||
/// | ||
/// Unless required by applicable law or agreed to in writing, software | ||
/// distributed under the License is distributed on an "AS IS" BASIS, | ||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
/// See the License for the specific language governing permissions and | ||
/// limitations under the License. | ||
#ifndef SANTA__SANTAD_PROCESSTREE_TREE_DARWIN_H | ||
#define SANTA__SANTAD_PROCESSTREE_TREE_DARWIN_H | ||
|
||
#include <bsm/libbsm.h> | ||
|
||
namespace santa::santad::process_tree { | ||
|
||
// Create a struct pid from the given audit token. | ||
struct pid PidFromAuditToken(const audit_token_t &tok); | ||
|
||
} // namespace santa::santad::process_tree | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters