Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
PanoptesServiceClient Class Reference

The Panoptes Service client used to talk to the service over gRPC. More...

#include <container_ipc.hpp>

Public Member Functions

 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.
bool SendResults_Yara (std::string PePath, std::string FileHash, DWORD ProcessId, std::string YaraRulesPath, INT MatchRules, std::vector< std::string > DetectedRules)
 PanoptesServiceClient ()
bool Hello (ExtensibilityType ExtensibilityType, int ContainerPort)
 Send a hello message to the Panoptes Service to bind to the service containing the type of extensibility and the port of the container that the extensibility is running in.
bool SendResults_ML (const std::string &PePath, const std::string &FileHash, const MlScanResult &Result)
 PanoptesServiceClient ()
bool Hello (ExtensibilityType extensibilityType, int ContainerPort)
bool SendResults_Yara (std::string PePath, std::string FileHash, std::vector< std::string > DetectedRules, const SignatureInfo &Signature)
 Send the results of the YARA scan to the Panoptes Service.
 PanoptesServiceClient ()
bool QueuePeScan (std::string PePath, std::string FileHash, std::string &message)
 Send a request to the Panoptes Service to scan a PE file.
 PanoptesServiceClient ()
 ~PanoptesServiceClient ()
 PanoptesServiceClient (const PanoptesServiceClient &)=delete
PanoptesServiceClient & operator= (const PanoptesServiceClient &)=delete
bool QueuePeScan (const std::string &PePath, const std::string &FileHash, bool Poll, ScanReply &Reply, std::string &Error)
 Asks the service to scan a file with every extension that hasn't yet. With Poll, only reads back the stored result and the scans still running (FileHash from an earlier reply, so the file needn't still be there).

Detailed Description

The Panoptes Service client used to talk to the service over gRPC.

The Panoptes Service Client that used to communicate via gRPC.

Definition at line 24 of file container_ipc.hpp.

Constructor & Destructor Documentation

◆ PanoptesServiceClient() [1/6]

PanoptesServiceClient::PanoptesServiceClient ( )

The PanoptesServiceClient class is a class that implements the PanoptesServiceClient class.

Constructor for the Panoptes Service Client.

Constructor for the Panoptes Service Client to set up the connection to the.

Returns
The PanoptesServiceClient class.

Definition at line 15 of file service_client.cpp.

15 {
16 std::string server_url = "localhost:" + std::to_string(SERVICE_PORT);
17 std::shared_ptr<grpc::Channel> channel = grpc::CreateChannel(server_url, grpc::InsecureChannelCredentials());
18 stub_ = PanoptesService::NewStub(channel);
19}
#define SERVICE_PORT
std::unique_ptr< PanoptesService::Stub > stub_

References SERVICE_PORT, and stub_.

Referenced by operator=(), and PanoptesServiceClient().

◆ PanoptesServiceClient() [2/6]

PanoptesServiceClient::PanoptesServiceClient ( )

◆ PanoptesServiceClient() [3/6]

PanoptesServiceClient::PanoptesServiceClient ( )

◆ PanoptesServiceClient() [4/6]

PanoptesServiceClient::PanoptesServiceClient ( )

◆ PanoptesServiceClient() [5/6]

PanoptesServiceClient::PanoptesServiceClient ( )

◆ ~PanoptesServiceClient()

PanoptesServiceClient::~PanoptesServiceClient ( )
default

◆ PanoptesServiceClient() [6/6]

PanoptesServiceClient::PanoptesServiceClient ( const PanoptesServiceClient & )
delete

Member Function Documentation

◆ Hello() [1/3]

bool PanoptesServiceClient::Hello ( ExtensibilityType extensibilityType,
int ContainerPort )

Send a hello message to the Panoptes Service to bind to the service containing the type of extensibility and the port of the container that the extensibility is running in.

Parameters
extensibilityTypeThe type of extensibility, in this case YARA
ContainerPortThe port of the container that the extensibility is running in
Returns
True if the hello message was sent successfully, false otherwise

Definition at line 51 of file service_client_ml.cpp.

52{
53 if (g_Stub == nullptr) {
54 return false;
55 }
56 ClientContext context;
57 SetDeadline(context);
58 ContainerInfo request;
59 request.set_container_type((ContainerType)Type);
60 request.set_grpc_port(ContainerPort);
61
62 AckMessage reply;
63 Status status = g_Stub->Hello(&context, request, &reply);
64 if (!status.ok()) {
65 // The container retries PanoBind with backoff
66 std::cerr << "PanoptesML: Hello failed: " << status.error_message() << std::endl;
67 return false;
68 }
69 return reply.ack_type() == AckType::SUCCESS;
70}

◆ Hello() [2/3]

bool PanoptesServiceClient::Hello ( ExtensibilityType extensibilityType,
int ContainerPort )

◆ Hello() [3/3]

bool PanoptesServiceClient::Hello ( ExtensibilityType extensibilityType,
std::string port )

The Hello function sends a Hello message to the Panoptes main service from the container.

