-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathTemplate.ps1
635 lines (441 loc) · 13.7 KB
/
Template.ps1
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
function Invoke-BloodHound
{
<#
.SYNOPSIS
Runs the BloodHound C# Ingestor using reflection. The assembly is stored in this file.
.DESCRIPTION
Using reflection and assembly.load, load the compiled BloodHound C# ingestor into memory
and run it without touching disk. Parameters are converted to the equivalent CLI arguments
for the SharpHound executable and passed in via reflection. The appropriate function
calls are made in order to ensure that assembly dependencies are loaded properly.
.PARAMETER CollectionMethod
Specifies the CollectionMethod being used. Possible value are:
Group - Collect group membership information
LocalGroup - Collect local group information for computers
LocalAdmin - Collect local admin users for computers
RDP - Collect remote desktop users for computers
DCOM - Collect distributed COM users for computers
PSRemote - Collected members of the Remote Management Users group for computers
Session - Collect session information for computers
Trusts - Enumerate domain trust data
ACL - Collect ACL (Access Control List) data
Container - Collect GPO/OU Data
ComputerOnly - Collects Local Group and Session data
GPOLocalGroup - Collects Local Group information using GPO (Group Policy Objects)
LoggedOn - Collects session information using privileged methods (needs admin!)
ObjectProps - Collects node property information for users and computers
SPNTargets - Collects SPN targets (currently only MSSQL)
Default - Collects Group Membership, Local Admin, Sessions, Containers, ACLs and Domain Trusts
DcOnly - Collects Group Membership, ACLs, ObjectProps, Trusts, Containers, and GPO Admins
All - Collect all data
This can be a list of comma seperated valued as well to run multiple collection methods!
.PARAMETER Domain
Specifies the domain to enumerate. If not specified, will enumerate the current
domain your user context specifies.
.PARAMETER SearchForest
Search all trusted domains in the forest.
.PARAMETER Stealth
Use stealth collection options, will sacrifice data quality in favor of much reduced
network impact
.PARAMETER LdapFilter
Append this ldap filter to the search filter to further filter the results enumerated
.PARAMETER DistinguishedName
DistinguishedName to start LDAP searches at. Equivalent to the old -Ou option
.PARAMETER ComputerFile
A file containing a list of computers to enumerate. This option can only be used with the following Collection Methods:
Session, Session, LocalGroup, ComputerOnly, LoggedOn
.PARAMETER OutputDirectory
Folder to output files too
.PARAMETER OutputPrefix
Prefix to add to output files
.PARAMETER CacheName
Name for the cache file dropped to disk (default: unique hash generated per machine)
.PARAMETER MemCache
Don't write the cache file to disk. Caching will still be performed in memory.
.PARAMETER RebuildCache
Invalidate and rebuild the cache file
.PARAMETER RandomFileNames
Randomize file names completely
.PARAMETER ZipFilename
Name for the zip file output by data collection
.PARAMETER NoZip
Do NOT zip the json files
.PARAMETER ZipPassword
Encrypt the zip file with the specified password
.PARAMETER TrackComputerCalls
Write a CSV file with the results of each computer API call to disk
.PARAMETER PrettyPrint
Output "pretty" json with formatting for readability
.PARAMETER LdapUsername
Username for connecting to LDAP. Use this if you're using a non-domain account for connecting to computers
.PARAMETER LdapPassword
Password for connecting to LDAP. Use this if you're using a non-domain account for connecting to computers
.PARAMETER DomainController
Domain Controller to connect too. Specifiying this can result in data loss
.PARAMETER LdapPort
Port LDAP is running on. Defaults to 389/686 for LDAPS
.PARAMETER SecureLDAP
Connect to LDAPS (LDAP SSL) instead of regular LDAP
.PARAMETER DisableCertVerification
Disable certificate verification for secure LDAP
.PARAMETER DisableSigning
Disables keberos signing/sealing, making LDAP traffic viewable
.PARAMETER SkipPortCheck
Skip SMB port checks when connecting to computers
.PARAMETER PortScanTimeout
Timeout for port checks
.PARAMETER SkipPasswordCheck
Skip checking of PwdLastSet time for computer scanning
.PARAMETER ExcludeDCs
Exclude domain controllers from enumeration (usefult o avoid Microsoft ATP/ATA)
.PARAMETER Throttle
Throttle requests to computers (in milliseconds)
.PARAMETER Jitter
Add jitter to throttle
.PARAMETER Threads
Number of threads to run enumeration with (Default: 50)
.PARAMETER SkipRegistryLoggedOn
Disable remote registry check in LoggedOn collection
.PARAMETER OverrideUserName
Override username to filter for NetSessionEnum
.PARAMETER RealDNSName
Overrides the DNS name used for API calls
.PARAMETER CollectAllProperties
Collect all string LDAP properties on objects
.PARAMETER Loop
Perform looping for computer collection
.PARAMETER LoopDuration
Duration to perform looping (Default 02:00:00)
.PARAMETER LoopInterval
Interval to sleep between loops (Default 00:05:00)
.PARAMETER StatusInterval
Interval for displaying status in milliseconds
.PARAMETER Verbosity
Change verbosity of output. Default 2 (lower is more)
.PARAMETER Help
Display this help screen
.PARAMETER Version
Display version information
.EXAMPLE
PS C:\> Invoke-BloodHound
Executes the default collection options and exports JSONs to the current directory, compresses the data to a zip file,
and then removes the JSON files from disk
.EXAMPLE
PS C:\> Invoke-BloodHound -Loop -LoopInterval 00:01:00 -LoopDuration 00:10:00
Executes session collection in a loop. Will wait 1 minute after each run to continue collection
and will continue running for 10 minutes after which the script will exit
.EXAMPLE
PS C:\> Invoke-BloodHound -CollectionMethod All
Runs ACL, ObjectProps, Container, and Default collection methods, compresses the data to a zip file,
and then removes the JSON files from disk
.EXAMPLE
PS C:\> Invoke-BloodHound -CollectionMethod DCOnly -NoSaveCache -RandomizeFilenames -EncryptZip
(Opsec!) Run LDAP only collection methods (Groups, Trusts, ObjectProps, ACL, Containers, GPO Admins) without outputting the cache file to disk.
Randomizes filenames of the JSON files and the zip file and adds a password to the zip file
#>
[CmdletBinding(PositionalBinding = $false)]
param(
[Alias("c")]
[String[]]
$CollectionMethod = [String[]]@('Default'),
[Alias("d")]
[String]
$Domain,
[Alias("s")]
[Switch]
$SearchForest,
[Switch]
$Stealth,
[String]
$LdapFilter,
[String]
$DistinguishedName,
[String]
$ComputerFile,
[ValidateScript({ Test-Path -Path $_ })]
[String]
$OutputDirectory = $( Get-Location ),
[ValidateNotNullOrEmpty()]
[String]
$OutputPrefix,
[String]
$CacheName,
[Switch]
$MemCache,
[Switch]
$RebuildCache,
[Switch]
$RandomFilenames,
[String]
$ZipFilename,
[Switch]
$NoZip,
[String]
$ZipPassword,
[Switch]
$TrackComputerCalls,
[Switch]
$PrettyPrint,
[String]
$LdapUsername,
[String]
$LdapPassword,
[string]
$DomainController,
[ValidateRange(0, 65535)]
[Int]
$LdapPort,
[Switch]
$SecureLdap,
[Switch]
$DisableCertVerification,
[Switch]
$DisableSigning,
[Switch]
$SkipPortCheck,
[ValidateRange(50, 5000)]
[Int]
$PortCheckTimeout = 500,
[Switch]
$SkipPasswordCheck,
[Switch]
$ExcludeDCs,
[Int]
$Throttle,
[ValidateRange(0, 100)]
[Int]
$Jitter,
[Int]
$Threads,
[Switch]
$SkipRegistryLoggedOn,
[String]
$OverrideUsername,
[String]
$RealDNSName,
[Switch]
$CollectAllProperties,
[Switch]
$Loop,
[String]
$LoopDuration,
[String]
$LoopInterval,
[ValidateRange(500, 60000)]
[Int]
$StatusInterval,
[Alias("v")]
[ValidateRange(0, 5)]
[Int]
$Verbosity,
[Alias("h")]
[Switch]
$Help,
[Switch]
$Version
)
$vars = New-Object System.Collections.Generic.List[System.Object]
if ($CollectionMethod)
{
$vars.Add("--CollectionMethods");
foreach ($cmethod in $CollectionMethod)
{
$vars.Add($cmethod);
}
}
if ($Domain)
{
$vars.Add("--Domain");
$vars.Add($Domain);
}
if ($SearchForest)
{
$vars.Add("--SearchForest")
}
if ($Stealth)
{
$vars.Add("--Stealth")
}
if ($LdapFilter)
{
$vars.Add("--LdapFilter");
$vars.Add($LdapFilter);
}
if ($DistinguishedName)
{
$vars.Add("--DistinguishedName")
$vars.Add($DistinguishedName)
}
if ($ComputerFile)
{
$vars.Add("--ComputerFile");
$vars.Add($ComputerFile);
}
if ($OutputDirectory)
{
$vars.Add("--OutputDirectory");
$vars.Add($OutputDirectory);
}
if ($OutputPrefix)
{
$vars.Add("--OutputPrefix");
$vars.Add($OutputPrefix);
}
if ($CacheName)
{
$vars.Add("--CacheName");
$vars.Add($CacheName);
}
if ($NoSaveCache)
{
$vars.Add("--MemCache");
}
if ($RebuildCache)
{
$vars.Add("--RebuildCache");
}
if ($RandomFilenames)
{
$vars.Add("--RandomFilenames");
}
if ($ZipFileName)
{
$vars.Add("--ZipFileName");
$vars.Add($ZipFileName);
}
if ($NoZip)
{
$vars.Add("--NoZip");
}
if ($ZipPassword)
{
$vars.Add("--ZipPassword");
$vars.Add($ZipPassword)
}
if ($TrackComputerCalls)
{
$vars.Add("--TrackComputerCalls")
}
if ($PrettyPrint)
{
$vars.Add("--PrettyPrint");
}
if ($LdapUsername)
{
$vars.Add("--LdapUsername");
$vars.Add($LdapUsername);
}
if ($LdapPassword)
{
$vars.Add("--LdapPassword");
$vars.Add($LdapPassword);
}
if ($DomainController)
{
$vars.Add("--DomainController");
$vars.Add($DomainController);
}
if ($LdapPort)
{
$vars.Add("--LdapPort");
$vars.Add($LdapPort);
}
if ($SecureLdap)
{
$vars.Add("--SecureLdap");
}
if ($DisableCertVerification)
{
$vars.Add("--DisableCertVerification")
}
if ($DisableSigning)
{
$vars.Add("--DisableSigning");
}
if ($SkipPortCheck)
{
$vars.Add("--SkipPortCheck");
}
if ($PortCheckTimeout)
{
$vars.Add("--PortCheckTimeout")
$vars.Add($PortCheckTimeout)
}
if ($SkipPasswordCheck)
{
$vars.Add("--SkipPasswordCheck");
}
if ($ExcludeDCs)
{
$vars.Add("--ExcludeDCs")
}
if ($Throttle)
{
$vars.Add("--Throttle");
$vars.Add($Throttle);
}
if ($Jitter -gt 0)
{
$vars.Add("--Jitter");
$vars.Add($Jitter);
}
if ($Threads)
{
$vars.Add("--Threads")
$vars.Add($Threads)
}
if ($SkipRegistryLoggedOn)
{
$vars.Add("--SkipRegistryLoggedOn")
}
if ($OverrideUserName)
{
$vars.Add("--OverrideUserName")
$vars.Add($OverrideUsername)
}
if ($RealDNSName)
{
$vars.Add("--RealDNSName")
$vars.Add($RealDNSName)
}
if ($CollectAllProperties)
{
$vars.Add("--CollectAllProperties")
}
if ($Loop)
{
$vars.Add("--Loop")
}
if ($LoopDuration)
{
$vars.Add("--LoopDuration")
$vars.Add($LoopDuration)
}
if ($LoopInterval)
{
$vars.Add("--LoopInterval")
$vars.Add($LoopInterval)
}
if ($StatusInterval)
{
$vars.Add("--StatusInterval")
$vars.Add($StatusInterval)
}
if ($Verbosity)
{
$vars.Add("-v");
$vars.Add($Verbosity);
}
if ($Help)
{
$vars.clear()
$vars.Add("--Help");
}
if ($Version)
{
$vars.clear();
$vars.Add("--Version");
}
$passed = [string[]]$vars.ToArray()
#ENCODEDCONTENTHERE
}