This repository was archived by the owner on Sep 7, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathEvidenceLocker.cpp
More file actions
174 lines (152 loc) · 4.64 KB
/
Copy pathEvidenceLocker.cpp
File metadata and controls
174 lines (152 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "EvidenceLocker.hpp"
/*
AddFlagged - adds `flag` to our flagged/detections list
returns `true` if the flag was added, returns `false` if the flag is a duplicate (to prevent multiple repeat data pushes for the same thing)
*/
bool EvidenceLocker::AddFlagged(__in const DetectionFlags flag)
{
if (std::find(this->FlaggedList.begin(), this->FlaggedList.end(), flag) == this->FlaggedList.end())
{
std::lock_guard<std::mutex> lock(this->EvidenceListMutex);
this->FlaggedList.push_back(flag);
this->SentFlags[flag] = false;
return true;
}
return false;
}
/*
AddFlagged - adds `flag` to our flagged/detections list, along with `data` to our evidence list. evidence is additional data associated with a flag
returns `true` if the flag was added, returns `false` if the flag is a duplicate (to prevent multiple repeat data pushes for the same thing)
*/
bool EvidenceLocker::AddFlagged(__in const DetectionFlags flag, __in const std::string data, __in const DWORD pid)
{
bool AlreadyAdded = false;
for (auto evidence : this->EvidenceData)
{
if (evidence.data == data)
AlreadyAdded = true;
}
if (!AlreadyAdded) //is not already sent
{
std::lock_guard<std::mutex> lock(this->EvidenceListMutex);
this->FlaggedList.push_back(flag);
this->SentFlags[flag] = false;
AddEvidence(flag, data, pid);
return true;
}
return false;
}
/*
AddEvidence - Adds `data` to our evidence list for `flag` type. Evidence is any additional string data associated with a flag, such as a memory address, a module name, a python script, etc
returns `true` if the flag was added, returns `false` if the flag is a duplicate (to prevent multiple repeat data pushes for the same thing)
*/
void EvidenceLocker::AddEvidence(__in const DetectionFlags flag, __in const std::string data, __in const DWORD pid)
{
Evidence evi;
evi.type = flag;
evi.data = data;
evi.pid = pid;
this->EvidenceData.push_back(evi);
this->HasEvidenceData[flag] = true;
}
/*
SendFlag - send a detected flag to the server (without evidence)
returns `true` on success
*/
bool EvidenceLocker::SendFlag(__in const DetectionFlags flag)
{
bool wasDuplicate = AddFlagged(flag);
if (wasDuplicate) //prevent duplicate server comms
return true;
if (this->NetworkClient != nullptr)
{
std::lock_guard<std::mutex> lock(this->SendFlagMutex);
if (this->NetworkClient->FlagCheater(flag) != Error::OK)
{
#if USE_LOG_MESSAGES
Logger::logf(Err, "Failed to notify server of cheating status.");
#endif
return false;
}
}
else
{
#if USE_LOG_MESSAGES
Logger::logf(Err, "NetClient was NULL @ EvidenceLog::SendFlag");
#endif
return false;
}
this->SentFlags[flag] = true; //only mark as sent flag if send() was successful
return true;
}
/*
FlagWithData - send a detected flag to the server (with evidence)
returns `true` on success
*/
bool EvidenceLocker::FlagWithData(__in const DetectionFlags flag, __in const std::string data, __in const DWORD pid, __in const bool ShouldMarkAsSent)
{
bool wasDuplicate = AddFlagged(flag);
if (wasDuplicate) //prevent duplicate server comms
return true;
if (this->NetworkClient != nullptr)
{
std::lock_guard<std::mutex> lock(this->SendFlagMutex);
if (this->NetworkClient->FlagCheater(flag, data, pid) != Error::OK)
{
#if USE_LOG_MESSAGES
Logger::logf(Err, "Failed to notify server of cheating status.");
#endif
return false;
}
}
else
{
#if USE_LOG_MESSAGES
Logger::logf(Err, "NetClient was NULL @ Detections::Flag");
#endif
return false;
}
AlreadySentEvidence.push_back(data);
if (ShouldMarkAsSent)
this->SentFlags[flag] = true; //only mark as sent flag if send() was successful
return true;
}
/*
PushAllEvidence - push all unsent flags to server, if any evidence is with a flag it will also send that
returns `true` if no flag sends fail. if one or more flag sends fail, return `false`
*/
bool EvidenceLocker::PushAllEvidence()
{
bool flagSendFailed = false;
for (auto flag : FlaggedList)
{
if (!SentFlags[flag]) //todo: make sure that all evidence is properly sending, and that some isnt being blocked
{
if (HasEvidenceData[flag])
{
for (auto evidence : this->EvidenceData) //send extra evidence with flag
{
if (evidence.type == flag)
{
if (std::find(AlreadySentEvidence.begin(), AlreadySentEvidence.end(), evidence.data) == AlreadySentEvidence.end()) //send only if we didnt already sent this evidence
{
if (!FlagWithData(flag, evidence.data, evidence.pid, false))
{
flagSendFailed = true;
}
}
this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}
}
else
{
if (!SendFlag(flag))
{
flagSendFailed = true;
}
}
}
}
return flagSendFailed;
}