forked from Netflix/Fido
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThe_Director.cs
279 lines (243 loc) · 10.1 KB
/
The_Director.cs
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
*
* Copyright 2015 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
//using Fido_Main.Logger;
using System;
using System.Collections.Generic;
using System.Linq;
using Fido_Main.Director.Director_Helper;
using Fido_Main.Director.Scoring;
using Fido_Main.Fido_Support.ErrorHandling;
using Fido_Main.Fido_Support.FidoDB;
using Fido_Main.Fido_Support.Objects.Fido;
using Fido_Main.Main.Detectors;
namespace Fido_Main.Director
{
public static class TheDirector
{
public static void Direct(FidoReturnValues lFidoReturnValues)
{
var sSrcIP = lFidoReturnValues.SrcIP;
var sHostname = lFidoReturnValues.Hostname;
try
{
//check detector values versus whitelist and exclude if true
var isFound = new The_Director_Whitelist().CheckFidoWhitelist(lFidoReturnValues.DstIP, lFidoReturnValues.Hash, lFidoReturnValues.DNSName, lFidoReturnValues.Url);
if (isFound)
{
return;
}
}
catch (Exception e)
{
Fido_EventHandler.SendEmail("Fido Error", "Fido Failed: {0} Exception caught in Director processing whitelist:" + e);
}
try
{
//if HostDetection is turned on, then gather information directly from host
if (Object_Fido_Configs.GetAsBool("fido.director.hostdetection", true)) lFidoReturnValues = The_Director_HostDetection.HostDetection(lFidoReturnValues, sHostname, sSrcIP);
//Write results out to console
if (!string.IsNullOrEmpty(sHostname))
{
Console.WriteLine(@"Detected hostname=" + sHostname + @", gathering detailed inventory.");
}
else
{
Console.WriteLine(@"Unable to detect hostname, gathering detailed inventory for " + sSrcIP + @".");
}
//go to our sysmgmt data sources to get detailed inventory information
if (Object_Fido_Configs.GetAsBool("fido.director.runinventory", false)) lFidoReturnValues = The_Director_HostDetection.SQLFidoReturnValues(lFidoReturnValues, sSrcIP, sHostname);
//determine if hostname from host discover matches inventory data
if (string.IsNullOrEmpty(lFidoReturnValues.Hostname))
{
Console.WriteLine(@"Hostname still unknown. Proceeding to evaluate threat.");
lFidoReturnValues.IsHostKnown = false;
lFidoReturnValues.Hostname = "unknown";
}
else if (lFidoReturnValues.Hostname.ToLower() == "unknown")
{
//todo: need to write code to take existing data
//hold it for %configurable% minutes and then
//send it out 'unmanaged' if hostinfo continues to come
//back empty
}
else
{
if (Object_Fido_Configs.GetAsBool("fido.director.userdetect", false)) lFidoReturnValues = The_Director_HostDetection.GetUserInfo(lFidoReturnValues);
}
if (lFidoReturnValues.Username != null)
{
var runUserDetect = Object_Fido_Configs.GetAsBool("fido.director.userdetect", false);
if (runUserDetect) lFidoReturnValues = The_Director_HostDetection.GetUserInfo(lFidoReturnValues);
}
}
catch (Exception e)
{
Fido_EventHandler.SendEmail("Fido Error", "Fido Failed: {0} Exception caught in Director gathering host information:" + e);
}
try
{
//Gather more information about destination IP address
lFidoReturnValues = The_Director_ThreatFeeds_URL.ThreatGRIDIPInfo(lFidoReturnValues);
}
catch (Exception e)
{
Fido_EventHandler.SendEmail("Fido Error", "Fido Failed: {0} Exception caught in Director gathering host IP/GEO information:" + e);
}
try
{
//todo: this area is half-baked... why is bit9 return not being assigned to lFidoReturnValues?
//If detector == AV then check if AV information has a filepath/name
//then parse and send to bit9 to get additional info
if ((lFidoReturnValues.Antivirus != null) && (The_Director_HostDetection.IsBit9Installed()))
{
AntiVirusToBit9(lFidoReturnValues);
}
}
catch (Exception e)
{
Fido_EventHandler.SendEmail("Fido Error", "Fido Failed: {0} Exception caught in Director sending AV info to Bit9:" + e);
}
try
{
//this area will take detector hashes and reference them against Bit9
//to see if Bit9 has seen the hash, where and if it was executed
if (The_Director_HostDetection.IsBit9Installed())
{
Console.WriteLine(@"Bit9 detected... cross-referencing hashes.");
//if FireEye has hashes send to Bit9
if ((lFidoReturnValues.FireEye != null) && (lFidoReturnValues.FireEye.MD5Hash.Any()))
{
if (lFidoReturnValues.Bit9 == null)
{
lFidoReturnValues.Bit9 = new Bit9ReturnValues();
}
lFidoReturnValues.Bit9.Bit9Hashes = Detect_Bit9.GetFileInfo(lFidoReturnValues.FireEye.MD5Hash, null).ToArray();
//lFidoReturnValues = FireEyeHashToBit9(lFidoReturnValues);
}
//if FireEyeMPS has hashes send to Bit9
//if PaloAlto has hashes send to Bit9
//if Cyphort has hashes send to Bit9
//if Protectwise has hashes send to Bit9
}
}
catch (Exception e)
{
Fido_EventHandler.SendEmail("Fido Error", "Fido Failed: {0} Exception caught in Director sending network detector info to Bit9:" + e);
}
try
{
//this area will send hash data to threatfeeds to get additional information
//to be used in scoring for the attack
lFidoReturnValues = The_Director_ThreatFeeds_Hash.DetectorsToThreatFeeds(lFidoReturnValues);
//this area will send URL data to threatfeeds to get additional information
//to be used in scoring for the attack
lFidoReturnValues = The_Director_ThreatFeeds_URL.DetectorsToThreatFeeds(lFidoReturnValues);
}
catch (Exception e)
{
Fido_EventHandler.SendEmail("Fido Error", "Fido Failed: {0} Exception caught in Director sending network detector info to threat feeds:" + e);
}
//Send accumulated information to the Matrix for scoring
Console.WriteLine(@"Running scoring matrix.");
lFidoReturnValues = Matrix.RunMatrix(lFidoReturnValues);
Console.WriteLine(@"Exiting scoring matrix.");
var actions = new List<string>();
//handoff to enforcement
//
//
//todo: more whack
if (!lFidoReturnValues.IsSendAlert)
{
actions.Add("Created Ticket");
actions.Add("Not Needed");
}
else
{
actions.Add("Created Ticket");
actions.Add("Success");
}
//Thebelow highlighted out as the Service-Now module is too proprietary
//in its current form to be included with OSS. What will happen in a future
//version is a module to handle the different ticketing solutions,
//Service-Now, Zendesk, ServiceDesk, etc., so that tickets can be
//created based on user configuration.
//ServiceNowUpdate.InsertResponse(lFidoReturnValues);
lFidoReturnValues.Actions = actions;
//send information for notifications
Console.WriteLine(@"Sending notification.");
Notification.Notification.Notify(lFidoReturnValues);
//Send configurable information for output to syslog
//SysLogger.SendEventToSyslog(lFidoReturnValues);
//todo: WTF is this? It's whack, thats what...
actions.Add("Update FIDO DB");
actions.Add("Success");
//update FIDO DB with event information
Console.WriteLine(@"Updating FidoDB.");
Fido_UpdateDB.InsertEventToDB(lFidoReturnValues);
}
private static void AntiVirusToBit9(FidoReturnValues lFidoReturnValues)
{
var lBit9ReturnValues = new Bit9ReturnValues();
var sFileInfo = lFidoReturnValues.Antivirus.FilePath.Split('\\');
if ((sFileInfo != null) && (sFileInfo.Length != 0))
{
Console.WriteLine(@"Antivirus detector found! Cross-referencing with Bit9.");
lBit9ReturnValues.FileName = sFileInfo[sFileInfo.Length - 1];
lFidoReturnValues.Antivirus.FileName = lBit9ReturnValues.FileName;
for (var i = 0; i < sFileInfo.Length - 1; i++)
{
if (i == sFileInfo.Length - 2)
{
lBit9ReturnValues.FilePath += sFileInfo[i];
}
else
{
if (!sFileInfo[i].Contains("'"))
{
lBit9ReturnValues.FilePath += sFileInfo[i] + "\\";
}
else
{
break;
}
}
}
lBit9ReturnValues.HostName = lFidoReturnValues.Hostname;
var lBit9Info = Detect_Bit9.GetFileInfo(null, lBit9ReturnValues);
}
}
//todo: is this still necessary? should we handle this in the bit9 module?
private static FidoReturnValues FireEyeHashToBit9(FidoReturnValues lFidoReturnValues)
{
//Check FireEye returns and go to Bit9 to see if the hash exists, where and
//if it was executed, then go to VT and pass hash info on there too
var lVirusTotalReturnValues = new VirusTotalReturnValues();
List<string> sBit9FileInfo = Detect_Bit9.GetFileInfo(lFidoReturnValues.FireEye.MD5Hash, null);
if (sBit9FileInfo.Count == 0) return lFidoReturnValues;
if (lFidoReturnValues.Bit9 == null)
{
lFidoReturnValues.Bit9 = new Bit9ReturnValues {Bit9Hashes = sBit9FileInfo.ToArray()};
}
else
{
lFidoReturnValues.Bit9.Bit9Hashes = sBit9FileInfo.ToArray();
}
return lFidoReturnValues;
}
}
}