forked from netwrix/pingcastle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompromiseGraphData.cs
352 lines (313 loc) · 9.32 KB
/
CompromiseGraphData.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
//
// Copyright (c) Ping Castle. All rights reserved.
// https://www.pingcastle.com
//
// Licensed under the Non-Profit OSL. See LICENSE file in the project root for full license information.
//
using PingCastle.Healthcheck;
using PingCastle.Rules;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Xml.Serialization;
using PingCastle.ADWS;
using PingCastle.Graph.Database;
using System.Runtime.Serialization;
namespace PingCastle.Data
{
public enum CompromiseGraphDataObjectRisk
{
Critical,
High,
Medium,
Other
}
[DebuggerDisplay("{Name}")]
public class CompromiseGraphData
{
public void SetExportLevel(PingCastleReportDataExportLevel level)
{
//Level = level;
}
public List<SingleCompromiseGraphData> Data { get; set; }
public List<CompromiseGraphDependancyData> Dependancies { get; set; }
public List<CompromiseGraphAnomalyAnalysisData> AnomalyAnalysis { get; set; }
public int GlobalScore { get; set; }
public int StaleObjectsScore { get; set; }
public int PrivilegiedGroupScore { get; set; }
public int TrustScore { get; set; }
public int AnomalyScore { get; set; }
[XmlIgnore]
public IList<DomainKey> DomainKnown
{
get
{
var output = new List<DomainKey>();
foreach (var d in Dependancies)
{
output.Add(d.Domain);
}
return output;
}
}
}
public class CompromiseGraphAnomalyAnalysisData
{
[XmlAttribute]
public CompromiseGraphDataObjectRisk ObjectRisk { get; set; }
[XmlAttribute]
public int NumberOfObjectsScreened { get; set; }
[XmlAttribute]
public int NumberOfObjectsWithIndirect { get; set; }
[XmlAttribute]
public int MaximumIndirectNumber { get; set; }
[XmlAttribute]
public int MaximumDirectIndirectRatio { get; set; }
[XmlAttribute]
[DefaultValue(false)]
public bool CriticalObjectFound { get; set; }
}
public enum CompromiseGraphDataTypology
{
[Description("Admin groups")]
PrivilegedAccount = 10,
[Description("Critical Infrastructure")]
Infrastructure = 20,
[Description("User Defined")]
UserDefined = 100,
}
[DebuggerDisplay("{Name}")]
[XmlType("userMember")]
public class SingleCompromiseGraphUserMemberData
{
[XmlAttribute]
public string Name { get; set; }
[XmlAttribute]
public string DistinguishedName { get; set; }
[XmlAttribute]
[DefaultValue(false)]
public bool IsEnabled { get; set; }
[XmlAttribute]
[DefaultValue(false)]
public bool IsActive { get; set; }
[XmlAttribute]
[DefaultValue(false)]
public bool IsLocked { get; set; }
[XmlAttribute]
[DefaultValue(false)]
public bool DoesPwdNeverExpires { get; set; }
[XmlAttribute]
[DefaultValue(false)]
public bool CanBeDelegated { get; set; }
[XmlAttribute]
public DateTime LastLogonTimestamp { get; set; }
[XmlAttribute]
public DateTime PwdLastSet { get; set; }
[XmlAttribute]
[DefaultValue(false)]
public bool SmartCardRequired { get; set; }
[XmlAttribute]
[DefaultValue(false)]
public bool IsService { get; set; }
// not used for the moment
[XmlIgnore]
public List<string> SPN { get; set; }
[XmlAttribute]
[DefaultValue(false)]
public bool IsPwdNotRequired { get; set; }
}
[DebuggerDisplay("{Name}")]
[XmlType("computerMember")]
public class SingleCompromiseGraphComputerMemberData
{
[XmlAttribute]
public string Name { get; set; }
[XmlAttribute]
public string DistinguishedName { get; set; }
[XmlAttribute]
[DefaultValue(false)]
public bool IsEnabled { get; set; }
[XmlAttribute]
[DefaultValue(false)]
public bool IsActive { get; set; }
[DefaultValue(false)]
[XmlAttribute]
public bool IsLocked { get; set; }
[DefaultValue(false)]
[XmlAttribute]
public bool CanBeDelegated { get; set; }
[XmlAttribute]
public DateTime LastLogonTimestamp { get; set; }
// not used for the moment
[XmlIgnore]
public List<string> SPN { get; set; }
}
[XmlType("indirectMember")]
public class SingleCompromiseGraphIndirectMemberData
{
[XmlAttribute]
public string Name { get; set; }
[XmlAttribute]
public string Sid { get; set; }
[XmlAttribute]
public int Distance { get; set; }
[XmlAttribute]
public string AuthorizedObject { get; set; }
[XmlAttribute]
public string Path { get; set; }
}
[XmlType("dependancyMember")]
public class SingleCompromiseGraphDependancyMemberData
{
[XmlAttribute]
public string Name { get; set; }
[XmlAttribute]
public string Sid { get; set; }
}
[XmlType("detail")]
public class CompromiseGraphDependancyDetailData
{
[XmlAttribute]
public CompromiseGraphDataTypology Typology { get; set; }
[XmlAttribute]
public int NumberOfResolvedItems { get; set; }
[XmlAttribute]
public int NumberOfUnresolvedItems { get; set; }
[XmlAttribute]
public int NumberOfGroupImpacted { get; set; }
[XmlIgnore]
public List<string> Items { get; set; }
}
[XmlType("dependancyData")]
public class CompromiseGraphDependancyData
{
[XmlAttribute]
public string Netbios { get; set; }
[XmlAttribute]
public string FQDN { get; set; }
[XmlAttribute]
public string Sid { get; set; }
public List<CompromiseGraphDependancyDetailData> Details { get; set; }
private DomainKey _domain;
[XmlIgnore]
public DomainKey Domain
{
get
{
if (_domain == null)
{
_domain = DomainKey.Create(FQDN, Sid, Netbios);
}
return _domain;
}
}
}
[XmlType("singleDependancyData")]
public class SingleCompromiseGraphDependancyData
{
[XmlAttribute]
public string Netbios { get; set; }
[XmlAttribute]
public string FQDN { get; set; }
[XmlAttribute]
public string Sid {get; set;}
[XmlAttribute]
public int NumberOfResolvedItems { get; set; }
[XmlAttribute]
public int NumberOfUnresolvedItems { get; set; }
public List<SingleCompromiseGraphDependancyMemberData> Items { get; set; }
}
[XmlType("deletedData")]
public class SingleCompromiseGraphDeletedData
{
[XmlAttribute]
public string Sid { get; set; }
}
[XmlType("data")]
public class SingleCompromiseGraphData
{
[IgnoreDataMember]
[XmlIgnore]
public PingCastleReportDataExportLevel Level { get; set; }
[XmlAttribute]
public string Name { get; set; }
[XmlAttribute]
public string Description { get; set; }
[XmlAttribute]
public CompromiseGraphDataTypology Typology { get; set; }
[XmlAttribute]
public CompromiseGraphDataObjectRisk ObjectRisk { get; set; }
public bool ShouldSerializeNodes() { return (int)Level <= (int)PingCastleReportDataExportLevel.Full; }
public List<SingleCompromiseGraphNodeData> Nodes { get; set; }
public bool ShouldSerializeLinks() { return (int)Level <= (int)PingCastleReportDataExportLevel.Full; }
public List<SingleCompromiseGraphLinkData> Links { get; set; }
[DefaultValue(false)]
public bool OnDemandAnalysis { get; set; }
[XmlAttribute]
[DefaultValue(false)]
public bool CriticalObjectFound { get; set; }
public int NumberOfDirectUserMembers { get; set; }
public int NumberOfDirectComputerMembers { get; set; }
public int NumberOfIndirectMembers { get; set; }
public int NumberOfDeletedObjects { get; set; }
public bool ShouldSerializeDirectUserMembers() { return (int)Level <= (int)PingCastleReportDataExportLevel.Full; }
public List<SingleCompromiseGraphUserMemberData> DirectUserMembers { get; set; }
public bool ShouldSerializeDirectComputerMembers() { return (int)Level <= (int)PingCastleReportDataExportLevel.Full; }
public List<SingleCompromiseGraphComputerMemberData> DirectComputerMembers { get; set; }
public bool ShouldSerializeIndirectMembers() { return (int)Level <= (int)PingCastleReportDataExportLevel.Full; }
public List<SingleCompromiseGraphIndirectMemberData> IndirectMembers { get; set; }
public bool ShouldSerializeDependancies() { return (int)Level <= (int)PingCastleReportDataExportLevel.Light; }
public List<SingleCompromiseGraphDependancyData> Dependancies { get; set; }
public bool ShouldSerializeDeletedObjects() { return (int)Level <= (int)PingCastleReportDataExportLevel.Full; }
public List<SingleCompromiseGraphDeletedData> DeletedObjects { get; set; }
}
[XmlType("node")]
public class SingleCompromiseGraphNodeData
{
[XmlAttribute]
public int Id { get; set; }
[XmlAttribute]
public string Name { get; set; }
[XmlAttribute]
public string Type { get; set; }
[IgnoreDataMember]
[XmlIgnore]
public bool IsTypeAUser
{
get
{
return (string.Equals(Type, "user", StringComparison.OrdinalIgnoreCase)
|| string.Equals(Type, "inetOrgPerson", StringComparison.OrdinalIgnoreCase)
|| string.Equals(Type, "msDS-GroupManagedServiceAccount", StringComparison.OrdinalIgnoreCase)
|| string.Equals(Type, "msDS-ManagedServiceAccountt", StringComparison.OrdinalIgnoreCase)
);
}
}
[XmlAttribute]
public string ShortName { get; set; }
[XmlAttribute]
public int Distance {get; set; }
[XmlAttribute]
[DefaultValue(false)]
public bool Suspicious { get; set; }
[XmlAttribute]
[DefaultValue(false)]
public bool Critical { get; set; }
// used when building the structure
[XmlIgnore]
[IgnoreDataMember]
internal ADItem ADItem { get; set; }
}
[XmlType("link")]
public class SingleCompromiseGraphLinkData
{
[XmlAttribute]
public int Source { get; set; }
[XmlAttribute]
public int Target { get; set; }
[XmlAttribute]
public string Hints { get; set; }
}
}