52{
53
54
55
59 }
60
61#ifndef _DEBUG
62 if (IsDebuggerPresent()) {
66 }
67#endif
68
69#ifdef _DEBUG
70
71
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");
77 _getch();
78 }
79#endif
80
83
84#pragma region Admin Check
85#ifndef _DEBUG
90 }
91#endif
92#pragma endregion
93
94#pragma region Mutex Check
100 }
101 }
102 else {
106 }
107#pragma endregion
108
109#pragma region Shutdown Handling
110
111
115 }
116#pragma endregion
117
118#pragma region Panoptes Configuration
119#ifdef _DEBUG
121#else
122 std::string configPath = "C:\\ProgramData\\Panoptes\\Panoptes.config";
123#endif
124
126 try {
127 configuration->
Parse();
129 }
130 catch (const int& err) {
132 }
133 catch (const std::exception& e) {
134
135 std::cerr << "Failed to parse " << configPath << ": " << e.what() << std::endl;
137 }
138#pragma endregion
139
140#pragma region Database
142 errCode = dbTmp.InitializeDatabase();
145 }
146#pragma endregion
147
148#pragma region GRPC Server
149 g_grpcThread = CreateThread(
150 NULL,
151 0,
154 0,
155 NULL
156 );
157 Sleep(2000);
158
161 }
162#pragma endregion
163
164#pragma region Container Start
165#ifndef _DEBUG
169 }
170#endif
171#pragma endregion
172
173#pragma region Detector
174
175
179 }
180#pragma endregion
181
182#pragma region Driver
183
184
185 bool useDriver = true;
186#ifdef _DEBUG
188#endif
189
190 if (useDriver) {
191
194 }
195
198 {
199
200
202 }
204 {
206 }
207
208
209
212 {
214 }
215
216
219 {
221 }
222
225 {
227 }
228 }
229#pragma endregion
230
231#pragma region Hook Events
232
233
234
238 {
240 }
241 }
242 else {
243 std::cerr << "Not running elevated: hook events will not be collected" << std::endl;
244 }
245#pragma endregion
246
248 std::cout << "Shutting down" << std::endl;
249
250 StopService();
251 delete configuration;
253 return 0;
254}
#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...
ERRORCODE StartContainers()
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_...
PanoptesContext * serviceContext
VOID RunServiceServer(LPVOID lpParam)
ERRORCODE StartHookEvents()
Starts a real-time ETW session for the hook DLL's "Panoptes.Hook" TraceLogging provider and a thread ...
ERRORCODE SetEnvironmentMutex()
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.
std::string GetExecutableDirectory()
bool HasCommandLineFlag(const char *flag)