Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions AaronLocker/Support/BuildRulesForFilesInWritableDirectories.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,23 @@ foreach($fsp in $FileSystemPaths)
# Get-AppLockerFileInformation -Directory inspects files with these extensions:
# .com, .exe, .dll, .ocx, .msi, .msp, .mst, .bat, .cmd, .js, .ps1, .vbs, .appx
# But this script drops .msi, .msp, .mst, and .appx
[array]$scanFileTypes = @('*.bat','*.com','*.exe','*.dll','*.ocx','*.js','*.ps1','*.pyd','*.vbs','*.xll')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish we could specify arbitrary file extensions, but the PowerShell cmdlets don't support them. The problem is that when you pass the Get-AppLockerFileInformation results to New-AppLockerPolicy, it relies on file extension to determine file type based on its own hardcoded list. If you try to manipulate the path name in the file information object to give it a standard extension before passing it to New-AppLockerPolicy, it will still fail because it goes to look for that file and doesn't find it. I considered and quickly discarded an idea to create hard links to the new names and then deleting them after building. For now I'm just running Scan-Directories.ps1 and pulling data out of there for HashRuleData.ps1, or just insisting on good publisher/productname data.


if ($RecurseDirectories)
{
$arrALFI += Get-AppLockerFileInformation -FileType Exe,Dll,Script -Directory $fsp -Recurse
$files += Get-ChildItem * -Path $fsp -File -Force -Recurse -Include $scanFileTypes
for ($i = 0; $i -lt $files.Count; $i++)
{
$arrALFI += Get-AppLockerFileInformation -Path $files[$i].FullName
}
}
else
{
$arrALFI += Get-AppLockerFileInformation -FileType Exe,Dll,Script -Directory $fsp
$files += Get-ChildItem * -Path $fsp -File -Force -Include $scanFileTypes
for ($i = 0; $i -lt $files.Count; $i++)
{
$arrALFI += Get-AppLockerFileInformation -Path $files[$i].FullName
}
}
}
elseif ($fspInfo -is [System.IO.FileInfo])
Expand Down