Last active
December 8, 2022 23:13
-
-
Save jdgregson/616eeadf8e284fb5a8a92a2279097d9a to your computer and use it in GitHub Desktop.
Scan for insecure permissions on program files directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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