Extracting certs/private keys from Windows using mimikatz and intercepting calls with burpsuite
Extracting certs/private keys from certificates that disable private key exporting and use BurpSuite to intercept the requests.

Situation

    I have installed a new client certificate on my Windows machine
    I cannot export the private key for this certificate (the export flag is false)
    I am a Linux user that needs to have the cert and private key to import it on BurpSuite to perform tests ...

Install/export certificate using Windows VM

    2.
    Install the certificate through the VM as needed
    3.
    In Internet Explorer, click the settings icon (looks like a gear) and choose "Internet Options"
    4.
    Click the "Content Tab"
    5.
    Click "Certificates"
    6.
    Click the certificate you installed (likely on the Personal tab) and click the "Export..." button
    7.
    Click "Next" through the next few prompts in the Certificate Export Wizard
    8.
    On the "File to Export" screen, click "Browse" and find a location (like your Desktop) to save the file to and give it a name
    9.
    Click "Next" and "Finish"
    10.
    Bring the certificate back over to Linux

Run mimikatz to get the private key

    1.
    Download mimikatz - a tool that will extract the private key from installed certificates
    2.
    Extract the mimikatz files to a directory (you only need the Win32 folder)
    3.
    Run cmd.exe as an Administrator (you may need to navigate to C:\Windows\System32\ and right-click the cmd.exe file)
    4.
    Run the mimikatz.exe from the command prompt
    5.
    Run the following commands:
1
privilege::debug
2
crypto::capi
3
crypto::keys /export
Copied!
If you need to extract the certificates:
1
crypto::certificates /export
Copied!
You should have a .pvk (private key) file in the same directory as mimikatz.exe now—probably just the one you installed. If you see multiple private keys, you'll have to determine which one is the one you installed.
You can use some other tools to work with the certificate stores. The certutil tool has some uses, for example you can view all the personal certificates for the current user with:
1
certutil -user -viewstore My
2
certutil -store -user
3
4
If you simply want to dump all the information in the console, you can use:
5
certutil -user -store My
6
7
To do the same for the computer account, simply drop the ‘-user’ parameter:
8
certutil -store My or certutil -viewstore My
9
10
For the PowerShell lovers, the Cert: drive can provide most of the needed information. Here are some uses:
11
PS C:\> cd Cert:; dir
12
13
To list all the certificates in the ‘Personal’ store for the current user, use:
14
PS Cert:\> dir Cert:\CurrentUser\My
15
16
To get all the details for a particular certificate, you can use the thumbprint:
17
PS Cert:\> dir Cert:\CurrentUser\My\106796B4130A9AE14BF38C7CE553353204613796 | fl *
Copied!

Convert PVK to PEM

You can convert the Windows proprietary ".pvk" file to a useful ".pem" file by using the following command:
1
openssl rsa -inform pvk -in YOUR_PRIVATE_KEY.pvk -outform pem -out YOUR_NEW_PRIVATE_KEY.pem
Copied!

Import the PFX certificate from mimikatz on BurpSuite

In BurpSuite "User Options / TLS" option, import the PFX certificate directly obtained from mimikatz, and everything will work fine.
The PFX password is "mimikatz" by default
🤓
From here, you can intercept all the traffic between your browser and the server, use enumeration tools from Linux such as gobuster, dirsearch and, so on. You need to use the BurpSuite as a proxy everytime, or your requests will not be valid (bad SSL handshake).
1
python3 dirsearch.py -e php,html,js -u https://target --proxy 127.0.0.1:8080
Copied!

References

burpsuite import client certificate of website - Programmer Sought
Windows certificate stores
Blog

Bonus

GitHub - TheWover/CertStealer: A .NET tool for exporting and importing certificates without touching disk.
GitHub
Last modified 5mo ago