Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
Test_PanoptesYara.cpp
Go to the documentation of this file.
1#include "gtest/gtest.h"
2#include "PanoptesYara.h"
3
4#define YARA_RULES "rules.pkg"
5#define EICAR_PATH "eicarcom2.zip"
6
7namespace Yara {
8 class YaraScanTest : public ::testing::Test {
9 protected:
11
12 void SetUp() override {
14 }
15
16 void TearDown() override {
17 delete yaraScan;
18 yaraScan = nullptr;
19 }
20 };
21
22 TEST_F(YaraScanTest, ScanNotePad) {
23 std::vector<string> result = yaraScan->YaraScanFile("C:\\Windows\\System32\\notepad.exe");
24 EXPECT_EQ(result.size(), 0);
25 }
26
27 TEST_F(YaraScanTest, ScanEicar) {
28 std::vector<string> result = yaraScan->YaraScanFile(EICAR_PATH);
29 EXPECT_GT(result.size(), 0);
30 }
31
32 // A file deleted before its scan used to free the scanner twice (heap corruption that
33 // ended the container). It must throw cleanly, and the scanner must still work afterwards
34 TEST_F(YaraScanTest, MissingFileThrowsAndScannerStillWorks) {
35 for (int i = 0; i < 3; i++) {
36 EXPECT_THROW(yaraScan->YaraScanFile("C:\\does\\not\\exist.exe"), std::runtime_error);
37 }
38 EXPECT_EQ(yaraScan->YaraScanFile("C:\\Windows\\System32\\notepad.exe").size(), 0);
39 }
40
41 TEST(SignatureTest, NotePadIsTrusted) {
42 SignatureInfo info = VerifyFileSignature("C:\\Windows\\System32\\notepad.exe");
43 EXPECT_TRUE(info.isSigned);
44 EXPECT_TRUE(info.trusted);
45 EXPECT_TRUE(info.catalogSigned);
46 EXPECT_EQ(info.trustStatus, ERROR_SUCCESS);
47 EXPECT_FALSE(info.signer.empty());
48 }
49
50 TEST(SignatureTest, EmbeddedSignatureIsTrusted) {
51 // MpSigStub.exe ships with Defender and has an embedded signature
52 const char* path = "C:\\Windows\\System32\\MpSigStub.exe";
53 if (GetFileAttributesA(path) == INVALID_FILE_ATTRIBUTES) {
54 GTEST_SKIP() << "MpSigStub.exe is not present";
55 }
56
58 EXPECT_TRUE(info.isSigned);
59 EXPECT_TRUE(info.trusted);
60 EXPECT_FALSE(info.catalogSigned);
61 EXPECT_FALSE(info.signer.empty());
62 }
63
64 TEST(SignatureTest, EicarIsUnsigned) {
66 EXPECT_FALSE(info.isSigned);
67 EXPECT_FALSE(info.trusted);
68 EXPECT_FALSE(info.catalogSigned);
69 EXPECT_TRUE(info.signer.empty());
70 }
71}
SignatureInfo VerifyFileSignature(const std::string &PathToFile)
Verify the Authenticode signature of a file using WinVerifyTrust. The embedded signature is checked f...
#define EICAR_PATH
#define YARA_RULES
The YaraScanner class that is used to scan a file using YARA rules.
void TearDown() override
TEST(SignatureTest, NotePadIsTrusted)
TEST_F(YaraScanTest, ScanNotePad)
The result of verifying a file's Authenticode signature with WinVerifyTrust.
bool trusted
True if WinVerifyTrust reported the signature as valid and trusted.
std::string signer
The signing certificate's display name (UTF-8), empty if unsigned.
LONG trustStatus
The WinVerifyTrust result, 0 if trusted.
bool isSigned
True if the file has an embedded or catalog signature.
bool catalogSigned
True if the signature came from a catalog file rather than being embedded.