Reply to topic  [ 12 posts ]  Go to page 1, 2  Next
Recovery wallet.dat after delete from hdd (python script) 
Author Message

Posts: 6
os: linux
Reply with quote
Post Recovery wallet.dat after delete from hdd (python script)
I am fighting with recovery my NMC wallet > (private key)
I was found this python script:

Code:
#!/usr/bin/python

import binascii
import os
import hashlib
import sys

# bytes to read at a time from file (10meg)
readlength=10*1024*1024

if len(sys.argv)!=2:
  print "./keyhunter.py <filename>"
  exit()

filename = sys.argv[1]

f = open(filename)
magic = '\x01\x30\x82\x01\x13\x02\x01\x01\x04\x20'
magiclen = len(magic)



##### start code from pywallet.py #############
__b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
__b58base = len(__b58chars)

def b58encode(v):
  """ encode v, which is a string of bytes, to base58.
  """

  long_value = 0L
  for (i, c) in enumerate(v[::-1]):
    long_value += (256**i) * ord(c)

  result = ''
  while long_value >= __b58base:
    div, mod = divmod(long_value, __b58base)
    result = __b58chars[mod] + result
    long_value = div
  result = __b58chars[long_value] + result

  # Bitcoin does a little leading-zero-compression:
  # leading 0-bytes in the input become leading-1s
  nPad = 0
  for c in v:
    if c == '\0': nPad += 1
    else: break

  return (__b58chars[0]*nPad) + result

def Hash(data):
  return hashlib.sha256(hashlib.sha256(data).digest()).digest()

def EncodeBase58Check(secret):
  hash = Hash(secret)
  return b58encode(secret + hash[0:4])

########## end code from pywallet.py ############



# read through target file
# one block at a time
while True:
  data = f.read(readlength)
  if not data:
    break

  # look in this block for keys
  x=0
  while True:
    # find the magic number
    pos=data.find(magic,x)
    #pos=data.find('\13\02\01\01\04\20',0)
    if pos==-1:
      break
    print EncodeBase58Check('\x80'+data[pos+magiclen:pos+magiclen+32])
    x+=(pos+1)
 
  # are we at the end of the file?
  if len(data) < readlength:
    break

  # make sure we didn't miss any keys at the end of the block
  f.seek(f.tell()-(32+magiclen))

# code grabbed from pywallet.py


It's working, but is for BTC, so the format of output privat key is incorrect.
Anyone can help witch adaptation for NMC format?


Thu Jul 06, 2017 3:14 pm
Profile

Posts: 1927
os: linux
Reply with quote
Post Re: Recovery wallet.dat after delete from hdd (python script
I suspect that this line:

Code:
print EncodeBase58Check('\x80'+data[pos+magiclen:pos+magiclen+32])


Is the one that needs to be changed. 0x80 == 128. Note the presence of 128 here: https://github.com/namecoin/namecoin-co ... s.cpp#L136 , and note that it's changed to 180 here: https://github.com/namecoin/namecoin-co ... s.cpp#L169 . 180 == 0xb4. So it might be as easy as replacing '\x80' with '\xb4'.

Let us know if that helps.

_________________
Jeremy Rand, Lead Namecoin Application Engineer
NameID: id/jeremy
DyName: Dynamic DNS update client for .bit domains.

Donations: BTC 1EcUWRa9H6ZuWPkF3BDj6k4k1vCgv41ab8 ; NMC NFqbaS7ReiQ9MBmsowwcDSmp4iDznjmEh5


Fri Jul 07, 2017 8:24 am
Profile

Posts: 6
os: linux
Reply with quote
Post Re: Recovery wallet.dat after delete from hdd (python script
unfortunately no...
in oryginal script (bitcoin version) every recovery private-key is starting from 5K (5Kxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
after change to \xb4 is "74xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
IMHO should be "5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
any other idea?

here is few empty wallets:

Code:
dumpprivkey NKhnrWFD2p1o9KwjpTksg3JBJCCLBt7ECd
5KYDw7RTQrBwjJg2GTqkPtWe7eXKmCSdKEc5KE9thiGPnBcME7C

dumpprivkey N866PG7iifPA9WHafUGRXkoCgMuk3konye
5HqeTraeULEMaBvXyZvPhZ1W5TuQMdoaVh8DxWKhxy7LmHUrVun

dumpprivkey N2vNkx21Ni4ELCKj7Uagx2ebXchnA822gc
5Jzn6SNAGVEvCTuHTy8wwnh6j8RuiLtQpQMz2a8Gy5HMYT2A9K5

dumpprivkey N7u8KwasRHiDNbTsRq9gVigSLuB3W7JQbj
5HtGH2TnjJEDCGSbd8aHS3mSHh2br9GR9MGR52TFeNs6SmM3aGT

dumpprivkey MyoKUADnGDda7TsKs4urJNyzervR7c7oGp
5KYmprJdF3xLDdMxwq9hukCMaQTnfdHMo38QetAcLp19n3hhUyo


Fri Jul 07, 2017 2:47 pm
Profile

Posts: 1927
os: linux
Reply with quote
Post Re: Recovery wallet.dat after delete from hdd (python script
operator17 wrote:
unfortunately no...
in oryginal script (bitcoin version) every recovery private-key is starting from 5K (5Kxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
after change to \xb4 is "74xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
IMHO should be "5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
any other idea?

here is few empty wallets:

Code:
dumpprivkey NKhnrWFD2p1o9KwjpTksg3JBJCCLBt7ECd
5KYDw7RTQrBwjJg2GTqkPtWe7eXKmCSdKEc5KE9thiGPnBcME7C

dumpprivkey N866PG7iifPA9WHafUGRXkoCgMuk3konye
5HqeTraeULEMaBvXyZvPhZ1W5TuQMdoaVh8DxWKhxy7LmHUrVun

dumpprivkey N2vNkx21Ni4ELCKj7Uagx2ebXchnA822gc
5Jzn6SNAGVEvCTuHTy8wwnh6j8RuiLtQpQMz2a8Gy5HMYT2A9K5

dumpprivkey N7u8KwasRHiDNbTsRq9gVigSLuB3W7JQbj
5HtGH2TnjJEDCGSbd8aHS3mSHh2br9GR9MGR52TFeNs6SmM3aGT

dumpprivkey MyoKUADnGDda7TsKs4urJNyzervR7c7oGp
5KYmprJdF3xLDdMxwq9hukCMaQTnfdHMo38QetAcLp19n3hhUyo


I just used dumpprivkey on one of my Namecoin addresses, and the result started with 7. What version of Namecoin are you using? (I'm on 0.13.99-name-tab-beta1.)

_________________
Jeremy Rand, Lead Namecoin Application Engineer
NameID: id/jeremy
DyName: Dynamic DNS update client for .bit domains.

Donations: BTC 1EcUWRa9H6ZuWPkF3BDj6k4k1vCgv41ab8 ; NMC NFqbaS7ReiQ9MBmsowwcDSmp4iDznjmEh5


Sat Jul 08, 2017 1:06 am
Profile

Posts: 6
os: linux
Reply with quote
Post Re: Recovery wallet.dat after delete from hdd (python script
biolizard89 wrote:
I just used dumpprivkey on one of my Namecoin addresses, and the result started with 7. What version of Namecoin are you using? (I'm on 0.13.99-name-tab-beta1.)


old one
0.3.80


Sat Jul 08, 2017 5:25 am
Profile

Posts: 1083
Reply with quote
Post Re: Recovery wallet.dat after delete from hdd (python script
The difference might be between compressed and uncompressed keys - the old client only has uncompressed keys, while the new client uses compressed ones.

_________________
BTC: 1domobKsPZ5cWk2kXssD8p8ES1qffGUCm | NMC: NCdomobcmcmVdxC5yxMitojQ4tvAtv99pY
BM-GtQnWM3vcdorfqpKXsmfHQ4rVYPG5pKS
Use your Namecoin identity as OpenID: https://nameid.org/


Mon Jul 10, 2017 3:38 pm
Profile WWW

Posts: 6
os: linux
Reply with quote
Post Re: Recovery wallet.dat after delete from hdd (python script
What I should remove from script to disable "compression" in them?


Tue Jul 11, 2017 12:44 pm
Profile

Posts: 1927
os: linux
Reply with quote
Post Re: Recovery wallet.dat after delete from hdd (python script
operator17 wrote:
biolizard89 wrote:
I just used dumpprivkey on one of my Namecoin addresses, and the result started with 7. What version of Namecoin are you using? (I'm on 0.13.99-name-tab-beta1.)


old one
0.3.80


May I ask why you're not using a newer release? It's entirely possible that the issue you're encountering is a bug that was fixed since 0.3.80.

_________________
Jeremy Rand, Lead Namecoin Application Engineer
NameID: id/jeremy
DyName: Dynamic DNS update client for .bit domains.

Donations: BTC 1EcUWRa9H6ZuWPkF3BDj6k4k1vCgv41ab8 ; NMC NFqbaS7ReiQ9MBmsowwcDSmp4iDznjmEh5


Tue Jul 18, 2017 2:16 am
Profile

Posts: 6
os: linux
Reply with quote
Post Re: Recovery wallet.dat after delete from hdd (python script
biolizard89 wrote:
May I ask why you're not using a newer release? It's entirely possible that the issue you're encountering is a bug that was fixed since 0.3.80.


this is old hdd, from drawer
in this time 0.3.80 was a newset version


Sat Jul 22, 2017 8:18 am
Profile

Posts: 1927
os: linux
Reply with quote
Post Re: Recovery wallet.dat after delete from hdd (python script
operator17 wrote:
biolizard89 wrote:
May I ask why you're not using a newer release? It's entirely possible that the issue you're encountering is a bug that was fixed since 0.3.80.


this is old hdd, from drawer
in this time 0.3.80 was a newset version


You're trying to import the recovered private keys into a new wallet, right? Why not import them into a current Namecoin Core wallet?

_________________
Jeremy Rand, Lead Namecoin Application Engineer
NameID: id/jeremy
DyName: Dynamic DNS update client for .bit domains.

Donations: BTC 1EcUWRa9H6ZuWPkF3BDj6k4k1vCgv41ab8 ; NMC NFqbaS7ReiQ9MBmsowwcDSmp4iDznjmEh5


Sat Jul 29, 2017 4:30 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.