Exploit databaseDownload repository ZIP
GH-e0e6dfd641f78928850d6bb19e8ad663
o0matte0o/cve-2022-41099-fix
Sources for CVE-2022-41099
1 sourcePreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.
Repository files6
o0matte0o/cve-2022-41099-fixRevision 4c2ba6d75fd1
- CVE-2022-41099.ps1
- Create-Custom-Image.md
- DetectionScript.ps1
- LICENSE
- PatchWinREScript_2004plus.ps1
- README.md
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
CVE-2022-41099.ps1
Suggested starting filePowerShell · 3,369 bytesStart-Transcript -Path "C:\WinRE-Logs.log" -Force
$WindowsVersion = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").UBR
If ($WindowsVersion -eq "2486 ") {
#Correct Windows Version
Write-Host "Correct Version of Windows Detected (OS Build 19044.2486)"
# Check Version of Recovery Drive (WinRE.wim)
Write-Host "Checking winre.wim Version:"
$WINREA = reagentc /info | findstr "\\?\GLOBALROOT\device"
$WINREB = $WINREA.replace("Windows RE location: ","").TRIM()
$WINREC = $WINREB + "\winre.wim"
$WINRED = $WINREC + " /index:1"
$WINREE = "Dism /Get-ImageInfo /ImageFile:$WINRED"
$WINREF = Invoke-Expression $WINREE
#Check winre.wim version
If ($WINREF -contains "ServicePack Build : 2486") {
Write-Host "No Action required your winre.wim file is up-to-date"
} Else {
Write-Host "Detecting Recovery Drives"
$DiskNo = (Get-Disk).Number
$RecoveryDiskNo = (Get-Partition | Where-Object -FilterScript {$_.Type -eq 'Recovery'}).PartitionNumber
Write-Host "Found Recovery Disk on Partition: " $RecoveryDiskNo
#Check for recovery drives
foreach ($Drive in $RecoveryDiskNo) {
#Create Random drive letter, not testing on network drives
$DriveLetter = ls function:[d-v]: -n | ?{ !(test-path $_) } | random
$DriveLetter = $DriveLetter -replace "[:]",""
Get-Partition -PartitionNumber $Drive | Set-Partition -NewDriveLetter $DriveLetter
$DriveLetter = $DriveLetter + ":"
#Check if drive has winre.wim file, otherwise ignore
If (Test-Path $DriveLetter\recovery\windowsre\winre.wim) {
Write-Host "Windows Recovery Drive Detected"
#check current owner for recovery
$CurrentOwner = (get-acl $DriveLetter).owner
$OriginalOwner = New-Object System.Security.Principal.NTAccount($CurrentOwner)
Write-Host "Updating WinRE.wim file"
#take ownership of files and folders so file can be copied
Takeown /F "$DriveLetter\recovery\windowsre\" /A /R /D Y
ICACLS "$DriveLetter\recovery\windowsre\" /grant administrators:F
attrib -h -r -s /s /d $DriveLetter\*.*
Copy-Item -Path ".\winre-compress.wim" -destination "$DriveLetter\recovery\windowsre\winre.wim" -Force -Verbose
#reset the folder permissions and ownership back to original settings
$acl = get-acl "$DriveLetter\recovery\windowsre\"
$acl.SetOwner($OriginalOwner)
Set-Acl "$DriveLetter\recovery\windowsre\" -AclObject $acl
ICACLS "$DriveLetter\recovery\windowsre\" /reset
#remove drive letter and hide drive again.
Remove-PartitionAccessPath -DiskNumber $DiskNo -PartitionNumber $Drive -AccessPath $DriveLetter
} else {
Write-Error "Manufaturers Recovery Drive Detected"
Write-Error "No action required"
Remove-PartitionAccessPath -DiskNumber $DiskNo -PartitionNumber $Drive -AccessPath $DriveLetter
}
}
}
} else {
#Wrong Version of Windows
Write-Error "Your Running the wrong version of windows"
}
Stop-Transcript