Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
dllmain.cpp File Reference
#include "PanoptesYara.h"
#include <string>
#include <iostream>
#include <stdexcept>

Go to the source code of this file.

Functions

BOOL APIENTRY DllMain (HMODULE module, DWORD dllAction, LPVOID lpReserved)
 The main entry point for the DLL.
PANO_API int PanoBind (int ContainerPort)
 Bind to the Panoptes Service by sending a hello message containing the extensibility type and the port of the container that the extensibility is running in.
PANO_API bool PanoEntry (PeScan *data)
 The entry point for the YARA extensibility.
PANO_API bool PanoUnbind ()
 Unbind from the Panoptes Service by freeing the DLL.

Function Documentation

◆ DllMain()

BOOL APIENTRY DllMain ( HMODULE module,
DWORD dllAction,
LPVOID lpReserved )

The main entry point for the DLL.

Parameters
moduleThe module handle
dllActionThe action to take
lpReservedReserved
Returns

Definition at line 11 of file dllmain.cpp.

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}

◆ PanoBind()

PANO_API int PanoBind ( int ContainerPort)

Bind to the Panoptes Service by sending a hello message containing the extensibility type and the port of the container that the extensibility is running in.

Parameters
ContainerPortThe port of the container that the extensibility is running in
Returns
The container port

Definition at line 34 of file dllmain.cpp.

35{
37 if (!client.Hello(ExtensibilityType::EXTENSIBILITY_TYPE_YARA, ContainerPort)) {
38 return 0;
39 }
40
41 return ContainerPort;
42}
@ EXTENSIBILITY_TYPE_YARA
The Panoptes Service client used to talk to the service over gRPC.
bool Hello(ExtensibilityType extensibilityType, std::string port)
The Hello function sends a Hello message to the Panoptes main service from the container.

References EXTENSIBILITY_TYPE_YARA, PanoptesServiceClient::Hello(), and PANO_API.

◆ PanoEntry()

PANO_API bool PanoEntry ( PeScan * data)

The entry point for the YARA extensibility.

Parameters
dataThe information about the file to be scanned
Returns
True if the scan was successful, false otherwise

Definition at line 47 of file dllmain.cpp.

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}
SignatureInfo VerifyFileSignature(const std::string &PathToFile)
Verify the Authenticode signature of a file using WinVerifyTrust. The embedded signature is checked f...
bool SendResults_Yara(std::string PePath, std::string FileHash, DWORD ProcessId, std::string YaraRulesPath, INT MatchRules, std::vector< std::string > DetectedRules)
The YaraScanner class that is used to scan a file using YARA rules.
std::string FileHash
std::string PePath
The result of verifying a file's Authenticode signature with WinVerifyTrust.

References PeScan::FileHash, PANO_API, PeScan::PePath, PanoptesServiceClient::SendResults_Yara(), VerifyFileSignature(), and YaraScanner::YaraScanFile().

◆ PanoUnbind()

PANO_API bool PanoUnbind ( )

Unbind from the Panoptes Service by freeing the DLL.

Returns
True if the unbind was successful, false otherwise

Definition at line 74 of file dllmain.cpp.

75{
76 HMODULE hModule = GetModuleHandleA("PanoptesYara.dll");
77 if (hModule != NULL) {
78 FreeLibraryAndExitThread(hModule, 0);
79 }
80 return true;
81}

References PANO_API.