如果你正在努力 Adv200005安全咨询 为了 CVE-2020-0796,主要的解决方法是禁用og体育上的SMB压缩。让我们来看看如何用PowerShell在注册表中做到这一点。
更新: 微软发布了 KB4551762 解决了安全咨询。不再需要此解决方法,但我在这里离开这篇文章,因为它涵盖了使用PowerShell在组织中应用注册表更改的一般方法。
指数
禁用SMBV3压缩
SMB Compression is managed using the HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\DisableCompression
key in the registry and does not require a reboot. Powershell makes this really simple.
#Requires -RunAsAdministrator
$parameters = @{
Path = "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters"
Name = 'DisableCompression'
Type = 'DWORD'
Value = 1
Force = $true
}
Set-ItemProperty @parameters
You do have to run this on every host. We can use Invoke-Command
to do that (Assuming 电源外壳 Remoting. 正在你的环境中工作)。我们将原始脚本放在脚本块中。
$Session = New-PSSession -ComputerName 'ATX-FILE01','ATX-FILE02','LAX-SQL05'
Invoke-Command -Session $Session -ScriptBlock {
$parameters = @{
Path = "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters"
Name = 'DisableCompression'
Type = 'DWORD'
Value = 1
Force = $true
}
Write-Verbose "Disabling [$env:computername]" -Verbose
Set-ItemProperty @parameters
}
$Session | Remove-PSSession
启用
我们可以使用值0而不是1启用SMBv3压缩。
#Requires -RunAsAdministrator
$parameters = @{
Path = "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters"
Name = 'DisableCompression'
Type = 'DWORD'
Value = 0
Force = $true
}
Set-ItemProperty @parameters
如果我们收到修补程序来修复安全咨询,请确保返回并启用此功能。
当前状态
我不了解你,但是当我正在进行批量变化时,我喜欢拥有一个脚本,告诉我我在我做出更改之前和之后可以运行的所有内容的状态。我从这样的东西开始:
$parameters = @{
Path = "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters"
}
$properties = Get-ItemProperty @parameters
if (1 -eq $properties.DisableCompression){
Write-Verbose "[$env:ComputerName] is Disabled" -Verbose
} else {
Write-Verbose "[$env:ComputerName] is Enabled" -Verbose
}
I could have used Get-ItemProperty to get just the value of DisableCompression
, but it will throw an error if that property does not exist. My logic above is very subtly working around that scenario.
We can also wrap this in an Invoke-Command
to get the results from multiple hosts.
$Session = New-PSSession -ComputerName 'ATX-FILE01','ATX-FILE02','LAX-SQL05'
Invoke-Command -Session $Session -ScriptBlock {
$parameters = @{
Path = 'HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters'
}
$properties = Get-ItemProperty @parameters
if (1 -eq $properties.DisableCompression) {
Write-Verbose "[$env:ComputerName] is Disabled" -Verbose
} else {
Write-Verbose "[$env:ComputerName] is Enabled" -Verbose
}
}
$Session | Remove-PSSession
pssessions.
You may have noticed that I used New-PSSession
to create sessions instead of using Invoke-Command -ComputerName
. I did this because I tend to run multiple commands back to back on a collection of hosts. I first run my script to get the current status. This gives me a clear picture of what I am about to change. I then run my change for a small set of hosts before running it on everything. When I am done, I run the status check again to verify everything is correct.
虽然我确实包括两个示例中的会话创建和清理,但我确实在制作更改时重复使用会话。
IDEMPotent变化
让您的更改脚本安全地在同一og体育上执行多次。此示例仅设置注册表项,并且可以安全地设置一遍又一遍才能设置。如果您正在进行其他更改,如删除文件,请确保如果文件不存在于第二次运行中,则确保脚本不会出错。
你永远不知道当你将成为改变一大群主人的一部分,并且必须出于某种原因重新开始。如果您可以在整个组上安全地重新运行脚本,它将保存您必须访问RESOON已更改的og体育并从下一次运行中排除它们。
配置管理
这也是我们可以使用DSC制作的变化。我们可以通过使用单一来完成它 DSC注册表资源.
Configuration DisableSMBv3CompressionConfig {
Node localhost {
Registry DisableSMBv3Compression {
Ensure = 'Present'
Key = 'HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters'
ValueName = 'DisableCompression'
ValueData = '1'
ValueType = 'Dword'
}
}
}
DisableSMBv3CompressionConfig -Output c:\DSC
Start-DscConfiguration -Path C:\DSC -Wait -Force -Verbose
This example just configures localhost
but you could specify your hosts instead. Ideally, you are already using DSC and can just add this to your existing configuration.
为什么配置管理
我只是想打电话给答案,即使你把这样的变化爆炸到每个人,也很重要,可以将其移动到您的配置管理系统中。这样做,以这种方式只获取此时在线在线的og体育。如果og体育关闭,或者从备份恢复到快照,或者部署新og体育,则需要进行这些更改。
我常常急于赶出变化,但任务并没有真正完成,直到它的托管设置。我不在乎该组织策略,SCCM,DSC,Puppet,Chef还是其他的。不要只是火,忘记这样的变化。
结束语
希望你在我发现一些价值解释如何用PowerShell改变这样的变化。原始的安全咨询确实包括单行脚本来制作相同的更改,以便我想要花一些时间并添加更多的上下文。如果您喜欢这样的内容,请使用下面的链接在Twitter上共享它。当读者与他人分享我的内容时,我总是很感激。