-
Notifications
You must be signed in to change notification settings - Fork 37
Improve windows stemcell hardening by explicitly handeling inherited … #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: windows-2019
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -100,33 +100,49 @@ function Protect-Dir | |||||
| [bool]$disableInheritance = $True | ||||||
| ) | ||||||
|
|
||||||
| if ($disableInheritance) | ||||||
| { | ||||||
| Write-Log "Protect-Dir: Disable Inheritance" | ||||||
| icacls.exe $path /inheritance:d /T | ||||||
| if ($LASTEXITCODE -ne 0) | ||||||
| { | ||||||
| Throw "Error disabling inheritance for $path exited with $LASTEXITCODE" | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| Write-Log "Protect-Dir: Grant Administrator" | ||||||
| cmd.exe /c cacls.exe $path /T /E /P Administrators:F | ||||||
| icacls.exe $path /grant "Administrators:(OI)(CI)F" /T | ||||||
| if ($LASTEXITCODE -ne 0) | ||||||
|
Comment on lines
113
to
115
|
||||||
| { | ||||||
| Throw "Error setting ACL for $path exited with $LASTEXITCODE" | ||||||
| } | ||||||
|
|
||||||
| Write-Log "Protect-Dir: Remove BUILTIN\Users" | ||||||
| cmd.exe /c cacls.exe $path /T /E /R "BUILTIN\Users" | ||||||
| icacls.exe $path /remove "BUILTIN\Users" /T | ||||||
| if ($LASTEXITCODE -ne 0) | ||||||
| { | ||||||
| Throw "Error setting ACL for $path exited with $LASTEXITCODE" | ||||||
| } | ||||||
|
|
||||||
| Write-Log "Protect-Dir: Remove BUILTIN\IIS_IUSRS" | ||||||
| cmd.exe /c cacls.exe $path /T /E /R "BUILTIN\IIS_IUSRS" | ||||||
| icacls.exe $path /remove "BUILTIN\IIS_IUSRS" /T | ||||||
| if ($LASTEXITCODE -ne 0) | ||||||
| { | ||||||
| Throw "Error setting ACL for $path exited with $LASTEXITCODE" | ||||||
| } | ||||||
|
|
||||||
| if ($disableInheritance) | ||||||
| Write-Log "Protect-Dir: Remove NT AUTHORITY\Authenticated Users" | ||||||
| icacls.exe $path /remove "NT AUTHORITY\Authenticated Users" /T | ||||||
| if ($LASTEXITCODE -ne 0) | ||||||
| { | ||||||
| Write-Log "Protect-Dir: Disable Inheritance" | ||||||
| $acl = Get-ACL -LiteralPath $path | ||||||
| $acl.SetAccessRuleProtection($True, $True) | ||||||
| Set-Acl -LiteralPath $path -AclObject $acl | ||||||
| Throw "Error setting ACL for $path exited with $LASTEXITCODE" | ||||||
| } | ||||||
|
|
||||||
| Write-Log "Protect-Dir: Remove Everyone" | ||||||
| icacls.exe $path /remove "Everyone" /T | ||||||
|
Comment on lines
+134
to
+142
|
||||||
| if ($LASTEXITCODE -ne 0) | ||||||
| { | ||||||
| Throw "Error setting ACL for $path exited with $LASTEXITCODE" | ||||||
| } | ||||||
|
Comment on lines
+134
to
146
|
||||||
| } | ||||||
|
|
||||||
|
|
@@ -137,6 +153,16 @@ function Protect-Path | |||||
| [bool]$disableInheritance = $True | ||||||
| ) | ||||||
|
|
||||||
| if ($disableInheritance) | ||||||
| { | ||||||
| Write-Log "Protect-Path: Disable Inheritance" | ||||||
| icacls.exe $path /inheritance:d | ||||||
| if ($LASTEXITCODE -ne 0) | ||||||
| { | ||||||
| Throw "Error disabling inheritance for $path exited with $LASTEXITCODE" | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| Write-Log "Protect-Path: Grant Administrator" | ||||||
| icacls.exe $path /grant "Administrators:(OI)(CI)F" | ||||||
|
||||||
| icacls.exe $path /grant "Administrators:(OI)(CI)F" | |
| icacls.exe $path /grant:r "Administrators:(OI)(CI)F" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$items = @(Get-Item ...) + @(Get-ChildItem -Recurse ...)materializes the entire recursive file list in memory before processing. On large trees (e.g.,C:\var) this can significantly increase memory/time compared to the previous streaming pipeline. Consider processingGet-Item $pathfirst and then streamingGet-ChildItem -Recursethrough the same per-item check (e.g., via a helper function) to avoid building a full array.