Skip the permission pass when it is right, and log command lines
The cleanup job wrote the user's grant on C:\msys2 on every run, which goes through all 30000 files and kept the only processor busy for half a minute every half hour. It is now only written when it is not there yet; a run takes 17 seconds instead of up to two minutes. Process creation events now carry the command line, so what a visitor ran is known even when they deleted their shell history along with the installation. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
b142a1c5d2
commit
3e1beb9994
1 changed files with 15 additions and 3 deletions
|
|
@ -314,9 +314,16 @@ foreach ($copy in Get-ChildItem -LiteralPath $copies -Recurse -File -Force) {
|
|||
# Modify rather than full control, which would also let them delete files whose own permissions do not allow it - the
|
||||
# protected ones below. The folders that lead to those belong to the administrators and cannot be renamed either: a
|
||||
# folder put in the place of one would hand the server files the user wrote. The home directory keeps its own
|
||||
# protected permissions because they are set without inheritance.
|
||||
# protected permissions because they are set without inheritance. The grant is only written when it is not there yet:
|
||||
# writing it goes through all 30000 files of the installation, which takes the only processor half a minute.
|
||||
if ($sid) {
|
||||
icacls $msys /grant:r "*${sid}:(OI)(CI)M" | Out-Null
|
||||
$user = New-Object System.Security.Principal.SecurityIdentifier($sid)
|
||||
$granted = @((Get-Acl -LiteralPath $msys).GetAccessRules($true, $false, [System.Security.Principal.SecurityIdentifier]) |
|
||||
Where-Object { $_.AccessControlType -eq 'Allow' -and $_.IdentityReference -eq $user })
|
||||
if ($granted.Count -ne 1 -or $granted[0].FileSystemRights -ne 'Modify, Synchronize' -or
|
||||
$granted[0].InheritanceFlags -ne 'ContainerInherit, ObjectInherit') {
|
||||
icacls $msys /grant:r "*${sid}:(OI)(CI)M" | Out-Null
|
||||
}
|
||||
foreach ($folder in $msys, "$msys\etc", "$msys\usr", "$msys\usr\bin", "$msys\opt") {
|
||||
New-Item -ItemType Directory -Force -Path $folder | Out-Null
|
||||
Set-Undeletable $folder
|
||||
|
|
@ -629,6 +636,11 @@ wevtutil sl Security /ms:1073741824 | Out-Null
|
|||
# launched and how each process ended: the history of the scheduled tasks, and the start and end of every process.
|
||||
wevtutil sl Microsoft-Windows-TaskScheduler/Operational /e:true /ms:104857600 | Out-Null
|
||||
auditpol /set '/subcategory:{0CCE922B-69AE-11D9-BED3-505054503030},{0CCE922C-69AE-11D9-BED3-505054503030}' /success:enable | Out-Null
|
||||
# The start of a process is recorded with its command line, so what a visitor ran is known even when they deleted their
|
||||
# shell history along with everything else.
|
||||
$audit = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit'
|
||||
if (-not (Test-Path $audit)) { New-Item -Path $audit | Out-Null }
|
||||
Set-ItemProperty -Path $audit -Name ProcessCreationIncludeCmdLine_Enabled -Value 1 -Type DWord
|
||||
|
||||
# The installation's own cygrunsrv sshd service would fight for port 22; the scheduled task owns the sshd instead.
|
||||
Set-Service $service -StartupType Disabled -ErrorAction SilentlyContinue
|
||||
|
|
|
|||
Loading…
Reference in a new issue