Author

Topic: Bitcoin Wallet Key Batch Extractor. (Read 412 times)

legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
July 16, 2020, 08:03:29 AM
#5
Dear Sir,
I would like to inform you that i have try to run your script (bitwalletrecover.py) for recovering my old or encrypted wallet.dat (Bitcoin); but it is not run following error massage found:

Traceback (most recent call last):
File "bitwalletrecover.py", line 23, in
from pycoin.ecdsa import generator_secp256k1, public_pair_for_secret_exponent
ImportError: cannot import name 'generator_secp256k1' from 'pycoin.ecdsa' (C:\Python37\lib\site-packages\pycoin-0.0.0-py3.7.egg\pycoin\ecdsa_init_.py)

Could you please advice how it is solve..

Thanks & Regards,
Md. Ashraful Alam

Have you installed pycoin library, if you haven't, you should do it with one of these command

Code:
pip install pycoin
Code:
pip3 install pycoin


Have you installed Python 2.7 or Python 3? Huh

I suspect that most of these older scripts that you're trying to run will NOT work with Python 3... so make sure you have downloaded and installed Python 2.7 from here: https://www.python.org/downloads/release/python-2717/

Without a doubt OP's script uses Python 3 since it uses print("") rather than print ""
jr. member
Activity: 51
Merit: 30
August 19, 2023, 04:22:38 PM
#4
Quote
Dear Sir,
I would like to inform you that i have try to run your script (bitwalletrecover.py) for recovering my old or encrypted wallet.dat (Bitcoin); but it is not run following error massage found:

Traceback (most recent call last):
File "bitwalletrecover.py", line 23, in
from pycoin.ecdsa import generator_secp256k1, public_pair_for_secret_exponent
ImportError: cannot import name 'generator_secp256k1' from 'pycoin.ecdsa' (C:\Python37\lib\site-packages\pycoin-0.0.0-py3.7.egg\pycoin\ecdsa_init_.py)

Could you please advice how it is solve..

Thanks & Regards,
Md. Ashraful Alam
Old thread but

I encountered the same issue. It seems to be caused by the latest pycoin release. It was corrected with.


Set python to version 2.7 as default.
https://netslovers.com/post/how-install-python-27-pip-ubuntu-22-04/

sudo python -m pip uninstall pycoin
sudo python -m pip install pycoin==0.80
sudo python -m pip install pycrypto

HCP
legendary
Activity: 2086
Merit: 4363
July 15, 2020, 06:05:38 PM
#3
Have you installed Python 2.7 or Python 3? Huh

I suspect that most of these older scripts that you're trying to run will NOT work with Python 3... so make sure you have downloaded and installed Python 2.7 from here: https://www.python.org/downloads/release/python-2717/
newbie
Activity: 24
Merit: 0
July 15, 2020, 11:45:29 AM
#2
donator
Activity: 3228
Merit: 1226
★Bitvest.io★ Play Plinko or Invest!
October 17, 2019, 08:53:24 AM
#1
Basically, I was searching through my drive and old files, and forgot about this tool, not sure if its a working version or not.
Might be useful to others that are digging through their old files. I used this about a year ago and found 300,000 dogecoins and 0.3 Bitcoins.

I combined several codes together and came up with a utility a year ago or so. The prompt: "Gather Keys or Check Keys"

Might be useful, for users digging up wallet.dat files, or searching files back from 2010,2011, etc. I have attached both the source code, and the executable file. KeyExtractor.rar - "PrivateKey.exe" - https://filebin.net/peiyfi092vs1m6w0

1)



2)



3)



4)



Executable File:

Code:
import re
import hashlib
import base58
import binascii
import argparse
import glob
import fileinput
import argparse
import requests
import pycoin
from time import sleep
 
from pycoin.key.Key import Key
from pycoin.ecdsa import generator_secp256k1, public_pair_for_secret_exponent
 
mode = input('(gather) keys or (check) balanaces: ')
location = input('Location of .dat files or keylist: ')
coinname = input('BTC, LTC, DOGE, or DASH: ').upper()
 
def from_long(v, prefix, base, charset):
    l = bytearray()
    while v > 0:
        try:
            v, mod = divmod(v, base)
            l.append(charset(mod))
        except Exception:
            raise EncodingError("can't convert to character corresponding to %d" % mod)
    l.extend([charset(0)] * prefix)
    l.reverse()
    return bytes(l)
 
def to_bytes_32(v):
    v = from_long(v, 0, 256, lambda x: x)
    if len(v) > 32:
        raise ValueError("input to to_bytes_32 is too large")
    return ((b'\0' * 32) + v)[-32:]
 
def bytetohex(byteStr):
    return ''.join( [ "%02X" % x for x in byteStr ] ).strip()
 
litecoin = [b"\x30", b"\xb0"]
dogecoin = [b"\x1e", b"\x71"]
bitcoin = [b"\x00", b"\x80"]
dash = [b"\x4c", b"\xcc"]
 
if coinname == "LTC": cointype = litecoin
elif coinname == "BTC": cointype = bitcoin
elif coinname == "DOGE": cointype = dogecoin
elif coinname == "DASH": cointype = dash
 
