-
Notifications
You must be signed in to change notification settings - Fork 3
/
driver.ps1
425 lines (390 loc) · 16.5 KB
/
driver.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
<#
.Synopsis
Hardens a Windows domain
.DESCRIPTION
Uses a series of predefined GPO and programs to secure core aspects of the Windows operating system across a domain
.EXAMPLE
& driver.ps1
.EXAMPLE
start.bat
.INPUTS
None
.OUTPUTS
C:\incred.csv with plaintext usernames and passwords for domain and local users
.NOTES
File Name : driver.ps1
Author : Msfv3n0m
Requires : GroupPolicy, ActiveDirectory, Microsoft.PowerShell.Utility, Microsoft.PowerShell.Management, Microsoft.PowerShell.Security, Microsoft.PowerShell.LocalAccounts PowerShell modules
.LINK
https://github.com/Msfv3n0m/SteamRoller3
#>
function Resume () {
$input = ""
While ($input -ne "cont") {
Write-Host "Type 'cont' to continue `n" -ForegroundColor Yellow
$input = Read-Host "input"
}
Write-Host "`n"
}
function GetTools ($cd, $downloads) {
gci -file $downloads | ?{$_.name -like "*hollows_hunter*"} | %{Copy-Item $_.fullname $cd\SharingIsCaring\tools}
gci -file $downloads | ?{$_.name -like "*processhacker*"} | %{Copy-Item $_.fullname $cd\SharingIsCaring\tools}
gci -file $downloads | ?{$_.name -like "*bluespawn*"} | %{Copy-Item $_.fullname $cd\SharingIsCaring\tools}
gci -file $downloads\7z*.msi | %{Move-Item $_.FullName $cd\SharingIsCaring\7z.msi}
Copy-Item $downloads\modsecurity*.msi | %{Move-Item $_.FullName $cd\SharingIsCaring\modsecurity.msi}
Copy-Item $cd\netstat.ps1 $cd\SharingIsCaring\tools
if (Test-Path $downloads\Sysinternals\) {
Copy-Item $downloads\Sysinternals\sdelete.exe $cd
Copy-Item $downloads\Sysinternals\TCPVCon.exe $cd\SharingIsCaring\tools
Copy-Item $downloads\Sysinternals\PSExec.exe $cd\SharingIsCaring\tools
Copy-Item $downloads\Sysinternals\sdelete.exe $cd\SharingIsCaring\tools
Copy-Item $downloads\Sysinternals\Autoruns.exe $cd\SharingIsCaring\tools
Copy-Item $downloads\Sysinternals\strings.exe $cd\SharingIsCaring\tools
Copy-Item $downloads\Sysinternals\TCPView.exe $cd\SharingIsCaring\tools
Copy-Item $downloads\Sysinternals\procexp.exe $cd\SharingIsCaring\tools
Copy-Item $downloads\Sysinternals\Sysmon.exe $cd\SharingIsCaring
}
Write-Host "`nEnsure that the appropriate tools are in the .\SharingIsCaring\tools folder" -ForegroundColor Yellow
Resume
}
function ImportGPO2 ([String]$rootdir,[switch]$formatOutput) {
<#
This function is a derivative of a script found in Microsoft's Security Compliance Toolkit
#>
$results = New-Object System.Collections.SortedList
Get-ChildItem -Recurse -Include backup.xml $rootdir | ForEach-Object {
$guid = $_.Directory.Name
$displayName = ([xml](gc $_)).GroupPolicyBackupScheme.GroupPolicyObject.GroupPolicyCoreSettings.DisplayName.InnerText
$results.Add($displayName, $guid)
}
if ($formatOutput)
{
$results | Format-Table -AutoSize
}
else
{
$results
}
}
function ImportGPO1 ($cd) {
<#
This function is a derivative of a script found in Microsoft's Security Compliance Toolkit
#>
Write-Host "Importing GPOs" -ForegroundColor Green
$GpoMap = ImportGPO2("$cd\GPO")
#Write-Host "Importing the following GPOs:"
#Write-Host
#$GpoMap.Keys | ForEach-Object { Write-Host $_ }
#Write-Host
#Write-Host
$gpoDir = "$cd\GPO"
$GpoMap.Keys | ForEach-Object {
$key = $_
$guid = $GpoMap[$key]
#Write-Host ($guid + ": " + $key)
Import-GPO -BackupId $guid -Path $gpoDir -TargetName "$key" -CreateIfNeeded | Out-Null
}
}
function CreateOUAndDistribute () {
Write-Host "Creating OUs and Distributing Computers" -ForegroundColor Green
$root = (Get-ADRootDSE | Select -ExpandProperty RootDomainNamingContext)
Get-ADComputer -Filter {OperatingSystem -like "*Windows*"} -SearchBase "CN=Computers,$root" | %{
$input1 = "CN=" + $_.Name + ",CN=Computers," + $root
$input2 = "OU=" + $_.Name + "," + $root
New-ADOrganizationalUnit -Name $_.Name -Path $root
Move-ADObject -Identity $input1 -TargetPath $input2
New-GPLink -Name "Tools" -Target $input2 -LinkEnabled Yes -Enforced Yes
New-GPLink -Name "WinRM (http)" -Target $input2 -LinkEnabled Yes -Enforced Yes
New-GPLink -Name "General" -Target $input2 -LinkEnabled Yes -Enforced Yes
New-GPLink -Name "Events" -Target $input2 -LinkEnabled Yes -Enforced No
New-GPLink -Name "RDP" -Target $input2 -LinkEnabled Yes -Enforced Yes
}
Get-ADComputer -Filter {OperatingSystem -like "*Windows*"} -SearchBase "OU=Domain Controllers,$root" | %{
$input1 = "CN=" + $_.Name + ",OU=Domain Controllers," + $root
$input2 = "OU=" + $_.Name + "," + $root
New-ADOrganizationalUnit -Name $_.Name -Path $root
Move-ADObject -Identity $input1 -TargetPath $input2
New-GPLink -Name "Tools" -Target $input2 -LinkEnabled Yes -Enforced Yes
New-GPLink -Name "WinRM (http)" -Target $input2 -LinkEnabled Yes -Enforced Yes
New-GPLink -Name "General" -Target $input2 -LinkEnabled Yes -Enforced Yes
New-GPLink -Name "Events" -Target $input2 -LinkEnabled Yes -Enforced No
New-GPLink -Name "RDP" -Target $input2 -LinkEnabled Yes -Enforced Yes
New-GPLink -Name "SMB" -Target $input2 -LinkEnabled Yes -Enforced Yes
New-GPLink -Name "ADDS (LDAP)" -Target $input2 -LinkEnabled Yes -Enforced Yes
}
}
function Replace ($cd) {
Write-Host "Inserting DC Name into GPOs" -ForegroundColor Green
Get-ChildItem "$cd\GPO\" | %{
$path1 = $_.FullName + "\gpreport.xml"
if (Test-Path -Path $path1 -PathType Leaf) {
(Get-Content $path1) -replace "replaceme1", "$(hostname)" | Set-Content $path1
}
$path2 = $_.FullName + "\DomainSysvol\GPO\Machine\Preferences\Files\Files.xml"
if (Test-Path -Path $path2 -PathType Leaf) {
(Get-Content $path2) -replace "replaceme1", "$(hostname)" | Set-Content $path2
}
}
}
function StartSMBShare ($cd) {
Write-Host "Starting SMB Share" -ForegroundColor Green
net share SharingIsCaring="$cd\SharingIsCaring"
icacls.exe "$cd\SharingIsCaring" /inheritancelevel:e /grant "*S-1-5-11:(OI)(CI)(R)" #grant acess to authenticated users
}
$passFuncs = {
function ChangeLocalPasswords ($ServersList, $cd, $admin) {
Write-Host "Changing local passwords" -ForegroundColor Green
$newPass="Superchiapet1"
$cmdCommand1 = @"
For /f %a in ('wmic useraccount get name') do net user %a password123?
"@ # > null
$ServersList | %{
Write-Host "Attempting to change passwords on $_" -ForegroundColor Green
Try {
Invoke-Command -ComputerName $_ -ArgumentList $cmdCommand, $admin -ScriptBlock {
Param($cmdCommand, $admin)
Try {
Add-Type -AssemblyName System.Web
Get-LocalUser | ?{$_.Name -ne $admin -and $_.Name -ne 'bone' -and $_.Name -ne 'bwo' -and $_.Name -ne 'bee'} | %{
$pass=[System.Web.Security.Membership]::GeneratePassword(17,2)
Set-LocalUser -Name $_.Name -Password (ConvertTo-SecureString -AsPlainText $pass -Force)
Write-Output "$(hostname)\$_,$pass"
$pass = $Null
}
Write-Host "Passwords randomized on $(hostname)" -ForegroundColor Green
}
Catch {
Add-Type -AssemblyName System.Web
Get-WMIObject -Class Win32_UserAccount | ?{$_.Name -ne $admin} | %{
$name = $_.Name
$pass=[System.Web.Security.Membership]::GeneratePassword(17,2)
net user $_.Name $pass > $Null
Write-Output "$(hostname)\$name,$pass"
$pass = $Null
}
wevtutil cl Microsoft-Windows-Powershell/Operational
Write-Host "Passwords randomized on $(hostname) with wmi" -ForegroundColor Green
}
} # >> C:\incred.csv
# & $cd\PsExec.exe \\$_ -nobanner -accepteula powershell -command "Add-Type -AssemblyName System.Web;`$c = ','; `$h=`$(hostname); Get-LocalUser | ?{`$_.Name -ne 'Administrator'} | %{`$pass=[System.Web.Security.Membership]::GeneratePassword(20,2); Set-LocalUser -Name `$_.Name -Password (ConvertTo-SecureString -AsPlainText `$pass -Force); Write-Output `$h\`$_`$c`$pass; `$pass = `$Null}" >> C:\incred.csv
}
Catch {
Write-Output "Could not access " $_
}
}
}
function ChangeADPass () {
Write-Host "Changing Active Directory Users' Passwords" -ForegroundColor Green
$domain = $(Get-ADDomain | Select -ExpandProperty NetBIOSName)
Add-Type -AssemblyName System.Web
# Write-Output "Username,Password" > C:\incred.csv
Get-ADUser -Filter * | ?{$_.Name -ne $env:username} | %{
$user = $_.Name
$pass = [System.Web.Security.Membership]::GeneratePassword(17,2)
Write-Output "$domain\$user,$pass"
Set-ADAccountPassword -Identity $_.Name -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $pass -Force)
$pass = $Null
}
}
}
function RemoveFirewallRules($ServersList, $DCList) {
Write-Host "Blocking default inbound and outbound traffic" -ForegroundColor Green
if ($ServersList -ne $Null)
{
$ServersList| %{
Invoke-Command -ComputerName $_ -ScriptBlock {
Try {
netsh advfirewall firewall set rule all new enable=no
}
Catch {
Write-Host "Could not block default inbound and outbound traffic on $_" -ForegroundColor Red
}
}
}
}
if ($ServersList -ne $Null)
{
$DCList| %{
Invoke-Command -ComputerName $_ -ScriptBlock {
Try {
netsh advfirewall firewall set rule all new enable=no
}
Catch {
Write-Host "Could not block default inbound and outbound traffic on $_" -ForegroundColor Red
}
}
}
}
}
function RemoveLinks ($ServersList, $DCList) {
Write-Host "Removing GPO links" -ForegroundColor Green
$root = (Get-ADRootDSE | Select -ExpandProperty RootDomainNamingContext)
if ($ServersList -ne $Null)
{
$ServersList| %{
$input2 = "OU=" + $_.Name + "," + $root
Remove-GPLink -Name "Tools" -Target $input2
# Remove-GPLink -Name "WinRM (http)" -Target $input2
Remove-GPLink -Name "Events" -Target $input2
}
}
$DCList | %{
$input2 = "OU=" + $_.Name + "," + $root
Remove-GPLink -Name "Tools" -Target $input2
# Remove-GPLink -Name "WinRM (http)" -Target $input2
Remove-GPLink -Name "Events" -Target $input2
}
}
function ChangeAdminPass () {
Write-Host "Setting a new administrator password" -ForegroundColor Yellow
net user $env:username *
# $newPass = Read-Host "Please set a new password for $(whoami)" -AsSecureString
# Set-ADAccountPassword -Identity $env:username -NewPassword $newPass -Reset
# netdom resetpwd /s:localhost /ud: $env:username /pd:*
}
function StopSMBShare () {
Write-Host "Deleting SMB Share" -ForegroundColor Green
net share SharingIsCaring /del /yes
}
function DeleteDriver ($cd) {
Write-Host "Deleting driver.ps1" -ForegroundColor Green
& "$cd\sdelete.exe" -accepteula -p 3 "$(pwd)\driver.ps1" > $Null
}
# Main
# Variables
$root = (Get-ADRootDSE | Select -ExpandProperty RootDomainNamingContext) # used in removelinks and createouanddistribute
$cd = $(pwd) # used in changelocalpasswords, gettools, importgpo1, deletedriver, startsmbshare, replace
$gpoDir = "$(pwd)\GPO" # used in importgpo1
$domain = $(Get-ADDomain | Select -ExpandProperty NetBIOSName) # used in changeadpass
$downloads = "$home\Downloads" # used in gettools
$root = (Get-ADRootDSE | Select -ExpandProperty RootDomainNamingContext)
$ServersList = $(Get-ADComputer -Filter {OperatingSystem -like "*Windows*"} -SearchBase "CN=Computers,$root") # used in createouanddistribute, removelinks, changelocalpasswords
$DCList = $(Get-ADComputer -Filter {OperatingSystem -like "*Windows*"} -SearchBase "OU=Domain Controllers,$root") # used in createouanddistribute, removelinks, changelocalpasswords
$ServersList | Select -ExpandProperty Name >> servers.txt
$ServersList | Select -ExpandProperty Name >> all.txt
$DCList | Select -ExpandProperty Name >> all.txt
$DCList | Select -ExpandProperty Name >> dc.txt
$AllServers = $ServersList + $DCList
$job1 = Start-Job -ScriptBlock {
param($downloads)
gci -file $downloads | ?{$_.name -like "*Sysinternals*"} | %{Expand-Archive $_.Fullname $downloads\Sysinternals -Force}
} -ArgumentList $downloads
ChangeAdminPass
while ($boolInput -eq $Null)
{
$i = Read-Host "Do you want to output a file of the new passwords? (yes or no)"
if ($i -eq "yes")
{
$boolInput = $True
}
elseif ($i -eq "no")
{
$boolInput = $False
}
else
{
Write-Host "Input not accepted" -ForegroundColor Red
}
}
if ($boolInput)
{
$filePath = Read-Host "What is the filepath/name you want to store the passwords in? "
$filePathAD = $filePath + "_AD.csv"
$filePathLocal = $filePath + "_Local.csv"
Write-Output "Username,Password" > $filePathAD
Write-Output "Username,Password" > $filePathLocal
}
$admin = $env:username
$job8 = Start-Job -ScriptBlock{
param($filePathAD, $boolInput)
$output = ChangeADPass
if ($boolInput)
{
$output | Out-File -FilePath $filePathAD -Append
}
$output = $Null
} -InitializationScript $passFuncs -ArgumentList $filePathAD, $boolInput
$job1 | Wait-Job
Write-Host "Copying tools to SharingIsCaring folder" -ForegroundColor Green
GetTools $cd $downloads
$job2 = Start-Job -ScriptBlock {
param($cd)
Compress-Archive $cd\SharingIsCaring\tools $cd\SharingIsCaring\tools.zip
} -ArgumentList $cd
# $job3 = Start-Job -ScriptBlock ${Function:Replace} -ArgumentList $cd
# $job3 | Wait-Job
Replace $cd
ImportGPO1 $cd
# $job4 = Start-Job -ScriptBlock ${Function:ImportGPO1} -InitializationScript $init -ArgumentList $cd
# $job4 | Wait-Job
$job5 = Start-Job -ScriptBlock ${Function:CreateOUAndDistribute}
$job6 = Start-Job -ScriptBlock ${Function:StartSMBShare} -ArgumentList $cd
$job2 | Wait-Job
$job5 | Wait-Job
$job6 | Wait-Job
Write-Host "`nManually upate the group policy configuration on each member in the domain" -ForegroundColor Yellow
gpupdate /force
Resume
$job7 = Start-Job -ScriptBlock {
param($ServersList, $filePathLocal, $boolInput, $admin)
if ($ServersList.Name -ne $Null)
{
$output = ChangeLocalPasswords $ServersList.Name $cd $admin
}
if ($boolInput)
{
$output | Out-File -FilePath $filePathLocal -Append
}
$output = $Null
} -InitializationScript $passFuncs -ArgumentList $ServersList, $filePathLocal, $boolInput, $admin
while ($job7.State -eq 'Running')
{
$job7output = Receive-Job $job7
if ($job7output) {
Write-Host $job7output
}
$job8output = Receive-Job $job8
if ($job8output) {
Write-Host $job8output
}
Start-Sleep -Milliseconds 500
}
# RemoveFirewallRules $ServersList.Name $DCList.Name
RemoveLinks $ServersList $DCList
StopSMBShare
$job8 | Wait-Job
$job8output = Receive-Job $job8
if ($job8output) {
Write-Host $job8output
}
Write-Host "Enter bone password" -ForegroundColor Yellow
net user bone * /add
Write-Host "Enter bwo password" -ForegroundColor Yellow
net user bwo * /add
Write-Host "Enter bee password" -ForegroundColor Yellow
net user bee * /add
net localgroup administrators bone bwo bee /add
net group "Domain admins" bone bwo bee /add
del $env:homepath\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
New-GPLink -Name "PSLogging" -Target "$root" -LinkEnabled Yes -Enforced Yes
$job9 = Start-Job -Scriptblock {
$AllServers | %{
icm -cn $_ -scriptblock {
gpupdate /force
takeown /F C:\Windows\System32\sethc.exe
icacls C:\Windows\System32\sethc.exe /grant administrators:F
del C:\Windows\System32\sethc.exe
takeown /F C:\Windows\System32\utilman.exe
icacls C:\Windows\System32\utilman.exe /grant administrators:F
del C:\Windows\System32\utilman.exe
takeown /F C:\Windows\System32\osk.exe
icacls C:\Windows\System32\osk.exe /grant administrators:F
del C:\Windows\System32\osk.exe
}
}
}
Write-Host "The program has completed successfully. Now, Manually update the group policy configuration on all computers in the domain" -ForegroundColor Green
gpmc.msc
# DeleteDriver $cd
gpupdate /force
powershell