19#define PANO_GRPC_THREAD_WAIT_MS 5000
21static HANDLE g_grpcThread = NULL;
25static void StopService() {
32 if (g_grpcThread != NULL) {
34 CloseHandle(g_grpcThread);
51int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow)
62 if (IsDebuggerPresent()) {
73 DWORD pid = GetCurrentProcessId();
74 printf(
"PanoptesService PID %lu (0x%lx)\n", pid, pid);
75 printf(
" WinDbg (kernel): !process 0x%lx 0 then .process /i <EPROCESS>; g; .reload /user\n", pid);
76 printf(
"Press any key to start...\n");
84#pragma region Admin Check
94#pragma region Mutex Check
109#pragma region Shutdown Handling
118#pragma region Panoptes Configuration
122 std::string configPath =
"C:\\ProgramData\\Panoptes\\Panoptes.config";
127 configuration->
Parse();
130 catch (
const int& err) {
133 catch (
const std::exception& e) {
135 std::cerr <<
"Failed to parse " << configPath <<
": " << e.what() << std::endl;
140#pragma region Database
142 errCode = dbTmp.InitializeDatabase();
148#pragma region GRPC Server
149 g_grpcThread = CreateThread(
164#pragma region Container Start
173#pragma region Detector
185 bool useDriver =
true;
231#pragma region Hook Events
243 std::cerr <<
"Not running elevated: hook events will not be collected" << std::endl;
248 std::cout <<
"Shutting down" << std::endl;
251 delete configuration;
#define PANO_SERVICE_STOPPED
#define PANO_SERVICE_RUNNING
#define GRPC_SERVER_ERROR
std::vector< std::string > m_fileEvents
The groups of file system events the driver reports, from FileEventNames(). Every group if FileEvents...
void Parse()
Parse the configuration file.
std::vector< std::string > m_dontInject
Processes the driver does not inject the hook DLL into. Each entry is either a file name such as "mse...
static void CloseDatabase()
Flushes and closes the database. Safe to call if it was never opened.
ERRORCODE StartContainers()
void StopContainers()
Ends every container started by StartContainers. Safe to call if none were started.
ERRORCODE StartDetector()
Starts PanoptesDetector.exe from the service's folder with the rules in its rules subfolder,...
ERRORCODE StartKernelService()
Starts the Panoptes driver service. It is installed as demand start, so it is not running after a reb...
ERRORCODE SetInjectionExclusionsInDriver(const std::vector< std::string > &imageNames)
Replaces the driver's list of process image names it does not inject the hook DLL into (IOCTL_PANOPTE...
ERRORCODE GetKernelServiceStatus()
ERRORCODE SetFileEventsInDriver(const std::vector< std::string > &groups)
Tells the driver which groups of file system events to report (IOCTL_PANOPTES_SET_FILE_EVENTS).
ERRORCODE StartDriverEvents(const Configuration *configuration)
Opens the Panoptes driver device and starts the threads that read events from it (IOCTL_PANOPTES_GET_...
void StopDriverEvents()
Cancels the pending event requests and stops the reader threads.
std::string GetErrorMessage(UINT resourceID)
void DisplayErrorMessage(std::string errorMessage)
PanoptesContext * serviceContext
VOID StopServiceServer()
Shuts down the server RunServiceServer started, cancelling calls still in flight after a short grace ...
VOID RunServiceServer(LPVOID lpParam)
void StopHookEvents()
Stops the ETW session and waits for the consumer thread to deliver what it buffered.
ERRORCODE StartHookEvents()
Starts a real-time ETW session for the hook DLL's "Panoptes.Hook" TraceLogging provider and a thread ...
ERRORCODE SetEnvironmentMutex()
#define PANO_GRPC_THREAD_WAIT_MS
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
ERRORCODE CleanupWithError(ERRORCODE err)
ERRORCODE InitializeShutdown()
Creates the stop event and installs the console handler and session-end window. The stop event can on...
void WaitForShutdownRequest()
Blocks until a shutdown is requested.
ERRORCODE RequestServiceStop()
Implements –stop: sets a running service's stop event and waits for it to exit.
void NotifyShutdownComplete()
Tells console handlers and the session-end window that teardown has finished, so they can return and ...
std::string GetExecutableDirectory()
bool HasCommandLineFlag(const char *flag)