Skip to content

Export private keys marked as not-exportable on Windows

During certificate import, Windows marks private keys as non-exportable by default:

The effect can be seen here:

This will prevent everyone (attackers and legitimate users) from exporting the private key in the future.

Option 1: jailbreak

Prerequisites

You will need to download jailbreak which your endpoint security software will most likely flag as malicious or dangerous. Prevent this from happening by temporarily excluding your download folder from scans. Please refer to the appropriate documentation of your endpoint security software on how to achieve this. Here is Microsoft’s documentation for Defender.

The following workflow prevents Windows Defender from interfering.

Open a PowerShell Terminal window as Administrator (press Win+R, enter pwsh and press Ctrl+Shift+Enter):

# create new target directory
New-Item -ItemType Directory -Force -Path "C:\tools\jailbreak"

Create an exception only if you are using Microsoft Defender

# create Defender exception for C:\tools\jailbreak
Add-MpPreference -ExclusionPath "C:\tools\jailbreak"

Download and extract jailbreak:

# Download jailbreak
irm "https://github.com/iSECPartners/jailbreak/archive/a3bd2d77429e579c918411ad3a119682c8e79f4b.zip" -OutFile "C:\tools\jailbreak.zip"

# extract downloaded archive
Expand-Archive "C:\tools\jailbreak.zip" "C:\tools\jailbreak"

# 
cd "C:\tools\jailbreak\jailbreak-a3bd2d77429e579c918411ad3a119682c8e79f4b"

Exporting private keys

Choose one of these two options.

Option 1: Interactive Export

Enter

.\jbcert64.bat
in your elevated PowerShell. A MMC with the Local Machine and Current-User Certificate snap-ins will load. All certificates are now marked as exportable. Use the certificate UI to export certificates and their private keys:

You should now have the option to export the private key:

See this page for details.

Option 2: Batch Export

This will simply export all of the user’s certificates into a single PKCS12 file.

Run

.\jbstore64.bat -a -o $HOME\Desktop\export.pfx

A new PKCS12 file named export.pfx will appear on the user’s desktop; the password is password (use -p secret) to set a different password. Running .\jbstore64.bat without arguments prints a help message that explains all options.

Cleanup

Remove jailbreak:

Remove-Item -Recurse -Force "C:\tools\jailbreak"

Finally, only if you made an exception for Windows Defender, remove it:

Remove-MpPreference -ExclusionPath "C:\tools\jailbreak"   # remove the exclusion when done

Option 2: mimikatz.exe

Does not work on Windows 11

Initial testing suggests that this does not work on Windows 11. Further testing is needed and user feedback is appreciated.

Prerequisites

You will need to download mimikatz which your endpoint security software will most likely flag as malicious or dangerous. Prevent this from happening by temporarily excluding your download folder from scans. Please refer to the appropriate documentation of your endpoint security software on how to achieve this. Here is Microsoft’s documentation for Defender.

Download the current release (usually called mimikatz_trunk.zip) of mimikatz to the directory that you previously excluded from security scans. Extract the archive.

Exporting private keys

Open a command shell (press Win+R, enter cmd and press Enter).

Run with Administrator rights

You may need a shell with elevated right. To start such a shell press Win+R, enter cmd and press Ctrl+Shift+Enter

Change into the directory that contains mimikatz and run x64\mimikatz.exe:

cd %HOMEPATH%\Downloads\mimikatz_trunk
.\x64\mimikatz.exe

Enter these commands to export all certificates and keys (see the mimikatz wiki for details):

crypto::capi
privilege::debug
crypto::cng
crypto::certificates /export

The exported certificates and keys are in the current directory; the password is mimikatz.

Cleanup

Remove mimikatz and re-enable on-access scanning.