Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
ext_server.cpp
Go to the documentation of this file.
1#include <grpcpp/grpcpp.h>
2#include "panoptes.pb.h"
3#include "panoptes.grpc.pb.h"
4
5#include "container_ipc.hpp"
6#include <objbase.h>
7#include <iostream>
8#include <vector>
9
14 InitializeCriticalSection(&cs_);
15 InitializeConditionVariable(&cv_);
16}
17
21void PeMessageQueue::enqueue(const PeScan& message) {
22 EnterCriticalSection(&cs_);
23 queue_.push(message);
24 std::cout << "Enqueued item. Queue size: " << queue_.size() << std::endl;
25 LeaveCriticalSection(&cs_);
26 WakeConditionVariable(&cv_);
27}
28
32 EnterCriticalSection(&cs_);
33 while (queue_.empty()) {
34 std::cout << "Queue empty, waiting..." << std::endl;
35 SleepConditionVariableCS(&cv_, &cs_, INFINITE);
36 }
37 PeScan message = queue_.front();
38 queue_.pop();
39 // std::cout << "Dequeued item. Remaining queue size: " << queue_.size() << std::endl;
40 LeaveCriticalSection(&cs_);
41 return message;
42}
43
48 std::unique_lock<std::mutex> lock(mutex_);
49 queue_.push(message);
50 cv_.notify_one();
51}
52
56 std::unique_lock<std::mutex> lock(mutex_);
57 cv_.wait(lock, [this] { return !queue_.empty(); });
58 MemScan message = queue_.front();
59 queue_.pop();
60
61 return message;
62}
63
66class PanoptesImpl : public PanoptesExtensibility::Service {
72 ::grpc::Status PEScan(::grpc::ServerContext* context, const ::PeScanInfo* request, ::AckMessage* response) override {
73 PeScan scanInfo;
74 scanInfo.PePath = request->portable_executable_path();
75 scanInfo.FileHash = request->file_hash();
76
77 if (message_queue_pe_ != NULL) {
78 message_queue_pe_->enqueue(scanInfo);
79 }
80
81 response->set_ack_type(AckType::SUCCESS);
82 return ::grpc::Status::OK;
83 }
84
90 ::grpc::Status MemoryScan(::grpc::ServerContext* context, const ::MemoryScanInfo* request, ::AckMessage* response) override {
91 MemScan scanInfo;
92 scanInfo.ProcessId = request->process_id();
93
94 if (message_queue_pe_ != NULL) {
95 message_queue_mem_->enqueue(scanInfo);
96 }
97
98 response->set_ack_type(AckType::SUCCESS);
99 return ::grpc::Status::OK;
100 }
101};
102
105void RunContainerServer(LPVOID lpParam)
106{
107 int* ContainerPort = (int*)(lpParam);
108
109 PanoptesImpl service;
110 grpc::ServerBuilder builder;
111 std::string server_url = "localhost:" + std::to_string(*ContainerPort);
112 builder.AddListeningPort(server_url, grpc::InsecureServerCredentials(), ContainerPort);
113 builder.RegisterService(&service);
114 std::unique_ptr<grpc::Server> server(builder.BuildAndStart());
115 server->Wait();
116}
void enqueue(const MemScan &message)
The enqueue function enqueues a MemScan message to the queue.
MemScan dequeue()
The dequeue function dequeues a MemScan messages from the queue.
The PanoptesImpl class is a class that implements the PanoptesExtensibility::Service interface from t...
PeMessageQueue()
The PeMessageQueue class is a thread-safe queue for PeScan messages.
PeScan dequeue()
The dequeue function dequeues a PeScan messages from the queue.
void enqueue(const PeScan &message)
The enqueue function is a function that enqueues a PeScan message to the queue.
MemoryMessageQueue * message_queue_mem_
Definition container.cpp:16
PeMessageQueue * message_queue_pe_
Definition container.cpp:15
void RunContainerServer(LPVOID lpParam)
The RunContainerServer function is a function that runs the container server.
The information about the memory to be scanned that passed between the container, extensibility and t...
The information about the file to be scanned that passed between the container, extensibility and the...
std::string FileHash
std::string PePath