Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
service_client_pe.cpp
Go to the documentation of this file.
1#include <grpcpp/grpcpp.h>
2#include "panoptes.grpc.pb.h"
3#include "PanoptesPE.h"
4
5using grpc::ClientContext;
6using grpc::Status;
7
8std::unique_ptr<PanoptesService::Stub> stub_;
9
10bool GetRegistryPortValue(DWORD& portValue) {
11 HKEY hKey;
12 DWORD dwType = REG_DWORD;
13 DWORD dwSize = sizeof(DWORD);
14
15 // Open the key
16 LONG lResult = RegOpenKeyExA(
17 HKEY_LOCAL_MACHINE,
18 "SOFTWARE\\Panoptes",
19 0,
20 KEY_READ,
21 &hKey
22 );
23
24 if (lResult != ERROR_SUCCESS) {
25 std::cerr << "Error opening registry key. Error code: " << lResult << std::endl;
26 return false;
27 }
28
29 // Read the SRV_PORT value
30 lResult = RegQueryValueExA(
31 hKey,
32 "SRV_PORT",
33 NULL,
34 &dwType,
35 reinterpret_cast<LPBYTE>(&portValue),
36 &dwSize
37 );
38
39 RegCloseKey(hKey);
40
41 if (lResult != ERROR_SUCCESS) {
42 std::cerr << "Error reading registry value. Error code: " << lResult << std::endl;
43 return false;
44 }
45
46 if (dwType != REG_DWORD) {
47 std::cerr << "Unexpected value type in registry." << std::endl;
48 return false;
49 }
50
51 return true;
52}
53
55 DWORD portValue;
56 if (!GetRegistryPortValue(portValue)) {
57 std::cerr << "Failed to get registry port value." << std::endl;
58 return;
59 }
60 std::string server_url = "localhost:" + std::to_string(portValue);
61 std::shared_ptr<grpc::Channel> channel = grpc::CreateChannel(server_url, grpc::InsecureChannelCredentials());
62 stub_ = PanoptesService::NewStub(channel);
63}
64
65bool PanoptesServiceClient::Hello(ExtensibilityType extensibilityType, int ContainerPort) {
66 AckMessage reply;
67 ContainerInfo request;
68 ClientContext g_context;
69
70 request.set_container_type((ContainerType)extensibilityType);
71 request.set_grpc_port(ContainerPort);
72
73 Status status = stub_->Hello(&g_context, request, &reply);
74
75 if (!status.ok()) {
76 //std::cout << status.error_code() << ": " << status.error_message() << std::endl;
77 exit(1);
78 }
79
80 return reply.ack_type();
81}
82
84 AckMessage reply;
85 ContainerReply request;
86 ClientContext g_context;
87
88 ScanPE results;
89 request.set_portable_executable_path(PePath);
90 request.set_file_hash(PePath);
91 results.set_signed_(data.isSigned);
92 for (int i = 0; i < data.imports.size(); i++) {
93 results.add_imports(data.imports[i]);
94 }
95
96 for (int i = 0; i < data.sections.size(); i++) {
97 results.add_sections(data.sections[i]);
98 }
99
100 for (int i = 0; i < data.section_entropy.size(); i++) {
101 results.add_section_entropy(data.section_entropy[i]);
102 }
103
104 request.mutable_pe_scan()->CopyFrom(results);
105
106 Status status = stub_->ScanResults(&g_context, request, &reply);
107
108 if (!status.ok()) {
109 //std::cout << status.error_code() << ": " << status.error_message() << std::endl;
110 exit(1);
111 }
112
113 return reply.ack_type();
114}
ExtensibilityType
The type of extensibility.
PanoptesServiceClient()
The PanoptesServiceClient class is a class that implements the PanoptesServiceClient class.
bool SendResults_PE(std::string PePath, bool IsPeSigned, std::string PeSignerSubject, std::vector< std::string > PeImports)
bool Hello(ExtensibilityType extensibilityType, std::string port)
The Hello function sends a Hello message to the Panoptes main service from the container.
bool GetRegistryPortValue(DWORD &portValue)
Get the gRPC port value from the registry.
Definition container.cpp:24
unsigned long DWORD
Definition inject.h:2
std::unique_ptr< PanoptesService::Stub > stub_
std::unique_ptr< PanoptesService::Stub > stub_
bool GetRegistryPortValue(DWORD &portValue)
The data that is sent to the Panoptes Service.
Definition PanoptesPE.h:11
std::vector< std::string > imports
Definition PanoptesPE.h:12
std::vector< double > section_entropy
Definition PanoptesPE.h:14
std::vector< std::string > sections
Definition PanoptesPE.h:13