Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
Configuration Class Reference

#include <Configuration.hpp>

Public Types

enum  ContainerType : int { CONTAINER_TYPE_NONE = 0 , CONTAINER_TYPE_YARA = 30 , CONTAINER_TYPE_ML = 31 }
 The type of container that the extensibility is running in. More...

Public Member Functions

 Configuration (std::string configurationPath)
 Constructor for the Configuration class.
void Parse ()
 Parse the configuration file.
void IsValidJson ()
 Check if the configuration file is valid.
void ValidateSettings ()
 Check that each setting has the right type, after IsValidJson. Throws std::runtime_error naming the first invalid setting.
std::vector< std::string > GetJsonKeys ()
 Get the keys from the configuration file.

Static Public Member Functions

static const std::vector< std::string > & FileEventNames ()
 The names FileEvents accepts, one per group of file system events the driver can report. When FileEvents is not set, all of them are reported.
static bool IsPathInList (const std::vector< std::string > &patterns, const std::string &path)
 Check whether a path matches any pattern in an exclusion list. A pattern with no wildcard matches every path that starts with it. A pattern containing * (any run of characters, including ) or ? (a single character) must match the whole path. Matching ignores case. / in the path is treated as \; patterns loaded by Parse are normalized the same way.

Public Attributes

std::vector< std::string > m_exclusions
 Path patterns that are not scanned (see IsPathInList).
bool m_quartine = false
 The quarantine malicious files from the configuration file.
std::vector< std::string > m_logExclusions
 Path patterns whose driver events are not logged (see IsPathInList). Files matching them are still scanned.
std::vector< std::string > m_dontInject
 Processes the driver does not inject the hook DLL into. Each entry is either a file name such as "msedge.exe", matching that image in any folder, or a full path such as "C:\Tools\app.exe" (/ is normalized to ), matching only that image. Compared without regard to case. Sent to the driver with IOCTL_PANOPTES_SET_INJECTION_EXCLUSIONS when the service starts.
std::vector< std::string > m_fileEvents = FileEventNames()
 The groups of file system events the driver reports, from FileEventNames(). Every group if FileEvents is not set. Sent to the driver with IOCTL_PANOPTES_SET_FILE_EVENTS when the service starts.
bool m_enforceDetectionActions = false
 Whether the service carries out the kill and quarantine actions of detector rules. When false (the default) those detections are logged and notified only.

Protected Member Functions

void GetScannerExclusions ()
 Get the scanner exclusions from the configuration file.
void GetQuarantineMaliciousFiles ()
 Get the quarantine malicious files from the configuration file.
void GetLogExclusions ()
 Get the optional log exclusions from the configuration file.
void GetDontInject ()
 Get the optional DontInject list from the configuration file.
void GetFileEvents ()
 Get the optional FileEvents list from the configuration file.
void GetEnforceDetectionActions ()
 Get the optional EnforceDetectionActions setting from the configuration file.

Protected Attributes

nlohmann::json m_data
std::ifstream m_fileStream

Detailed Description

Definition at line 7 of file Configuration.hpp.

Member Enumeration Documentation

◆ ContainerType

The type of container that the extensibility is running in.

Enumerator
CONTAINER_TYPE_NONE 
CONTAINER_TYPE_YARA 
CONTAINER_TYPE_ML 

Definition at line 35 of file Configuration.hpp.

Constructor & Destructor Documentation

◆ Configuration()

Configuration::Configuration ( std::string configurationPath)

Constructor for the Configuration class.

Parameters
configurationPathThe path to the configuration file

Definition at line 90 of file Configuration.cpp.

91{
92 m_fileStream = std::ifstream(configurationPath);
93}
std::ifstream m_fileStream

References m_fileStream.

Member Function Documentation

◆ FileEventNames()

const std::vector< std::string > & Configuration::FileEventNames ( )
static

The names FileEvents accepts, one per group of file system events the driver can report. When FileEvents is not set, all of them are reported.

Definition at line 124 of file Configuration.cpp.