Parameters
extensibilityTypeThe type of extensibility.
portThe port of the Panoptes main service.
Returns
True if the Hello message is sent successfully, false otherwise.

Definition at line 25 of file service_client.cpp.

25 {
26 AckMessage reply;
27 ContainerInfo request;
28 ClientContext g_context;
29
30 int grpc_port = std::stoi(port);
31 request.set_container_type((ContainerType)extensibilityType);
32 request.set_grpc_port(grpc_port);
33
34 Status status = stub_->Hello(&g_context, request, &reply);
35
36 if (!status.ok()) {
37 std::cout << status.error_code() << ": " << status.error_message() << std::endl;
38 return !reply.ack_type();
39 }
40
41 return !reply.ack_type();
42}

References stub_.

Referenced by PanoBind().

◆ operator=()

PanoptesServiceClient & PanoptesServiceClient::operator= ( const PanoptesServiceClient & )
delete

◆ QueuePeScan() [1/2]

bool PanoptesServiceClient::QueuePeScan ( const std::string & PePath,
const std::string & FileHash,
bool Poll,
ScanReply & Reply,
std::string & Error )

Asks the service to scan a file with every extension that hasn't yet. With Poll, only reads back the stored result and the scans still running (FileHash from an earlier reply, so the file needn't still be there).

Returns
False on an error, described in Error

Definition at line 78 of file scanner_ipc.cpp.

78 {
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}
std::vector< std::string > Pending
std::string Results
std::string FileHash

References ScanReply::FileHash, ScanReply::Pending, and ScanReply::Results.

◆ QueuePeScan() [2/2]

bool PanoptesServiceClient::QueuePeScan ( std::string PePath,
std::string FileHash,
std::string & message )

Send a request to the Panoptes Service to scan a PE file.

Parameters
PePathThe path to the PE file
FileHashThe hash of the PE file
messageThe message to send to the Panoptes Service
Returns
True if the request was sent successfully, false otherwise

Definition at line 79 of file scanner_ipc.cpp.

79 {
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}

References stub_.

Referenced by WinMain().

◆ SendResults_ML()

bool PanoptesServiceClient::SendResults_ML ( const std::string & PePath,
const std::string & FileHash,
const MlScanResult & Result )

Definition at line 72 of file service_client_ml.cpp.

73{
74 if (g_Stub == nullptr) {
75 return false;
76 }
77 ClientContext context;
78 SetDeadline(context);
79 ContainerReply request;
80 request.set_portable_executable_path(PePath);
81 request.set_file_hash(FileHash);
82
83 ScanML* scan = request.mutable_ml_scan();
84 scan->set_score(Result.Score);
85 scan->set_threshold(PANO_ML_THRESHOLD);
86 scan->set_malicious(Result.Malicious);
87 scan->set_model(Result.Model);
88 scan->set_feature_version(PANO_ML_FEATURE_VERSION);
89 scan->set_is_pe(Result.IsPe);
90 scan->set_error(Result.Error);
91
92 AckMessage reply;
93 Status status = g_Stub->ScanResults(&context, request, &reply);
94 if (!status.ok()) {
95 std::cerr << "PanoptesML: ScanResults failed: " << status.error_message() << std::endl;
96 return false;
97 }
98 return reply.ack_type() == AckType::SUCCESS;
99}
#define PANO_ML_THRESHOLD
Score at or above which a file is reported as malicious.
Definition PanoptesML.h:14
#define PANO_ML_FEATURE_VERSION
Version of the feature layout below. A model is trained for one layout; change this whenever a featur...
Definition PanoptesML.h:23
std::string Model
Definition PanoptesML.h:115
std::string Error
Definition PanoptesML.h:116

References MlScanResult::Error, MlScanResult::IsPe, MlScanResult::Malicious, MlScanResult::Model, PANO_ML_FEATURE_VERSION, PANO_ML_THRESHOLD, and MlScanResult::Score.

Referenced by PanoEntry().

◆ SendResults_Yara() [1/2]

bool PanoptesServiceClient::SendResults_Yara ( std::string PePath,
std::string FileHash,
DWORD ProcessId,
std::string YaraRulesPath,
INT MatchRules,
std::vector< std::string > DetectedRules )

Referenced by PanoEntry().

◆ SendResults_Yara() [2/2]

bool PanoptesServiceClient::SendResults_Yara ( std::string pePath,
std::string fileHash,
std::vector< std::string > detectedRules,
const SignatureInfo & signature )

Send the results of the YARA scan to the Panoptes Service.

Parameters
pePathThe path of the file that was scanned
fileHashThe hash of the file that was scanned
detectedRulesThe rules that were detected
signatureThe result of verifying the file's signature
Returns
True if the results were sent successfully, false otherwise

Definition at line 105 of file service_client_yara.cpp.

105 {
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}
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.

References SignatureInfo::catalogSigned, SignatureInfo::isSigned, SignatureInfo::signer, stub_, SignatureInfo::trusted, and SignatureInfo::trustStatus.


The documentation for this class was generated from the following files: