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
10public:
11 std::unique_ptr<PanoptesService::Stub> Stub;
12};
13
14// Debug builds of the service run unelevated and publish the port under HKCU
15#ifdef _DEBUG
16#define PANOPTES_REG_ROOT HKEY_CURRENT_USER
17#else
18#define PANOPTES_REG_ROOT HKEY_LOCAL_MACHINE
19#endif // _DEBUG
20
24bool GetRegistryPortValue(DWORD& portValue) {
25 HKEY hKey;
26 DWORD dwType = REG_DWORD;
27 DWORD dwSize = sizeof(DWORD);
28
29 // Open the key
30 LONG lResult = RegOpenKeyExA(
32 "SOFTWARE\\Panoptes",
33 0,
34 KEY_READ,
35 &hKey
36 );
37
38 if (lResult != ERROR_SUCCESS) {
39 std::cerr << "Error opening registry key. Error code: " << lResult << std::endl;
40 return false;
41 }
42
43 // Read the SRV_PORT value
44 lResult = RegQueryValueExA(
45 hKey,
46 "SRV_PORT",
47 NULL,
48 &dwType,
49 reinterpret_cast<LPBYTE>(&portValue),
50 &dwSize
51 );
52
53 RegCloseKey(hKey);
54
55 if (lResult != ERROR_SUCCESS) {
56 std::cerr << "Error reading registry value. Error code: " << lResult << std::endl;
57 return false;
58 }
59
60 if (dwType != REG_DWORD) {
61 std::cerr << "Unexpected value type in registry." << std::endl;
62 return false;
63 }
64
65 return true;
66}
67
70 DWORD SERVICE_PORT = 0;
72 std::string server_url = "localhost:0" + std::to_string(SERVICE_PORT);
73 std::shared_ptr<grpc::Channel> channel = grpc::CreateChannel(server_url, grpc::InsecureChannelCredentials());
74 m_stub = std::make_unique<PanoptesService_Stub_Holder>();
75 m_stub->Stub = PanoptesService::NewStub(channel);
76}
77
78bool PanoptesServiceClient::QueuePeScan(const std::string& PePath, const std::string& FileHash, bool Poll, ScanReply& Reply, std::string& Error) {
79 AckMessage reply;
80 ClientContext context;
81 // The service only queues the scans; it answers quickly
82 context.set_deadline(std::chrono::system_clock::now() + std::chrono::seconds(30));
83
84 PeScanInfo request;
85 request.set_file_hash(FileHash);
86 request.set_portable_executable_path(PePath);
87 request.set_poll(Poll);
88
89 Status status = m_stub->Stub->QueuePeScan(&context, request, &reply);
90 if (!status.ok()) {
91 Error = status.error_message();
92 return false;
93 }
94 Reply.Results = reply.message();
95 Reply.FileHash = reply.file_hash();
96 Reply.Pending.assign(reply.pending_scans().begin(), reply.pending_scans().end());
97 return true;
98}
99
#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.
std::unique_ptr< PanoptesService::Stub > Stub
#define PANOPTES_REG_ROOT
Definition container.cpp:24
bool GetRegistryPortValue(DWORD &portValue)
Get the gRPC port value from the registry.
Definition container.cpp:30
bool GetRegistryPortValue(DWORD &portValue)
Get the Panoptes Service port value from the registry.
What the service answered a scan request with.
std::vector< std::string > Pending
std::string Results
std::string FileHash