Skip to content

Commit c0433e1

Browse files
D.RoweD.Rowe
D.Rowe
authored and
D.Rowe
committed
added parameters for group create and computer create to remove the multiple get-ad calls in the code
1 parent d878695 commit c0433e1

File tree

4 files changed

+204
-98
lines changed

4 files changed

+204
-98
lines changed

AD_Computers_Create/CreateComputers.ps1

+125-57
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,140 @@
22
#Create Computer Objects
33
################################
44
Function CreateComputer{
5+
<#
6+
.SYNOPSIS
7+
Creates a Computer Object in an active directory environment based on random data
8+
9+
.DESCRIPTION
10+
Starting with the root container this tool randomly places users in the domain.
11+
12+
.PARAMETER Domain
13+
The stored value of get-addomain is used for this. It is used to call the PDC and other items in the domain
14+
15+
.PARAMETER OUList
16+
The stored value of get-adorganizationalunit -filter *. This is used to place Computers in random locations.
17+
18+
.PARAMETER UserList
19+
The stored value of get-aduser -filter *. This is used to put random ownership on computers.
20+
21+
.PARAMETER ScriptDir
22+
The location of the script. Pulling this into a parameter to attempt to speed up processing.
23+
24+
.EXAMPLE
25+
26+
27+
28+
.NOTES
29+
30+
31+
Unless required by applicable law or agreed to in writing, software
32+
distributed under the License is distributed on an "AS IS" BASIS,
33+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34+
See the License for the specific language governing permissions and
35+
limitations under the License.
36+
37+
Author's blog: https://www.secframe.com
38+
39+
40+
#>
41+
[CmdletBinding()]
42+
43+
param
44+
(
45+
[Parameter(Mandatory = $false,
46+
Position = 1,
47+
HelpMessage = 'Supply a result from get-addomain')]
48+
[Object[]]$Domain,
49+
[Parameter(Mandatory = $false,
50+
Position = 2,
51+
HelpMessage = 'Supply a result from get-adorganizationalunit -filter *')]
52+
[Object[]]$OUList,
53+
[Parameter(Mandatory = $false,
54+
Position = 3,
55+
HelpMessage = 'Supply a result from get-aduser -filter *')]
56+
[Object[]]$UserList,
57+
[Parameter(Mandatory = $false,
58+
Position = 4,
59+
HelpMessage = 'Supply the script directory for where this script is stored')]
60+
[string]$ScriptDir
61+
)
62+
63+
if(!$PSBoundParameters.ContainsKey('Domain')){
64+
if($args[0]){
65+
$setDC = $args[0].pdcemulator
66+
$dn = $args[0].distinguishedname
67+
}
68+
else{
69+
$d = Get-ADDomain
70+
$setDC = ($d).pdcemulator
71+
$dn = ($d).distinguishedname
72+
}
73+
}else {$setDC = $Domain.pdcemulator}
74+
if (!$PSBoundParameters.ContainsKey('OUList')){
75+
if($args[1]){
76+
$OUsAll = $args[1]
77+
}
78+
else{
79+
$OUsAll = get-adobject -Filter {objectclass -eq 'organizationalunit'} -ResultSetSize 300
80+
}
81+
}else {
82+
$OUsAll = $OUList
83+
}
84+
if (!$PSBoundParameters.ContainsKey('UserList')){
85+
if($args[1]){
86+
$UserList = $args[2]
87+
}
88+
else{
89+
$UserList = get-aduser -ResultSetSize 2500 -Server $setDC -Filter *
90+
}
91+
}else {
92+
$UserList = $UserList
93+
}
94+
if (!$PSBoundParameters.ContainsKey('ScriptDir')){
95+
96+
if($args[2]){
97+
98+
$scriptpath = $args[2]}
99+
else{
100+
$scriptpath = "$((Get-Location).path)\AD_Computers_Create\"
101+
}
102+
103+
}else{
104+
$scriptpath = $ScriptDir
105+
}
5106

6-
param(
107+
# param(
7108

8-
$Owner,
9-
$Creator,
10-
$WorkstationOrServer,
11-
$OUlocation,
12-
$Make,
13-
$Model,
14-
$SN,
15-
$IP,
16-
$DNS,
17-
$Gateway,
18-
$WorkstationType,
19-
$ServerApplication,
20-
$Description,
21-
$debug,
22-
$HideResults
23-
)
109+
# $Owner,
110+
# $Creator,
111+
# $WorkstationOrServer,
112+
# $OUlocation,
113+
# $Make,
114+
# $Model,
115+
# $SN,
116+
# $IP,
117+
# $DNS,
118+
# $Gateway,
119+
# $WorkstationType,
120+
# $ServerApplication,
121+
# $Description,
122+
# $debug,
123+
# $HideResults
124+
# )
24125

25126

26127
#=======================================================================
27128

28-
29-
$setDC = (Get-ADDomain).pdcemulator
30-
$userlist = get-adobject -Filter {objectclass -eq 'user'} -ResultSetSize 2500 -Server $setdc|Where-object -Property objectclass -eq user
31-
function Get-ScriptDirectory {
32-
Split-Path -Parent $PSCommandPath
33-
}
34-
$scriptPath = Get-ScriptDirectory
35129
$scriptparent = (get-item $scriptpath).parent.fullname
36130
$3lettercodes = import-csv ($scriptparent + "\AD_OU_CreateStructure\3lettercodes.csv")
37131
#=======================================================================
38-
$dn = (get-addomain).distinguishedname
39132

40-
#get owner all parameters and store as variable to call upon later
41-
$ownerinfo = Get-Random $userlist
42-
if ($PSBoundParameters.ContainsKey('Creator') -eq $true)
43-
{$adminID = $Creator
44-
}
45-
else{$adminID = $wtfwasthis = ((whoami) -split '\\')[1]}
133+
#get owner all parameters and store as variable to call upon later
134+
$ownerinfo = Get-Random $userlist
135+
if ($PSBoundParameters.ContainsKey('Creator') -eq $true)
136+
{$adminID = $Creator
137+
}
138+
else{$adminID = ((whoami) -split '\\')[1]}
46139

47140

48141
#=======================================================================
@@ -183,7 +276,7 @@ Function CreateComputer{
183276
# END SERVER OU identification
184277
#=========================================
185278
<#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#>
186-
$OUsAll = get-adobject -Filter {objectclass -eq 'organizationalunit'} -ResultSetSize 300
279+
# $OUsAll = get-adobject -Filter {objectclass -eq 'organizationalunit'} -ResultSetSize 300
187280
# removing containers right now. will add later $ousall += get-adobject -Filter {objectclass -eq 'container'} -ResultSetSize 300|where-object -Property objectclass -eq 'container'|where-object -Property distinguishedname -notlike "*}*"|where-object -Property distinguishedname -notlike "*DomainUpdates*"
188281

189282
$ouLocation = (Get-Random $OUsAll).distinguishedname
@@ -258,9 +351,6 @@ Function CreateComputer{
258351

259352
$ou = $oulocation
260353
[System.Collections.ArrayList]$att_to_add = @('servicePrincipalName')
261-
262-
263-
$division = $computernameprefix1
264354

265355
$manager = $ownerinfo.distinguishedname
266356
$sam = ($CompName) + "$"
@@ -320,26 +410,4 @@ Function CreateComputer{
320410
$done = @()
321411

322412

323-
}
324-
Function NewComputers{
325-
param(
326-
327-
$NumberOfMachines
328-
)
329-
330-
if ($PSBoundParameters.ContainsKey('NumberOfMachines') -eq $false){
331-
$NumberofMachines = 5
332-
#write-host No number specified. Defaulting to create 5 machines
333-
}
334-
335-
336-
$i = 1
337-
do {
338-
CreateComputer
339-
$i++
340-
341-
}
342-
while ($i -le $NumberOfMachines)
343-
344-
345413
}

AD_Groups_Create/CreateGroup.ps1

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Function CreateGroup {
1111
1212
.PARAMETER OUList
1313
The stored value of get-adorganizationalunit -filter *. This is used to place users in random locations.
14+
15+
.PARAMETER UserList
16+
The stored value of get-aduser -filter *. This is used to place make random users owners/managers of groups.
1417
1518
.PARAMETER ScriptDir
1619
The location of the script. Pulling this into a parameter to attempt to speed up processing.

AD_Users_Create/CreateUsers.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@
316316
try{Set-ADUser -Identity $name -UserPrincipalName "$upn" }
317317
catch{}
318318

319-
return $false
319+
# return $false
320320
################################
321321
#End Create User Objects
322322
################################

Invoke-BadBlood.ps1

+75-40
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[String]
1010
.NOTES
1111
Written by David Rowe, Blog secframe.com
12-
Twitter : @davidprowe
12+
Twitter : @davicdprowe
1313
I take no responsibility for any issues caused by this script. I am not responsible if this gets run in a production domain.
1414
Thanks HuskyHacks for user/group/computer count modifications. I moved them to parameters so that this tool can be called in a more rapid fashion.
1515
.FUNCTIONALITY
@@ -29,7 +29,7 @@ param
2929
[Parameter(Mandatory = $false,
3030
Position = 2,
3131
HelpMessage = 'Supply a count for user creation default 500')]
32-
[int32]$GroupCount = 500,
32+
[int32]$GroupCount = 10,
3333
[Parameter(Mandatory = $false,
3434
Position = 3,
3535
HelpMessage = 'Supply the script directory for where this script is stored')]
@@ -123,20 +123,84 @@ if ($badblood -eq 'badblood') {
123123

124124
.($basescriptPath + '\AD_Users_Create\CreateUsers.ps1')
125125
$createuserscriptpath = $basescriptPath + '\AD_Users_Create\'
126-
# write-host $createuserscriptpath
127-
#Add custom function to runspace pool https://devblogs.microsoft.com/scripting/powertip-add-custom-function-to-runspace-pool/
128-
#. .\AD_Users_Create\CreateUsers.ps1
126+
do {
127+
createuser -Domain $Domain -OUList $ousAll -ScriptDir $createuserscriptpath
128+
Write-Progress -Activity "Random Stuff into A domain - Creating $UserCount Users" -Status "Progress:" -PercentComplete ($x / $UserCount * 100)
129+
$x++
130+
}while ($x -lt $UserCount)
131+
132+
#Group Creation
133+
$AllUsers = Get-aduser -Filter *
134+
write-host "Creating Groups on Domain" -ForegroundColor Green
135+
129136
$x = 1
130-
$Definition = Get-Content Function:\CreateUser -ErrorAction Stop
131-
# $Definition = Get-Content ($basescriptPath + '\AD_Users_Create\CreateUsers.ps1') -ErrorAction Stop
137+
Write-Progress -Activity "Random Stuff into A domain - Creating $GroupCount Groups" -Status "Progress:" -PercentComplete ($i / $totalscripts * 100)
138+
$i++
139+
.($basescriptPath + '\AD_Groups_Create\CreateGroup.ps1')
140+
$createGroupScriptPath = $basescriptPath + '\AD_Groups_Create\'
141+
142+
do {
143+
Creategroup -Domain $Domain -OUList $ousAll -UserList $AllUsers -ScriptDir $createGroupScriptPath
144+
Write-Progress -Activity "Random Stuff into A domain - Creating $GroupCount Groups" -Status "Progress:" -PercentComplete ($x / $GroupCount * 100)
145+
$x++
146+
}while ($x -lt $GroupCount)
147+
$Grouplist = Get-ADGroup -Filter { GroupCategory -eq "Security" -and GroupScope -eq "Global" } -Properties isCriticalSystemObject
148+
$LocalGroupList = Get-ADGroup -Filter { GroupScope -eq "domainlocal" } -Properties isCriticalSystemObject
149+
150+
#Computer Creation Time
151+
write-host "Creating Computers on Domain" -ForegroundColor Green
152+
153+
$X = 1
154+
Write-Progress -Activity "Random Stuff into A domain - Creating Computers" -Status "Progress:" -PercentComplete ($i / $totalscripts * 100)
155+
.($basescriptPath + '\AD_Computers_Create\CreateComputers.ps1')
156+
$I++
157+
do {
158+
Write-Progress -Activity "Random Stuff into A domain - Creating $ComputerCount computers" -Status "Progress:" -PercentComplete ($x / $ComputerCount * 100)
159+
createcomputer
160+
$x++
161+
}while ($x -lt $ComputerCount)
162+
$Complist = get-adcomputer -filter *
163+
164+
165+
#Permission Creation of ACLs
166+
$I++
167+
write-host "Creating Permissions on Domain" -ForegroundColor Green
168+
Write-Progress -Activity "Random Stuff into A domain - Creating Random Permissions" -Status "Progress:" -PercentComplete ($i / $totalscripts * 100)
169+
.($basescriptPath + '\AD_Permissions_Randomizer\GenerateRandomPermissions.ps1')
170+
171+
172+
# Nesting of objects
173+
$I++
174+
write-host "Nesting objects into groups on Domain" -ForegroundColor Green
175+
.($basescriptPath + '\AD_Groups_Create\AddRandomToGroups.ps1')
176+
Write-Progress -Activity "Random Stuff into A domain - Adding Stuff to Stuff and Things" -Status "Progress:" -PercentComplete ($i / $totalscripts * 100)
177+
AddRandomToGroups -Domain $Domain -Userlist $AllUsers -GroupList $Grouplist -LocalGroupList $LocalGroupList -complist $Complist
178+
179+
# ATTACK Vector Automation
180+
181+
# SPN Generation
182+
$I++
183+
write-host "Adding random SPNs to a few User and Computer Objects" -ForegroundColor Green
184+
Write-Progress -Activity "SPN Stuff Now" -Status "Progress:" -PercentComplete ($i / $totalscripts * 100)
185+
.($basescriptpath + '\AD_Attack_Vectors\AD_SPN_Randomizer\CreateRandomSPNs.ps1')
186+
CreateRandomSPNs -SPNCount 50
187+
188+
189+
190+
}
191+
# $Definition = Get-Content Function:\CreateUser -ErrorAction Stop
192+
<#
193+
Attempt at multi threading. Issues with AD Limits and connections per user per second.
194+
#Add custom function to runspace pool https://devblogs.microsoft.com/scripting/powertip-add-custom-function-to-runspace-pool/
195+
$Definition = Get-Content ($basescriptPath + '\AD_Users_Create\CreateUsers.ps1') -ErrorAction Stop
132196
#Create a sessionstate function entry
133197
$SessionStateFunction = New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry -ArgumentList ‘CreateUser’, $Definition
134198
#Create a SessionStateFunction
135199
$InitialSessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
136200
$initialSessionState.ImportPSModule("ActiveDirectory")
137201
$InitialSessionState.Commands.Add($SessionStateFunction)
138202
139-
$RunspacePool = [RunspaceFactory]::CreateRunspacePool(1,10,$InitialSessionState,$Host)
203+
$RunspacePool = [RunspaceFactory]::CreateRunspacePool(1,5,$InitialSessionState,$Host)
140204
$RunspacePool.Open()
141205
$runspaces = $results = @()
142206
do {
@@ -191,7 +255,7 @@ if ($badblood -eq 'badblood') {
191255
$initialSessionState.ImportPSModule("ActiveDirectory")
192256
$InitialSessionState.Commands.Add($SessionStateFunction)
193257
194-
$RunspacePool = [RunspaceFactory]::CreateRunspacePool(1,10,$InitialSessionState,$Host)
258+
$RunspacePool = [RunspaceFactory]::CreateRunspacePool(1,5,$InitialSessionState,$Host)
195259
$RunspacePool.Open()
196260
$runspaces = $results = @()
197261
do {
@@ -237,7 +301,7 @@ if ($badblood -eq 'badblood') {
237301
$initialSessionState.ImportPSModule("ActiveDirectory")
238302
$InitialSessionState.Commands.Add($SessionStateFunction)
239303
240-
$RunspacePool = [RunspaceFactory]::CreateRunspacePool(1,10,$InitialSessionState,$Host)
304+
$RunspacePool = [RunspaceFactory]::CreateRunspacePool(1,5,$InitialSessionState,$Host)
241305
$RunspacePool.Open()
242306
$runspaces = $results = @()
243307
@@ -259,33 +323,4 @@ if ($badblood -eq 'badblood') {
259323
}
260324
$RunspacePool.Close()
261325
$RunspacePool.Dispose()
262-
263-
$Complist = get-adcomputer -filter *
264-
265-
266-
#Permission Creation of ACLs
267-
$I++
268-
write-host "Creating Permissions on Domain" -ForegroundColor Green
269-
Write-Progress -Activity "Random Stuff into A domain - Creating Random Permissions" -Status "Progress:" -PercentComplete ($i / $totalscripts * 100)
270-
.($basescriptPath + '\AD_Permissions_Randomizer\GenerateRandomPermissions.ps1')
271-
272-
273-
# Nesting of objects
274-
$I++
275-
write-host "Nesting objects into groups on Domain" -ForegroundColor Green
276-
.($basescriptPath + '\AD_Groups_Create\AddRandomToGroups.ps1')
277-
Write-Progress -Activity "Random Stuff into A domain - Adding Stuff to Stuff and Things" -Status "Progress:" -PercentComplete ($i / $totalscripts * 100)
278-
AddRandomToGroups -Domain $Domain -Userlist $AllUsers -GroupList $Grouplist -LocalGroupList $LocalGroupList -complist $Complist
279-
280-
# ATTACK Vector Automation
281-
282-
# SPN Generation
283-
$I++
284-
write-host "Adding random SPNs to a few User and Computer Objects" -ForegroundColor Green
285-
Write-Progress -Activity "SPN Stuff Now" -Status "Progress:" -PercentComplete ($i / $totalscripts * 100)
286-
.($basescriptpath + '\AD_Attack_Vectors\AD_SPN_Randomizer\CreateRandomSPNs.ps1')
287-
CreateRandomSPNs -SPNCount 50
288-
289-
290-
291-
}
326+
#>

0 commit comments

Comments
 (0)