Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
dllmain.cpp
Go to the documentation of this file.
1#include "PanoptesYara.h"
2#include <string>
3#include <iostream>
4#include <stdexcept>
5
11BOOL APIENTRY DllMain(HMODULE module, DWORD dllAction, LPVOID lpReserved)
12{
13 switch (dllAction)
14 {
15 case DLL_PROCESS_ATTACH:
16 //DisableThreadLibraryCalls(module);
17 break;
18 case DLL_THREAD_ATTACH:
19 // Code to run when a thread is created
20 break;
21 case DLL_THREAD_DETACH:
22 // Code to run when a thread ends
23 break;
24 case DLL_PROCESS_DETACH:
25 break;
26 }
27 return TRUE;
28}
29
34extern "C" PANO_API int PanoBind(int ContainerPort)
35{
37 if (!client.Hello(ExtensibilityType::EXTENSIBILITY_TYPE_YARA, ContainerPort)) {
38 return 0;
39 }
40
41 return ContainerPort;
42}
43
47extern "C" PANO_API bool PanoEntry(PeScan* data)
48{
49 std::string rules = "rules.pkg";
50
51 std::vector<std::string> scanDataResults;
52 try {
53 YaraScanner yaraScan(rules.c_str());
54 scanDataResults = yaraScan.YaraScanFile(data->PePath);
55 }
56 catch (const std::exception& e) {
57 // An exception must not leave this extern "C" export: it would end the container,
58 // and every later scan with it. A file deleted or locked before its scan is common
59 std::cerr << "YARA scan of " << data->PePath << " failed: " << e.what() << std::endl;
60 return false;
61 }
62 SignatureInfo signature = VerifyFileSignature(data->PePath);
63
65 if (!client.SendResults_Yara(data->PePath, data->FileHash, scanDataResults, signature)) {
66 return false;
67 }
68
69 return true;
70}
71
74extern "C" PANO_API bool PanoUnbind()
75{
76 HMODULE hModule = GetModuleHandleA("PanoptesYara.dll");
77 if (hModule != NULL) {
78 FreeLibraryAndExitThread(hModule, 0);
79 }
80 return true;
81}
#define PANO_API
@ EXTENSIBILITY_TYPE_YARA
SignatureInfo VerifyFileSignature(const std::string &PathToFile)
Verify the Authenticode signature of a file using WinVerifyTrust. The embedded signature is checked f...
The Panoptes Service client used to talk to the service over gRPC.
bool SendResults_Yara(std::string PePath, std::string FileHash, DWORD ProcessId, std::string YaraRulesPath, INT MatchRules, std::vector< std::string > DetectedRules)
bool Hello(ExtensibilityType extensibilityType, std::string port)
The Hello function sends a Hello message to the Panoptes main service from the container.
The YaraScanner class that is used to scan a file using YARA rules.
std::vector< std::string > YaraScanFile(std::string PathToFile)
Scan a file using YARA rules.
Definition yara-scan.cpp:82
ExtensibilityCore::PanoBindPtr PanoBind
Definition container.cpp:11
ExtensibilityCore::PanoEntryPtr PanoEntry
Definition container.cpp:12
BOOL APIENTRY DllMain(HMODULE module, DWORD dllAction, LPVOID lpReserved)
The main entry point for the DLL.
Definition dllmain.cpp:11
PANO_API bool PanoUnbind()
Unbind from the Panoptes Service by freeing the DLL.
Definition dllmain.cpp:74
The information about the file to be scanned that passed between the container, extensibility and the...
std::string FileHash
std::string PePath
The result of verifying a file's Authenticode signature with WinVerifyTrust.