r/msp • u/denismcapple • Jul 20 '24
Bootable USB to Fix Crowdstrike Issue (Fully unattended with Bitlocker Support)
Hi All,
All this drama got me thinking about what would be the fastest way to recover from something like this - Really what you want is something you can give to an end user, where they just boot up from a USB and it fixes the issue and reboots normally without any user interaction - Or, add a boot image and PXE boot the repair process.
The big challenge is around Bitlocker, having to find and type those keys. But surely we can automate this too.
So lets create a bootable USB that has a CSV file containing Bitlocker Volume ID's and Recovery Keys. It should boot into WinPE - Unlock the Drive - Delete the Files - Reboot, all fully unattended. This could also be runnable from a PXE Service like Windows Deployment Services.
I know its not ideal to have all of your bitlocker keys on a USB stick, but you can always mass-rotate your bitlocker keys once this mess is cleaned up.
How to rotate Bitlocker Keys
This was posted elsewhere by /u/notapplemaxwindowsReminder: Rotate your BitLocker keys! :
Connect-MgGraph -Scopes DeviceManagementManagedDevices.ReadWrite.All, DeviceManagementConfiguration.Read.All
Get-MgBetaDeviceManagementManagedDeviceEncryptionState -All -Filter "encryptionState eq 'notEncrypted'" | ForEach-Object {
Invoke-MgGraphRequest `
-Method POST `
-Uri "beta/deviceManagement/managedDevices('$($_.id)')/rotateBitLockerKeys"
}I've put something together in a hurry, and YMMV with it - but I did a quick proof of concept and I hope that it will help someone out there with potentially hundreds of machines to recover.
I've decided to use OSDCloud as part of this, since I am very familiar with it and can create Bootable USB's easily, inject drivers etc. Might be overkill, but it seemed like the simplest way to get going based on what i've done before. You could go about this in multiple ways, but this is the one I have chosen. Also, OSDCloud rules.
Step 1- Obtain all of your Bitlocker Recovery Keys
Azure AD
If you have them all saved in Azure AD - and you've the necessary access to pull these down, you're in luck, you can download them all using the script below.
Import-Module Microsoft.Graph.Identity.DirectoryManagement
Connect-MgGraph -Scopes "bitlockerkey.readbasic.all", "bitlockerkey.read.all"
$keys = Get-MgInformationProtectionBitlockerRecoveryKey -all | select Id,CreatedDateTime,DeviceId,@{n="Key";e={(Get-MgInformationProtectionBitlockerRecoveryKey -BitlockerRecoveryKeyId $_.Id -Property key).key}},VolumeType
$keys | export-csv c:\temp\Keys.csv -notypeinformation
On Prem AD (added thanks to u/PaddyStar**)**
If you have the keys stored on-prem, use the following code to generate c:\temp\Keys.csv
$Result = Get-ADObject -Filter {objectclass -eq 'msFVE-RecoveryInformation'} -Properties msFVE-RecoveryPassword | Select-Object @{n="Computername";e={$_.DistinguishedName.Split(",")[1].Replace("CN=","")} }, @{Name="Datum";Expression={[datetime]::Parse($($_.Name.Split("+,")[0]))}}, @{n="ID";e={$_.DistinguishedName.Split("{")[1].Split("}")[0]} }, msFVE-RecoveryPassword | Sort-Object Computername, Datum -Descending
$ModifiedResult = $Result | Select-Object Computername, Datum, ID, @{n="Key";e={$_."msFVE-RecoveryPassword"}}
$ModifiedResult | export-csv c:\temp\keys.csv -notypeinformation
Both above options will create a file in c:\temp called Keys.csv - you'll need this later.
If you cant get them from AD or Azure, but you do have them in some other format (RMM?), create a CSV file called keys.csv and populate it with two columns (ID and Key) where ID = Volume ID and Key = Recovery Key.
Or, you can just leave the file out, and the user will be prompted to enter the key to proceed.
Step 2 - Build the OSDCloud USB
- Install Windows 10 22H2 on a VM somewhere (or use an existing PC)
- Install Win 10 2004 version of ADK (Both Deployment Tools & Win PE) https://learn.microsoft.com/en-us/windows-hardware/get-started/adk-install
- Powershell (as Admin)
- Install-Module OSD -Force
- New-OSDCloudTemplate -Name "CSFix"
- Set-OSDCloudWorkspace "c:\CSFix"
Now go into C:\csfix\config\Scripts\startup and put both the keys.csv obtained or created earlier, and the following script
fix_crowdstrike.ps1
$manageBdeOutput = manage-bde -protectors -get c:$outputString = $manageBdeOutput | Out-String$newString = $outputString.Substring($outputString.IndexOf("Numerical Password:"))
if ($newString -match '\{([^\}]+)\}') {$VolID = $matches[1]}
write-host The Volume ID is $VolID$keys = import-csv x:\OSDCloud\Config\Scripts\startup\keys.csv$key = $keys | ? {$_.ID -eq $VolID}
if ($key) {manage-bde -unlock C: -RecoveryPassword $key.Key} else {write-host "No matching Volume ID found in keys.csv."$recoveryKey = Read-Host -Prompt "Please enter the BitLocker Recovery Key for the Volume with ID $VolID"manage-bde -unlock C: -RecoveryPassword $recoveryKey}
Set-Location -Path "C:\Windows\System32\drivers\CrowdStrike"$files = Get-ChildItem -Path . -Filter "C-00000291*.sys"
if ($files) {foreach ($file in $files) {write-host "Deleting file: $($file.FullName)"Remove-Item -Path $file.FullName -Force}} else {write-host "No files matching 'C-00000291*.sys' found."}write-host "Process completed - Please remove the USB Stick"pausewpeutil reboot
Back into PowerShell again and run the final command
- Edit-OSDCloudWinPE -CloudDriver * -Startnet "PowerShell -NoL -C x:\OSDCloud\config\scripts\startup\fix_crowdstrike.ps1"
This will edit the boot.wim file, adding the scripts and the startup command for when it boots up.
It will also inject drivers into the boot.wim to support most storage controllers out there.
** As per Drivers | OSDCloud.com
Step 3 - Make USB Media, or PXE Boot
USB Media
Copy "c:\csfix\OSDCloud_NoPrompt.iso" onto a computer with access to a USB port and then install OSD Modules on that computer (Install-Module OSD -Force)
Then, create a Bootable USB stick. You can create multiple.
- New-OSDCloudUSB -fromIsoFile c:\csfix\OSDCloud_NoPrompt.iso
PXE Boot
Add the file c:\csfix\Media\Sources\boot.wim to your Boot Images on Windows Deployment Services and just boot off that.
This was all very rushed and cobbled together with very little testing, but the premise is sound and if I had a few hundred computers to repair, this is the approach I would take. The script could be cleaner, feel free to clean it up!
If anyone does attempt this, let me know how you get on!
7
u/EquivalentBrief6600 Jul 20 '24
PXE boot this?
5
u/avicario96 Jul 20 '24
Amazing guide, unfortunately my bitlocker keys are on active directory and not Azure yet. Curious if anyone has PowerShell script to pull keys from active directory?
4
u/Daveid MSP - US Jul 20 '24
This is awesome, but just thought you and everyone should know that rebooting 15-20 times works too. No joke. As long as the machine has a network connection, after enough reboots from BSOD it will download and apply the corrected patch.
3
u/Illustrious-Ad-3523 Jul 22 '24
With hours of troubleshooting along with OP IT WORKS!!! i was able to ping down 10 pcs in department in not even 5 minutes. Got 1000 pcs left to go at my org🤦♂️. Thank you OP you are a genius
3
u/Nate2003 Jul 23 '24
Thank you so much for providing this!!!
This worked amazing in our environment!
Rather than using OSD Cloud for the boot image though, I did one in ConfigMgr along with guidance from this blog. I had added all the misc Intel RST VMD drivers which I believed to be needed which I already had.
https://jrudlin.github.io/2019/03/01/run-scripts-before-the-format-disk-step-in-your-sccm-osd-task-sequence-using-a-vdisk/
2
u/Marx418 Jul 20 '24
Can someone create an ISO file that I can have users boot from a supplied USB and it deletes the file without the need for bitlocker??
2
u/LakeResident6451 Jul 21 '24
Attempted got hit by winpe in x:
Disk: usb
So it doesn't get to C drive. Added c: at the top of the script also does not work.
34
u/Steve_reddit1 Jul 20 '24 edited Jul 21 '24
I applaud the effort.
FWIW my wife’s (large) company did not have a working BitLocker key. From the Recovery screen command prompt we used bcdedit to enter safe mode, delete the file, and bcdedit to revert. Even though she’s a standard user normally.
Edit: as noted below I found her account is indeed a local admin, they just had anything I had tried “as admin” prompting for UAC anyway, in normal mode.
9
u/whitedragon551 Jul 20 '24
Absolute money. Nice work!
24
u/brokerceej Creator of StackJack.io | Author of The Trunk Slammer Saga Jul 20 '24
Mods! Pin this shit immediately!
7
u/blackpoint_APG Jul 20 '24
Thank you so much for outlining this! We just posted on our socials to help boost the signal.
~S
5
u/AlwaysForeverAgain Jul 20 '24
NICE!!
5
u/Illustrious-Can-5602 Jul 20 '24
Great share
1
u/Natural-Guard4286 Jul 20 '24
Are the column names Volume ID and recovery KEY or ID and Key?
1
u/toddgak Jul 21 '24
The solution to a security product bricking your endpoints is to dump every bitlocker key into a csv and then copy that csv onto a bunch of USB drives?
1
u/xBrawl Jul 22 '24
Downloaded the ADK, but every time on the VM through Powershell as an Admin, I get the following:
Cannot find path "C:\Program Files (x86)\Windows Kits\Assessment and Deployment Kit\Deployment Tools\AMD64\OScdimg\etfsboot.com" does not exist.
3
u/AnonymooseRedditor Jul 21 '24
https://techcommunity.microsoft.com/t5/intune-customer-success/new-recovery-tool-to-help-with-crowdstrike-issue-impacting/ba-p/4196959 Microsoft released a tool too
1
u/shunny14 Jul 22 '24 edited Jul 22 '24
Your command to update -startnet is also incorrect based on the name you previously provided...
should be
Edit-OSDCloudWinPE -Startnet "PowerShell -NoL -C x:\OSDCloud\config\scripts\startup\crowdstrike_fix.ps1"
if one followed the name listed in the code
Something is also getting confused by the drive letter when I ran the script. Also, a Start-Sleep 5s before reboot would be nice in case something didn't work and you manually want to do something in the WinPE yourself.
2
u/dmatech2 Jul 21 '24
Another approach might be to use a bootable Linux drive and Dislocker to mount the NTFS volume (using a recovery key either from some network service or manual input), make the changes, then reboot. If using a network service, it could track the status of every machine. You could then replace the recovery key or even re-encrypt the whole volume for added security.
1
u/mrtechead Jul 20 '24
Shared with several folks already. Great work and write up!
1
u/RielBitcoin Jul 21 '24 edited Jul 21 '24
I’ve added this post to our step #1 https://www.reddit.com/r/sysadmin/s/689LMFAoK7
1
u/[deleted] Jul 21 '24
Lisan Al-Gaib
1
u/shunny14 Jul 22 '24 edited Jul 22 '24
edit: dont do this... run New-OSDCloudWorkspace c:\csfix instead
Trying this now. New-OSDCloudTemplate -Name "CSFix" makes a folder in C:\ProgramData\OSDCloud\Templates\CSFix that seems to be what you are referring to. Guess I'll copy that to C:\CSFix and try the rest?
1
u/shunny14 Jul 22 '24
When booting to it, it appears PowerShell is not in the PE, so you just get the error "PowerShell" is not recognized as an internal or external command.
1
u/shunny14 Jul 22 '24
OK i think i figured out what the error is, you should have people run "New-OSDCloudWorkspace "c:\CSFix", not Set-...
I also may have needed to reboot after installing ADK etc, but running New... makes more sense.
1
u/Wrong-Appearance3277 Jul 22 '24
Good take
1
u/lazytechnologist Jul 25 '24
Ensure you read and understand the code before you run it. CrowdStrike are warning on scams and phishers pretending to have fixes that are actually malicious.