125{
126 // The service maps each one to a PANO_FILE_EVENT_GROUP bit (driver.cpp)
127 static const std::vector<std::string> names = {
128 "Create", // files created, overwritten or superseded
129 "Write", // one FileModified event per handle that wrote
130 "DeleteRename", // deletes (including delete-on-close) and renames
131 "PipeMailslot", // named pipe and mailslot creates and opens
132 "Security", // security descriptor (permission/owner) changes
133 "ExtendedAttributes" // extended attribute writes
134 };
135 return names;
136}

Referenced by GetFileEvents(), TEST(), and TEST_F().

◆ GetDontInject()

void Configuration::GetDontInject ( )
protected

Get the optional DontInject list from the configuration file.

Get the optional list of process image names the hook DLL is not injected into.

Definition at line 199 of file Configuration.cpp.

199 {
200 if (!m_data.contains("DontInject")) {
201 return;
202 }
203
204 if (!m_data["DontInject"].is_array()) {
205 throw std::runtime_error("DontInject must be an array of process image names");
206 }
207
208 std::vector<std::string> names = NormalizePatterns(m_data["DontInject"].template get<std::vector<std::string>>());
209 for (const auto& name : names) {
210 if (name.empty()) {
211 throw std::runtime_error("DontInject entries must not be empty");
212 }
213 // * and ? are wildcards. The driver matches with FsRtlIsNameInExpression, which also
214 // treats < > and " as DOS wildcards; they cannot appear in a file name anyway
215 if (name.find_first_of("<>\"") != std::string::npos) {
216 throw std::runtime_error("DontInject entries must not contain < > or \": \"" + name + "\"");
217 }
218 if (name.find('\\') == std::string::npos) {
219 continue; // A file name, matched in any folder
220 }
221
222 // A full path. The service converts the drive letter to the NT device the driver sees,
223 // so it must be an absolute path on a drive letter: C:\Folder\app.exe
224 bool absoluteDrivePath = name.size() > 3 && std::isalpha((unsigned char)name[0]) &&
225 name[1] == ':' && name[2] == '\\' && name.back() != '\\';
226 if (!absoluteDrivePath) {
227 throw std::runtime_error("DontInject entries must be a file name such as \"msedge.exe\" or a full path such as \"C:\\\\Tools\\\\app.exe\": \"" + name + "\"");
228 }
229 }
230 m_dontInject = names;
231}
nlohmann::json m_data
std::vector< std::string > m_dontInject
Processes the driver does not inject the hook DLL into. Each entry is either a file name such as "mse...

References m_data, and m_dontInject.

Referenced by Parse(), and ValidateSettings().

◆ GetEnforceDetectionActions()

void Configuration::GetEnforceDetectionActions ( )
protected

Get the optional EnforceDetectionActions setting from the configuration file.

Get the optional EnforceDetectionActions setting.

Definition at line 234 of file Configuration.cpp.

234 {
235 if (!m_data.contains("EnforceDetectionActions")) {
236 return;
237 }
238
239 if (!m_data["EnforceDetectionActions"].is_boolean()) {
240 throw std::runtime_error("EnforceDetectionActions must be true or false");
241 }
242 m_enforceDetectionActions = m_data["EnforceDetectionActions"].template get<bool>();
243}
bool m_enforceDetectionActions
Whether the service carries out the kill and quarantine actions of detector rules....

References m_data, and m_enforceDetectionActions.

Referenced by Parse(), and ValidateSettings().

◆ GetFileEvents()

void Configuration::GetFileEvents ( )
protected

Get the optional FileEvents list from the configuration file.

Get the optional list of file event groups the driver reports.

Definition at line 139 of file Configuration.cpp.

139 {
140 if (!m_data.contains("FileEvents")) {
142 return;
143 }
144
145 if (!m_data["FileEvents"].is_array()) {
146 throw std::runtime_error("FileEvents must be an array of event group names");
147 }
148
149 const auto& valid = FileEventNames();
150 std::vector<std::string> names = m_data["FileEvents"].template get<std::vector<std::string>>();
151 for (const auto& name : names) {
152 if (std::find(valid.begin(), valid.end(), name) == valid.end()) {
153 std::string list;
154 for (const auto& validName : valid) {
155 list += (list.empty() ? "" : ", ") + validName;
156 }
157 throw std::runtime_error("Unknown FileEvents entry \"" + name + "\". Valid entries: " + list);
158 }
159 }
160 m_fileEvents = names;
161}
static const std::vector< std::string > & FileEventNames()
The names FileEvents accepts, one per group of file system events the driver can report....
std::vector< std::string > m_fileEvents
The groups of file system events the driver reports, from FileEventNames(). Every group if FileEvents...

