Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
service_client_amsi.cpp
Go to the documentation of this file.
1#include <grpcpp/grpcpp.h>
2#include "panoptes.grpc.pb.h"
3#include "PanoptesAMSI.h"
4
5using grpc::ClientContext;
6using grpc::Status;
7
8std::unique_ptr<PanoptesService::Stub> stub_;
9
13bool GetRegistryPortValue(DWORD& portValue) {
14 HKEY hKey;
15 DWORD dwType = REG_DWORD;
16 DWORD dwSize = sizeof(DWORD);
17
18 // Open the key
19 LONG lResult = RegOpenKeyExA(
20 HKEY_LOCAL_MACHINE,
21 "SOFTWARE\\Panoptes",
22 0,
23 KEY_READ,
24 &hKey
25 );
26
27 if (lResult != ERROR_SUCCESS) {
28 std::cerr << "Error opening registry key. Error code: " << lResult << std::endl;
29 return false;
30 }
31
32 // Read the SRV_PORT value
33 lResult = RegQueryValueExA(
34 hKey,
35 "SRV_PORT",
36 NULL,
37 &dwType,
38 reinterpret_cast<LPBYTE>(&portValue),
39 &dwSize
40 );
41
42 RegCloseKey(hKey);
43
44 if (lResult != ERROR_SUCCESS) {
45 std::cerr << "Error reading registry value. Error code: " << lResult << std::endl;
46 return false;
47 }
48
49 if (dwType != REG_DWORD) {
50 std::cerr << "Unexpected value type in registry." << std::endl;
51 return false;
52 }
53
54 return true;
55}
56
60 DWORD portValue;
61 if (!GetRegistryPortValue(portValue)) {
62 std::cerr << "Failed to get registry port value." << std::endl;
63 return;
64 }
65 std::string server_url = "localhost:" + std::to_string(portValue);
66 std::shared_ptr<grpc::Channel> channel = grpc::CreateChannel(server_url, grpc::InsecureChannelCredentials());
67 stub_ = PanoptesService::NewStub(channel);
68}
69
74bool PanoptesServiceClient::Hello(ExtensibilityType extensibilityType,int ContainerPort) {
75 AckMessage reply;
76 ContainerInfo request;
77 ClientContext g_context;
78
79 request.set_container_type((ContainerType)extensibilityType);
80 request.set_grpc_port(ContainerPort);
81
82 Status status = stub_->Hello(&g_context, request, &reply);
83
84 if (!status.ok()) {
85 std::cout << status.error_code() << ": " << status.error_message() << std::endl;
86 exit(1);
87 }
88
89 return reply.ack_type();
90}
91
98 std::string PePath,
99 std::string FileHash,
100 DWORD AmsiResult)
101{
102 AckMessage reply;
103 ContainerReply request;
104 ClientContext g_context;
105
106 ScanAMSI results;
107 request.set_portable_executable_path(PePath);
108 request.set_file_hash(FileHash);
109 results.set_amsi_result(AmsiResult);
110
111 request.mutable_amsi_scan()->CopyFrom(results);
112
113 Status status = stub_->ScanResults(&g_context, request, &reply);
114
115 if (!status.ok()) {
116 std::cout << status.error_code() << ": " << status.error_message() << std::endl;
117 exit(1);
118 }
119
120 return !reply.ack_type();
121}
ExtensibilityType
The type of extensibility.
PanoptesServiceClient()
The PanoptesServiceClient class is a class that implements the PanoptesServiceClient class.
bool SendResults_AMSI(std::string PePath, DWORD AmsiResult)
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)
Get the Panoptes Service port from the registry.