recover IPSec VPN preshared key

This is a old question, but on Windows 7, if you used the OS to create the VPN, the information is stored there in a .Pbk's file.

C:\Users\\AppData\Roaming\Microsoft\Network\Connections\Pbk

Other vendor(s) VPN software would use there own path/file format.

Like an example from the Sonicwall GVC client, which save it's settings there in a .RCF file

C:\Users\username\AppData\Roaming\SonicWall\Global VPN Client \AppData\Roaming\SonicWall\Global VPN Client


If you are using SonicWall's Global VPN Client, as mentioned in @yagmoth555's answer, you can find the Connections.rcf file at C:\Users\username\AppData\Roaming\SonicWall\Global VPN Client (source) which contains an encrypted version of the Pre-Shared Key.

The key is encrypted with the currently logged in user account and can be decrypted with the following python snippet:

import binascii
import win32crypt

psk_encrypted = "01000000D08C9DDF0..."

print(win32crypt.CryptUnprotectData(
    DataIn=binascii.unhexlify(psk_encrypted),
    OptionalEntropy=None,
    Reserved=None,
    PromptStruct=None,
    Flags=0))

Dependencies: pip install pywin32

Docs: http://timgolden.me.uk/pywin32-docs/win32crypt.html