Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
service_client_yara.cpp
Go to the documentation of this file.
1#include <grpcpp/grpcpp.h>
2#include "panoptes.grpc.pb.h"
3#include "PanoptesYara.h"
4
5using grpc::ClientContext;
6using grpc::Status;
7
8std::unique_ptr<PanoptesService::Stub> stub_;
9
10// Debug builds of the service run unelevated and publish the port under HKCU
11#ifdef _DEBUG
12#define PANOPTES_REG_ROOT HKEY_CURRENT_USER
13#else
14#define PANOPTES_REG_ROOT HKEY_LOCAL_MACHINE
15#endif // _DEBUG
16
20bool GetRegistryPortValue(DWORD& portValue) {
21 HKEY hKey;
22 DWORD dwType = REG_DWORD;
23 DWORD dwSize = sizeof(DWORD);
24
25 // Open the key
26 LONG lResult = RegOpenKeyExA(
28 "SOFTWARE\\Panoptes",
29 0,
30 KEY_READ,
31 &hKey
32 );
33
34 if (lResult != ERROR_SUCCESS) {
35 std::cerr << "Error opening registry key. Error code: " << lResult << std::endl;
36 return false;
37 }
38
39 // Read the SRV_PORT value
40 lResult = RegQueryValueExA(
41 hKey,
42 "SRV_PORT",
43 NULL,
44 &dwType,
45 reinterpret_cast<LPBYTE>(&portValue),
46 &dwSize
47 );
48
49 RegCloseKey(hKey);
50
51 if (lResult != ERROR_SUCCESS) {
52 std::cerr << "Error reading registry value. Error code: " << lResult << std::endl;
53 return false;
54 }
55
56 if (dwType != REG_DWORD) {
57 std::cerr << "Unexpected value type in registry." << std::endl;
58 return false;
59 }
60
61 return true;
62}
63
66 DWORD portValue;
67 if (!GetRegistryPortValue(portValue)) {
68 std::cerr << "Failed to get registry port value." << std::endl;
69 return;
70 }
71 std::string server_url = "localhost:" + std::to_string(portValue);
72 std::shared_ptr<grpc::Channel> channel = grpc::CreateChannel(server_url, grpc::InsecureChannelCredentials());
73 stub_ = PanoptesService::NewStub(channel);
74}
75
81bool PanoptesServiceClient::Hello(ExtensibilityType extensibilityType, int ContainerPort) {
82 AckMessage reply;
83 ContainerInfo request;
84 ClientContext g_context;
85
86 request.set_container_type((ContainerType)extensibilityType);
87 request.set_grpc_port(ContainerPort);
88
89 Status status = stub_->Hello(&g_context, request, &reply);
90
91 if (!status.ok()) {
92 //std::cout << status.error_code() << ": " << status.error_message() << std::endl;
93 exit(1);
94 }
95
96 return reply.ack_type();
97}
98
105bool PanoptesServiceClient::SendResults_Yara(std::string pePath, std::string fileHash, std::vector<std::string> detectedRules, const SignatureInfo& signature) {
106 ClientContext context;
107 AckMessage reply;
108 ContainerReply request;
109
110 ScanYara results;
111 request.set_portable_executable_path(pePath);
112 request.set_file_hash(fileHash);
113
114 for (auto rule : detectedRules) {
115 results.add_detected_rules(rule);
116 }
117
118 char trustStatus[11];
119 sprintf_s(trustStatus, "0x%08X", static_cast<unsigned long>(signature.trustStatus));
120
121 ScanSignature* signatureResults = results.mutable_signature();
122 signatureResults->set_signed_(signature.isSigned);
123 signatureResults->set_trusted(signature.trusted);
124 signatureResults->set_catalog_signed(signature.catalogSigned);
125 signatureResults->set_signer(signature.signer);
126 signatureResults->set_trust_status(trustStatus);
127
128 request.mutable_yara_scan()->CopyFrom(results);
129
130 Status status = stub_->ScanResults(&context, request, &reply);
131
132 if (!status.ok()) {
133 std::cout << status.error_code() << ": " << status.error_message() << std::endl;
134 exit(1);
135 }
136
137 return reply.ack_type();
138}
ExtensibilityType
The type of extensibility.
bool SendResults_Yara(std::string PePath, std::string FileHash, DWORD ProcessId, std::string YaraRulesPath, INT MatchRules, std::vector< std::string > DetectedRules)
PanoptesServiceClient()
The PanoptesServiceClient class is a class that implements the PanoptesServiceClient class.
bool Hello(ExtensibilityType extensibilityType, std::string port)
The Hello function sends a Hello message to the Panoptes main service from the container.
#define PANOPTES_REG_ROOT
Definition container.cpp:24
bool GetRegistryPortValue(DWORD &portValue)
Get the gRPC port value from the registry.
Definition container.cpp:30
std::unique_ptr< PanoptesService::Stub > stub_
bool GetRegistryPortValue(DWORD &portValue)
Get the Panoptes Service port from the registry.
The result of verifying a file's Authenticode signature with WinVerifyTrust.
bool trusted
True if WinVerifyTrust reported the signature as valid and trusted.
std::string signer
The signing certificate's display name (UTF-8), empty if unsigned.
LONG trustStatus
The WinVerifyTrust result, 0 if trusted.
bool isSigned
True if the file has an embedded or catalog signature.
bool catalogSigned
True if the signature came from a catalog file rather than being embedded.