Python Forum
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying Again
#1
Now that I installed Windows 7 pro and Python 2.7.13 I am trying to get it running.

Newer "better" version found here:

https://github.com/danielchalef/pyethrecoverv3

This is my first snag:

Output:
C:\Users\admin\Desktop\ETH>python pyethrecover_v3.py -w wallet.json Traceback (most recent call last):   File "pyethrecover_v3.py", line 3, in <module>     from keys import decode_keystore_json #keys.py from pyethereum, we only want  the decode_keystore_json function   File "C:\Users\admin\Desktop\ETH\keys.py", line 6, in <module>     from ethereum.utils import encode_hex ImportError: No module named ethereum.utils C:\Users\admin\Desktop\ETH>pip install ethereum Collecting ethereum   Downloading ethereum-1.6.1.tar.gz (128kB)     100% |################################| 133kB 504kB/s Collecting repoze.lru (from ethereum)   Downloading repoze.lru-0.6.tar.gz Collecting PyYAML (from ethereum)   Downloading PyYAML-3.12-cp27-cp27m-win32.whl (182kB)     100% |################################| 184kB 547kB/s Requirement already satisfied: pbkdf2 in c:\python27\lib\site-packages (from eth ereum) Collecting bitcoin (from ethereum)   Downloading bitcoin-1.1.42.tar.gz Collecting pycryptodome>=3.3.1 (from ethereum)   Downloading pycryptodome-3.4.5-cp27-cp27m-win32.whl (7.4MB)     100% |################################| 7.4MB 115kB/s Collecting secp256k1 (from ethereum)   Downloading secp256k1-0.13.2.tar.gz (156kB)     100% |################################| 163kB 547kB/s     Complete output from command python setup.py egg_info:     'pkg-config' is required to install this package. Please see the README for details.     ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in c:\users\admin\ap pdata\local\temp\pip-build-jmb1k2\secp256k1\ C:\Users\admin\Desktop\ETH>
Reply
#2
Have you tried googling?

One of the first results shows
http://stackoverflow.com/questions/17109...in-windows

Have you tried these?
Recommended Tutorials:
Reply
#3
If I understand correctly, out of the lib I am trying to install or import, I only need one function - "decode_keystore_json".

So, I just copied it and placed it in my code and commented out the import request.

Now python does not ask for the import anymore but the program does two things - It is asking for a global variable "counter" and it hangs up where I can not end it's task with the windows task manager and I have to restart the computer.

Please review the following code.

#!/usr/bin/python
 
#from keys import decode_keystore_json #keys.py from pyethereum, #we only want the decode_keystore_json function
import json
import itertools
import sys
import traceback
from joblib import Parallel, delayed
import multiprocessing
 
wordlist = "words3.txt"
with open(wordlist) as f:
dictlist = f.read().splitlines()
 
w = {
"address": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"crypto": {
"cipher": "aes-128-ctr",
"ciphertext": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"cipherparams": {
"iv": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
"kdf": "scrypt",
"kdfparams": {
"dklen": 32,
"n": 262144,
"p": 1,
"r": 8,
"salt": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
"mac": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
"id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"version": 3
}
 
# Constructing passwords from possible combinations (see doc of pyethrecover)
grammar=[
 ('abe ', 'dan ', 'mary '),
 ('lincoln ', 'jesus ', 'johnson '),
 dictlist # we append the wordlist. This isn't necessary if you think you've included all possible words above
]
 
# print(grammar)
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]):
# print(w)
yield w
else:
yield tr
 
def attempt(w, pw):
# print(pw)
# sys.stdout.write("\r")
 
# sys.stdout.write("\rAttempt #%d: %s" % (counter.value, pw)) #prints simple progress with # in list that is tested and the pw string
sys.stdout.write("Attempt #%d: %s\n" % (counter.value, pw)) #prints simple progress with # in list that is tested and the pw string
sys.stdout.flush()
#print(counter.value)
counter.increment()
 
if len(pw) < 10:
return ""
try:
o = decode_keystore_json(w,pw)
print(o)
# print (pw)q
raise PasswordFoundException(
"""\n\nYour password is:\n%s""" % o)
except ValueError as e:
# print(e)
return ""
 
class Counter(object):
def __init__(self):
self.val = multiprocessing.Value('i', 0)
 
def increment(self, n=1):
with self.val.get_lock():
self.val.value += n
 
@property
def value(self):
return self.val.value
 
#-------------------------
def decode_keystore_json(jsondata, pw):
# Get KDF function and parameters
if "crypto" in jsondata:
cryptdata = jsondata["crypto"]
elif "Crypto" in jsondata:
cryptdata = jsondata["Crypto"]
else:
raise Exception("JSON data must contain \"crypto\" object")
kdfparams = cryptdata["kdfparams"]
kdf = cryptdata["kdf"]
if cryptdata["kdf"] not in kdfs:
raise Exception("Hash algo %s not supported" % kdf)
kdfeval = kdfs[kdf]["calc"]
# Get cipher and parameters
cipherparams = cryptdata["cipherparams"]
cipher = cryptdata["cipher"]
if cryptdata["cipher"] not in ciphers:
raise Exception("Encryption algo %s not supported" % cipher)
decrypt = ciphers[cipher]["decrypt"]
# Compute the derived key
derivedkey = kdfeval(pw, kdfparams)
assert len(derivedkey) >= 32, \
"Derived key must be at least 32 bytes long"
# print(b'derivedkey: ' + encode_hex(derivedkey))
enckey = derivedkey[:16]
# print(b'enckey: ' + encode_hex(enckey))
ctext = decode_hex(cryptdata["ciphertext"])
# Decrypt the ciphertext
# print(ctext, enckey, cipherparams)
o = decrypt(ctext, enckey, cipherparams)
# Compare the provided MAC with a locally computed MAC
# print(b'macdata: ' + encode_hex(derivedkey[16:32] + ctext))
mac1 = sha3(derivedkey[16:32] + ctext)
mac2 = decode_hex(cryptdata["mac"])
if mac1 != mac2:
raise ValueError("MAC mismatch. Password incorrect?")
return o
 
 
 
#----------------------------
 
def __main__():
global counter
counter = Counter()
pwds = []
pwds = itertools.chain(pwds, generate_all(grammar,''))
 
# n_pws = len(list(pwds))
# print 'Number of passwords to test: %d' % (n_pws)
 
try:
Parallel(n_jobs=-1)(delayed(attempt)(w, pw) for pw in pwds)
# print("\n")
except Exception, e:
traceback.print_exc()
while True:
sys.stdout.write('\a')
sys.stdout.flush()
 
if __name__ == "__main__":
__main__()
 
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020