Skip to content
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

fix folder permissions for programdata\ssh during server install #549

Merged
merged 12 commits into from
Feb 5, 2022
21 changes: 21 additions & 0 deletions contrib/win32/openssh/install-sshd.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# @friism - Fixed issue with invalid SDDL on Set-Acl
# @manojampalam - removed ntrights.exe dependency
# @bingbing8 - removed secedit.exe dependency
# @tessgauthier - added permissions check for %programData%/ssh

$ErrorActionPreference = 'Stop'

Expand Down Expand Up @@ -84,6 +85,26 @@ if (Test-Path $moduliPath -PathType Leaf)
Repair-ModuliFilePermission -FilePath $moduliPath @psBoundParameters -confirm:$false
}

#If %programData%/ssh folder already exists, fix permissions
$sshProgDataPath = Join-Path $env:ProgramData "ssh"
tgauth marked this conversation as resolved.
Show resolved Hide resolved
if (Test-Path $sshProgDataPath)
{
$sshProgDataAcl=Get-Acl $sshProgDataPath
# Folder permission is FullAccess to System and Builtin/Admins and read only access to Authenticated users
$sshProgDataAcl.SetSecurityDescriptorSddlForm("O:BAD:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICI;0x1200a9;;;AU)")
Set-Acl $sshProgDataPath $sshProgDataAcl
# private key files and log folder/files should only allow FullAccess to System and Builtin/Admins
$restricted_files = @("ssh_host_dsa_key", "ssh_host_ecdsa_key", "ssh_host_ed25519_key", "ssh_host_rsa_key")
$sshProgDataAcl.SetSecurityDescriptorSddlForm("O:BAD:PAI(A;;FA;;;SY)(A;;FA;;;BA)")
Get-ChildItem -Path (Join-Path $sshProgDataPath '*') -Recurse -Include $restricted_files -Force | Set-Acl -AclObject $sshProgDataAcl
$sshProgDataAcl.SetSecurityDescriptorSddlForm("O:BAD:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)")
tgauth marked this conversation as resolved.
Show resolved Hide resolved
$log_folder = Join-Path $sshProgDataPath "logs"
if (Test-Path $log_folder)
{
Set-Acl $log_folder $sshProgDataAcl
}
}

#register etw provider
wevtutil im `"$etwman`"

Expand Down