Skip to content

Commit

Permalink
Fixed bug with processing SafePathsToAllow
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuther1974 committed Jun 30, 2020
1 parent 90aa05f commit 12655dc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
17 changes: 17 additions & 0 deletions AaronLocker/Create-Policies-AppLocker.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,23 @@ $xRuleCollections = $xDocument.SelectNodes("//RuleCollection[@Type='Exe' or @Typ
foreach($xRuleCollection in $xRuleCollections)
{
$PathsToAllow | foreach {
# If path is an existing directory and doesn't have trailing "\*" appended, fix it so that it does.
# If path is a file, don't append \*. If the path ends with \*, no need for further validation.
# 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.
$pathToAllow = $_
if (!$pathToAllow.EndsWith("\*"))
{
$pathItem = Get-Item $pathToAllow -Force -ErrorAction SilentlyContinue
if ($pathItem -eq $null)
{
Write-Warning "Cannot verify path $pathItem; adding to rule set as is."
}
elseif ($pathItem -is [System.IO.DirectoryInfo])
{
Write-Warning "Appending `"\*`" to rule for $pathToAllow"
$pathToAllow = [System.IO.Path]::Combine($pathToAllow, "*")
}
}
$elemRule = $xDocument.CreateElement("FilePathRule")
$elemRule.SetAttribute("Action", "Allow")
$elemRule.SetAttribute("UserOrGroupSid", "S-1-1-0")
Expand Down
16 changes: 16 additions & 0 deletions AaronLocker/Create-Policies-WDAC.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,23 @@ $WDACPathsToAllow += $env:ProgramFiles+"\*"
if ($null -ne ${env:ProgramFiles(x86)}) {$WDACPathsToAllow += (${env:ProgramFiles(x86)}+"\*")}

$WDACPathsToAllow | foreach {
# If path is an existing directory and doesn't have trailing "\*" appended, fix it so that it does.
# If path is a file, don't append \*. If the path ends with \*, no need for further validation.
# 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.
$pathToAllow = $_
if (!$pathToAllow.EndsWith("\*"))
{
$pathItem = Get-Item $pathToAllow -Force -ErrorAction SilentlyContinue
if ($pathItem -eq $null)
{
Write-Warning "Cannot verify path $pathToAllow; adding to rule set as is."
}
elseif ($pathItem -is [System.IO.DirectoryInfo])
{
Write-Warning "Appending `"\*`" to rule for $pathToAllow"
$pathToAllow = [System.IO.Path]::Combine($pathToAllow, "*")
}
}
$WDACAllowRules += & New-CIPolicyRule -FilePathRule $pathToAllow -AllowFileNameFallbacks
}

Expand Down
19 changes: 0 additions & 19 deletions AaronLocker/Create-Policies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -228,25 +228,6 @@ if ( $Rescan -or ( ($AppLockerOrWDAC -in "Both","AppLocker") -and !(Test-Path($E
# Get additional authorized safe paths from the script that produces that list
Write-Host "Get authorized safe paths for later processing..." -ForegroundColor Cyan
$PathsToAllow = (& $ps1_GetSafePathsToAllow)
$PathsToAllow | foreach {
# If path is an existing directory and doesn't have trailing "\*" appended, fix it so that it does.
# If path is a file, don't append \*. If the path ends with \*, no need for further validation.
# 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.
$pathToAllow = $_
if (!$pathToAllow.EndsWith("\*"))
{
$pathItem = Get-Item $pathToAllow -Force -ErrorAction SilentlyContinue
if ($pathItem -eq $null)
{
Write-Warning "Cannot verify path $pathItem; adding to rule set as is."
}
elseif ($pathItem -is [System.IO.DirectoryInfo])
{
Write-Warning "Appending `"\*`" to rule for $pathToAllow"
$pathToAllow = [System.IO.Path]::Combine($pathToAllow, "*")
}
}
}

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

0 comments on commit 12655dc

Please sign in to comment.