Skip to content

Instantly share code, notes, and snippets.

@gurnec
Created August 16, 2017 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gurnec/e9638293b672b756250a0e881ab44368 to your computer and use it in GitHub Desktop.
Save gurnec/e9638293b672b756250a0e881ab44368 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from base64 import *
import sys, struct, zlib
print >> sys.stderr, 'btcrecover extract> ',
key_crc_data = b64decode(raw_input())
key_data = key_crc_data[:-4]
assert key_data[:3] == 'bc:'
# Check the CRC
(key_crc,) = struct.unpack('<I', key_crc_data[-4:])
assert zlib.crc32(key_data) & 0xffffffff == key_crc
mkey, salt, iter_count = struct.unpack('< 32s 8s I', key_data[3:])
print >> sys.stderr, 'John the Ripper compatible, Hashcat compatible, or both (j/h/b)? ',
choice = raw_input()[0].lower()
if choice != 'h':
mkey = 16 * '\0' + mkey
hash = '$bitcoin${}${}$16${}${}$0$$'.format(len(mkey)*2, b16encode(mkey).lower(), b16encode(salt).lower(), iter_count)
if choice == 'j':
pad_len = 2
else:
# From hashcat:
DISPLAY_LEN_MIN_11300 = 1 + 7 + 1 + 2 + 1 + 96 + 1 + 2 + 1 + 16 + 1 + 1 + 1 + 2 + 1 + 96 + 1 + 1 + 1 + 2
pad_len = DISPLAY_LEN_MIN_11300 - len(hash) - 2
assert pad_len > 0
pad_len += pad_len & 1 # round up to even
hash += '{}${}'.format(pad_len, pad_len * '0')
print hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment