Skip to content

Instantly share code, notes, and snippets.

@jdgregson
Last active December 8, 2022 23:13
Show Gist options
  • Save jdgregson/616eeadf8e284fb5a8a92a2279097d9a to your computer and use it in GitHub Desktop.
Save jdgregson/616eeadf8e284fb5a8a92a2279097d9a to your computer and use it in GitHub Desktop.
Scan for insecure permissions on program files directory
$filename = -join ((65..90) + (97..122) | Get-Random -Count 32 | % {[char]$_})
Write-Host "Testing with filename: $filename"
"C:\Program Files", "C:\Program Files (x86)" | ForEach-Object {
$outerDir = $_
Get-ChildItem -Directory -Recurse $outerDir | ForEach-Object {
$innerDir = $_
try {
$out = New-Item -Path $innerDir.FullName -Name $filename -ErrorAction Stop | Out-String
Write-Warning "Path is writable: $($innerDir.FullName)"
$out = Remove-Item -Path $($innerDir.FullName + "\$filename") -ErrorAction Stop | Out-String
} catch {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment