Merge pull request #1 from Dwerg/search-functions

Search functions
This commit is contained in:
Dwerg 2018-01-12 03:12:21 +01:00 committed by GitHub
commit 2987477cc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 87 additions and 52 deletions

View File

@ -1,8 +1,9 @@
# walletaid # Walletaid
1. Install python 2.7 and select "Add python.exe to Path" during installation. 1. Install python 2.7 and select "Add python.exe to Path" during installation.
2. Download ZIP of this repository. 2. Download ZIP of this repository.
3. Unzip walletaid. 3. Unzip walletaid.
4. Make a copy of wallet.dat in walletaid folder. 4. Make a copy of wallet.dat and place in walletaid folder.
5. Open config.ini and change parameters appropriate to the coin. 5. Open config.ini and change parameters appropriate to the coin.
6. Run "Extract keys.bat" 6. Run "Extract keys.bat"
7. Open "foundkeys.txt" to see the recovered keys and addresses. 7. Paste address to search specifically or leave blank to get all keys.
8. Open "foundkeys.txt" to see the recovered keys and addresses.

View File

@ -1,19 +1,22 @@
"""
Walletaid created by Dwerg using Python 2.7
Code for converting to addresses and WIF
borrowed from pywallet.
"""
import hashlib import hashlib
import binascii import binascii
from ConfigParser import SafeConfigParser from ConfigParser import SafeConfigParser
#Opens config.ini and gets settings
config = SafeConfigParser() config = SafeConfigParser()
config.read("config.ini") config.read("config.ini")
pubprefix = config.get("settings", "pubkeyprefix") pubprefix = config.get("settings", "pubkeyprefix")
privprefix = config.get("settings", "privkeyprefix") privprefix = config.get("settings", "privkeyprefix")
compressed = config.getboolean("settings", "compressed") compressed = config.getboolean("settings", "compressed")
if not compressed:
pref = "04"
suff = ""
else:
suff = "01"
#Calculates public key from a private key
class Point(object): class Point(object):
def __init__(self, _x, _y, _order = None): self.x, self.y, self.order = _x, _y, _order def __init__(self, _x, _y, _order = None): self.x, self.y, self.order = _x, _y, _order
@ -59,7 +62,9 @@ def inverse_mod(a):
p, INFINITY = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2FL, Point(None, None) # secp256k1 p, INFINITY = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2FL, Point(None, None) # secp256k1
g = Point(0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798L, 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8L, g = Point(0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798L, 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8L,
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141L) 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141L)
#End of code used to calculate public key
#Base58 encoder
__b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' __b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
__b58base = len(__b58chars) __b58base = len(__b58chars)
@ -78,8 +83,6 @@ def b58encode(v):
long_value = div long_value = div
result = __b58chars[long_value] + result result = __b58chars[long_value] + result
# Bitcoin does a little leading-zero-compression:
# leading 0-bytes in the input become leading-1s
nPad = 0 nPad = 0
for c in v: for c in v:
if c == '\0': nPad += 1 if c == '\0': nPad += 1
@ -87,9 +90,11 @@ def b58encode(v):
return (__b58chars[0]*nPad) + result return (__b58chars[0]*nPad) + result
#SHA-256 hashception function
def Hash(data): def Hash(data):
return hashlib.sha256(hashlib.sha256(data).digest()).digest() return hashlib.sha256(hashlib.sha256(data).digest()).digest()
#Takes hexadecimal public key, spits out address
def hashtoaddr(a): def hashtoaddr(a):
md = hashlib.new('ripemd160') md = hashlib.new('ripemd160')
md.update(hashlib.sha256(binascii.unhexlify(a)).digest()) md.update(hashlib.sha256(binascii.unhexlify(a)).digest())
@ -98,52 +103,81 @@ def hashtoaddr(a):
addr = md160 + h[0:4] addr = md160 + h[0:4]
return b58encode(binascii.unhexlify(pubprefix)+addr) return b58encode(binascii.unhexlify(pubprefix)+addr)
#Takes hexadecimal private key, spits out WIF
def hashtowif(b): def hashtowif(b):
presha = binascii.unhexlify(privprefix) + b + binascii.unhexlify(suff) presha = binascii.unhexlify(privprefix) + b
if compressed: presha = presha + binascii.unhexlify("01")
h = Hash(presha) h = Hash(presha)
key = presha + h[0:4] key = presha + h[0:4]
return b58encode(key) return b58encode(key)
header = binascii.unhexlify("f70001d63081d30201010420") #Takes hexadecimal private key, spits out address
keyl = 32 def address(c):
slist = open("foundkeys.txt","w") pubkey = str(g * c)
klist = [] if pubkey[63] == " ":
count = 0 pubkey = "0" + pubkey
print "Starting search" if compressed:
if int(pubkey[-1], base=16) % 2 == 0:
pref = "02"
else:
pref = "03"
pubkey = pubkey[0:64]
else:
pref = "04"
if len(pubkey) < 129:
pubkey = pubkey[:64] + "0" + pubkey[64:]
pubkey = pubkey.replace(" ", "")
return hashtoaddr(pref + pubkey)
#Loads wallet.dat into lists of addresses and private keys
with open('wallet.dat', 'rb') as f: with open('wallet.dat', 'rb') as f:
print "Loading wallet.dat"
count = 0
privlist = []
publist = []
klist = []
header = binascii.unhexlify("f70001d63081d30201010420")
data = f.read() data = f.read()
header_index = data.find(header, 0) header_index = data.find(header, 0)
if header_index >= 0: body = data[header_index + len(header): header_index + len(header) + 32]
body = data[header_index + len(header): header_index + len(header) + keyl] privkey = int(binascii.hexlify(body), base = 16)
privkey = int(binascii.hexlify(body), base = 16) while body is not None:
pubkey = str(g * privkey) print "\rLoaded {:0.2f} % ".format(float(header_index) / len(data) * 100),
while body is not None: if privkey not in klist:
print "\rScanned {:0.2f} % ".format(float(header_index) / len(data) * 100), count += 1
if privkey not in klist: privlist.append(hashtowif(body))
if pubkey[63] == " ": publist.append(address(privkey))
pubkey = "0" + pubkey klist.append(privkey)
if compressed: header_index = data.find(header,header_index + len(header) + 32)
if int(pubkey[-1], base=16) % 2 == 0: if header_index >= 0:
pref = "02" body = data[header_index + len(header): header_index + len(header) + 32]
else: privkey = int(binascii.hexlify(body), base = 16)
pref = "03" else:
pubkey = pubkey[0:64] body = None
else: print "\rScanned 100 % \nLoaded {} keys from wallet.dat\n".format(count)
if len(pubkey) < 129:
pubkey = pubkey[:64] + "0" + pubkey[64:] #Prompt user to paste address to search for
pubkey = pubkey.replace(" ", "") print "Paste address with CTRL+V. Leave blank to get all!"
count += 1 keysearch = raw_input("Address: ")
slist.write("Address: {}\nPrivate key: {}\n\n".format(hashtoaddr(pref + pubkey), hashtowif(body)))
klist.append(privkey) keyfile = open("foundkeys.txt","w")
#Search for address and print private key or dump everything to file
header_index = data.find(header,\ found = 0
header_index + len(header) + keyl) while keysearch:
if header_index >= 0: for addr in publist:
body = data[header_index + len(header): header_index + len(header) + keyl] if addr == keysearch:
privkey = int(binascii.hexlify(body), base = 16) foundkey = privlist[publist.index(addr)]
pubkey = str(g * privkey) print "Private key: " + foundkey + "\nA copy is also in 'foundkeys.txt'"
else: keyfile.write("Address: {}\nPrivate key: {}\n\n".format(addr, foundkey))
body = None found = True
print "\rScanned 100 % " break
print "Found %i keys in wallet, check 'foundkeys.txt'" % (count) if not found:
print "\nAddress was not found, try again or leave blank to get all."
keysearch = raw_input("Address: ")
else:
break
else:
for addr in publist:
foundkey = privlist[publist.index(addr)]
keyfile.write("Address: {}\nPrivate key: {}\n\n".format(addr, foundkey))
print "\nAll addresses and private keys saved in 'foundkeys.txt'\n"