References FileEventNames(), m_data, and m_fileEvents.

Referenced by Parse(), and ValidateSettings().

◆ GetJsonKeys()

std::vector< std::string > Configuration::GetJsonKeys ( )

Get the keys from the configuration file.

Returns
A vector of strings containing the keys

Definition at line 247 of file Configuration.cpp.

247 {
248 std::vector<std::string> keys;
249 if (m_data.is_object()) {
250 for (nlohmann::json::const_iterator it = m_data.begin(); it != m_data.end(); ++it) {
251 keys.push_back(it.key());
252 }
253 }
254 else {
255 throw std::runtime_error("The json data object was not set");
256 }
257
258 return keys;
259}

References m_data.

Referenced by main().

◆ GetLogExclusions()

void Configuration::GetLogExclusions ( )
protected

Get the optional log exclusions from the configuration file.

Definition at line 185 of file Configuration.cpp.

185 {
186 if (!m_data.contains("LogExclusions")) {
187 return;
188 }
189
190 if (m_data["LogExclusions"].is_array()) {
191 m_logExclusions = NormalizePatterns(m_data["LogExclusions"].template get<std::vector<std::string>>());
192 }
193 else {
194 throw std::runtime_error("LogExclusions must be an array of paths");
195 }
196}
std::vector< std::string > m_logExclusions
Path patterns whose driver events are not logged (see IsPathInList). Files matching them are still sc...

References m_data, and m_logExclusions.

Referenced by Parse(), and ValidateSettings().

◆ GetQuarantineMaliciousFiles()

void Configuration::GetQuarantineMaliciousFiles ( )
protected

Get the quarantine malicious files from the configuration file.

Definition at line 175 of file Configuration.cpp.

175 {
176 if (m_data["QuarantineMaliciousFiles"].is_boolean()) {
177 m_quartine = m_data["QuarantineMaliciousFiles"].template get<bool>();
178 }
179 else {
180 throw std::runtime_error("QuarantineMaliciousFiles was not set in the the configuration");
181 }
182}
bool m_quartine
The quarantine malicious files from the configuration file.

References m_data, and m_quartine.

Referenced by Parse(), and ValidateSettings().

◆ GetScannerExclusions()

void Configuration::GetScannerExclusions ( )
protected

Get the scanner exclusions from the configuration file.

Definition at line 164 of file Configuration.cpp.

165{
166 if (m_data["Exclusions"].is_array()) {
167 m_exclusions = NormalizePatterns(m_data["Exclusions"].template get<std::vector<std::string>>());
168 }
169 else {
170 throw std::runtime_error("Exclusions was not set in the the configuration");
171 }
172}
std::vector< std::string > m_exclusions
Path patterns that are not scanned (see IsPathInList).

References m_data, and m_exclusions.

Referenced by Parse(), and ValidateSettings().

◆ IsPathInList()

bool Configuration::IsPathInList ( const std::vector< std::string > & patterns,
const std::string & path )
static

Check whether a path matches any pattern in an exclusion list. A pattern with no wildcard matches every path that starts with it. A pattern containing * (any run of characters, including ) or ? (a single character) must match the whole path. Matching ignores case. / in the path is treated as \; patterns loaded by Parse are normalized the same way.

Definition at line 64 of file Configuration.cpp.

65{
66 std::string normalizedPath = NormalizeSeparators(path);
67
68 for (const auto& pattern : patterns) {
69 if (pattern.empty()) {
70 continue;
71 }
72
73 if (pattern.find_first_of("*?") != std::string::npos) {
74 if (WildcardMatch(pattern, normalizedPath)) {
75 return true;
76 }
77 }
78 else if (normalizedPath.size() >= pattern.size() &&
79 _strnicmp(normalizedPath.c_str(), pattern.c_str(), pattern.size()) == 0) {
80 return true;
81 }
82 }
83 return false;
84}
bool WildcardMatch(const char *pattern, const char *text)
Matches text against a pattern where '*' matches any run of characters.

