Skip to content

Commit 12655dc

Browse files
committed
Fixed bug with processing SafePathsToAllow
1 parent 90aa05f commit 12655dc

3 files changed

Lines changed: 33 additions & 19 deletions

File tree

AaronLocker/Create-Policies-AppLocker.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,23 @@ $xRuleCollections = $xDocument.SelectNodes("//RuleCollection[@Type='Exe' or @Typ
277277
foreach($xRuleCollection in $xRuleCollections)
278278
{
279279
$PathsToAllow | foreach {
280+
# If path is an existing directory and doesn't have trailing "\*" appended, fix it so that it does.
281+
# If path is a file, don't append \*. If the path ends with \*, no need for further validation.
282+
# If it doesn't end with \* but Get-Item can't identify it as a file or a directory, write a warning and accept it as is.
283+
$pathToAllow = $_
284+
if (!$pathToAllow.EndsWith("\*"))
285+
{
286+
$pathItem = Get-Item $pathToAllow -Force -ErrorAction SilentlyContinue
287+
if ($pathItem -eq $null)
288+
{
289+
Write-Warning "Cannot verify path $pathItem; adding to rule set as is."
290+
}
291+
elseif ($pathItem -is [System.IO.DirectoryInfo])
292+
{
293+
Write-Warning "Appending `"\*`" to rule for $pathToAllow"
294+
$pathToAllow = [System.IO.Path]::Combine($pathToAllow, "*")
295+
}
296+
}
280297
$elemRule = $xDocument.CreateElement("FilePathRule")
281298
$elemRule.SetAttribute("Action", "Allow")
282299
$elemRule.SetAttribute("UserOrGroupSid", "S-1-1-0")

AaronLocker/Create-Policies-WDAC.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,23 @@ $WDACPathsToAllow += $env:ProgramFiles+"\*"
5757
if ($null -ne ${env:ProgramFiles(x86)}) {$WDACPathsToAllow += (${env:ProgramFiles(x86)}+"\*")}
5858

5959
$WDACPathsToAllow | foreach {
60+
# If path is an existing directory and doesn't have trailing "\*" appended, fix it so that it does.
61+
# If path is a file, don't append \*. If the path ends with \*, no need for further validation.
62+
# If it doesn't end with \* but Get-Item can't identify it as a file or a directory, write a warning and accept it as is.
6063
$pathToAllow = $_
64+
if (!$pathToAllow.EndsWith("\*"))
65+
{
66+
$pathItem = Get-Item $pathToAllow -Force -ErrorAction SilentlyContinue
67+
if ($pathItem -eq $null)
68+
{
69+
Write-Warning "Cannot verify path $pathToAllow; adding to rule set as is."
70+
}
71+
elseif ($pathItem -is [System.IO.DirectoryInfo])
72+
{
73+
Write-Warning "Appending `"\*`" to rule for $pathToAllow"
74+
$pathToAllow = [System.IO.Path]::Combine($pathToAllow, "*")
75+
}
76+
}
6177
$WDACAllowRules += & New-CIPolicyRule -FilePathRule $pathToAllow -AllowFileNameFallbacks
6278
}
6379

AaronLocker/Create-Policies.ps1

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -228,25 +228,6 @@ if ( $Rescan -or ( ($AppLockerOrWDAC -in "Both","AppLocker") -and !(Test-Path($E
228228
# Get additional authorized safe paths from the script that produces that list
229229
Write-Host "Get authorized safe paths for later processing..." -ForegroundColor Cyan
230230
$PathsToAllow = (& $ps1_GetSafePathsToAllow)
231-
$PathsToAllow | foreach {
232-
# If path is an existing directory and doesn't have trailing "\*" appended, fix it so that it does.
233-
# If path is a file, don't append \*. If the path ends with \*, no need for further validation.
234-
# If it doesn't end with \* but Get-Item can't identify it as a file or a directory, write a warning and accept it as is.
235-
$pathToAllow = $_
236-
if (!$pathToAllow.EndsWith("\*"))
237-
{
238-
$pathItem = Get-Item $pathToAllow -Force -ErrorAction SilentlyContinue
239-
if ($pathItem -eq $null)
240-
{
241-
Write-Warning "Cannot verify path $pathItem; adding to rule set as is."
242-
}
243-
elseif ($pathItem -is [System.IO.DirectoryInfo])
244-
{
245-
Write-Warning "Appending `"\*`" to rule for $pathToAllow"
246-
$pathToAllow = [System.IO.Path]::Combine($pathToAllow, "*")
247-
}
248-
}
249-
}
250231

251232
# Run the script that gets "unsafe" user-writable paths for later processing. Should come in as a sequence of hashtables.
252233
if ( !(Test-Path($ps1_UnsafePathsToBuildRulesFor)) )

0 commit comments

Comments
 (0)