-
Notifications
You must be signed in to change notification settings - Fork 1
/
WAFS.ps1
438 lines (368 loc) · 21.5 KB
/
WAFS.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
#Requires -RunAsAdministrator
#################################################################################
#MIT License #
# #
#Copyright (c) 2023-2024 MikeHorn-git #
# #
#Permission is hereby granted, free of charge, to any person obtaining a copy #
#of this software and associated documentation files (the "Software"), to deal #
#in the Software without restriction, including without limitation the rights #
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #
#copies of the Software, and to permit persons to whom the Software is #
#furnished to do so, subject to the following conditions: #
# #
#The above copyright notice and this permission notice shall be included in all #
#copies or substantial portions of the Software. #
# #
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
#SOFTWARE. #
#################################################################################
<#
.SYNOPSIS
Windows Anti-Forensics Script (WAFS) hardened your Windows OS against forensics analysis.
.DESCRIPTION
Windows Anti-Forensics Script (WAFS) aim to make forensics investigations on a Windows OS more difficult.
WAFS allow you to clean/disable certain files, services, registry keys.
And WAFS provide some anti-forensics tools to improve countering forensics analysis.
To execute this script:
1) Open PowerShell window as administrator
2) Execute the script by running ".\WAFS.ps1"
.PARAMETER all
Install both features: tools and perform anti-forensics actions including disabling certain windows features and clearing
certain data. This includes the cleaning of various file and registry data.
.PARAMETER anti
Perform anti-forensics actions without requiring tools installation. This includes disabling certain windows features and
clearing various forensics-related data, such as browser caches, event logs, and session histories.
.PARAMETER tools
Install anti-forensics tools. This downloads various tools that can be used to enhance anti-forensics activities.
No other actions are performed with this option.
.PARAMETER clean
Perform only the cleaning actions. This will clean up various files, caches, and registry entries that may be used in
forensic investigations but will not disable any Windows features or services.
.PARAMETER disable
Only disable certain Windows features without performing any cleaning actions. This includes disabling services like
EventLog, Prefetch, and Shadow Copies, as well as disabling keylogging and other Windows telemetry features.
.EXAMPLE
.\WAFS.ps1 -anti
Description
---------------------------------------
Disable and clear certains windows features and parameters for anti-forensics.
.LINK
https://github.com/MikeHorn-git/WAFS
#>
[CmdletBinding()]
param (
[switch]$all,
[switch]$anti,
[switch]$tools,
[switch]$clean,
[switch]$disable
)
function Invoke-AntiForensics {
Write-Output '[+] Anti-Forensics Script'
# Cleaning
$PathsToRemove = @{
'ChromeCache' = "$Home\AppData\Local\Google\Chrome\User Data\Default\Cache"
'ChromeHistory' = "$Home\AppData\Local\Google\Chrome\User Data\Default\History"
'ChromeSessionRestore' = "$Home\AppData\Local\Google\Chrome\User Data\Default"
'EdgeCache' = "$Home\AppData\Local\Packages\microsoft.microsoftedge_*\AC\MicrosoftEdge\Cache"
'IEHistory' = 'HKCU:\Software\Microsoft\Internet Explorer\TypedURLs'
'IEWebCache' = "$Home\AppData\Local\Microsoft\Windows\WebCache\WebCacheV*.dat"
'FirefoxCache' = "$Home\AppData\Local\Mozilla\Firefox\Profiles\*.default\Cache"
'FirefoxHistory' = "$Home\AppData\Roaming\Mozilla\Firefox\Profiles\*.default\places.sqlite"
'FirefoxSessionRestore' = "$Home\AppData\Roaming\Mozilla\Firefox\Profiles\*.default\sessionstore.js"
'IECache' = "$Home\AppData\Local\Microsoft\Windows\INetCache\IE"
'IECacheStorage' = "$Home\AppData\Local\Microsoft\Internet Explorer\CacheStorage"
'IESessionRestore' = "$Home\AppData\Local\Microsoft\Internet Explorer\Recovery"
'LastVisitedMRU' = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedPidlMRU'
'OpenSaveMRU' = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSavePidlMRU'
'PlugAndPlayLogs' = "C:\Windows\INF\setupapi.dev*"
'Prefetch' = "C:\Windows\Prefetch"
'RecentItems' = "$HOME\AppData\Roaming\Microsoft\Windows\Recent"
'RecentDocs' = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs'
'RunMRU' = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU'
'ShadowCopies' = 'HKLM:\SYSTEM\CurrentControlSet\Control\BackupRestore\FilesNotToBackup'
'ShellBags' = 'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell'
'ShellNoRoam' = 'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\ShellNoRoam'
'ShellWow6432' = 'HKCU:\Software\Classes\Wow6432Node\Local Settings\Software\Microsoft\Windows\Shell\'
'Simcache' = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\AppCompatCache\'
'SRUDB' = "C:\Windows\System32\sru\SRUDB.dat"
'TempFiles' = "C:\Windows\temp\*"
'Thumbcache' = "$Home\AppData\Local\Microsoft\Windows\Explorer\thumbcache*.db\"
'USBHistory' = 'HKLM:\SYSTEM\CurrentControlSet\Enum\USBSTOR'
'USBEnum' = 'HKLM:\SYSTEM\CurrentControlSet\Enum\USB'
'UserAssist' = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\'
'VPNCache' = 'HKLM:\Microsoft\Windows NT\CurrentVersion\NetworkList\Nla\Cache'
'TimelineDB' = "$Home\AppData\Local\ConnectedDevicesPlatform\*\ActivitiesCache.db"
'PowerShellHistory' = "$HOME\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt"
}
foreach ($pathKey in $PathsToRemove.Keys) {
$path = $PathsToRemove[$pathKey]
if ($null -ne $path) {
try {
Remove-Item -Path $path -Recurse -Force -ErrorAction Stop
Write-Output "Removed: $path"
}
catch {
Write-Error "Failed to remove: $path. Error: $_"
}
}
}
# Disable
try {
# Disable Audit Success logs
auditpol /set /subcategory:"Filtering Platform Connection" /success:disable /failure:enable 2>$null
# Remove Cortana
Get-AppxPackage -AllUsers Microsoft.549981C3F5F10 | Remove-AppPackage 2>$null
# Clean DNS cache
ipconfig /flushdns >$null
# Disable Keylogger
Stop-Service -Name DiagTrack -Force 2>$null
Set-Service -Name DiagTrack -StartupType Disabled 2>$null
Stop-Service -Name dmwappushservice -Force 2>$null
Set-Service -Name dmwappushservice -StartupType Disabled 2>$null
Write-Output "" > C:\ProgramData\Microsoft\Diagnosis\ETLLogs\AutoLogger\AutoLogger-Diagtrack-Listener.etl 2>$null
# Disable NTFS Last Access Time
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'NtfsDisableLastAccessUpdate' -Value 1 -Force
fsutil behavior set disablelastaccess 3 >$null
# Disable Prefetch
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\' -Name 'EnablePrefetcher' -Value 0 -Force
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\' -Name 'EnableSuperfetch' -Value 0 -Force
# Clean RecycleBin
Clear-RecycleBin -Force 2>$null
# Disable previous Shadow Copies
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\' -Name 'DisableLocalPage' -Value 1 -Force
# Clean Shadow Copies
vssadmin delete shadows /All >$null
# Disable ShellBags
Set-ItemProperty -Path 'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell' -Name 'BagMRU Size' -Value 1 -Force
# Disable UserAssist
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\' -Name 'Start_TrackProgs' -Value 0 -Force
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\' -Name 'Start_TrackEnabled' -Value 0 -Force
# Disable Windows Event logs
Stop-Service -Name EventLog -Force 2>$null
Set-Service EventLog -StartupType Disabled
# Clean Windows Event logs
wevtutil el | ForEach-Object { wevtutil cl "$_" } 2>$null
# Clean Windows logs
Get-EventLog -LogName * | ForEach-Object { Clear-EventLog $_.Log } 2>$null
# Disable Windows Timeline DB
Stop-Service -Name CDPUserSvc* -Force 2>$null
# Disable $UsnJrnl
fsutil usn deletejournal /d c: 2>$null
# Clean Powershell history
Clear-History 2>$null
}
catch {
Write-Error "An error occurred: $_"
}
Write-Output '[+] Done, reboot your system'
Exit 0
}
function Invoke-Cleaning {
Write-Output '[+] Anti-Forensics Script - Cleaning'
$PathsToRemove = @{
'ChromeCache' = "$Home\AppData\Local\Google\Chrome\User Data\Default\Cache"
'ChromeHistory' = "$Home\AppData\Local\Google\Chrome\User Data\Default\History"
'ChromeSessionRestore' = "$Home\AppData\Local\Google\Chrome\User Data\Default"
'EdgeCache' = "$Home\AppData\Local\Packages\microsoft.microsoftedge_*\AC\MicrosoftEdge\Cache"
'IEHistory' = 'HKCU:\Software\Microsoft\Internet Explorer\TypedURLs'
'IEWebCache' = "$Home\AppData\Local\Microsoft\Windows\WebCache\WebCacheV*.dat"
'FirefoxCache' = "$Home\AppData\Local\Mozilla\Firefox\Profiles\*.default\Cache"
'FirefoxHistory' = "$Home\AppData\Roaming\Mozilla\Firefox\Profiles\*.default*\places.sqlite"
'FirefoxHistoryBackup' = "$Home\AppData\Roaming\Mozilla\Firefox\Profiles\*.default*\places.sqlite-*"
'FirefoxBookmarks' = "$Home\AppData\Roaming\Mozilla\Firefox\Profiles\*.default*\bookmarkbackups\*"
'FirefoxSessionRestore' = "$Home\AppData\Roaming\Mozilla\Firefox\Profiles\*.default*\sessionstore.js"
'FirefoxSessionRestoreBackup' = "$Home\AppData\Roaming\Mozilla\Firefox\Profiles\*.default*\sessionstore-backups\*"
'FirefoxCookies' = "$Home\AppData\Roaming\Mozilla\Firefox\Profiles\*.default*\cookies.sqlite*"
'IECache' = "$Home\AppData\Local\Microsoft\Windows\INetCache\IE"
'IECacheStorage' = "$Home\AppData\Local\Microsoft\Internet Explorer\CacheStorage"
'IESessionRestore' = "$Home\AppData\Local\Microsoft\Internet Explorer\Recovery"
'LastVisitedMRU' = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedPidlMRU'
'OpenSaveMRU' = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSavePidlMRU'
'PlugAndPlayLogs' = "C:\Windows\INF\setupapi.dev*"
'Prefetch' = "C:\Windows\Prefetch"
'RecentItems' = "$HOME\AppData\Roaming\Microsoft\Windows\Recent"
'RecentDocs' = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs'
'RunMRU' = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU'
'ShadowCopies' = 'HKLM:\SYSTEM\CurrentControlSet\Control\BackupRestore\FilesNotToBackup'
'ShellBags' = 'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell'
'ShellNoRoam' = 'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\ShellNoRoam'
'ShellWow6432' = 'HKCU:\Software\Classes\Wow6432Node\Local Settings\Software\Microsoft\Windows\Shell\'
'Simcache' = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\AppCompatCache\'
'SRUDB' = "C:\Windows\System32\sru\SRUDB.dat"
'TempFiles' = "C:\Windows\temp\*"
'Thumbcache' = "$Home\AppData\Local\Microsoft\Windows\Explorer\thumbcache*.db\"
'USBHistory' = 'HKLM:\SYSTEM\CurrentControlSet\Enum\USBSTOR'
'USBEnum' = 'HKLM:\SYSTEM\CurrentControlSet\Enum\USB'
'UserAssist' = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\'
'VPNCache' = 'HKLM:\Microsoft\Windows NT\CurrentVersion\NetworkList\Nla\Cache'
'TimelineDB' = "$Home\AppData\Local\ConnectedDevicesPlatform\*\ActivitiesCache.db"
'PowerShellHistory' = "$HOME\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt"
}
foreach ($pathKey in $PathsToRemove.Keys) {
$path = $PathsToRemove[$pathKey]
if ($null -ne $path) {
try {
Remove-Item -Path $path -Recurse -Force -ErrorAction Stop
Write-Output "Removed: $path"
}
catch {
Write-Error "Failed to remove: $path. Error: $_"
}
}
}
}
function Invoke-Disable {
Write-Output '[+] Anti-Forensics Script - Disable'
try {
# Disable Audit Success logs
auditpol /set /subcategory:"Filtering Platform Connection" /success:disable /failure:enable 2>$null
# Remove Cortana
Get-AppxPackage -AllUsers Microsoft.549981C3F5F10 | Remove-AppPackage 2>$null
# Clean DNS cache
ipconfig /flushdns >$null
# Disable Keylogger
Stop-Service -Name DiagTrack -Force 2>$null
Set-Service -Name DiagTrack -StartupType Disabled 2>$null
Stop-Service -Name dmwappushservice -Force 2>$null
Set-Service -Name dmwappushservice -StartupType Disabled 2>$null
Write-Output "" > C:\ProgramData\Microsoft\Diagnosis\ETLLogs\AutoLogger\AutoLogger-Diagtrack-Listener.etl 2>$null
# Disable NTFS Last Access Time
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'NtfsDisableLastAccessUpdate' -Value 1 -Force
fsutil behavior set disablelastaccess 3 >$null
# Disable Prefetch
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\' -Name 'EnablePrefetcher' -Value 0 -Force
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\' -Name 'EnableSuperfetch' -Value 0 -Force
# Clean RecycleBin
Clear-RecycleBin -Force 2>$null
# Disable previous Shadow Copies
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\' -Name 'DisableLocalPage' -Value 1 -Force
# Clean Shadow Copies
vssadmin delete shadows /All >$null
# Disable ShellBags
Set-ItemProperty -Path 'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell' -Name 'BagMRU Size' -Value 1 -Force
# Disable UserAssist
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\' -Name 'Start_TrackProgs' -Value 0 -Force
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\' -Name 'Start_TrackEnabled' -Value 0 -Force
# Disable Windows Event logs
Stop-Service -Name EventLog -Force 2>$null
Set-Service EventLog -StartupType Disabled
# Clean Windows Event logs
wevtutil el | ForEach-Object { wevtutil cl "$_" } 2>$null
# Clean Windows logs
Get-EventLog -LogName * | ForEach-Object { Clear-EventLog $_.Log } 2>$null
# Disable Windows Timeline DB
Stop-Service -Name CDPUserSvc* -Force 2>$null
# Disable $UsnJrnl
fsutil usn deletejournal /d c: 2>$null
# Clean Powershell history
Clear-History 2>$null
}
catch {
Write-Error "An error occurred: $_"
}
Write-Output '[+] Done, reboot your system'
Exit 0
}
function Install-Tools {
Write-Output '[+] Tools Script'
$toolsDirectory = "$HOME\Tools"
New-Item -Path $toolsDirectory -ItemType Directory -Force >$null
# URLs of tools to download
$FastURL = [ordered]@{
DSP = "https://github.com/LloydLabs/delete-self-poc/releases/download/v1.1/ds_x64.exe"
Exif = "https://www.two-pilots.com/colorpilot.com/load/exif_64.exe"
Timestomper = "https://github.com/slyd0g/TimeStomper/blob/master/Release/TimeStomper.exe"
USBSentinel = "https://github.com/thereisnotime/xxUSBSentinel/releases/download/v1/xxUSBSentinel.exe"
Veracrypt = "https://launchpad.net/veracrypt/trunk/1.26.15/+download/VeraCrypt%20Setup%201.26.15.exe"
}
foreach ($key in $FastURL.Keys) {
$url = $FastURL[$key]
$outputPath = "$toolsDirectory\$key.exe"
try {
Invoke-WebRequest -Uri $url -OutFile $outputPath -ErrorAction Stop
Write-Output "Downloaded $key from $url to $outputPath"
}
catch {
Write-Error "Failed to download $key from $url. $_"
}
}
$LongURL = [ordered]@{
Bleachbit = "https://download.bleachbit.org/BleachBit-4.6.2-portable.zip"
Buskill = "https://github.com/BusKill/buskill-app/releases/download/v0.7.0/buskill-win-v0.7.0-x86_64.zip"
Clamav = "https://www.clamav.net/downloads/production/clamav-1.4.1.win.x64.zip"
Sdelete = "https://download.sysinternals.com/files/SDelete.zip"
}
foreach ($key in $LongURL.Keys) {
$url = $LongURL[$key]
$downloadPath = "$Home\Downloads\$key.zip"
$extractPath = "$toolsDirectory\$key"
try {
Invoke-WebRequest -Uri $url -OutFile $downloadPath -ErrorAction Stop
Write-Output "Downloaded $key from $url to $downloadPath"
Expand-Archive -Path $downloadPath -DestinationPath $extractPath -Force
Write-Output "Extracted $key to $extractPath"
}
catch {
Write-Error "Failed to download or extract $key from $url. $_"
}
}
}
function Show-Usage {
Write-Host @"
██╗ ██╗ █████╗ ███████╗███████╗
██║ ██║██╔══██╗██╔════╝██╔════╝
██║ █╗ ██║███████║█████╗ ███████╗
██║███╗██║██╔══██║██╔══╝ ╚════██║
╚███╔███╔╝██║ ██║██║ ███████║
╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚══════╝
Windows Anti-Forensics Script
Syntax: wafs.ps1 -[all|anti|tools]
options:
-all Install both features.
-anti Disable and clear certain windows features and parameters for anti-forensics.
-tools Install anti-forensics tools.
-disable Only disable windows features without cleaning
-clean Only clean
"@
}
function Main {
if ($all) {
Start-Transcript -Path ".\logs_all.txt"
Install-Tools
Invoke-AntiForensics
Stop-Transcript
}
elseif ($anti) {
Start-Transcript -Path ".\logs_anti.txt"
Invoke-AntiForensics
Stop-Transcript
}
elseif ($tools) {
Start-Transcript -Path ".\logs_tools.txt"
Install-Tools
Write-Output '[+] Done, reboot your system'
Exit 0
Stop-Transcript
}
elseif ($clean) {
Start-Transcript -Path ".\logs_clean.txt"
Invoke-Cleaning
Stop-Transcript
}
elseif ($disable) {
Start-Transcript -Path ".\logs_disable.txt"
Invoke-Disable
Stop-Transcript
}
else {
Show-Usage
}
}
Main