Advertisement
YaBoiSwayZ

Patch v2 for CVE-2023-36884

Aug 7th, 2023 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 3.65 KB | Source Code | 0 0
  1. # Define the parameters for the script
  2. [CmdletBinding()]
  3. param (
  4.     [Parameter()]
  5.     [String]$OfficeProducts = "All", # Office products to be targeted for remediation
  6.     [Parameter()]
  7.     [Switch]$Undo                     # Switch to indicate whether to undo the changes
  8. )
  9.  
  10. function Test-IsElevated {
  11.     $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
  12.     $p = New-Object System.Security.Principal.WindowsPrincipal($id)
  13.     $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
  14. }
  15.  
  16. function Set-RegKey {
  17.     param (
  18.         $Path,
  19.         $Name,
  20.         $Value,
  21.         [ValidateSet("DWord", "QWord", "String", "ExpandedString", "Binary", "MultiString", "Unknown")]
  22.         $PropertyType = "DWord"
  23.     )
  24.     if (-not $(Test-Path -Path $Path)) {
  25.         New-Item -Path $Path -Force -ErrorAction Stop | Out-Null
  26.     }
  27.     $CurrentValue = (Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue).$Name
  28.     Set-ItemProperty -Path $Path -Name $Name -Value $Value -Force -Confirm:$false -ErrorAction Stop | Out-Null
  29.     Write-Host "$Path\$Name changed from $CurrentValue to $Value"
  30. }
  31.  
  32. function Remove-RegKey {
  33.     param (
  34.         $Path,
  35.         $Name
  36.     )
  37.     Remove-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue | Out-Null
  38.     if (Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue) {
  39.         Write-Error "ERROR: Unable to undo registry key $Name!"
  40.         exit 1
  41.     }
  42.     else {
  43.         Write-Host "Successfully removed registry key $Name!"
  44.     }
  45. }
  46.  
  47. function Perform-Remediation {
  48.     param (
  49.         [HashTable]$RemediationTargets,
  50.         [Switch]$Undo
  51.     )
  52.     $Path = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BLOCK_CROSS_PROTOCOL_FILE_NAVIGATION"
  53.     $RemediationTargets.GetEnumerator() | ForEach-Object {
  54.         Write-Host "$($_.Name) was selected for remediation."
  55.         if (-not $Undo) {
  56.             Set-RegKey -Path $Path -Name $_.Value -Value 1
  57.             Write-Host "Success!"
  58.         }
  59.         else {
  60.             Remove-RegKey -Path $Path -Name $_.Value
  61.         }
  62.     }
  63.     Write-Warning "A reboot may be required."
  64. }
  65.  
  66. begin {
  67.     if (-not (Test-IsElevated)) {
  68.         Write-Error "Please run the script with administrator privileges."
  69.         exit 1
  70.     }
  71.  
  72.     $RemediationValues = @{
  73.         "Word" = "WINWORD.EXE";
  74.         "Excel" = "EXCEL.EXE";
  75.         "PowerPoint" = "POWERPNT.EXE";
  76.         "All" = @("WINWORD.EXE", "EXCEL.EXE", "POWERPNT.EXE") # "All" includes all products
  77.     }
  78.  
  79.     $RemediationTargets = @{}
  80.     if ($OfficeProducts -ne "All") {
  81.         $OfficeProducts = $OfficeProducts.split(',') | ForEach-Object { $_.Trim() }
  82.         $OfficeProducts | ForEach-Object {
  83.             if ($RemediationValues.ContainsKey($_)) {
  84.                 $RemediationTargets.Add($_, $RemediationValues[$_])
  85.             }
  86.             else {
  87.                 Write-Error "ERROR: Invalid product $_. Please provide valid products."
  88.                 exit 1
  89.             }
  90.         }
  91.     }
  92.     else {
  93.         $RemediationValues["All"] | ForEach-Object { $RemediationTargets.Add($_, $_) }
  94.     }
  95.  
  96.     if ($RemediationTargets.Count -gt 0) {
  97.         Perform-Remediation -RemediationTargets $RemediationTargets -Undo:$Undo
  98.         exit 0
  99.     }
  100.     else {
  101.         Write-Warning "No products were selected! The valid values for -OfficeProducts are listed below. You can also use a comma-separated list or simply put 'All'."
  102.         $RemediationValues.Keys | Sort-Object | Format-Table | Out-String | Write-Host
  103.         Write-Error "ERROR: Nothing to do!"
  104.         exit 1
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement