Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
PanoptesLinter.cpp
Go to the documentation of this file.
1#include "PanoptesLinter.h"
2#include "Configuration.hpp"
3
5std::vector<std::string> AcceptableConfigParams = {
6 "Exclusions",
7 "QuarantineMaliciousFiles",
8 "LogExclusions",
9 "DontInject",
10 "FileEvents",
11 "EnforceDetectionActions"
12};
13
15std::vector<std::string> RequiredConfigParams = {
16 "Exclusions",
17 "QuarantineMaliciousFiles"
18};
19
23bool FileExists(const std::string& filePath) {
24 DWORD fileAttributes = GetFileAttributesA(filePath.c_str());
25 return (fileAttributes != INVALID_FILE_ATTRIBUTES &&
26 !(fileAttributes & FILE_ATTRIBUTE_DIRECTORY));
27}
28
32void RemoveStringFromVector(std::vector<std::string>& vec, const std::string& str) {
33 vec.erase(std::remove(vec.begin(), vec.end(), str), vec.end());
34}
35
40bool IsStringInVector(const std::vector<std::string>& vec, const std::string& str) {
41 return std::find(vec.begin(), vec.end(), str) != vec.end();
42}
43
44int main(int argc, char* argv[]) {
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.
int main()
Loads the hook DLL for this architecture from bin/<config>, one directory above the tests folder this...
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.