@@ -254,9 +254,9 @@ function Edit-SignedWDACConfig {
254
254
Remove-Item - Path " .\SupplementalPolicy$SuppPolicyName .xml" - Force - ErrorAction SilentlyContinue
255
255
# Get the current date so that instead of the entire event viewer logs, only audit logs created after running this module will be captured
256
256
# The notice about variable being assigned and never used should be ignored - it's being dot-sourced from Resources file
257
- $Date = Get-Date
257
+ [ datetime ] $Date = Get-Date
258
258
# An empty array that holds the Policy XML files - This array will eventually be used to create the final Supplemental policy
259
- $PolicyXMLFilesArray = @ ()
259
+ [ System.Array ] $PolicyXMLFilesArray = @ ()
260
260
261
261
# ################################## Initiate Live Audit Mode ###################################
262
262
@@ -269,8 +269,8 @@ function Edit-SignedWDACConfig {
269
269
270
270
# Defining Base policy
271
271
$xml = [xml ](Get-Content $PolicyPath )
272
- $PolicyID = $xml.SiPolicy.PolicyID
273
- $PolicyName = ($xml.SiPolicy.Settings.Setting | Where-Object { $_.provider -eq ' PolicyInfo' -and $_.valuename -eq ' Name' -and $_.key -eq ' Information' }).value.string
272
+ [ System.String ] $PolicyID = $xml.SiPolicy.PolicyID
273
+ [ System.String ] $PolicyName = ($xml.SiPolicy.Settings.Setting | Where-Object { $_.provider -eq ' PolicyInfo' -and $_.valuename -eq ' Name' -and $_.key -eq ' Information' }).value.string
274
274
275
275
# Remove any cip file if there is any
276
276
Remove-Item - Path ' .\*.cip' - Force - ErrorAction SilentlyContinue
@@ -335,7 +335,7 @@ CiTool --update-policy "$((Get-Location).Path)\$PolicyID.cip" -json; Remove-Item
335
335
Pause
336
336
337
337
# Store the program paths that user browses for in an array
338
- $ProgramsPaths = @ ()
338
+ [ System.Array ] $ProgramsPaths = @ ()
339
339
Write-Host " `n Select program directories to scan" - ForegroundColor Cyan
340
340
# Showing folder picker GUI to the user for folder path selection
341
341
do {
@@ -469,7 +469,7 @@ CiTool --update-policy "$((Get-Location).Path)\$PolicyID.cip" -json; Remove-Item
469
469
# Any other attempts such as "Get-FileHash" or "Get-AuthenticodeSignature" fail and ConfigCI Module cmdlets totally ignore these files and do not create allow rules for them
470
470
471
471
# Finding the file(s) first and storing them in an array
472
- $ExesWithNoHash = @ ()
472
+ [ System.Array ] $ExesWithNoHash = @ ()
473
473
# looping through each user-selected path(s)
474
474
foreach ($ProgramsPath in $ProgramsPaths ) {
475
475
# Making sure the currently processing path has any .exe in it
@@ -496,7 +496,7 @@ CiTool --update-policy "$((Get-Location).Path)\$PolicyID.cip" -json; Remove-Item
496
496
Write-Debug - Message " The following Kernel protected files detected, creating allow rules for them:`n "
497
497
if ($Debug ) { $ExesWithNoHash | ForEach-Object { Write-Debug - Message " $_ " } }
498
498
499
- $KernelProtectedHashesBlock = {
499
+ [ scriptblock ] $KernelProtectedHashesBlock = {
500
500
foreach ($event in Get-WinEvent - FilterHashtable @ {LogName = ' Microsoft-Windows-CodeIntegrity/Operational' ; ID = 3076 } - ErrorAction SilentlyContinue | Where-Object { $_.TimeCreated -ge $Date } ) {
501
501
$xml = [xml ]$event.toxml ()
502
502
$xml.event.eventdata.data |
@@ -621,7 +621,7 @@ CiTool --update-policy "$((Get-Location).Path)\$PolicyID.cip" -json; Remove-Item
621
621
Remove-Item - Path ' .\ProgramDir_ScanResults*.xml' - Force - ErrorAction SilentlyContinue
622
622
Remove-Item - Path " .\SupplementalPolicy$SuppPolicyName .xml" - Force - ErrorAction SilentlyContinue
623
623
# An empty array that holds the Policy XML files - This array will eventually be used to create the final Supplemental policy
624
- $PolicyXMLFilesArray = @ ()
624
+ [ System.Array ] $PolicyXMLFilesArray = @ ()
625
625
626
626
# Initiate Live Audit Mode
627
627
@@ -634,8 +634,8 @@ CiTool --update-policy "$((Get-Location).Path)\$PolicyID.cip" -json; Remove-Item
634
634
635
635
# Defining Base policy
636
636
$xml = [xml ](Get-Content $PolicyPath )
637
- $PolicyID = $xml.SiPolicy.PolicyID
638
- $PolicyName = ($xml.SiPolicy.Settings.Setting | Where-Object { $_.provider -eq ' PolicyInfo' -and $_.valuename -eq ' Name' -and $_.key -eq ' Information' }).value.string
637
+ [ System.String ] $PolicyID = $xml.SiPolicy.PolicyID
638
+ [ System.String ] $PolicyName = ($xml.SiPolicy.Settings.Setting | Where-Object { $_.provider -eq ' PolicyInfo' -and $_.valuename -eq ' Name' -and $_.key -eq ' Information' }).value.string
639
639
640
640
# Remove any cip file if there is any
641
641
Remove-Item - Path ' .\*.cip' - Force - ErrorAction SilentlyContinue
@@ -700,7 +700,7 @@ CiTool --update-policy "$((Get-Location).Path)\$PolicyID.cip" -json; Remove-Item
700
700
Pause
701
701
702
702
# Store the program paths that user browses for in an array
703
- $ProgramsPaths = @ ()
703
+ [ System.Array ] $ProgramsPaths = @ ()
704
704
Write-Host " `n Select program directories to scan`n " - ForegroundColor Cyan
705
705
# Showing folder picker GUI to the user for folder path selection
706
706
do {
@@ -906,17 +906,19 @@ CiTool --update-policy "$((Get-Location).Path)\$PolicyID.cip" -json; Remove-Item
906
906
Copy-Item - Path ' C:\Windows\schemas\CodeIntegrity\ExamplePolicies\DefaultWindows_Enforced.xml' - Destination ' .\DefaultWindows_Enforced.xml'
907
907
908
908
# Allowing SignTool to be able to run after Default Windows base policy is deployed
909
- & $WriteViolet " `n Creating allow rules for SignTool.exe in the DefaultWindows base policy so you can continue using it after deploying the DefaultWindows base policy."
909
+ & $WriteTeaGreen " `n Creating allow rules for SignTool.exe in the DefaultWindows base policy so you can continue using it after deploying the DefaultWindows base policy."
910
910
New-Item - Path " $env: TEMP \TemporarySignToolFile" - ItemType Directory - Force | Out-Null
911
911
Copy-Item - Path $SignToolPathFinal - Destination " $env: TEMP \TemporarySignToolFile" - Force
912
- New-CIPolicy - ScanPath " $env: TEMP \TemporarySignToolFile" - Level FilePublisher - Fallback Hash - UserPEs - UserWriteablePaths - MultiplePolicyFormat - FilePath .\SignTool.xml
912
+ New-CIPolicy - ScanPath " $env: TEMP \TemporarySignToolFile" - Level FilePublisher - Fallback Hash - UserPEs - UserWriteablePaths - MultiplePolicyFormat - AllowFileNameFallbacks - FilePath .\SignTool.xml
913
+ # Due to a bug Have to repeat this process twice: https://github.com/MicrosoftDocs/WDAC-Toolkit/issues/278
914
+ New-CIPolicy - ScanPath " $env: TEMP \TemporarySignToolFile" - Level FilePublisher - Fallback Hash - UserPEs - UserWriteablePaths - MultiplePolicyFormat - AllowFileNameFallbacks - FilePath .\SignTool.xml
913
915
# Delete the Temporary folder in the TEMP folder
914
- Remove-Item - Recurse - Path " $env: TEMP \TemporarySignToolFile" - Force
916
+ if ( ! $Debug ) { Remove-Item - Recurse - Path " $env: TEMP \TemporarySignToolFile" - Force }
915
917
916
918
# Scan PowerShell core directory and add them to the Default Windows base policy so that the module can be used after it's been deployed
917
919
if (Test-Path ' C:\Program Files\PowerShell' ) {
918
920
& $WriteViolet " `n Creating allow rules for PowerShell in the DefaultWindows base policy so you can continue using this module after deploying it."
919
- New-CIPolicy - ScanPath ' C:\Program Files\PowerShell' - Level FilePublisher - NoScript - Fallback Hash - UserPEs - UserWriteablePaths - MultiplePolicyFormat - FilePath .\AllowPowerShell.xml
921
+ New-CIPolicy - ScanPath ' C:\Program Files\PowerShell' - Level FilePublisher - NoScript - Fallback Hash - UserPEs - UserWriteablePaths - MultiplePolicyFormat - AllowFileNameFallbacks - FilePath .\AllowPowerShell.xml
920
922
Merge-CIPolicy - PolicyPaths .\DefaultWindows_Enforced.xml, .\AllowPowerShell.xml, .\SignTool.xml, ' .\Microsoft recommended block rules.xml' - OutputFilePath .\BasePolicy.xml | Out-Null
921
923
}
922
924
else {
@@ -931,8 +933,10 @@ CiTool --update-policy "$((Get-Location).Path)\$PolicyID.cip" -json; Remove-Item
931
933
if ($UpdateBasePolicy -and $RequireEVSigners ) { Set-RuleOption - FilePath .\BasePolicy.xml - Option 8 }
932
934
933
935
# Remove the extra files create during module operation that are no longer necessary
934
- Remove-Item ' .\AllowPowerShell.xml' , ' .\SignTool.xml' , ' .\AllowMicrosoft.xml' , ' .\DefaultWindows_Enforced.xml' - Force - ErrorAction SilentlyContinue
935
- Remove-Item ' .\Microsoft recommended block rules.xml' - Force
936
+ if (! $Debug ) {
937
+ Remove-Item ' .\AllowPowerShell.xml' , ' .\SignTool.xml' , ' .\AllowMicrosoft.xml' , ' .\DefaultWindows_Enforced.xml' - Force - ErrorAction SilentlyContinue
938
+ Remove-Item ' .\Microsoft recommended block rules.xml' - Force
939
+ }
936
940
937
941
# Get the policy ID of the currently deployed base policy based on the policy name that user selected
938
942
$CurrentID = ((CiTool - lp - json | ConvertFrom-Json ).Policies | Where-Object { $_.IsSystemPolicy -ne ' True' } | Where-Object { $_.Friendlyname -eq $CurrentBasePolicyName }).BasePolicyID
@@ -976,7 +980,7 @@ CiTool --update-policy "$((Get-Location).Path)\$PolicyID.cip" -json; Remove-Item
976
980
Remove-Item " .\$CurrentID .cip" - Force
977
981
Remove-Item $PolicyFiles [$NewBasePolicyType ] - Force - ErrorAction SilentlyContinue
978
982
Rename-Item - Path ' .\BasePolicy.xml' - NewName $PolicyFiles [$NewBasePolicyType ]
979
- & $WriteSubtleRainbow " Base Policy has been successfully updated to $NewBasePolicyType "
983
+ & $WritePink " Base Policy has been successfully updated to $NewBasePolicyType "
980
984
& $WriteLavender ' Keep in mind that your previous policy path saved in User Configurations is no longer valid as you just changed your Base policy.'
981
985
}
982
986
}
0 commit comments