#process all keys
if mode == 'check':
    fKeyListFiltered = open(str(location)+"\\unique_keys_"+coinname+".txt", "r")
    keylist = []
    for privkey in fKeyListFiltered:
        privkey = privkey.strip()
        if privkey not in keylist and privkey != '':
            keylist.append(privkey)
    keylist.sort()
 
    for key in keylist:
        key = bytes.fromhex(key)
        public_x, public_y = public_pair_for_secret_exponent(generator_secp256k1, int(bytetohex(key), 16))
        public_key = b'\4' + to_bytes_32(public_x) + to_bytes_32(public_y)
        compressed_public_key = bytes.fromhex("%02x%064x" % (2 + (public_y & 1), public_x))
 
        m = hashlib.new('ripemd160')
        m.update(hashlib.sha256(public_key).digest())
        ripe = m.digest()
 
        m = hashlib.new('ripemd160')
        m.update(hashlib.sha256(compressed_public_key).digest())
        ripe_c = m.digest()
 
        extRipe = cointype[0] + ripe
        extRipe_c = cointype[0] + ripe_c
 
        chksum = hashlib.sha256(hashlib.sha256(extRipe).digest()).digest()[:4] # Step 5-7
        chksum_c = hashlib.sha256(hashlib.sha256(extRipe_c).digest()).digest()[:4] # Step 5-7
 
        addr = extRipe + chksum
        addr_c = extRipe_c + chksum_c
 
        keyWIF = cointype[1] + key
        keyWIF_c = cointype[1] + key + b"\x01"
       
        chksum = hashlib.sha256(hashlib.sha256(keyWIF).digest()).digest()[:4]
        chksum_c = hashlib.sha256(hashlib.sha256(keyWIF_c).digest()).digest()[:4]
 
        addr = keyWIF + chksum
        addr_c = keyWIF_c + chksum_c
 
        str(bytetohex(key))
        private_key_static = str(bytetohex(key))
        extended_key = "80"+private_key_static
        first_sha256 = hashlib.sha256(binascii.unhexlify(extended_key)).hexdigest()
        second_sha256 = hashlib.sha256(binascii.unhexlify(first_sha256)).hexdigest()
        final_key = extended_key+second_sha256[:8]
        WIF = base58.b58encode(binascii.unhexlify(final_key))
        str(WIF)
 
       
        CWIF = base58.b58encode(addr_c)
        str(CWIF)
        pkey = Key(secret_exponent=int.from_bytes(key, 'big'))
        pkey._netcode = coinname
        address = pkey.address()
        fNoBalance = open(str(location)+"\\no_balance_"+coinname+".txt", "a")
        fHasBalance = open(str(location)+"\\has_balance_"+coinname+".txt", "a")
        success = False
        while success == False:
            #sleep(0.1) #enable/adjust this if you are getting rate limited or blocked.
            sleep(1)
            success = False
            if coinname == 'BTC': req = 'https://insight.bitpay.com/api/addr/'+address+'/balance'
            elif coinname == 'LTC': req = 'https://insight.litecore.io/api/addr/'+address+'/balance'
            elif coinname == 'DASH': req = 'https://insight.dash.org/api/addr/'+address+'/balance'
            elif coinname == 'DOGE': req = ' https://dogechain.info/api/v1/address/balance/'+address
            print(req)
            response = requests.get(req)
            if response.status_code == 200:
                content = response.json()
                if coinname == 'DOGE':
                    balance = float(content['balance'])
                else:
                    balance = content / 100000000
                out = "ADD:"+address+" BAL: "+str(balance)+" WIF:" + str(CWIF)[2:99][:-1] + "\n"
                print(out)
                if balance == 0: fNoBalance.write(out)
                else:
                    fHasBalance.write(out)
                    print("\a")
                success = True
            continue
 
#Gather all keys
elif mode == 'gather':
    walletHandle = []
    for file in glob.glob(str(location)+"/*.dat"):
        if file.endswith('.dat'):
            print(file)
            walletHandle = open(file, "rb")
            wallet = walletHandle.read()
            privKeys_re_c=re.compile(b'\x30\x81\xD3\x02\x01\x01\x04\x20(.{32})', re.DOTALL)
            privKeys=set(privKeys_re_c.findall(wallet))
            print("Found %d privKeys" % len(privKeys))
            fKeyList = open(str(location)+"\\all_keys_"+coinname+".txt", "a")
            for key in privKeys:
                #add to file containing ALL keys, just to make sure we don't accidently lose any data
                fKeyList.write(str(bytetohex(key))+"\n")
            continue
        else:
            continue
    fKeyList = open(str(location)+"\\all_keys_"+coinname+".txt", "r")
    keylist = []
 
    for privkey in fKeyList:
        privkey = privkey.strip()
        if privkey not in keylist and privkey != '':
            keylist.append(privkey)
 
    fKeyListFiltered = open(str(location)+"\\unique_keys_"+coinname+".txt", "w+")
    for privkey in fKeyListFiltered:
        privkey = privkey.strip()
        if privkey not in keylist and privkey != '':
            keylist.append(privkey)
    keylist.sort()
 
    #print("\n".join(keylist))
    fKeyListFiltered.write("\n".join(keylist))
    walletHandle.close()
Jump to: