|
1 | 1 | Remove-Module -Name BOSH.Utils -ErrorAction Ignore |
2 | 2 | Import-Module ./BOSH.Utils.psm1 |
3 | 3 |
|
| 4 | +#As of now, this function only supports DWords and Strings. |
| 5 | +function Restore-RegistryState { |
| 6 | + param( |
| 7 | + [bool]$KeyExists, |
| 8 | + [String]$KeyPath, |
| 9 | + [String]$ValueName, |
| 10 | + [PSObject]$ValueData |
| 11 | + ) |
| 12 | + if ($KeyExists) { |
| 13 | + if ($ValueData -eq $null) { |
| 14 | + Remove-ItemProperty -path $KeyPath -Name $ValueName |
| 15 | + } else { |
| 16 | + Set-ItemProperty -path $KeyPath -Name $ValueName -Value $ValueData |
| 17 | + } |
| 18 | + } else { |
| 19 | + Remove-Item -Path $KeyPath -ErrorAction SilentlyContinue |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +Describe "Restore-RegistryState" { |
| 24 | + BeforeEach { |
| 25 | + Mock Remove-ItemProperty {} |
| 26 | + Mock Set-ItemProperty {} |
| 27 | + Mock Remove-Item {} |
| 28 | + } |
| 29 | + It "restores the registry by deleting a registry key created by the test" { |
| 30 | + Restore-RegistryState -KeyExists $false -KeyPath "HKLM:\Some registry key" |
| 31 | + |
| 32 | + Assert-MockCalled Remove-Item -Times 1 -Scope It -ParameterFilter { $Path -eq "HKLM:\Some registry key" } |
| 33 | + Assert-MockCalled Remove-ItemProperty -Times 0 -Scope It |
| 34 | + Assert-MockCalled Set-ItemProperty -Times 0 -Scope It |
| 35 | + } |
| 36 | + |
| 37 | + It "restores the registry by deleting a registry value created by the test" { |
| 38 | + Restore-RegistryState -KeyExist $true -KeyPath "HKLM:\Some registry key" -ValueName "SomeValue" |
| 39 | + |
| 40 | + Assert-MockCalled Remove-Item -Times 0 -Scope It |
| 41 | + Assert-MockCalled Remove-ItemProperty -Times 1 -Scope It -ParameterFilter { $Path -eq "HKLM:\Some registry key" -and $Name -eq "SomeValue"} |
| 42 | + Assert-MockCalled Set-ItemProperty -Times 0 -Scope It |
| 43 | + } |
| 44 | + |
| 45 | + It "restores the registry by restoring a registry data modified by the test" { |
| 46 | + Restore-RegistryState -KeyExist $true -KeyPath "HKLM:\Some registry key" -ValueName "SomeValue" -ValueData "Some Data" |
| 47 | + Restore-RegistryState -KeyExist $true -KeyPath "HKLM:\Some dword reg key" -ValueName "SomeDwordValye" -ValueData 85432 |
| 48 | + |
| 49 | + Assert-MockCalled Remove-Item -Times 0 -Scope It |
| 50 | + Assert-MockCalled Remove-ItemProperty -Times 0 -Scope It |
| 51 | + Assert-MockCalled Set-ItemProperty -Times 1 -Scope It -ParameterFilter { $Path -eq "HKLM:\Some registry key" -and $Name -eq "SomeValue" -and $Value -eq "Some Data" } |
| 52 | + Assert-MockCalled Set-ItemProperty -Times 1 -Scope It -ParameterFilter { $Path -eq "HKLM:\Some dword reg key" -and $Name -eq "SomeDwordValye" -and $Value -eq 85432 } |
| 53 | + } |
| 54 | +} |
| 55 | + |
4 | 56 | function New-TempDir { |
5 | 57 | $parent = [System.IO.Path]::GetTempPath() |
6 | 58 | [string] $name = [System.Guid]::NewGuid() |
@@ -92,4 +144,89 @@ Describe "Protect-Dir" { |
92 | 144 | } |
93 | 145 | } |
94 | 146 |
|
| 147 | +Describe "Disable-RC4" { |
| 148 | + It "Disables the use of RC4 Cipher" { |
| 149 | + $rc4_128Path = "HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\RC4 128/128" |
| 150 | + $rc4_128PathExists = Test-Path -Path $rc4_128Path |
| 151 | + $oldRC4_128Value = (Get-ItemProperty -path $rc4_128Path -ErrorAction SilentlyContinue).'Enabled' |
| 152 | + |
| 153 | + $rc4_40Path = "HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\RC4 40/128" |
| 154 | + $rc4_40PathExists = Test-Path -Path $rc4_40Path |
| 155 | + $oldRC4_40Value = (Get-ItemProperty -path $rc4_40Path -ErrorAction SilentlyContinue).'Enabled' |
| 156 | + |
| 157 | + $rc4_56Path = "HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\RC4 56/128" |
| 158 | + $rc4_56PathExists = Test-Path -Path $rc4_56Path |
| 159 | + $oldRC4_56Value = (Get-ItemProperty -path $rc4_56Path -ErrorAction SilentlyContinue).'Enabled' |
| 160 | + |
| 161 | + { Disable-RC4 } | Should Not Throw |
| 162 | + |
| 163 | + (Get-ItemProperty -Path $rc4_128Path).'Enabled' | Should Be "0" |
| 164 | + (Get-ItemProperty -Path $rc4_40Path).'Enabled' | Should Be "0" |
| 165 | + (Get-ItemProperty -Path $rc4_56Path).'Enabled' | Should Be "0" |
| 166 | + |
| 167 | + Restore-RegistryState -KeyExists $rc4_128PathExists -KeyPath $rc4_128Path -ValueName 'Enabled' -ValueData $oldRC4_128Value |
| 168 | + Restore-RegistryState -KeyExists $rc4_40PathExists -KeyPath $rc4_40Path -ValueName 'Enabled' -ValueData $oldRC4_40Value |
| 169 | + Restore-RegistryState -KeyExists $rc4_56PathExists -KeyPath $rc4_56Path -ValueName 'Enabled' -ValueData $oldRC4_56Value |
| 170 | + } |
| 171 | +} |
| 172 | + |
| 173 | +Describe "Disable-TLS1" { |
| 174 | + It "Disables the use of TLS 1.0" { |
| 175 | + $serverPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Server' |
| 176 | + $serverPathExists = Test-Path -Path $serverPath |
| 177 | + |
| 178 | + $oldServerEnabledValue = (Get-ItemProperty -path $serverPath -ErrorAction SilentlyContinue).'Enabled' |
| 179 | + $oldServerDisabledValue = (Get-ItemProperty -path $serverPath -ErrorAction SilentlyContinue).'DisabledByDefault' |
| 180 | + $oldServerValue = (Get-ItemProperty -path $serverPath -ErrorAction SilentlyContinue).'Enabled' |
| 181 | + |
| 182 | + $clientPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Client' |
| 183 | + $clientPathExists = Test-Path -Path $clientPath |
| 184 | + |
| 185 | + $oldClientEnabledValue = (Get-ItemProperty -path $clientPath -ErrorAction SilentlyContinue).'Enabled' |
| 186 | + $oldClientDisabledValue = (Get-ItemProperty -path $clientPath -ErrorAction SilentlyContinue).'DisabledByDefault' |
| 187 | + |
| 188 | + { Disable-TLS1 } | Should Not Throw |
| 189 | + |
| 190 | + (Get-ItemProperty -Path $serverPath).'Enabled' | Should Be "0" |
| 191 | + (Get-ItemProperty -Path $serverPath).'DisabledByDefault' | Should Be "1" |
| 192 | + |
| 193 | + (Get-ItemProperty -Path $clientPath).'Enabled' | Should Be "0" |
| 194 | + (Get-ItemProperty -Path $clientPath).'DisabledByDefault' | Should Be "1" |
| 195 | + |
| 196 | + Restore-RegistryState -KeyExists $serverPathExists -KeyPath $serverPath -ValueName 'Enabled' -ValueData $oldServerValue |
| 197 | + Restore-RegistryState -KeyExists $serverPathExists -KeyPath $serverPath -ValueName 'DisabledByDefault' -ValueData $oldServerDisabledValue |
| 198 | + |
| 199 | + Restore-RegistryState -KeyExists $clientPathExists -KeyPath $clientPath -ValueName 'Enabled' -ValueData $oldClientValue |
| 200 | + Restore-RegistryState -KeyExists $clientPathExists -KeyPath $clientPath -ValueName 'DisabledByDefault' -ValueData $oldClientDisabledValue |
| 201 | + } |
| 202 | +} |
| 203 | + |
| 204 | +Describe "Disable-3DES" { |
| 205 | + It "Disables birthday attacks against 64 bit block TLS ciphers" { |
| 206 | + $registryPath = 'hklm:\system\currentcontrolset\control\securityproviders\schannel\ciphers\triple des 168' |
| 207 | + $tripleDESPathExists = Test-Path $registryPath |
| 208 | + $oldDESValue = (Get-ItemProperty -path $registryPath -ErrorAction SilentlyContinue).'Enabled' |
| 209 | + |
| 210 | + { Disable-3DES } | Should Not Throw |
| 211 | + |
| 212 | + (Get-ItemProperty -path $registryPath).'Enabled' | Should Be "0" |
| 213 | + |
| 214 | + Restore-RegistryState -KeyExists $tripleDESPathExists -KeyPath $registryPath -ValueName 'Enabled' -ValueData $oldDESValue |
| 215 | + } |
| 216 | +} |
| 217 | + |
| 218 | +Describe "Disable-DCOM" -Tag 'Focused' { |
| 219 | + It "Disables the use of DCOM" { |
| 220 | + $DCOMPath = 'HKLM:\Software\Microsoft\OLE' |
| 221 | + $oldDCOMValue = (Get-ItemProperty -Path $DCOMPath).'EnableDCOM' |
| 222 | + |
| 223 | + { Disable-DCOM } | Should Not Throw |
| 224 | + |
| 225 | + (Get-ItemProperty -Path $DCOMPath).'EnableDCOM' | Should Be "N" |
| 226 | + Set-ItemProperty -Path $DCOMPath -Name 'EnableDCOM' -Value $oldDCOMValue |
| 227 | + |
| 228 | + Restore-RegistryState -KeyExists $true -KeyPath $DCOMPath -ValueName 'EnableDCOM' -ValueData $oldDCOMValue |
| 229 | + } |
| 230 | +} |
| 231 | + |
95 | 232 | Remove-Module -Name BOSH.Utils -ErrorAction Ignore |
0 commit comments