Referenced by ShippedConfiguration::LogExcluded(), RespondToDetection(), ShippedConfiguration::ScanExcluded(), SelfQueuePeScan(), TEST(), and TEST().

◆ IsValidJson()

void Configuration::IsValidJson ( )

Check if the configuration file is valid.

Definition at line 108 of file Configuration.cpp.

109{
110 m_data = nlohmann::json::parse(m_fileStream);
111}

References m_data, and m_fileStream.

Referenced by main().

◆ Parse()

void Configuration::Parse ( )

Parse the configuration file.

Definition at line 96 of file Configuration.cpp.

97{
98 m_data = nlohmann::json::parse(m_fileStream);
105}
void GetLogExclusions()
Get the optional log exclusions from the configuration file.
void GetScannerExclusions()
Get the scanner exclusions from the configuration file.
void GetQuarantineMaliciousFiles()
Get the quarantine malicious files from the configuration file.
void GetEnforceDetectionActions()
Get the optional EnforceDetectionActions setting from the configuration file.
void GetFileEvents()
Get the optional FileEvents list from the configuration file.
void GetDontInject()
Get the optional DontInject list from the configuration file.

References GetDontInject(), GetEnforceDetectionActions(), GetFileEvents(), GetLogExclusions(), GetQuarantineMaliciousFiles(), GetScannerExclusions(), m_data, and m_fileStream.

Referenced by WinMain().

◆ ValidateSettings()

void Configuration::ValidateSettings ( )

Check that each setting has the right type, after IsValidJson. Throws std::runtime_error naming the first invalid setting.

Check that each setting has the right type, after IsValidJson.

Definition at line 114 of file Configuration.cpp.

References GetDontInject(), GetEnforceDetectionActions(), GetFileEvents(), GetLogExclusions(), GetQuarantineMaliciousFiles(), and GetScannerExclusions().

Referenced by main().

Member Data Documentation

◆ m_data

◆ m_dontInject

std::vector<std::string> Configuration::m_dontInject

Processes the driver does not inject the hook DLL into. Each entry is either a file name such as "msedge.exe", matching that image in any folder, or a full path such as "C:\Tools\app.exe" (/ is normalized to ), matching only that image. Compared without regard to case. Sent to the driver with IOCTL_PANOPTES_SET_INJECTION_EXCLUSIONS when the service starts.

Definition at line 56 of file Configuration.hpp.

Referenced by GetDontInject(), and WinMain().

◆ m_enforceDetectionActions

bool Configuration::m_enforceDetectionActions = false

Whether the service carries out the kill and quarantine actions of detector rules. When false (the default) those detections are logged and notified only.

Definition at line 65 of file Configuration.hpp.

Referenced by GetEnforceDetectionActions(), and RespondToDetection().

◆ m_exclusions

std::vector<std::string> Configuration::m_exclusions

Path patterns that are not scanned (see IsPathInList).

Definition at line 42 of file Configuration.hpp.

Referenced by GetScannerExclusions(), and RespondToDetection().

◆ m_fileEvents

std::vector<std::string> Configuration::m_fileEvents = FileEventNames()

The groups of file system events the driver reports, from FileEventNames(). Every group if FileEvents is not set. Sent to the driver with IOCTL_PANOPTES_SET_FILE_EVENTS when the service starts.

Definition at line 61 of file Configuration.hpp.

Referenced by GetFileEvents(), and WinMain().

◆ m_fileStream

std::ifstream Configuration::m_fileStream
protected

Definition at line 10 of file Configuration.hpp.

Referenced by Configuration(), IsValidJson(), and Parse().

◆ m_logExclusions

std::vector<std::string> Configuration::m_logExclusions

Path patterns whose driver events are not logged (see IsPathInList). Files matching them are still scanned.

Definition at line 49 of file Configuration.hpp.

Referenced by GetLogExclusions(), and StartDriverEvents().

◆ m_quartine

bool Configuration::m_quartine = false

The quarantine malicious files from the configuration file.

Definition at line 45 of file Configuration.hpp.

Referenced by GetQuarantineMaliciousFiles().


The documentation for this class was generated from the following files: