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 "ExtensibilitySelected",
7 "Exclusions",
8 "IgnoreDriver",
9 "QuarantineMaliciousFiles",
10 "EventProviders"
11};
12
14std::vector<std::string> RequiredConfigParams = {
15 "ExtensibilitySelected",
16 "EventProviders"
17};
18
22bool FileExists(const std::string& filePath) {
23 DWORD fileAttributes = GetFileAttributesA(filePath.c_str());
24 return (fileAttributes != INVALID_FILE_ATTRIBUTES &&
25 !(fileAttributes & FILE_ATTRIBUTE_DIRECTORY));
26}
27
31void RemoveStringFromVector(std::vector<std::string>& vec, const std::string& str) {
32 vec.erase(std::remove(vec.begin(), vec.end(), str), vec.end());
33}
34
39bool IsStringInVector(const std::vector<std::string>& vec, const std::string& str) {
40 return std::find(vec.begin(), vec.end(), str) != vec.end();
41}
42
43int main(int argc, char* argv[]) {
44 bool goodConfig = false;
45
46 if (argc < 2) {
47 std::cerr << "[!] Missing configuration file path" << std::endl;
48 return 1;
49 }
50
51 if (!FileExists(argv[1])) {
52 std::cerr << "[!] Configuration file does not exist: " << argv[1] << std::endl;
53 return 1;
54 }
55
56#pragma region Checking if the configuration file is a valid JSON file
57 Configuration config = Configuration(argv[1]);
58 try {
59 config.IsValidJson();
60 }
61 catch (const nlohmann::json::parse_error& e) {
62 std::cerr << "JSON parse error: " << e.what() << std::endl;
63 }
64 catch (const std::runtime_error& e) {
65 //Checking for the error in the configuration file
66 std::cerr << "[!] Error: " << e.what() << std::endl;
67 }
68#pragma endregion
69
70#pragma region Check for unknown keys
71 std::vector<std::string> keys;
72 try {
73 keys = config.GetJsonKeys();
74 }
75 catch (const std::runtime_error& e) {
76 std::cerr << "[!] Error: " << e.what() << std::endl;
77 }
78
79 for (const auto& key : keys) {
81 std::cerr << "[!] Invalid Panoptes Configuration Key: " << key << std::endl;
82 goodConfig = false;
83 continue;
84 }
85 }
86
87#pragma endregion
88
89#pragma region Check for required keys
90 // Check for required keys
91 for (const auto& key : keys) {
94 }
95 }
96
97 //Printing out the missing required keys
98 if (RequiredConfigParams.size() > 0) {
99 std::cerr << "[!] Missing Required Panoptes Configuration Key(s): " << std::endl;
100 for (const auto& key : RequiredConfigParams) {
101 std::cerr << key << std::endl;
102 }
103 std::cerr << std::endl;
104 }
105
106 if (RequiredConfigParams.size() == 0) {
107 goodConfig = true;
108 }
109#pragma endregion
110
111 end:
112 if (goodConfig) {
113 std::cout << "[+] Panoptes Configuration is valid" << std::endl;
114 }
115 else {
116 std::cerr << "[!] Panoptes Configuration is invalid" << std::endl;
117 }
118
119}
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 IsValidJson()
Check if the configuration file is valid.
unsigned long DWORD
Definition inject.h:2
int main()
Definition scan_cli.cpp:11