├── .gitattributes
├── .gitignore
├── DET.Tests
├── ComputerTests.cs
├── DACLTests.cs
├── DET.Tests.csproj
├── DomainSearcherTests.cs
├── DomainTests.cs
├── GPOTests.cs
├── GroupTests.cs
├── LDAPTests.cs
├── OUTests.cs
└── UserTests.cs
├── DET.sln
├── DET
├── Computers.cs
├── DACL.cs
├── DET.csproj
├── Domain.cs
├── DomainSearcher.cs
├── GroupPolicyObjects.cs
├── Groups.cs
├── LAPS.cs
├── LDAP.cs
├── OrganizationalUnits.cs
└── Users.cs
├── LICENSE
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Aa][Rr][Mm]/
27 | [Aa][Rr][Mm]64/
28 | bld/
29 | [Bb]in/
30 | [Oo]bj/
31 | [Ll]og/
32 | [Ll]ogs/
33 |
34 | # Visual Studio 2015/2017 cache/options directory
35 | .vs/
36 | # Uncomment if you have tasks that create the project's static files in wwwroot
37 | #wwwroot/
38 |
39 | # Visual Studio 2017 auto generated files
40 | Generated\ Files/
41 |
42 | # MSTest test Results
43 | [Tt]est[Rr]esult*/
44 | [Bb]uild[Ll]og.*
45 |
46 | # NUnit
47 | *.VisualState.xml
48 | TestResult.xml
49 | nunit-*.xml
50 |
51 | # Build Results of an ATL Project
52 | [Dd]ebugPS/
53 | [Rr]eleasePS/
54 | dlldata.c
55 |
56 | # Benchmark Results
57 | BenchmarkDotNet.Artifacts/
58 |
59 | # .NET Core
60 | project.lock.json
61 | project.fragment.lock.json
62 | artifacts/
63 |
64 | # StyleCop
65 | StyleCopReport.xml
66 |
67 | # Files built by Visual Studio
68 | *_i.c
69 | *_p.c
70 | *_h.h
71 | *.ilk
72 | *.meta
73 | *.obj
74 | *.iobj
75 | *.pch
76 | *.pdb
77 | *.ipdb
78 | *.pgc
79 | *.pgd
80 | *.rsp
81 | *.sbr
82 | *.tlb
83 | *.tli
84 | *.tlh
85 | *.tmp
86 | *.tmp_proj
87 | *_wpftmp.csproj
88 | *.log
89 | *.vspscc
90 | *.vssscc
91 | .builds
92 | *.pidb
93 | *.svclog
94 | *.scc
95 |
96 | # Chutzpah Test files
97 | _Chutzpah*
98 |
99 | # Visual C++ cache files
100 | ipch/
101 | *.aps
102 | *.ncb
103 | *.opendb
104 | *.opensdf
105 | *.sdf
106 | *.cachefile
107 | *.VC.db
108 | *.VC.VC.opendb
109 |
110 | # Visual Studio profiler
111 | *.psess
112 | *.vsp
113 | *.vspx
114 | *.sap
115 |
116 | # Visual Studio Trace Files
117 | *.e2e
118 |
119 | # TFS 2012 Local Workspace
120 | $tf/
121 |
122 | # Guidance Automation Toolkit
123 | *.gpState
124 |
125 | # ReSharper is a .NET coding add-in
126 | _ReSharper*/
127 | *.[Rr]e[Ss]harper
128 | *.DotSettings.user
129 |
130 | # JustCode is a .NET coding add-in
131 | .JustCode
132 |
133 | # TeamCity is a build add-in
134 | _TeamCity*
135 |
136 | # DotCover is a Code Coverage Tool
137 | *.dotCover
138 |
139 | # AxoCover is a Code Coverage Tool
140 | .axoCover/*
141 | !.axoCover/settings.json
142 |
143 | # Visual Studio code coverage results
144 | *.coverage
145 | *.coveragexml
146 |
147 | # NCrunch
148 | _NCrunch_*
149 | .*crunch*.local.xml
150 | nCrunchTemp_*
151 |
152 | # MightyMoose
153 | *.mm.*
154 | AutoTest.Net/
155 |
156 | # Web workbench (sass)
157 | .sass-cache/
158 |
159 | # Installshield output folder
160 | [Ee]xpress/
161 |
162 | # DocProject is a documentation generator add-in
163 | DocProject/buildhelp/
164 | DocProject/Help/*.HxT
165 | DocProject/Help/*.HxC
166 | DocProject/Help/*.hhc
167 | DocProject/Help/*.hhk
168 | DocProject/Help/*.hhp
169 | DocProject/Help/Html2
170 | DocProject/Help/html
171 |
172 | # Click-Once directory
173 | publish/
174 |
175 | # Publish Web Output
176 | *.[Pp]ublish.xml
177 | *.azurePubxml
178 | # Note: Comment the next line if you want to checkin your web deploy settings,
179 | # but database connection strings (with potential passwords) will be unencrypted
180 | *.pubxml
181 | *.publishproj
182 |
183 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
184 | # checkin your Azure Web App publish settings, but sensitive information contained
185 | # in these scripts will be unencrypted
186 | PublishScripts/
187 |
188 | # NuGet Packages
189 | *.nupkg
190 | # NuGet Symbol Packages
191 | *.snupkg
192 | # The packages folder can be ignored because of Package Restore
193 | **/[Pp]ackages/*
194 | # except build/, which is used as an MSBuild target.
195 | !**/[Pp]ackages/build/
196 | # Uncomment if necessary however generally it will be regenerated when needed
197 | #!**/[Pp]ackages/repositories.config
198 | # NuGet v3's project.json files produces more ignorable files
199 | *.nuget.props
200 | *.nuget.targets
201 |
202 | # Microsoft Azure Build Output
203 | csx/
204 | *.build.csdef
205 |
206 | # Microsoft Azure Emulator
207 | ecf/
208 | rcf/
209 |
210 | # Windows Store app package directories and files
211 | AppPackages/
212 | BundleArtifacts/
213 | Package.StoreAssociation.xml
214 | _pkginfo.txt
215 | *.appx
216 | *.appxbundle
217 | *.appxupload
218 |
219 | # Visual Studio cache files
220 | # files ending in .cache can be ignored
221 | *.[Cc]ache
222 | # but keep track of directories ending in .cache
223 | !?*.[Cc]ache/
224 |
225 | # Others
226 | ClientBin/
227 | ~$*
228 | *~
229 | *.dbmdl
230 | *.dbproj.schemaview
231 | *.jfm
232 | *.pfx
233 | *.publishsettings
234 | orleans.codegen.cs
235 |
236 | # Including strong name files can present a security risk
237 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
238 | #*.snk
239 |
240 | # Since there are multiple workflows, uncomment next line to ignore bower_components
241 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
242 | #bower_components/
243 |
244 | # RIA/Silverlight projects
245 | Generated_Code/
246 |
247 | # Backup & report files from converting an old project file
248 | # to a newer Visual Studio version. Backup files are not needed,
249 | # because we have git ;-)
250 | _UpgradeReport_Files/
251 | Backup*/
252 | UpgradeLog*.XML
253 | UpgradeLog*.htm
254 | ServiceFabricBackup/
255 | *.rptproj.bak
256 |
257 | # SQL Server files
258 | *.mdf
259 | *.ldf
260 | *.ndf
261 |
262 | # Business Intelligence projects
263 | *.rdl.data
264 | *.bim.layout
265 | *.bim_*.settings
266 | *.rptproj.rsuser
267 | *- [Bb]ackup.rdl
268 | *- [Bb]ackup ([0-9]).rdl
269 | *- [Bb]ackup ([0-9][0-9]).rdl
270 |
271 | # Microsoft Fakes
272 | FakesAssemblies/
273 |
274 | # GhostDoc plugin setting file
275 | *.GhostDoc.xml
276 |
277 | # Node.js Tools for Visual Studio
278 | .ntvs_analysis.dat
279 | node_modules/
280 |
281 | # Visual Studio 6 build log
282 | *.plg
283 |
284 | # Visual Studio 6 workspace options file
285 | *.opt
286 |
287 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
288 | *.vbw
289 |
290 | # Visual Studio LightSwitch build output
291 | **/*.HTMLClient/GeneratedArtifacts
292 | **/*.DesktopClient/GeneratedArtifacts
293 | **/*.DesktopClient/ModelManifest.xml
294 | **/*.Server/GeneratedArtifacts
295 | **/*.Server/ModelManifest.xml
296 | _Pvt_Extensions
297 |
298 | # Paket dependency manager
299 | .paket/paket.exe
300 | paket-files/
301 |
302 | # FAKE - F# Make
303 | .fake/
304 |
305 | # CodeRush personal settings
306 | .cr/personal
307 |
308 | # Python Tools for Visual Studio (PTVS)
309 | __pycache__/
310 | *.pyc
311 |
312 | # Cake - Uncomment if you are using it
313 | # tools/**
314 | # !tools/packages.config
315 |
316 | # Tabs Studio
317 | *.tss
318 |
319 | # Telerik's JustMock configuration file
320 | *.jmconfig
321 |
322 | # BizTalk build output
323 | *.btp.cs
324 | *.btm.cs
325 | *.odx.cs
326 | *.xsd.cs
327 |
328 | # OpenCover UI analysis results
329 | OpenCover/
330 |
331 | # Azure Stream Analytics local run output
332 | ASALocalRun/
333 |
334 | # MSBuild Binary and Structured Log
335 | *.binlog
336 |
337 | # NVidia Nsight GPU debugger configuration file
338 | *.nvuser
339 |
340 | # MFractors (Xamarin productivity tool) working folder
341 | .mfractor/
342 |
343 | # Local History for Visual Studio
344 | .localhistory/
345 |
346 | # BeatPulse healthcheck temp database
347 | healthchecksdb
348 |
349 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
350 | MigrationBackup/
351 |
352 | # Ionide (cross platform F# VS Code tools) working folder
353 | .ionide/
354 |
355 | # JetBrains
356 | .idea
357 |
--------------------------------------------------------------------------------
/DET.Tests/ComputerTests.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 |
3 | using Xunit;
4 |
5 | namespace DET.Tests;
6 |
7 | public class ComputerTests
8 | {
9 | [Fact]
10 | public void GetAllComputersAndProperties()
11 | {
12 | var searcher = new DomainSearcher();
13 | var computers = new Computers(searcher);
14 |
15 | var results = computers.GetComputers();
16 |
17 | Assert.NotNull(results);
18 | Assert.True(results.Any());
19 | Assert.True(results.First().Value.Values.Count > 30);
20 | }
21 |
22 | [Fact]
23 | public void GetSingleComputerAllProperties()
24 | {
25 | var searcher = new DomainSearcher();
26 | var computers = new Computers(searcher);
27 | var computerNames = new[] { "dc-1" };
28 |
29 | var results = computers.GetComputers(computerNames);
30 |
31 | Assert.NotNull(results);
32 | Assert.True(results.Count == 1);
33 | Assert.True(results.First().Value.Values.Count > 30);
34 | }
35 |
36 | [Fact]
37 | public void GetTwoComputersAllProperties()
38 | {
39 | var searcher = new DomainSearcher();
40 | var computers = new Computers(searcher);
41 | var computerNames = new[] { "dc-1", "wkstn-1" };
42 |
43 | var results = computers.GetComputers(computerNames);
44 |
45 | Assert.NotNull(results);
46 | Assert.True(results.Count == 2);
47 | Assert.True(results.First().Value.Values.Count > 30);
48 | }
49 |
50 | [Fact]
51 | public void GetSingleComputerSingleProperty()
52 | {
53 | var searcher = new DomainSearcher();
54 | var computers = new Computers(searcher);
55 | var computerNames = new[] { "dc-1" };
56 | var properties = new[] { "serviceprincipalname" };
57 |
58 | var results = computers.GetComputers(computerNames, properties);
59 |
60 | Assert.NotNull(results);
61 | Assert.True(results.Count == 1);
62 | Assert.True(results.First().Value.Values.Count == 2);
63 | }
64 |
65 | [Fact]
66 | public void GetAllComputersSingleProperty()
67 | {
68 | var searcher = new DomainSearcher();
69 | var computers = new Computers(searcher);
70 | var properties = new[] { "serviceprincipalname" };
71 |
72 | var results = computers.GetComputers(properties: properties);
73 |
74 | Assert.NotNull(results);
75 | Assert.True(results.Any());
76 | Assert.True(results.First().Value.Values.Count == 2);
77 | }
78 |
79 | [Fact]
80 | public void GetUnconstrainedDelegation()
81 | {
82 | var searcher = new DomainSearcher();
83 | var computers = new Computers(searcher);
84 |
85 | var results = computers.GetTrustedForUnconstrainedDelegation();
86 |
87 | Assert.NotNull(results);
88 | Assert.True(results.Any());
89 | }
90 |
91 | [Fact]
92 | public void GetAllowedToDelegateTo()
93 | {
94 | var searcher = new DomainSearcher();
95 | var computers = new Computers(searcher);
96 |
97 | var results = computers.GetAllowedToDelegateTo();
98 |
99 | Assert.NotNull(results);
100 | Assert.True(results.Any());
101 | }
102 | }
--------------------------------------------------------------------------------
/DET.Tests/DACLTests.cs:
--------------------------------------------------------------------------------
1 | using Xunit;
2 |
3 | namespace DET.Tests;
4 |
5 | public class DACLTests
6 | {
7 | [Fact]
8 | public void TestGetDACL()
9 | {
10 | var searcher = new DomainSearcher();
11 | var dacl = new DACL(searcher);
12 |
13 | // Test GPO
14 | var dn = "CN={31B2F340-016D-11D2-945F-00C04FB984F9},CN=Policies,CN=System,DC=testlab,DC=local";
15 |
16 | var result = dacl.GetDacl(dn);
17 |
18 | Assert.NotNull(result);
19 | Assert.True(result.Count > 0);
20 | }
21 | }
--------------------------------------------------------------------------------
/DET.Tests/DET.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 |
6 | false
7 |
8 | 10
9 |
10 |
11 |
12 |
13 |
14 |
15 | runtime; build; native; contentfiles; analyzers; buildtransitive
16 | all
17 |
18 |
19 | runtime; build; native; contentfiles; analyzers; buildtransitive
20 | all
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/DET.Tests/DomainSearcherTests.cs:
--------------------------------------------------------------------------------
1 | using Xunit;
2 |
3 | namespace DET.Tests;
4 |
5 | public class DomainSearcherTests
6 | {
7 | [Fact]
8 | public void CreateDefaultSearcher()
9 | {
10 | var searcher = new DomainSearcher();
11 |
12 | Assert.NotNull(searcher);
13 | Assert.NotNull(searcher.Directory);
14 | }
15 |
16 | [Fact]
17 | public void CreateSearcherWithPath()
18 | {
19 | var path = "LDAP://DC=testlab,DC=local";
20 |
21 | var searcher = new DomainSearcher(path);
22 |
23 | Assert.NotNull(searcher);
24 | Assert.NotNull(searcher.Directory);
25 | Assert.Equal(searcher.Directory.Path, path);
26 | }
27 |
28 | [Fact]
29 | public void CreateSearcherWithCredentials()
30 | {
31 | var path = "LDAP://DC=testlab,DC=local";
32 | var username = "LAB\\testuser";
33 | var password = "Passw0rd!";
34 |
35 | var searcher = new DomainSearcher(path, username, password);
36 |
37 | Assert.NotNull(searcher);
38 | Assert.NotNull(searcher.Directory);
39 | Assert.Equal(searcher.Directory.Path, path);
40 | Assert.Equal(searcher.Directory.Username, username);
41 | }
42 |
43 | [Fact]
44 | public void ModifyAuthenticationTypes()
45 | {
46 | var searcher = new DomainSearcher();
47 | var types = System.DirectoryServices.AuthenticationTypes.Secure | System.DirectoryServices.AuthenticationTypes.Delegation;
48 |
49 | searcher.SetAuthenticationTypes(types);
50 |
51 | Assert.NotNull(searcher);
52 | Assert.NotNull(searcher.Directory);
53 | Assert.Equal(searcher.Directory.AuthenticationType, types);
54 | }
55 | }
--------------------------------------------------------------------------------
/DET.Tests/DomainTests.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 |
3 | using Xunit;
4 |
5 | namespace DET.Tests;
6 |
7 | public class DomainTests
8 | {
9 | [Fact]
10 | public void GetDomainControllers()
11 | {
12 | var searcher = new DomainSearcher();
13 | var detDomain = new Domain(searcher);
14 |
15 | var domainControllers = detDomain.GetDomainControllers();
16 |
17 | Assert.NotNull(domainControllers);
18 | Assert.True(domainControllers.Count > 0);
19 | }
20 |
21 | [Fact]
22 | public void GetDomainSid()
23 | {
24 | var searcher = new DomainSearcher();
25 | var domain = new Domain(searcher);
26 |
27 | var result = domain.GetDomainSid();
28 |
29 | Assert.NotNull(result);
30 | Assert.True(result.Length == 40);
31 | }
32 |
33 | [Fact]
34 | public void GetDomainTrusts()
35 | {
36 | var searcher = new DomainSearcher();
37 | var domain = new Domain(searcher);
38 |
39 | var result = domain.GetDomainTrusts();
40 |
41 | Assert.NotNull(result);
42 | Assert.True(result.Any());
43 | }
44 | }
--------------------------------------------------------------------------------
/DET.Tests/GPOTests.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 |
3 | using Xunit;
4 |
5 | namespace DET.Tests;
6 |
7 | public class GPOTests
8 | {
9 | [Fact]
10 | public void GetAllGPOsAllProperties()
11 | {
12 | var searcher = new DomainSearcher();
13 | var ous = new GroupPolicyObjects(searcher);
14 |
15 | var results = ous.GetGPOs();
16 |
17 | Assert.NotNull(results);
18 | Assert.True(results.Any());
19 | Assert.True(results.First().Value.Values.Count > 20);
20 | }
21 |
22 | [Fact]
23 | public void GetSingleGPOAllProperties()
24 | {
25 | var searcher = new DomainSearcher();
26 | var ous = new GroupPolicyObjects(searcher);
27 | var names = new[] { "Default Domain Policy" };
28 |
29 | var results = ous.GetGPOs(names);
30 |
31 | Assert.NotNull(results);
32 | Assert.True(results.Count == 1);
33 | }
34 |
35 | [Fact]
36 | public void GetSingleGPOSingleProperty()
37 | {
38 | var searcher = new DomainSearcher();
39 | var ous = new GroupPolicyObjects(searcher);
40 | var names = new[] { "Default Domain Policy" };
41 | var properties = new[] { "gpcfilesyspath" };
42 |
43 | var results = ous.GetGPOs(names, properties);
44 |
45 | Assert.NotNull(results);
46 | Assert.True(results.Count == 1);
47 | Assert.True(results.First().Value.Values.Count == 2);
48 | }
49 |
50 | [Fact]
51 | public void GetAllGPOsSingleProperty()
52 | {
53 | var searcher = new DomainSearcher();
54 | var ous = new GroupPolicyObjects(searcher);
55 | var properties = new[] { "gpcfilesyspath" };
56 |
57 | var results = ous.GetGPOs(properties: properties);
58 |
59 | Assert.NotNull(results);
60 | Assert.True(results.Any());
61 | Assert.True(results.First().Value.Values.Count == 2);
62 | }
63 | }
--------------------------------------------------------------------------------
/DET.Tests/GroupTests.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 |
3 | using Xunit;
4 |
5 | namespace DET.Tests;
6 |
7 | public class GroupTests
8 | {
9 | [Fact]
10 | public void GetAllGroupsAndProperties()
11 | {
12 | var searcher = new DomainSearcher();
13 | var groups = new Groups(searcher);
14 |
15 | var results = groups.GetGroups();
16 |
17 | Assert.NotNull(results);
18 | Assert.True(results.Any());
19 | Assert.True(results.First().Value.Values.Count > 20);
20 | }
21 |
22 | [Fact]
23 | public void GetSingleGroupAllProperties()
24 | {
25 | var searcher = new DomainSearcher();
26 | var groups = new Groups(searcher);
27 | var names = new[] { "Domain Admins" };
28 |
29 | var results = groups.GetGroups(names);
30 |
31 | Assert.NotNull(results);
32 | Assert.True(results.Count == 1);
33 | }
34 |
35 | [Fact]
36 | public void GetSingleGroupSingleProperty()
37 | {
38 | var searcher = new DomainSearcher();
39 | var groups = new Groups(searcher);
40 | var names = new[] { "Domain Admins" };
41 | var properties = new[] { "member" };
42 |
43 | var results = groups.GetGroups(names, properties);
44 |
45 | Assert.NotNull(results);
46 | Assert.True(results.Count == 1);
47 | Assert.True(results.First().Value.Values.Count == 2);
48 | }
49 |
50 | [Fact]
51 | public void GetAllGroupsSingleProperty()
52 | {
53 | var searcher = new DomainSearcher();
54 | var groups = new Groups(searcher);
55 | var properties = new[] { "member" };
56 |
57 | var results = groups.GetGroups(properties: properties);
58 |
59 | Assert.NotNull(results);
60 | Assert.True(results.Any());
61 | Assert.True(results.First().Value.Values.Count == 2);
62 | }
63 | }
--------------------------------------------------------------------------------
/DET.Tests/LDAPTests.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 |
3 | using Xunit;
4 |
5 | namespace DET.Tests;
6 |
7 | public class LDAPTests
8 | {
9 | [Fact]
10 | public void RawQueryTest()
11 | {
12 | var filter = "(&(objectCategory=computer))";
13 | var searcher = new DomainSearcher();
14 | var ldap = new LDAP(searcher);
15 |
16 | var result = ldap.ExecuteQuery(filter);
17 |
18 | Assert.NotNull(result);
19 | Assert.True(result.Any());
20 | }
21 | }
--------------------------------------------------------------------------------
/DET.Tests/OUTests.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 |
3 | using Xunit;
4 |
5 | namespace DET.Tests;
6 |
7 | public class OUTests
8 | {
9 | [Fact]
10 | public void GetAllOUsAndProperties()
11 | {
12 | var searcher = new DomainSearcher();
13 | var ous = new OrganizationalUnits(searcher);
14 |
15 | var results = ous.GetOrganizationalUnits();
16 |
17 | Assert.NotNull(results);
18 | Assert.True(results.Any());
19 | Assert.True(results.First().Value.Values.Count > 15);
20 | }
21 |
22 | [Fact]
23 | public void GetSingleOUAllProperties()
24 | {
25 | var searcher = new DomainSearcher();
26 | var ous = new OrganizationalUnits(searcher);
27 | var names = new[] { "TestOU" };
28 |
29 | var results = ous.GetOrganizationalUnits(names);
30 |
31 | Assert.NotNull(results);
32 | Assert.True(results.Count == 1);
33 | }
34 |
35 | [Fact]
36 | public void GetSingleOUSingleProperty()
37 | {
38 | var searcher = new DomainSearcher();
39 | var ous = new OrganizationalUnits(searcher);
40 | var names = new[] { "TestOU" };
41 | var properties = new[] { "distinguishedname" };
42 |
43 | var results = ous.GetOrganizationalUnits(names, properties);
44 |
45 | Assert.NotNull(results);
46 | Assert.True(results.Count == 1);
47 | Assert.True(results.First().Value.Values.Count == 2);
48 | }
49 |
50 | [Fact]
51 | public void GetAllOUsSingleProperty()
52 | {
53 | var searcher = new DomainSearcher();
54 | var ous = new OrganizationalUnits(searcher);
55 | var properties = new[] { "distinguishedname" };
56 |
57 | var results = ous.GetOrganizationalUnits(properties: properties);
58 |
59 | Assert.NotNull(results);
60 | Assert.True(results.Any());
61 | Assert.True(results.First().Value.Values.Count == 2);
62 | }
63 | }
--------------------------------------------------------------------------------
/DET.Tests/UserTests.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 |
3 | using Xunit;
4 |
5 | namespace DET.Tests;
6 |
7 | public class UserTests
8 | {
9 | [Fact]
10 | public void GetAllUsersAllProperties()
11 | {
12 | var searcher = new DomainSearcher();
13 | var users = new Users(searcher);
14 |
15 | var results = users.GetUsers();
16 |
17 | Assert.NotNull(results);
18 | Assert.True(results.Any());
19 | Assert.True(results.First().Value.Values.Count > 30);
20 | }
21 |
22 | [Fact]
23 | public void GetSingleUserAllProperties()
24 | {
25 | var searcher = new DomainSearcher();
26 | var users = new Users(searcher);
27 | var userNames = new[] { "user1" };
28 |
29 | var results = users.GetUsers(userNames);
30 |
31 | Assert.NotNull(results);
32 | Assert.True(results.Count == 1);
33 | }
34 |
35 | [Fact]
36 | public void GetSingleUserSingleProperty()
37 | {
38 | var searcher = new DomainSearcher();
39 | var users = new Users(searcher);
40 | var userNames = new[] { "user1" };
41 | var properties = new[] { "pwdlastset" };
42 |
43 | var results = users.GetUsers(userNames, properties);
44 |
45 | Assert.NotNull(results);
46 | Assert.True(results.Count == 1);
47 | Assert.True(results.First().Value.Values.Count == 2);
48 | }
49 |
50 | [Fact]
51 | public void GetAllUsersSingleProperty()
52 | {
53 | var searcher = new DomainSearcher();
54 | var users = new Users(searcher);
55 | var properties = new[] { "pwdlastset" };
56 |
57 | var results = users.GetUsers(properties: properties);
58 |
59 | Assert.NotNull(results);
60 | Assert.True(results.Any());
61 | Assert.True(results.First().Value.Values.Count == 2);
62 | }
63 |
64 | [Fact]
65 | public void GetKerberoastableUsers()
66 | {
67 | var searcher = new DomainSearcher();
68 | var users = new Users(searcher);
69 |
70 | var results = users.GetKerberoastableUsers();
71 |
72 | Assert.NotNull(results);
73 | Assert.True(results.Any());
74 | }
75 |
76 | [Fact]
77 | public void GetASREPRoastableUsers()
78 | {
79 | var searcher = new DomainSearcher();
80 | var users = new Users(searcher);
81 |
82 | var results = users.GetASREPRoastableUsers();
83 |
84 | Assert.NotNull(results);
85 | Assert.True(results.Any());
86 | }
87 |
88 | [Fact]
89 | public void GetAllowedToDelegateTo()
90 | {
91 | var searcher = new DomainSearcher();
92 | var users = new Users(searcher);
93 |
94 | var results = users.GetAllowedToDelegateTo();
95 |
96 | Assert.NotNull(results);
97 | Assert.True(results.Any());
98 | }
99 |
100 | [Fact]
101 | public void GetNoneExpiringPasswords()
102 | {
103 | var searcher = new DomainSearcher();
104 | var users = new Users(searcher);
105 |
106 | var results = users.GetPasswordNeverExpires();
107 |
108 | Assert.NotNull(results);
109 | Assert.True(results.Any());
110 | }
111 | }
--------------------------------------------------------------------------------
/DET.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.31112.23
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DET", "DET\DET.csproj", "{B74E5D01-22F8-4CF6-B37A-2FB9F70C29E4}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DET.Tests", "DET.Tests\DET.Tests.csproj", "{159FB407-0702-4004-AD15-7B8636B22427}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {B74E5D01-22F8-4CF6-B37A-2FB9F70C29E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {B74E5D01-22F8-4CF6-B37A-2FB9F70C29E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {B74E5D01-22F8-4CF6-B37A-2FB9F70C29E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {B74E5D01-22F8-4CF6-B37A-2FB9F70C29E4}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {159FB407-0702-4004-AD15-7B8636B22427}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {159FB407-0702-4004-AD15-7B8636B22427}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {159FB407-0702-4004-AD15-7B8636B22427}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {159FB407-0702-4004-AD15-7B8636B22427}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {4365BD88-FE62-4692-B77B-901F1233D823}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/DET/Computers.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace DET;
4 |
5 | public class Computers
6 | {
7 | private readonly DomainSearcher _searcher;
8 |
9 | ///
10 | /// Initializes a new instance of the DET.Computers class.
11 | ///
12 | /// An instance of the DET.DomainSearcher class.
13 | public Computers(DomainSearcher searcher)
14 | {
15 | _searcher = searcher;
16 | }
17 |
18 | ///
19 | /// Get the specified computers and their properties.
20 | ///
21 | /// Limit the response to the these computer names.
22 | /// An array of properties to return.
23 | /// A multi-level dictionary of computers and their properties.
24 | public Dictionary> GetComputers(string[] computerNames = null, string[] properties = null)
25 | {
26 | var ldap = new LDAP(_searcher);
27 | var filter = "(&(objectCategory=computer)";
28 |
29 | if (computerNames is not null)
30 | {
31 | filter += "(|";
32 |
33 | foreach (var computerName in computerNames)
34 | filter += $"(dnshostname=*{computerName}*)";
35 |
36 | filter += ")";
37 | }
38 |
39 | filter += ")";
40 |
41 | return ldap.ExecuteQuery(filter, properties);
42 | }
43 |
44 | ///
45 | /// Get computers permitted to perform unconstrained delegation.
46 | ///
47 | /// An array of properties to return.
48 | /// A multi-level dictionary of computers and their properties.
49 | public Dictionary> GetTrustedForUnconstrainedDelegation(string[] properties = null)
50 | {
51 | var ldap = new LDAP(_searcher);
52 | const string filter = "(&(objectCategory=computer)(userAccountControl:1.2.840.113556.1.4.803:=524288))";
53 |
54 | return ldap.ExecuteQuery(filter, properties);
55 | }
56 |
57 | public Dictionary> GetAllowedToDelegateTo(string[] properties = null)
58 | {
59 | var ldap = new LDAP(_searcher);
60 | const string filter = "(&(objectCategory=computer)(msds-allowedtodelegateto=*))";
61 |
62 | return ldap.ExecuteQuery(filter, properties);
63 | }
64 | }
--------------------------------------------------------------------------------
/DET/DACL.cs:
--------------------------------------------------------------------------------
1 | using System.DirectoryServices;
2 | using System.Linq;
3 | using System.Security.AccessControl;
4 |
5 | namespace DET;
6 |
7 | public class DACL
8 | {
9 | private readonly DomainSearcher _searcher;
10 |
11 | ///
12 | /// Initializes a new instance of the DET.DACL class.
13 | ///
14 | /// An instance of the DET.DomainSearcher class.
15 | public DACL(DomainSearcher searcher)
16 | {
17 | _searcher = searcher;
18 | }
19 |
20 | ///
21 | /// Get an Discretionary Access Control List.
22 | ///
23 | /// The target DN.
24 | /// RawAcl.
25 | public RawAcl GetDacl(string distinguishedName)
26 | {
27 | var ldap = new LDAP(_searcher, SecurityMasks.Dacl);
28 | var filter = $"(distinguishedname={distinguishedName})";
29 | var results = ldap.ExecuteQuery(filter, new string[] { "ntsecuritydescriptor" });
30 |
31 | var rawDacl = results.First().Value["ntsecuritydescriptor"][0] as byte[];
32 |
33 | var descriptor = new RawSecurityDescriptor(rawDacl, 0);
34 | return descriptor.DiscretionaryAcl;
35 | }
36 | }
--------------------------------------------------------------------------------
/DET/DET.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | 10
6 | Domain-Enumeration-Tool
7 | 0.0.3
8 | Daniel Duggan
9 | Zero-Point Security Ltd
10 | Domain-Enumeration-Tool
11 | Perform Windows domain enumeration via LDAP
12 | https://www.zeropointsecurity.co.uk/
13 | https://github.com/ZeroPointSecurity/Domain-Enumeration-Tool
14 | GitHub
15 | true
16 |
17 | 0.0.5
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/DET/Domain.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using System.Security.Principal;
4 |
5 | namespace DET;
6 |
7 | public class Domain
8 | {
9 | private readonly DomainSearcher _searcher;
10 |
11 | ///
12 | /// Initializes a new instance of the DET.Domain class.
13 | ///
14 | /// An instance of the DET.DomainSearcher class.
15 | public Domain(DomainSearcher searcher)
16 | {
17 | _searcher = searcher;
18 | }
19 |
20 | ///
21 | /// Get a collection of Domain Controllers for the domain.
22 | ///
23 | /// An array of properties to return.
24 | /// A multi-level dictionary of domain and its properties.
25 | public Dictionary> GetDomainControllers(string[] properties = null)
26 | {
27 | var ldap = new LDAP(_searcher);
28 | const string filter = "(&(objectCategory=computer)(userAccountControl:1.2.840.113556.1.4.803:=8192))";
29 |
30 | return ldap.ExecuteQuery(filter, properties);
31 | }
32 |
33 | ///
34 | /// Get the domain SID.
35 | ///
36 | /// String.
37 | public string GetDomainSid()
38 | {
39 | var properties = new string[] { "objectsid" };
40 | var domainControllers = GetDomainControllers(properties);
41 |
42 | var firstDc = domainControllers.Values.First();
43 | var dcSidBytes = firstDc["objectsid"].First() as byte[];
44 | var dcSid = new SecurityIdentifier(dcSidBytes, 0);
45 |
46 | return dcSid.Value.Substring(0, dcSid.Value.LastIndexOf('-'));
47 | }
48 |
49 | ///
50 | /// Get domain trusts
51 | ///
52 | /// An array of properties to return.
53 | /// A multi-level dictionary of domain trust and its properties.
54 | public Dictionary> GetDomainTrusts(string[] properties = null)
55 | {
56 | var ldap = new LDAP(_searcher);
57 | const string filter = "(objectClass=trustedDomain)";
58 |
59 | return ldap.ExecuteQuery(filter, properties);
60 | }
61 | }
--------------------------------------------------------------------------------
/DET/DomainSearcher.cs:
--------------------------------------------------------------------------------
1 | using System.DirectoryServices;
2 |
3 | namespace DET;
4 |
5 | public class DomainSearcher
6 | {
7 | public DirectoryEntry Directory { get; }
8 |
9 | ///
10 | /// Initializes a new instance of the DET.DomainSearcher class.
11 | ///
12 | public DomainSearcher()
13 | {
14 | Directory = new DirectoryEntry();
15 | }
16 |
17 | ///
18 | /// Initializes a new instance of the DET.DomainSearcher class.
19 | ///
20 | /// The path at which to bind the System.DirectoryServices.DirectoryEntry
21 | public DomainSearcher(string path)
22 | {
23 | Directory = new DirectoryEntry(path);
24 | }
25 |
26 | ///
27 | /// Initializes a new instance of the DET.DomainSearcher class.
28 | ///
29 | /// The path at which to bind the System.DirectoryServices.DirectoryEntry.
30 | /// The username to use when authenticating.
31 | /// The password to use when authenticating.
32 | public DomainSearcher(string path, string username, string password)
33 | {
34 | Directory = new DirectoryEntry(path, username, password);
35 | }
36 |
37 | ///
38 | /// Modify the AuthenticateType used on the System.DirectoryServices.DirectoryEntry.
39 | ///
40 | /// One or more of the System.DirectoryServices.AuthenticationTypes values.
41 | public void SetAuthenticationTypes(AuthenticationTypes authenticationTypes)
42 | {
43 | Directory.AuthenticationType = authenticationTypes;
44 | }
45 | }
--------------------------------------------------------------------------------
/DET/GroupPolicyObjects.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace DET;
4 |
5 | public class GroupPolicyObjects
6 | {
7 | private readonly DomainSearcher _searcher;
8 |
9 | ///
10 | /// Initializes a new instance of the DET.GroupPolicyObjects class.
11 | ///
12 | /// An instance of the DET.DomainSearcher class.
13 | public GroupPolicyObjects(DomainSearcher searcher)
14 | {
15 | _searcher = searcher;
16 | }
17 |
18 | ///
19 | /// Get the specified GPOs and their properties.
20 | ///
21 | /// Limit the response to the these GPO display names.
22 | /// An array of properties to return.
23 | /// A multi-level dictionary of GPOs and their properties.
24 | public Dictionary> GetGPOs(string[] gpoNames = null, string[] properties = null)
25 | {
26 | var ldap = new LDAP(_searcher);
27 | var filter = "(&(objectCategory=groupPolicyContainer)";
28 |
29 | if (gpoNames is not null)
30 | {
31 | filter += "(|";
32 |
33 | foreach (var gpoName in gpoNames)
34 | filter += $"(displayname=*{gpoName}*)";
35 |
36 | filter += ")";
37 | }
38 |
39 | filter += ")";
40 |
41 | return ldap.ExecuteQuery(filter, properties);
42 | }
43 | }
--------------------------------------------------------------------------------
/DET/Groups.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace DET;
4 |
5 | public class Groups
6 | {
7 | private readonly DomainSearcher _searcher;
8 |
9 | ///
10 | /// Initializes a new instance of the DET.Groups class.
11 | ///
12 | /// An instance of the DET.DomainSearcher class.
13 | public Groups(DomainSearcher searcher)
14 | {
15 | _searcher = searcher;
16 | }
17 |
18 | ///
19 | /// Get the specified groups and their properties.
20 | ///
21 | /// Limit the response to the these group names.
22 | /// An array of properties to return.
23 | /// A multi-level dictionary of groups and their properties.
24 | public Dictionary> GetGroups(string[] groupNames = null, string[] properties = null)
25 | {
26 | var ldap = new LDAP(_searcher);
27 | var filter = "(&(objectCategory=group)";
28 |
29 | if (groupNames is not null)
30 | {
31 | filter += "(|";
32 |
33 | foreach (var groupName in groupNames)
34 | filter += $"(name=*{groupName}*)";
35 |
36 | filter += ")";
37 | }
38 |
39 | filter += ")";
40 |
41 | return ldap.ExecuteQuery(filter, properties);
42 | }
43 | }
--------------------------------------------------------------------------------
/DET/LAPS.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace DET;
4 |
5 | public class LAPS
6 | {
7 | private readonly DomainSearcher _searcher;
8 |
9 | ///
10 | /// Initializes a new instance of the DET.LAPS class.
11 | ///
12 | /// An instance of the DET.DomainSearcher class.
13 | public LAPS(DomainSearcher searcher)
14 | {
15 | _searcher = searcher;
16 | }
17 |
18 | ///
19 | /// Get computers were the ms-Mcs-AdmPwdExpirationTime attribute is not null
20 | ///
21 | /// An array of properties to return.
22 | /// A multi-level dictionary of domain and its properties.
23 | public Dictionary> GetComputersWithLAPS(string[] properties = null)
24 | {
25 | var ldap = new LDAP(_searcher);
26 | const string filter = "(&(objectCategory=computer)(ms-Mcs-AdmPwdExpirationTime=*))";
27 |
28 | return ldap.ExecuteQuery(filter, properties);
29 | }
30 | }
--------------------------------------------------------------------------------
/DET/LDAP.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 | using System.Collections.Generic;
3 | using System.DirectoryServices;
4 |
5 | namespace DET;
6 |
7 | public class LDAP
8 | {
9 | private readonly DomainSearcher _searcher;
10 | private readonly SecurityMasks _securityMasks;
11 |
12 | ///
13 | /// Initializes a new instance of the DET.LDAP class.
14 | ///
15 | /// An instance of the DET.DomainSearcher class.
16 | public LDAP(DomainSearcher searcher)
17 | {
18 | _searcher = searcher;
19 | _securityMasks = SecurityMasks.None;
20 | }
21 |
22 | ///
23 | /// Initializes a new instance of the DET.LDAP class.
24 | ///
25 | /// An instance of the DET.DomainSearcher class.
26 | /// The security mask for the DirectorySearcher.
27 | public LDAP(DomainSearcher searcher, SecurityMasks securityMasks)
28 | {
29 | _searcher = searcher;
30 | _securityMasks = securityMasks;
31 | }
32 |
33 | ///
34 | /// Execute a raw LDAP query.
35 | ///
36 | /// The LDAP filter.
37 | /// Optional parameters.
38 | /// A multi-level dictionary of LDAP properties and an array of their values.
39 | public Dictionary> ExecuteQuery(string filter, string[] properties = null)
40 | {
41 | var searcher = new DirectorySearcher(_searcher.Directory)
42 | {
43 | Filter = filter,
44 | SecurityMasks = _securityMasks
45 | };
46 |
47 | if (properties is not null)
48 | {
49 | searcher.PropertiesToLoad.AddRange(properties);
50 | }
51 |
52 | var searchResultCollection = searcher.FindAll();
53 |
54 | var resultDictionary = new Dictionary>();
55 |
56 | foreach (SearchResult searchResult in searchResultCollection)
57 | {
58 | resultDictionary.Add(searchResult.Path, null);
59 |
60 | var dictionary = new Dictionary();
61 |
62 | foreach (DictionaryEntry entry in searchResult.Properties)
63 | {
64 | var values = new List