Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
Functions | Variables
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 22 of file PanoptesLinter.cpp.

22 {
23 DWORD fileAttributes = GetFileAttributesA(filePath.c_str());
24 return (fileAttributes != INVALID_FILE_ATTRIBUTES &&
25 !(fileAttributes & FILE_ATTRIBUTE_DIRECTORY));
26}
unsigned long DWORD
Definition inject.h:2

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 39 of file PanoptesLinter.cpp.

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

Referenced by main().

◆ main()

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

Definition at line 43 of file PanoptesLinter.cpp.

43 {
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.

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

◆ RemoveStringFromVector()

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

Remove a string from a vector.

Remove a string from a vector

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

Definition at line 31 of file PanoptesLinter.cpp.

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

Referenced by main().

Variable Documentation

◆ AcceptableConfigParams

std::vector<std::string> AcceptableConfigParams
Initial value:
= {
"ExtensibilitySelected",
"Exclusions",
"IgnoreDriver",
"QuarantineMaliciousFiles",
"EventProviders"
}

The acceptable configuration parameters.

Definition at line 5 of file PanoptesLinter.cpp.

5 {
6 "ExtensibilitySelected",
7 "Exclusions",
8 "IgnoreDriver",
9 "QuarantineMaliciousFiles",
10 "EventProviders"
11};

Referenced by main().

◆ RequiredConfigParams

std::vector<std::string> RequiredConfigParams
Initial value:
= {
"ExtensibilitySelected",
"EventProviders"
}

The required configuration parameters.

Definition at line 14 of file PanoptesLinter.cpp.

14 {
15 "ExtensibilitySelected",
16 "EventProviders"
17};

Referenced by main().