6

I'm trying to get pyethrecover.py running via Python on one of my .json files that were created by Ethereum-wallet for Mac. It seems that my .json file is v3 and the pyethrecover.py only works for v1 files (the pyethrecover.py looks for 'encseed and 'ethaddr' that isn't available on v3 versions of .json files).

Is there a way to transfer v3 files into v1 files (without having to input the password) or another way to brute force my .json file were I've forgetting my exact password on? Or maybe alter my v3 .json file to help the pyethrecover.py working on it?

I've already email ethereal.org with my issue, but no response.

Hope you can help me!

2 Answers 2

3

I had the same problem. I had created a wallet using geth and somehow I wrote down the wrong password. I used the simple python code below to solve the issue. I know it's not pretty, but I just needed a quick solution to my problem. Someone else might pick this up and make a proper tool, or perhaps I get around to it one day as a good python learning experience. I tested some 100k password and I was able to recover using this code. It follows a similar format as pyethrecover (the presale tool) and uses pyethereum to decode the keystore file.

You need to download/install the pyethereum library: https://github.com/ethereum/pyethereum
See documentation there for requirements and how to.

From pyethereum we need keys.py which has the function decode_keystore_json

from keys import decode_keystore_json #keys.py from pyethereum, we only want the decode_keystore_json function
import json
import itertools
import sys

f = open('wallet.json') # the json account file from keystore, here renamed
jsondata=json.load(f)

Run the following if you have a text file with the different passwords you want to try written down, one on each line:

# Reading possible passwords from a text file
with open('listofpasswords.txt') as fpw: # a text file with possible passwords on each line
    lines = fpw.read().splitlines()

n_pws = len(lines)
print 'Number of passwords to test: %d' % (n_pws,)
i=1
for l in lines:
    try:
        decode_keystore_json(jsondata,l)
        print '\n*** found password in text file:'
        print l
        break
    except:
        sys.stdout.write("\r#%d %s" % (i,l)) #prints simple progress with # in list that is tested and the pw string
        sys.stdout.flush()
        i+=1

Or this code if you want to construct passwords from possible combinations (see pyethrecover example 2):

# Constructing passwords from possible combinations (see doc of pyethrecover)
grammar=[
    ('correct',),
    ('horse','donkey'),
    ('staple','STAPLE'),
    ('','battery')
]

pwds=[]
def generate_all(el, tr): #taken from pyethrecover
    if el:
        for j in xrange(len(el[0])):
            for w in generate_all(el[1:], tr + el[0][j]):
                yield w
    else:
        yield tr


pwds = itertools.chain(pwds, generate_all(grammar,''))
pwds_l = list(pwds)
n_pws = len(pwds_l)
print 'Number of passwords to test: %d' % (n_pws,)
i=1
for l in pwds_l:
    try:
        decode_keystore_json(jsondata,l)
        print '\n*** found password in grammar list:'
        print l
        break
    except:
        sys.stdout.write("\r#%d %s" % (i,l)) #prints simple progress with # in list that is tested and the pw string
        sys.stdout.flush()
        i+=1

Good luck!

1

@rhkarls answer was a life saver !

I just had to adapt the code a bit for my version of Python (3.5.2)

from keys import decode_keystore_json #keys.py from pyethereum, we only want the decode_keystore_json function
import json
import itertools
import sys
print(sys.version)

# the json account file from keystore, here renamed, normally has a name like 
# Ethereum\keystore\UTC--2016-12-23T11-51-50.069518500Z--637f383c240g512be19d3ffa3b45d7f03babf091
f = open('ethereum-wallet.json')
jsondata=json.load(f)

combinations=[
    ('beautiful', 'ugly', 'elegant', 'clumsy', ''),
    ('blue', 'red', 'yellow', 'green'),
    ('horse', 'dog', 'cat')
]

pwds=[]
def generate_all(el, tr): #taken from pyethrecover
    if el:
        for j in range(len(el[0])):
            for w in generate_all(el[1:], tr + el[0][j]):
                yield w
    else:
        yield tr


pwds = itertools.chain(pwds, generate_all(combinations,''))
pwds_l = list(pwds)
n_pws = len(pwds_l)

print('Number of passwords to test {0} '.format(n_pws))

i=1
found = 0
for l in pwds_l:    
    try:
        decode_keystore_json(jsondata,l)
        print('\n*** found password in text file {0} '.format(l))
        found = 1
        break
    except:   
        i+=1

if found == 0:
    print('Password not found in {0} attempts'.format(n_pws))
1

Not the answer you're looking for? Browse other questions tagged or ask your own question.