1#include <grpcpp/grpcpp.h>
2#include "panoptes.grpc.pb.h"
6using grpc::ClientContext;
9static std::unique_ptr<PanoptesService::Stub> g_Stub;
13#define PANOPTES_REG_ROOT HKEY_CURRENT_USER
15#define PANOPTES_REG_ROOT HKEY_LOCAL_MACHINE
19#define PANO_ML_RPC_TIMEOUT_MS 8000
22static bool GetServicePort(DWORD& Port)
24 DWORD size =
sizeof(Port);
25 LONG result = RegGetValueA(
PANOPTES_REG_ROOT,
"SOFTWARE\\Panoptes",
"SRV_PORT", RRF_RT_REG_DWORD, NULL, &Port, &size);
26 if (result != ERROR_SUCCESS) {
27 std::cerr <<
"PanoptesML: cannot read the service port (error " << result <<
")" << std::endl;
35 if (g_Stub !=
nullptr) {
39 if (!GetServicePort(port)) {
42 auto channel = grpc::CreateChannel(
"localhost:" + std::to_string(port), grpc::InsecureChannelCredentials());
43 g_Stub = PanoptesService::NewStub(channel);
46static void SetDeadline(ClientContext& Context)
48 Context.set_deadline(std::chrono::system_clock::now() + std::chrono::milliseconds(
PANO_ML_RPC_TIMEOUT_MS));
53 if (g_Stub ==
nullptr) {
56 ClientContext context;
58 ContainerInfo request;
59 request.set_container_type((ContainerType)Type);
60 request.set_grpc_port(ContainerPort);
63 Status status = g_Stub->Hello(&context, request, &reply);
66 std::cerr <<
"PanoptesML: Hello failed: " << status.error_message() << std::endl;
69 return reply.ack_type() == AckType::SUCCESS;
74 if (g_Stub ==
nullptr) {
77 ClientContext context;
79 ContainerReply request;
80 request.set_portable_executable_path(PePath);
81 request.set_file_hash(FileHash);
83 ScanML* scan = request.mutable_ml_scan();
84 scan->set_score(Result.
Score);
87 scan->set_model(Result.
Model);
89 scan->set_is_pe(Result.
IsPe);
90 scan->set_error(Result.
Error);
93 Status status = g_Stub->ScanResults(&context, request, &reply);
95 std::cerr <<
"PanoptesML: ScanResults failed: " << status.error_message() << std::endl;
98 return reply.ack_type() == AckType::SUCCESS;
ExtensibilityType
The type of extensibility.
#define PANO_ML_THRESHOLD
Score at or above which a file is reported as malicious.
#define PANO_ML_FEATURE_VERSION
Version of the feature layout below. A model is trained for one layout; change this whenever a featur...
PanoptesServiceClient()
The PanoptesServiceClient class is a class that implements the PanoptesServiceClient class.
bool SendResults_ML(const std::string &PePath, const std::string &FileHash, const MlScanResult &Result)
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
#define PANO_ML_RPC_TIMEOUT_MS
One file's result, as sent to the service.