Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
scanner_ipc.cpp
Go to the documentation of this file.
1#include <grpcpp/grpcpp.h>
2#include "panoptes.grpc.pb.h"
3#include "scanner_ipc.hpp"
4
5using grpc::Channel;
6using grpc::ClientContext;
7using grpc::Status;
8
9std::unique_ptr<PanoptesService::Stub> stub_;
10
11// Debug builds of the service run unelevated and publish the port under HKCU
12#ifdef _DEBUG
13#define PANOPTES_REG_ROOT HKEY_CURRENT_USER
14#else
15#define PANOPTES_REG_ROOT HKEY_LOCAL_MACHINE
16#endif // _DEBUG
17
21bool GetRegistryPortValue(DWORD& portValue) {
22 HKEY hKey;
23 DWORD dwType = REG_DWORD;
24 DWORD dwSize = sizeof(DWORD);
25
26 // Open the key
27 LONG lResult = RegOpenKeyExA(
29 "SOFTWARE\\Panoptes",
30 0,
31 KEY_READ,
32 &hKey
33 );
34
35 if (lResult != ERROR_SUCCESS) {
36 std::cerr << "Error opening registry key. Error code: " << lResult << std::endl;
37 return false;
38 }
39
40 // Read the SRV_PORT value
41 lResult = RegQueryValueExA(
42 hKey,
43 "SRV_PORT",
44 NULL,
45 &dwType,
46 reinterpret_cast<LPBYTE>(&portValue),
47 &dwSize
48 );
49
50 RegCloseKey(hKey);
51
52 if (lResult != ERROR_SUCCESS) {
53 std::cerr << "Error reading registry value. Error code: " << lResult << std::endl;
54 return false;
55 }
56
57 if (dwType != REG_DWORD) {
58 std::cerr << "Unexpected value type in registry." << std::endl;
59 return false;
60 }
61
62 return true;
63}
64
67 DWORD SERVICE_PORT;
69 std::string server_url = "localhost:0" + std::to_string(SERVICE_PORT);
70 std::shared_ptr<grpc::Channel> channel = grpc::CreateChannel(server_url, grpc::InsecureChannelCredentials());
71 stub_ = PanoptesService::NewStub(channel);
72}
73
79bool PanoptesServiceClient::QueuePeScan(std::string PePath, std::string FileHash, std::string& message) {
80 AckMessage reply;
81 ClientContext context;
82 std::chrono::system_clock::time_point deadline = std::chrono::system_clock::now() + std::chrono::milliseconds(8000); // 8 second timeout
83 context.set_deadline(deadline);
84 PeScanInfo request;
85 request.set_file_hash(FileHash);
86 request.set_portable_executable_path(PePath);
87
88 Status status = stub_->QueuePeScan(&context, request, &reply);
89 if (!status.ok()) {
90 if (status.error_code() != grpc::StatusCode::UNKNOWN || status.error_code() != grpc::StatusCode::DEADLINE_EXCEEDED) {
91 message = status.error_message();
92 return false;
93 }
94 }
95
96 return true;
97}
#define SERVICE_PORT
PanoptesServiceClient()
The PanoptesServiceClient class is a class that implements the PanoptesServiceClient class.
bool QueuePeScan(std::string PePath, std::string FileHash, std::string &message)
Send a request to the Panoptes Service to scan a PE file.
#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 value from the registry.