-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDSAccess.cs
More file actions
62 lines (55 loc) · 2.13 KB
/
DSAccess.cs
File metadata and controls
62 lines (55 loc) · 2.13 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
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.DirectoryServices;
using System.Linq;
using System.Runtime.Caching;
using System.Text;
using System.Threading.Tasks;
namespace PropertyChange
{
class DSAccess : DSEvent<DSAccessRecord>
{
public DSAccess(string remoteComputer, string domain, string username, string password)
: base(remoteComputer, domain, username, password) { }
public DSAccess(string remoteComputer)
: base(remoteComputer) { }
public DSAccess() : base() { }
protected override string GetQueryString()
{
return "*[System[EventID=4662]]";
}
protected override DSAccessRecord Parse(EventRecord item)
{
var ds = new DSAccessRecord();
ds.Time = item.TimeCreated.Value;
try
{
ds.TargetGuid = new Guid(((string)item.Properties[6].Value).Trim(' ', '%', '{', '}'));
}
catch
{
ds.TargetGuid = Guid.Empty;
}
ds.Operation = Operation.GetOperation(((string)item.Properties[9].Value).Trim(' ', '%', '\r', '\n', '\t'));
ds.TargetGuid = new Guid(((string)item.Properties[6].Value).Trim(' ', '%', '{', '}'));
ds.Target = GetDN(((string)item.Properties[6].Value).Trim(' ', '%', '{', '}'));
ds.Properties = ((string)item.Properties[11].Value).Split('\n').Select(l => l.Trim(' ', '{', '\t', '}', '\r'))
.Where(l => !String.IsNullOrWhiteSpace(l) && !l.StartsWith("%%"))
.Select(l => Property.GetPropertyName(new Guid(l)))
.Where(n => n != null)
.ToArray();
ds.Operator = item.Properties[1].Value as string;
return ds;
}
}
class DSAccessRecord
{
public Guid TargetGuid { get; set; }
public DateTime Time { get; set; }
public String Operation { get; set; }
public String Target { get; set; }
public String[] Properties { get; set; }
public String Operator { get; set; }
}
}