Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
PanoptesLinter.cpp File Reference
#include "PanoptesLinter.h"
#include "Configuration.hpp"

Go to the source code of this file.

Functions

bool FileExists (const std::string &filePath)
 Check if a file exists.
void RemoveStringFromVector (std::vector< std::string > &vec, const std::string &str)
 Remove a string from a vector.
bool IsStringInVector (const std::vector< std::string > &vec, const std::string &str)
 Check if a string is in a vector.
int main (int argc, char *argv[])

Variables

std::vector< std::string > AcceptableConfigParams
 The acceptable configuration parameters.
std::vector< std::string > RequiredConfigParams
 The required configuration parameters.

Function Documentation

◆ FileExists()

bool FileExists ( const std::string & filePath)

Check if a file exists.

Parameters
filePathThe path to the file
Returns
True if the file exists, false otherwise

Definition at line 23 of file PanoptesLinter.cpp.

23 {
24 DWORD fileAttributes = GetFileAttributesA(filePath.c_str());
25 return (fileAttributes != INVALID_FILE_ATTRIBUTES &&
26 !(fileAttributes & FILE_ATTRIBUTE_DIRECTORY));
27}

Referenced by main().

◆ IsStringInVector()

bool IsStringInVector ( const std::vector< std::string > & vec,
const std::string & str )

Check if a string is in a vector.

Parameters
vecThe vector to check
strThe string to check
Returns
True if the string is in the vector, false otherwise

Definition at line 40 of file PanoptesLinter.cpp.

40 {
41 return std::find(vec.begin(), vec.end(), str) != vec.end();
42}

Referenced by main().

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 44 of file PanoptesLinter.cpp.

44 {
45 bool goodConfig = false;
46
47 if (argc < 2) {
48 std::cerr << "[!] Missing configuration file path" << std::endl;
49 return 1;
50 }
51
52 if (!FileExists(argv[1])) {
53 std::cerr << "[!] Configuration file does not exist: " << argv[1] << std::endl;
54 return 1;
55 }
56
57#pragma region Checking if the configuration file is a valid JSON file
58 Configuration config = Configuration(argv[1]);
59 try {
60 config.IsValidJson();
61 }
62 catch (const nlohmann::json::parse_error& e) {
63 std::cerr << "JSON parse error: " << e.what() << std::endl;
64 }
65 catch (const std::runtime_error& e) {
66 //Checking for the error in the configuration file
67 std::cerr << "[!] Error: " << e.what() << std::endl;
68 }
69#pragma endregion
70
71#pragma region Check for unknown keys
72 std::vector<std::string> keys;
73 try {
74 keys = config.GetJsonKeys();
75 }
76 catch (const std::runtime_error& e) {
77 std::cerr << "[!] Error: " << e.what() << std::endl;
78 }
79
80 for (const auto& key : keys) {
82 std::cerr << "[!] Invalid Panoptes Configuration Key: " << key << std::endl;
83 goodConfig = false;
84 continue;
85 }
86 }
87
88#pragma endregion
89
90#pragma region Check for required keys
91 // Check for required keys
92 for (const auto& key : keys) {
95 }
96 }
97
98 //Printing out the missing required keys
99 if (RequiredConfigParams.size() > 0) {
100 std::cerr << "[!] Missing Required Panoptes Configuration Key(s): " << std::endl;
101 for (const auto& key : RequiredConfigParams) {
102 std::cerr << key << std::endl;
103 }
104 std::cerr << std::endl;
105 }
106
107 if (RequiredConfigParams.size() == 0) {
108 goodConfig = true;
109 }
110#pragma endregion
111
112#pragma region Check setting types
113 if (goodConfig) {
114 try {
115 config.ValidateSettings();
116 }
117 catch (const std::exception& e) {
118 std::cerr << "[!] Error: " << e.what() << std::endl;
119 goodConfig = false;
120 }
121 }
122#pragma endregion
123
124 end:
125 if (goodConfig) {
126 std::cout << "[+] Panoptes Configuration is valid" << std::endl;
127 }
128 else {
129 std::cerr << "[!] Panoptes Configuration is invalid" << std::endl;
130 }
131
132}
bool FileExists(const std::string &filePath)
Check if a file exists.
bool IsStringInVector(const std::vector< std::string > &vec, const std::string &str)
Check if a string is in a vector.
void RemoveStringFromVector(std::vector< std::string > &vec, const std::string &str)
Remove a string from a vector.
std::vector< std::string > AcceptableConfigParams
The acceptable configuration parameters.
std::vector< std::string > RequiredConfigParams
The required configuration parameters.
std::vector< std::string > GetJsonKeys()
Get the keys from the configuration file.
void ValidateSettings()
Check that each setting has the right type, after IsValidJson. Throws std::runtime_error naming the f...
void IsValidJson()
Check if the configuration file is valid.

References AcceptableConfigParams, FileExists(), Configuration::GetJsonKeys(), IsStringInVector(), Configuration::IsValidJson(), RemoveStringFromVector(), RequiredConfigParams, and Configuration::ValidateSettings().

◆ RemoveStringFromVector()

void RemoveStringFromVector ( std::vector< std::string > & vec,
const std::string & str )

Remove a string from a vector.

Parameters
vecThe vector to remove the string from
strThe string to remove

Definition at line 32 of file PanoptesLinter.cpp.

32 {
33 vec.erase(std::remove(vec.begin(), vec.end(), str), vec.end());
34}

Referenced by main().

Variable Documentation

◆ AcceptableConfigParams

std::vector<std::string> AcceptableConfigParams
Initial value:
= {
"Exclusions",
"QuarantineMaliciousFiles",
"LogExclusions",
"DontInject",
"FileEvents",
"EnforceDetectionActions"
}

The acceptable configuration parameters.

Definition at line 5 of file PanoptesLinter.cpp.

5 {
6 "Exclusions",
7 "QuarantineMaliciousFiles",
8 "LogExclusions",
9 "DontInject",
10 "FileEvents",
11 "EnforceDetectionActions"
12};

Referenced by main().

◆ RequiredConfigParams

std::vector<std::string> RequiredConfigParams
Initial value:
= {
"Exclusions",
"QuarantineMaliciousFiles"
}

The required configuration parameters.

Definition at line 15 of file PanoptesLinter.cpp.

15 {
16 "Exclusions",
17 "QuarantineMaliciousFiles"
18};

Referenced by main().