Skip to content

Instantly share code, notes, and snippets.

@adamwalz
Created November 20, 2014 22:50
Show Gist options
  • Save adamwalz/ef9b46949722f1444cf5 to your computer and use it in GitHub Desktop.
Save adamwalz/ef9b46949722f1444cf5 to your computer and use it in GitHub Desktop.
VPN Shared Secret decoder for networkConnect files
#!/usr/bin/python
# Decoder for the ExportedSharedSecret values stored in .networkConnect files
# Tested with .networkConnect files created in Mac OS X 10.10
#
# Author: Martin Rakhmanov, http://jimmers.info
#
# Example invocation and output:
#
# python vpn_shared_secret_decoder.py TLthF+e88vwmAYhK
# Shared Secret: 12345
import sys
import base64
if len(sys.argv) != 2:
print("Provide ExportedSharedSecret value from .networkConnect file")
sys.exit(1)
cryptotext = base64.b64decode(sys.argv[1])
decryption_key = [0x7d, 0x89, 0x52, 0x23, 0xd2, 0xbc, 0xdd, 0xea, 0xa3, 0xb9, 0x1f]
i = 0
cleartext = ""
for ch in cryptotext:
b = ord(ch) ^ decryption_key[i]
if b == 0x00:
break
cleartext += chr(b)
i += 1
i = i % len(decryption_key)
print("Shared Secret: %s" %(cleartext))
@elgs
Copy link

elgs commented Dec 15, 2014

What is the algorithm to generate the cryptotext from the clear text?

@elgs
Copy link

elgs commented Dec 15, 2014

Inspired by your code, and given the fact that if A ^ B = C, then C ^ B = A, or C ^ A = B. I wrote the following code attempting to generate the crypto text. However, I only get similar crypto code. It seems Apple put some rand data at the tail of the crypto text. So do you have idea how to generate exactly the same crypto code? Thanks.

#!/usr/bin/python

import sys
import base64

cleartext = sys.argv[1]

decryption_key = [0x7d, 0x89, 0x52, 0x23, 0xd2, 0xbc, 0xdd, 0xea, 0xa3, 0xb9, 0x1f]

i = 0
cryptotext = ""

for ch in cleartext:
    b = ord(ch) ^ decryption_key[i]
    cryptotext += chr(b)
    i += 1
    i = i % len(decryption_key)

result = base64.b64encode(cryptotext)


print("Shared Secret: %s" %(result))

@carlfriess
Copy link

It seems the clear text string's length needs to be a multiple of 12. Filling the remaining characters with null bytes worked for me.

#!/usr/bin/python

import sys
import base64

cleartext = sys.argv[1]

while len(cleartext) % 12 != 0:
    cleartext += chr(0x00)

decryption_key = [0x7d, 0x89, 0x52, 0x23, 0xd2, 0xbc, 0xdd, 0xea, 0xa3, 0xb9, 0x1f]

i = 0
cryptotext = ""

for ch in cleartext:
    b = ord(ch) ^ decryption_key[i]
    cryptotext += chr(b)
    i += 1
    i = i % len(decryption_key)

result = base64.b64encode(cryptotext)


print("Shared Secret: %s" %(result))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment