Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: J1800 on April 28, 2021, 10:25:46 AM



Title: recover keys from wallet.dat without using pywallet
Post by: J1800 on April 28, 2021, 10:25:46 AM
I've been trying to install the right version of python and packages etc to run pywallet all morning, it's just error after error. even tried an "installer" and it just tries to grab packages and times out. all I want to do is get private keys from an old wallet.dat. can someone just make a simple gui or something? why cannot i just extract them using notepad? I just need to know which numbers are the private keys. someone let me know what to do. thanks

edit: i think this was actually made with an early version of electrum... somehow i have to convert it or find an old version of electrum that can read it


Title: Re: recover keys from wallet.dat without using pywallet
Post by: BitMaxz on April 28, 2021, 06:09:31 PM
I just want to add this from ETFbitcoin post above.
If you are going to test it with a different Electrum version I suggest you make a copy of the wallet.dat before you import it to any version of Electrum.

I think Electrum doesn't generate a wallet.dat file it usually generates a wallet file with no extension.

So it should be work on BitcoinQT just make sure to make an original copy of wallet.dat before you use any tool to decrypt and extract the private key.


Why not try to install Bitcoin core instead and replace the new wallet.dat with your old wallet.dat file and maybe your old addresses might show up on the addresses tab.
Or if you know the exact address of your wallet you can go to the console tab to dump the private key of a single address.

Here's the sample command

Code:
dumpprivkey "yourbitcoinaddress"

Remove double quote after you replace it with your BTC address and if the wallet.dat file is encrypted with a passphrase do this command first.

Code:
walletpassphrase mypassword 60

60 is the time limit in seconds. After that apply the code above with the exact address the result should be your private key in WIF format. You can import it to any wallet like Electrum.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: NotATether on April 29, 2021, 08:34:55 AM
While the answers have already been given above, I just want to make a point that you cannot open wallet.dat files in a text editor because they are binary files (Berkeley DB 4.8 files to be specific), which is why specialized tools like pywallet or bitcoin-wallet are required for reading the file contents.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: BASE16 on April 30, 2021, 05:32:40 PM
Code:
sudo apt-get install db-util

Code:
db_dump -d a wallet.dat > walletdump.txt


Title: Re: recover keys from wallet.dat without using pywallet
Post by: HCP on May 02, 2021, 12:42:10 AM
1. We don't know the data is private key, public key or other data (maybe it's possible by check HEX length).
Should be easy enough given that the Database Schema is public knowledge...

Even some basic "trial and error" type testing using PyWallet output or other known data (private keys/public keys etc) should mean it would be relatively simple (if somewhat time consuming) to be able to determine which outputs in the db_dump are the private keys etc.

for instance:
Code:
page 4: btree leaf: LSN [0][1]: level 1
        prev:    0 next:   84 entries:   90 offset: 2432
        [000] 8148 len:  39 data: 04636b6579210201df7814f1bfdc65694230553d9fea229e34fc096b27611881e5924e045e955e
        [001] 8064 len:  81 data: 305048baa5553a6e650272560b11709abe027d96d01a6cdb67646632ebb3d39bafdeb5af63e8386e899c5f03194afd925e5a0dea80180867296864761c6d4a583d21dc7b6ac7a7cea38c2eea0825a25aef
        [002] 8020 len:  39 data: 04636b6579210201e1dadb18af47c2f457aeb9892e9bc9986101d2a5a32cb85fce217b191472f9
        [003] 7936 len:  81 data: 300f05de99d0a5bcaa86f15d9fc7d809b45a61f6826e559d0041f48f5fa4568b495cb973d7d8238a85e5afabce56e5fcfb0d7e0f66e7379f04fc181544273bfdde701587c745ce0d552d25546bcf01c69c

From PyWallet:
Code:
    "keys": [
        {
            "addr": "1NU7VwXy3Ugb1NPFYy9Y76Q6DvzMtrihuj",
            "compressed": true,
            "encrypted_privkey": "5048baa5553a6e650272560b11709abe027d96d01a6cdb67646632ebb3d39bafdeb5af63e8386e899c5f03194afd925e",
            "pubkey": "0201df7814f1bfdc65694230553d9fea229e34fc096b27611881e5924e045e955e",
            "reserve": 1
        },
        {
            "addr": "18NvdAH4yGytm6C9vpPAvrHHXLdKwaERFK",
            "compressed": true,
            "encrypted_privkey": "0f05de99d0a5bcaa86f15d9fc7d809b45a61f6826e559d0041f48f5fa4568b495cb973d7d8238a85e5afabce56e5fcfb",
            "pubkey": "0201e1dadb18af47c2f457aeb9892e9bc9986101d2a5a32cb85fce217b191472f9",
            "reserve": 1
        },

We can see that the pubkeys are in the "len 39" data with a prefix of "04636b657921":
Quote from: pywallet
"pubkey": "0201e1dadb18af47c2f457aeb9892e9bc9986101d2a5a32cb85fce217b191472f9"
Quote from: db_dump
[000] 8148 len:  39 data: 04636b6579210201df7814f1bfdc65694230553d9fea229e34fc096b27611881e5924e045e955e


We can also see that the encrypted privkey data is in the "len81" data with a prefix of "30" and a unique trailing sequence of bytes:
Quote from: pywallet
"encrypted_privkey": "5048baa5553a6e650272560b11709abe027d96d01a6cdb67646632ebb3d39bafdeb5af63e8386e8 99c5f03194afd925e",
Quote from: db_dump
[001] 8064 len:  81 data: 305048baa5553a6e650272560b11709abe027d96d01a6cdb67646632ebb3d39bafdeb5af63e8386e8 99c5f03194afd925e5a0dea80180867296864761c6d4a583d21dc7b6ac7a7cea38c2eea0825a25aef


The real issue is extracting the encrypted data... I'm not sure if the db_dump "-P" parameter is actually able to decrypt the encrypted keys or if it is meant for some other purpose. I can't get it to produce the unencrypted keys in the db_dump output. :-\


Title: Re: recover keys from wallet.dat without using pywallet
Post by: BASE16 on May 02, 2021, 06:53:53 PM
Code:
sudo apt-get install db-util

Code:
db_dump -d a wallet.dat > walletdump.txt

I've tried it for a bit & looks like it works. However since it dump all data and looks like all dumped data use HEX format, there are few problem
1. We don't know the data is private key, public key or other data (maybe it's possible by check HEX length).
2. We don't know whether is encrypted or not (since the tools worked on both encrypted & non-encrypted wallet).
3. Some regex needed to select only needed data (Assuming the characteristic of data you're looking for).

That's just a basic syntax and using designated database tools/utility since the topic starter wrote he wanted something else then Python.
Of course you can extend it into a script that will plot keys and addresses and the relevant info you desire since its a btree and you can use bytekeys.
Oracle can deal with encryption but from what i can see it is likely that if there is any encrypted data then it will be encrypted and decrypted by the bitcoin application itself, in such case the database file is just a structure that hold keys it does not know anything about encryption it just stores the data so in those cases a encryption switch parameter can not be used to work with encrypted data in the tree.
The easiest way to find the desired key is to extract all data and then use the address as identifier to search the file and then find the key that relates to that particular address.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: NotATether on May 02, 2021, 07:26:49 PM
The easiest way to find the desired key is to extract all data and then use the address as identifier to search the file and then find the key that relates to that particular address.

I read somewhere on Github that the wallet.dat file format sometimes does not write keys and values contiguously but rather in arbitrary positions, so we may end up with a bunch of rows like HCP's output but with keys and values split along multiple rows.

For example, the output lists 84 entries. I highly doubt Bitcoin Core's code defines that many keys.

The real issue is extracting the encrypted data... I'm not sure if the db_dump "-P" parameter is actually able to decrypt the encrypted keys or if it is meant for some other purpose. I can't get it to produce the unencrypted keys in the db_dump output. :-\

I guess no, Bitcoin Core wallet only encrypt some information (e.g. private key and master private key), while others (e.g. public key and address) isn't encrypted.

It won't because a generic database dumper is not designed to specifically read AES keys and decrypt them with a secret stored somewhere else in the file.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: Btcspot on May 03, 2021, 12:02:26 AM
I can help you, i have some command lines that can get the info. How much do you have in it? Its complicated but i can help you along the way or you can reach me by email:coolgamesman1@gmail.com


Title: Re: recover keys from wallet.dat without using pywallet
Post by: BASE16 on May 03, 2021, 09:10:42 AM
The easiest way to find the desired key is to extract all data and then use the address as identifier to search the file and then find the key that relates to that particular address.

I read somewhere on Github that the wallet.dat file format sometimes does not write keys and values contiguously but rather in arbitrary positions, so we may end up with a bunch of rows like HCP's output but with keys and values split along multiple rows.

For example, the output lists 84 entries. I highly doubt Bitcoin Core's code defines that many keys.

It won't because a generic database dumper is not designed to specifically read AES keys and decrypt them with a secret stored somewhere else in the file.

You can deal with that if you know what you are doing as is with most things.
These are regular database files they have keys as identifiers which relate to the target data, that is how they work.
Your doubts and beliefs are really irrelevant because these things work along exact protocols that are very well defined.
If you want you can always extend functionality, i do this all the time.
There can be many keys in a database file.

https://i.ibb.co/WKspdhB/keys.png (https://ibb.co/MN95jvP)

I made a wallet parser specifically for corrupt wallet files that works on the byte level and it produces ~ 200.000 keys from just the one wallet.
It does so because it is told to ignore the key index since these could have become corrupted and so instead of using those, it assumes the possible data locations.
This results in huge files with countless possibilities.
It leaves no byte unturned and if the key is still in there, then it's going to find it.
That is working on a much deeper level than what most programs and scripts do and it takes more effort and time but the results will be crystal clear.
If there is any doubt you can just pull up the oracle documentation and read the specifications because these things are well defined and used in many applications so not just for crypto currencies.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: BASE16 on May 03, 2021, 01:23:12 PM
I've tried it for a bit & looks like it works. However since it dump all data and looks like all dumped data use HEX format, there are few problem
1. We don't know the data is private key, public key or other data (maybe it's possible by check HEX length).
2. We don't know whether is encrypted or not (since the tools worked on both encrypted & non-encrypted wallet).
3. Some regex needed to select only needed data (Assuming the characteristic of data you're looking for).
That's just a basic syntax and using designated database tools/utility since the topic starter wrote he wanted something else then Python.

True, but OP mentioned he had hard time time getting pywallet works, so your solution isn't what OP looking for (but useful for more advance user who read this thread).
[/quote]

You don't know that.
It's only two lines of code.
Maybe it was exactly what he was looking for.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: morbius55 on May 03, 2021, 01:31:14 PM
What would be the minimum data required to decrypt a private key? Would it be ckey! and mkey, what about salt, is that part of the mkey? All depends on having the correct passphrase of course. My corrupt wallets have been either fragmented with groups of ckeys that have been separated from the mkey, or other data in the wallet has been corrupted causing the wallet to be unusable with normal methods. I'm pretty sure that the hex values of the mkey and ckeys can be found quite easily by using Winhex or similar. If possible, it would be fantastic to have a tool for manually inputting the keys and passphrase that doesn't get tied up with other corrupt data in the wallet.dat.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: BASE16 on May 03, 2021, 06:05:26 PM
What would be the minimum data required to decrypt a private key? Would it be ckey! and mkey, what about salt, is that part of the mkey? All depends on having the correct passphrase of course. My corrupt wallets have been either fragmented with groups of ckeys that have been separated from the mkey, or other data in the wallet has been corrupted causing the wallet to be unusable with normal methods. I'm pretty sure that the hex values of the mkey and ckeys can be found quite easily by using Winhex or similar. If possible, it would be fantastic to have a tool for manually inputting the keys and passphrase that doesn't get tied up with other corrupt data in the wallet.dat.

1. The target address. ( maybe not see below)
2. The passphrase (and encryption method)
3. The exact 32 (consecutive) bytes of the private key somewhere in the file.

For un-encrypted keys:
The principle is very simple and assumes that the key is still somewhere in the (corrupted / partly overwritten etc.) file.
You slide over all of the remaining file data in 32 byte sized blocks and turn every block into a address (of the same target address method).
Then you compare the generated address to the target address.
If there is no match you move or slide the block to the next nibble or byte.
Then when your byte scanner moves above the correct block of bytes, that holds the correct byte sequence, the resulting address will match the target address.
You can then print out/save the found data/key and exit.
This will work without the presence of any btree structure and without (looking for) the original database index keys because it only looks for the exact 32 bytes of key itself and not the combined database index entry plus relevant data.
In this respect this method will outperform recovery tools that only look for the standard database index key entries and their following variable field.
So it's as close to a RAW method as it can possibly get, simply because one nibble or byte more, or one less and you will completely miss your target.
It will work most of the time but not in case of missing/corrupt bytes in the key itself and for fragmented keys because then it will obviously produce a mismatch in target address.
In that case your chances on a success are extremely limited and will depend on how hard you decide to push it further with the scrambled data that is left.
You could start and try to rotate individual bytes but it could take forever, this is not something I would advice in combination with this method.
In case you do not know the target address you will have to verify the actual balance of every address that rolls out of those scanned blocks on the blockchain.
So you could even do it with less.

https://i.ibb.co/0rWhYqh/nibbles.png (https://imgbb.com/)

For encrypted keys it will get a bit more difficult because your goal then is the decryption of partial encrypted data and then you (usually) also need the preceding 16 bytes (CBC Cypher Block Chain) as part of the decryption method to enable the decryption of the next block of data depending on the decryption method you use, there are several but it get's a bit technical here it is best imagined that you no longer search for the exact key but for a block of data that 'makes sense' by this i mean when your output will be mostly garbage and non base16 characters then you know that you are off target, and when a block arrives with a perfect string of only base16 hexadecimal bytes then you can be absolutely sure that you have something of real value.
I always compare it to turning a knob of those old analog radio's it's mostly noise until a crystal clear channel pops up.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: morbius55 on May 03, 2021, 07:05:48 PM
I've searched the 0201010420 trailing bytes and checked hundreds of private keys manually but with no success as yet. I could see they were bitcoin core keys with the data and text surrounding them. I suspect that the private key I need is encrypted and there are hundreds of those as well, plus mkeys. I noticed that each ckey marker 000104636b65 79 is followed at a point later by the trailing byte of 30 as discovered and shown in HCP's example. I'm thinking that maybe the bytes following 30 is the encrypted key and the public key is between 79 and 30 maybe?


Title: Re: recover keys from wallet.dat without using pywallet
Post by: BASE16 on May 04, 2021, 08:13:32 PM
I've searched the 0201010420 trailing bytes and checked hundreds of private keys manually but with no success as yet. I could see they were bitcoin core keys with the data and text surrounding them. I suspect that the private key I need is encrypted and there are hundreds of those as well, plus mkeys. I noticed that each ckey marker 000104636b65 79 is followed at a point later by the trailing byte of 30 as discovered and shown in HCP's example. I'm thinking that maybe the bytes following 30 is the encrypted key and the public key is between 79 and 30 maybe?

If you can grab the entire block of encrypted data from start to end then you can decrypt it using standard methods in which you start with your IV (Initialization Vector) so from the start and not like a partial/damaged or orphaned block in which you need to use the chain code from the previous block.
From what you wrote it seems that the data is still intact so there should be no problem to find it.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: morbius55 on May 04, 2021, 09:34:28 PM
Would an offline version of this work if you had the mkey ckey and passphrase? https://www.devglan.com/online-tools/aes-encryption-decryption


Title: Re: recover keys from wallet.dat without using pywallet
Post by: HCP on May 05, 2021, 07:36:16 AM
I don't think you will be able to use that site, as there are some other background things happening that I don't think that website supports, but assuming you can decrypt the master key, then it should theoretically be possible to then decrypt individual private keys.


As for decrypting the master key, I found this project which claims to be able to extract the encrypted master key, salt, IV etc from a wallet.dat: https://github.com/brichard19/core-decrypt

There is also an OpenCL based project included (and a precompiled .exe ???) that claims to be able to test the master key decryption using a password dictionary. The idea being that you can identify what the wallet passphrase is... it doesn't decrypt individual keys, and it doesn't show the decrypted master key etc. It just seems to test the "encrypted master key" decryption using passwords you pass in.


If this information regarding wallet.dat encryption is still valid: https://en.bitcoin.it/wiki/Wallet_encryption

Then it looks like you would need to start playing with your wallet passphrase, SHA512 and OpenSSL "EVP_BytesToKey" (https://www.openssl.org/docs/man1.0.2/man3/EVP_BytesToKey.html) functionality (along with the extracted IV, Salt, iteration count etc as extracted by the python script) to derive the "key" needed to decrypt the "encrypted master key"...

and then once you have the "unencrypted master key", you should be able to decrypt the individual private keys.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: morbius55 on May 05, 2021, 05:42:05 PM
I don't think you will be able to use that site, as there are some other background things happening that I don't think that website supports, but assuming you can decrypt the master key, then it should theoretically be possible to then decrypt individual private keys.


As for decrypting the master key, I found this project which claims to be able to extract the encrypted master key, salt, IV etc from a wallet.dat: https://github.com/brichard19/core-decrypt

There is also an OpenCL based project included (and a precompiled .exe ???) that claims to be able to test the master key decryption using a password dictionary. The idea being that you can identify what the wallet passphrase is... it doesn't decrypt individual keys, and it doesn't show the decrypted master key etc. It just seems to test the "encrypted master key" decryption using passwords you pass in.


If this information regarding wallet.dat encryption is still valid: https://en.bitcoin.it/wiki/Wallet_encryption

Then it looks like you would need to start playing with your wallet passphrase, SHA512 and OpenSSL "EVP_BytesToKey" (https://www.openssl.org/docs/man1.0.2/man3/EVP_BytesToKey.html) functionality (along with the extracted IV, Salt, iteration count etc as extracted by the python script) to derive the "key" needed to decrypt the "encrypted master key"...

and then once you have the "unencrypted master key", you should be able to decrypt the individual private keys.
The passphrase is no problem as I already know it. I wonder if the salt and iteration are viewable within the wallet file? How do these various scripts find them?


Title: Re: recover keys from wallet.dat without using pywallet
Post by: BASE16 on May 06, 2021, 06:29:53 AM
It looks for a specific header.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: HCP on May 06, 2021, 12:31:30 PM
The passphrase is no problem as I already know it. I wonder if the salt and iteration are viewable within the wallet file? How do these various scripts find them?
The "mkey" data stored in the wallet.dat is unpacked as follows:
Code:
encrypted_master_key, salt, method, iter_count = struct.unpack_from("< 49p 9p I I", mkey)
So, it's actually a 48 byte record called the "encrypted_master_key", the 8 byte salt, the 'method' (should be a 4 byte unsigned Int value 0) and the iteration count (4 byte unsigned Int).

Then, the 48 byte "encrypted_master_key", is actually parsed as:
Code:
iv = binascii.hexlify(encrypted_master_key[16:32])
ct = binascii.hexlify(encrypted_master_key[-16:])

first 16 bytes are ignored?
2nd 16 bytes are the "iv" (initialisation vector)
last 16 bytes are the "ct" (cipher text)


The hex that the walletinfo.py script outputs is:
Code:
s = iv + ct + binascii.hexlify(salt) + iterations

return s
So it is actually iv (16 bytes) + cipher text (16 bytes) + salt (8 bytes) + iteration (8 bytes, it gets padded out from 4 bytes)

I assume this is because the OpenCL portion of that project is expecting the data in this format (to test passphrases) with.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: morbius55 on May 07, 2021, 11:02:03 PM
When a recovered wallet is dumped with pywallet, is the master key near the end the encrypted version and if so, is it a result of the passphrase given for the recovered wallet? It would be great if the original decrypted master key, or master keys were listed, as I presume that possibly more than one original lot of wallet keys are gathered into the one recovered wallet. This would be handy for trying fragmented wallets where other ckeys were not gathered and processed.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: HCP on May 08, 2021, 12:52:10 AM
When you create a recovered wallet... you have to specify a passphrase that the "recovered wallet.dat" is going to use... you then specify the "possible" passphrases it should try when recovering keys/data etc...

The script attempts to decrypt any encrypted keys found using the "possible" passphrases... and then puts them into the recovered wallet.dat, encrypted with a master key derived from the "recovered wallet.dat" passphrase (NOT the passphrase of the original wallet)


Title: Re: recover keys from wallet.dat without using pywallet
Post by: morbius55 on May 08, 2021, 09:24:40 AM
When you create a recovered wallet... you have to specify a passphrase that the "recovered wallet.dat" is going to use... you then specify the "possible" passphrases it should try when recovering keys/data etc...

The script attempts to decrypt any encrypted keys found using the "possible" passphrases... and then puts them into the recovered wallet.dat, encrypted with a master key derived from the "recovered wallet.dat" passphrase (NOT the passphrase of the original wallet)
Thought so. I presume that while dumping private keys it wouldn't be impossible to show any decrypted master keys also. It would be a handy feature for any other ckeys that may share the same master key but were not gathered into the recovery.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: BASE16 on May 08, 2021, 09:27:04 AM
Code:
Private key encryption is done based on a CMasterKey, which holds a salt and random encryption key.

CMasterKeys are encrypted using AES-256-CBC using a key derived using derivation method nDerivationMethod (0 == EVP_sha512()) and derivation iterations nDeriveIterations. vchOtherDerivationParameters is provided for alternative algorithms which may require more parameters (such as scrypt).

Wallet Private Keys are then encrypted using AES-256-CBC with the double-sha256 of the public key as the IV, and the master key's key as the encryption key (see keystore.[ch]). Master key for wallet encryption


Title: Re: recover keys from wallet.dat without using pywallet
Post by: HCP on May 09, 2021, 12:51:51 AM
...
For the curious... Gavin Anderson explains some of this here: https://bitcointalk.org/index.php?topic=34028.msg656114#msg656114

And it seems that Joric showed some specific Python based code for dealing with the encryption/decryption here: https://bitcointalk.org/index.php?topic=34028.msg708668#msg708668

I will have to experiment further when I get some time... but it's Mother's Day here today ;)


Title: Re: recover keys from wallet.dat without using pywallet
Post by: morbius55 on May 17, 2021, 06:39:09 PM
How hard would it be for jackjack or someone to create a standalone tool to decrypt private keys, if the correct hex strings and passphrase were inputted? Not that I'm implying he should, as he seems to be a very busy person. But If you can search out the required info with a hex editor, it would be a very flexible tool for fragmented wallet files.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: HCP on May 18, 2021, 12:26:29 PM
How hard would it be for jackjack or someone to create a standalone tool to decrypt private keys, if the correct hex strings and passphrase were inputted? Not that I'm implying he should, as he seems to be a very busy person. But If you can search out the required info with a hex editor, it would be a very flexible tool for fragmented wallet files.
Probably not very difficult... because it didn't take me too long to bang this out: https://keybase.pub/hcp/python/core_decrypter.py

It's pretty rough... but basically, if you can feed it an "encrypted master key" (or decrypted master key), "encrypted private key" and matching "public key"... it will prompt for wallet passphrase and then attempt to decrypt the master key... then use that to decrypt the private key before outputting the Address+WIF.

I've run some tests on some newly generated wallet.dat data... and the master key/priv key/pub key data from the code example in joric's post (https://bitcointalk.org/index.php?topic=34028.msg708668#msg708668) that I linked to earlier... and it seems to be working OK.

As per the comment at the top of the script, it borrows very heavily from the "Proof of Concept" code from joric's post. (https://bitcointalk.org/index.php?topic=34028.msg708668#msg708668)... full credit to them! ;)




NOTES:

- Python 2.7x compatible only for now... if there is enough interest, I'll see if I can make it Python3 compatible.
- requires a couple of libraries that you'll likely already have installed if you've been using PyWallet etc (ie. pycrypto, ecdsa etc)... if Python moans at you about modules not being found then install them with pip :P





- (For now) The encrypted master key needs to be the full 66/67 bytes (132/134 hex chars) of the mkey record in the wallet.dat... This should be of the form:

"30" - 48 byte data record indicator
"48 bytes worth of encrypted master key"
"08" - 8 byte data record indicator
"8 bytes worth of salt"
"4 bytes worth of method" - should be 0 (ie. 00000000)
"4 bytes worth of iterations" - in Little Endian (ie.  1fb80000 ==> 0x0000b8f1 ==> 47345)
"00" - 1 byte end of record indicator (optional)

for example:
Code:
3008adc5605413b38a04979bf465d0cff826a25c2c8812e582241477052c6d45c11b27690ba3bf2c1da144600789c2baaa08d8659791be653e15000000001760030000

Quote
3008adc5605413b38a04979bf465d0cff826a25c2c8812e582241477052c6d45c11b27690ba3bf2 c1da144600789c2baaa08d8659791be653e15000000001760030000

This modified version of the walletinfo.py script (original here (https://github.com/brichard19/core-decrypt)) will output the "full mkey" from a wallet.dat: https://keybase.pub/hcp/python/walletinfo.py

Usage:
Code:
python walletinfo.py wallet.dat

otherwise, you'll have to do some hexediting of the wallet.dat file to find the data you need... have fun with that :P

I am also considering modifying the script so you can supply the "parsed" master key data (ie. encrypted key, salt, iterations etc) individually... I guess it depends on what is the most likely format of the hex data extracted from the wallet.dat file. ???





On subsequent runs for private keys from the same wallet.dat (ie. encrypted with the same master key), you can just use the "decrypted master key" that is output instead of using the "encrypted" master key + walletpassphrase

Example:
Code:
C:\core_decrypter>C:\Python27\python.exe core_decrypter.py --enc_mkey 3008ADC5605413B38A04979BF465D0CFF826A25C2C8812E582241477052C6D45C11B27690BA3BF2C1DA144600789C2BAAA08D8659791BE653E150000000017600300 BF1356ABEEB7FD2C7CD6757BA4B459AF64D62A3855592B24F685F642D7143D7F6725230C8B8D9B65D42DA5634DDA9A73 020016BE1AFB579AB2EF6F57220E8946B0653FD5B883E09D70A7825F17C3B07F3D

Enter wallet passphrase:

Keys successfully decrypted:

decrypted mkey:  84d1f2f2380eb3a089ea256b851553ebfbc95555eb11b28a9eaaa7eeb97db4d6
--------------------------------------------------------------
uncomp addr:  13y8obG15gqVBmuRzD7HnokyVqGhQJZBfC
uncomp WIF :  5JXMD129XHcfpWF8hrzKG7eW4zDwZtuQ82gkwfMLz9aQRTxvsrh
--------------------------------------------------------------
comp addr  :  15V1kJedt9CJDsEYCofuvfWTyapqJPW4C9
comp WIF   :  KzLxBy64cgLSLg5P1MdybiLXJba7rC6H42SUxGGoDErSNtSKCJKP
--------------------------------------------------------------

C:\core_decrypter>

On the next run, you can just use the "decrypted mkey" that was displayed:
Code:
84d1f2f2380eb3a089ea256b851553ebfbc95555eb11b28a9eaaa7eeb97db4d6

... and remove the --enc_mkey flag from the commandline:
Code:
C:\core_decrypter>C:\Python27\python.exe core_decrypter.py 84d1f2f2380eb3a089ea256b851553ebfbc95555eb11b28a9eaaa7eeb97db4d6 ba946bb7db1a98e628d1a93104369d7cbb7a4cba9c9705223a2c7891bdc888a8b1019c27d2c17b28728513a51ba54f1e 0200cc635c13471b913e22bbe568711c19fd7bcb7449a9f09885f9ca53aff3cc6e

Keys successfully decrypted:

decrypted mkey:  84d1f2f2380eb3a089ea256b851553ebfbc95555eb11b28a9eaaa7eeb97db4d6
--------------------------------------------------------------
uncomp addr:  1K3p8CZCRZoKuXtzzawYs2LmKuN1uV2jvd
uncomp WIF :  5JsNBq7rwGPqp1jZLSgawvtusp3E47c2PjPex2QgK4Mhj4Bneuv
--------------------------------------------------------------
comp addr  :  1CVQVAeTCPhNUCcVsmSqrZoXWQCksbmgmc
comp WIF   :  L1sJWoPHQWwpSWEqipMiqSt8PGcpck9b9L6zVsDWWhpNkErSrJwf
--------------------------------------------------------------

C:\core_decrypter>
NOTE that there is no "wallet passphrase" prompt! ;)





If the walletpassphrase is not correct or the hex data is corrupt/incorrect, you will see a warning like this:
Code:
C:\core_decrypter>C:\Python27\python.exe core_decrypter.py --enc_mkey 3008ADC5605413B38A04979BF465D0CFF826A25C2C8812E582241477052C6D45C11B27690BA3BF2C1DA144600789C2BAAA08D8659791BE653E150000000017600300 BF1356ABEEB7FD2C7CD6757BA4B459AF64D62A3855592B24F685F642D7143D7F6725230C8B8D9B65D42DA5634DDA9A73 020016BE1AFB579AB2EF6F57220E8946B0653FD5B883E09D70A7825F17C3B07F3D

Enter wallet passphrase:


WARNING!!!
WARNING!!! - computed public keys DO NOT match, passphrase is probably incorrect or hex data is corrupt
WARNING!!!

C:\core_decrypter>
The script calculates the pubkey from the decrypted privkey, then compares to the user supplied "hex pub key". If both the calculated compressed and uncompressed pubkeys do not match the user provided pubkey, then either the wallet passphrase was incorrect (resulting in a bad master key decrypt) or the priv/pub key hex data could be corrupt/incorrect.





Wallet passphrase for the examples above: password123

Partial Pywallet dump (with encrypted privkeys):
Code:
keys": [
        {
            "addr": "15V1kJedt9CJDsEYCofuvfWTyapqJPW4C9",
            "compressed": true,
            "encrypted_privkey": "bf1356abeeb7fd2c7cd6757ba4b459af64d62a3855592b24f685f642d7143d7f6725230c8b8d9b65d42da5634dda9a73",
            "pubkey": "020016be1afb579ab2ef6f57220e8946b0653fd5b883e09d70a7825f17c3b07f3d",
            "reserve": 1
        },
        {
            "addr": "1CVQVAeTCPhNUCcVsmSqrZoXWQCksbmgmc",
            "compressed": true,
            "encrypted_privkey": "ba946bb7db1a98e628d1a93104369d7cbb7a4cba9c9705223a2c7891bdc888a8b1019c27d2c17b28728513a51ba54f1e",
            "pubkey": "0200cc635c13471b913e22bbe568711c19fd7bcb7449a9f09885f9ca53aff3cc6e",
            "reserve": 1
        },
        {
            "addr": "1JSo3zCQ8xaj9oGgfts8DMATtQ5ptnwigk",
            "compressed": true,
            "encrypted_privkey": "65207b28be9d6b142837e192797cc782e3c8f868fddb2fb901895dd4115c6bc1367c0787544f48bc631ec7e8fa0ebb51",
            "pubkey": "02020828662e18c691abd0ca216d655c576bbbac560a8852e7aafb42acb76ed9b9",
            "reserve": 1
        },


Title: Re: recover keys from wallet.dat without using pywallet
Post by: BASE16 on May 18, 2021, 01:56:10 PM
Perhaps you can add this also then you can do it

Code:
from Crypto.Cipher import AES

 


Title: Re: recover keys from wallet.dat without using pywallet
Post by: HCP on May 18, 2021, 08:20:25 PM
Perhaps you can add this also then you can do it

Code:
from Crypto.Cipher import AES
I'm not sure what you mean by this? ???

That is one of the first things the script attempts to do... it checks to see if pycrypto is installed, if so then it sets up the "crypter" to use that... otherwise it tries OpenSSL, if that fails, then it tries to use "slowaes" and if that fails it prints an error message and exits.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: morbius55 on May 18, 2021, 09:07:55 PM
Thanks so much for doing this HCP, it gives me another avenue to pursue (probably the last). I don't have much spare time at the moment to try it out and it's very time consuming for me, being the computer thicko that I am :). I might need some pointers if you don't mind, once I have a go at it. Thanks again, nice work. :)


Title: Re: recover keys from wallet.dat without using pywallet
Post by: BASE16 on May 19, 2021, 06:12:32 AM
Perhaps you can add this also then you can do it

Code:
from Crypto.Cipher import AES
I'm not sure what you mean by this? ???

That is one of the first things the script attempts to do... it checks to see if pycrypto is installed, if so then it sets up the "crypter" to use that... otherwise it tries OpenSSL, if that fails, then it tries to use "slowaes" and if that fails it prints an error message and exits.

I hope you will get it someday.
You just need to dig a little bit deeper pull it apart and reassemble it in a slightly altered way.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: HCP on May 19, 2021, 06:54:52 AM
I hope you will get it someday.
You just need to dig a little bit deeper pull it apart and reassemble it in a slightly altered way.
Are you being deliberately obtuse? or am I just missing something obvious? ??? I honestly have no idea what you're talking about when you say that "you can do it"... do what exactly? ???

The script takes the raw encrypted "mkey" hex, breaks it down into the actual key, the salt, the iterations etc... then prompts for the wallet passphrase... then decrypts the master key... then uses that decrypted master key to decrypt a given "ckey" record (note that the pubkey part of the "ckey" is required as it is used to form the "IV" for the encrypted private key)


So why do I need to dig a little bit deeper? What needs pulling apart? ??? What does the script not currently do, that you think it should? ???


Title: Re: recover keys from wallet.dat without using pywallet
Post by: BASE16 on May 19, 2021, 09:46:18 AM
Spit out the right key if you don't know the password.

 


Title: Re: recover keys from wallet.dat without using pywallet
Post by: Ankur3806 on July 03, 2022, 06:05:10 PM
I hope you will get it someday.
You just need to dig a little bit deeper pull it apart and reassemble it in a slightly altered way.
Are you being deliberately obtuse? or am I just missing something obvious? ??? I honestly have no idea what you're talking about when you say that "you can do it"... do what exactly? ???

The script takes the raw encrypted "mkey" hex, breaks it down into the actual key, the salt, the iterations etc... then prompts for the wallet passphrase... then decrypts the master key... then uses that decrypted master key to decrypt a given "ckey" record (note that the pubkey part of the "ckey" is required as it is used to form the "IV" for the encrypted private key)


So why do I need to dig a little bit deeper? What needs pulling apart? ??? What does the script not currently do, that you think it should? ???

YOU SAID THAT script takes the raw encrypted "mkey" hex, breaks it down into the actual key, so this actual key is AES key?
And if we crack this actual key do we get decrypted mkey?
(from above example decrypted mkey-84d1f2f2380eb3a089ea256b851553ebfbc95555eb11b28a9eaaa7eeb97db4d6)


Title: Re: recover keys from wallet.dat without using pywallet
Post by: EdouardDuval on August 29, 2022, 09:15:32 PM
How hard would it be for jackjack or someone to create a standalone tool to decrypt private keys, if the correct hex strings and passphrase were inputted? Not that I'm implying he should, as he seems to be a very busy person. But If you can search out the required info with a hex editor, it would be a very flexible tool for fragmented wallet files.
Probably not very difficult... because it didn't take me too long to bang this out: https://keybase.pub/hcp/python/core_decrypter.py

It's pretty rough... but basically, if you can feed it an "encrypted master key" (or decrypted master key), "encrypted private key" and matching "public key"... it will prompt for wallet passphrase and then attempt to decrypt the master key... then use that to decrypt the private key before outputting the Address+WIF.

I've run some tests on some newly generated wallet.dat data... and the master key/priv key/pub key data from the code example in joric's post (https://bitcointalk.org/index.php?topic=34028.msg708668#msg708668) that I linked to earlier... and it seems to be working OK.

As per the comment at the top of the script, it borrows very heavily from the "Proof of Concept" code from joric's post. (https://bitcointalk.org/index.php?topic=34028.msg708668#msg708668)... full credit to them! ;)




NOTES:

- Python 2.7x compatible only for now... if there is enough interest, I'll see if I can make it Python3 compatible.
- requires a couple of libraries that you'll likely already have installed if you've been using PyWallet etc (ie. pycrypto, ecdsa etc)... if Python moans at you about modules not being found then install them with pip :P





- (For now) The encrypted master key needs to be the full 66/67 bytes (132/134 hex chars) of the mkey record in the wallet.dat... This should be of the form:

"30" - 48 byte data record indicator
"48 bytes worth of encrypted master key"
"08" - 8 byte data record indicator
"8 bytes worth of salt"
"4 bytes worth of method" - should be 0 (ie. 00000000)
"4 bytes worth of iterations" - in Little Endian (ie.  1fb80000 ==> 0x0000b8f1 ==> 47345)
"00" - 1 byte end of record indicator (optional)

for example:
Code:
3008adc5605413b38a04979bf465d0cff826a25c2c8812e582241477052c6d45c11b27690ba3bf2c1da144600789c2baaa08d8659791be653e15000000001760030000

Quote
3008adc5605413b38a04979bf465d0cff826a25c2c8812e582241477052c6d45c11b27690ba3bf2 c1da144600789c2baaa08d8659791be653e15000000001760030000

This modified version of the walletinfo.py script (original here (https://github.com/brichard19/core-decrypt)) will output the "full mkey" from a wallet.dat: https://keybase.pub/hcp/python/walletinfo.py

Usage:
Code:
python walletinfo.py wallet.dat

otherwise, you'll have to do some hexediting of the wallet.dat file to find the data you need... have fun with that :P

I am also considering modifying the script so you can supply the "parsed" master key data (ie. encrypted key, salt, iterations etc) individually... I guess it depends on what is the most likely format of the hex data extracted from the wallet.dat file. ???





On subsequent runs for private keys from the same wallet.dat (ie. encrypted with the same master key), you can just use the "decrypted master key" that is output instead of using the "encrypted" master key + walletpassphrase

Example:
Code:
C:\core_decrypter>C:\Python27\python.exe core_decrypter.py --enc_mkey 3008ADC5605413B38A04979BF465D0CFF826A25C2C8812E582241477052C6D45C11B27690BA3BF2C1DA144600789C2BAAA08D8659791BE653E150000000017600300 BF1356ABEEB7FD2C7CD6757BA4B459AF64D62A3855592B24F685F642D7143D7F6725230C8B8D9B65D42DA5634DDA9A73 020016BE1AFB579AB2EF6F57220E8946B0653FD5B883E09D70A7825F17C3B07F3D

Enter wallet passphrase:

Keys successfully decrypted:

decrypted mkey:  84d1f2f2380eb3a089ea256b851553ebfbc95555eb11b28a9eaaa7eeb97db4d6
--------------------------------------------------------------
uncomp addr:  13y8obG15gqVBmuRzD7HnokyVqGhQJZBfC
uncomp WIF :  5JXMD129XHcfpWF8hrzKG7eW4zDwZtuQ82gkwfMLz9aQRTxvsrh
--------------------------------------------------------------
comp addr  :  15V1kJedt9CJDsEYCofuvfWTyapqJPW4C9
comp WIF   :  KzLxBy64cgLSLg5P1MdybiLXJba7rC6H42SUxGGoDErSNtSKCJKP
--------------------------------------------------------------

C:\core_decrypter>

On the next run, you can just use the "decrypted mkey" that was displayed:
Code:
84d1f2f2380eb3a089ea256b851553ebfbc95555eb11b28a9eaaa7eeb97db4d6

... and remove the --enc_mkey flag from the commandline:
Code:
C:\core_decrypter>C:\Python27\python.exe core_decrypter.py 84d1f2f2380eb3a089ea256b851553ebfbc95555eb11b28a9eaaa7eeb97db4d6 ba946bb7db1a98e628d1a93104369d7cbb7a4cba9c9705223a2c7891bdc888a8b1019c27d2c17b28728513a51ba54f1e 0200cc635c13471b913e22bbe568711c19fd7bcb7449a9f09885f9ca53aff3cc6e

Keys successfully decrypted:

decrypted mkey:  84d1f2f2380eb3a089ea256b851553ebfbc95555eb11b28a9eaaa7eeb97db4d6
--------------------------------------------------------------
uncomp addr:  1K3p8CZCRZoKuXtzzawYs2LmKuN1uV2jvd
uncomp WIF :  5JsNBq7rwGPqp1jZLSgawvtusp3E47c2PjPex2QgK4Mhj4Bneuv
--------------------------------------------------------------
comp addr  :  1CVQVAeTCPhNUCcVsmSqrZoXWQCksbmgmc
comp WIF   :  L1sJWoPHQWwpSWEqipMiqSt8PGcpck9b9L6zVsDWWhpNkErSrJwf
--------------------------------------------------------------

C:\core_decrypter>
NOTE that there is no "wallet passphrase" prompt! ;)





If the walletpassphrase is not correct or the hex data is corrupt/incorrect, you will see a warning like this:
Code:
C:\core_decrypter>C:\Python27\python.exe core_decrypter.py --enc_mkey 3008ADC5605413B38A04979BF465D0CFF826A25C2C8812E582241477052C6D45C11B27690BA3BF2C1DA144600789C2BAAA08D8659791BE653E150000000017600300 BF1356ABEEB7FD2C7CD6757BA4B459AF64D62A3855592B24F685F642D7143D7F6725230C8B8D9B65D42DA5634DDA9A73 020016BE1AFB579AB2EF6F57220E8946B0653FD5B883E09D70A7825F17C3B07F3D

Enter wallet passphrase:


WARNING!!!
WARNING!!! - computed public keys DO NOT match, passphrase is probably incorrect or hex data is corrupt
WARNING!!!

C:\core_decrypter>
The script calculates the pubkey from the decrypted privkey, then compares to the user supplied "hex pub key". If both the calculated compressed and uncompressed pubkeys do not match the user provided pubkey, then either the wallet passphrase was incorrect (resulting in a bad master key decrypt) or the priv/pub key hex data could be corrupt/incorrect.





Wallet passphrase for the examples above: password123

Partial Pywallet dump (with encrypted privkeys):
Code:
keys": [
        {
            "addr": "15V1kJedt9CJDsEYCofuvfWTyapqJPW4C9",
            "compressed": true,
            "encrypted_privkey": "bf1356abeeb7fd2c7cd6757ba4b459af64d62a3855592b24f685f642d7143d7f6725230c8b8d9b65d42da5634dda9a73",
            "pubkey": "020016be1afb579ab2ef6f57220e8946b0653fd5b883e09d70a7825f17c3b07f3d",
            "reserve": 1
        },
        {
            "addr": "1CVQVAeTCPhNUCcVsmSqrZoXWQCksbmgmc",
            "compressed": true,
            "encrypted_privkey": "ba946bb7db1a98e628d1a93104369d7cbb7a4cba9c9705223a2c7891bdc888a8b1019c27d2c17b28728513a51ba54f1e",
            "pubkey": "0200cc635c13471b913e22bbe568711c19fd7bcb7449a9f09885f9ca53aff3cc6e",
            "reserve": 1
        },
        {
            "addr": "1JSo3zCQ8xaj9oGgfts8DMATtQ5ptnwigk",
            "compressed": true,
            "encrypted_privkey": "65207b28be9d6b142837e192797cc782e3c8f868fddb2fb901895dd4115c6bc1367c0787544f48bc631ec7e8fa0ebb51",
            "pubkey": "02020828662e18c691abd0ca216d655c576bbbac560a8852e7aafb42acb76ed9b9",
            "reserve": 1
        },
root@RémiM:~# python2.7 core_decrypter.py?dl=1.1
Traceback (most recent call last):
  File "core_decrypter.py?dl=1.1", line 14, in <module>
    import base58
ImportError: No module named base58
root@RémiM:~# pip install base58
Requirement already satisfied: base58 in /usr/local/lib/python3.9/dist-packages (2.1.1)
can you help please? Thanks
everytime i try i get thiis


Title: Re: recover keys from wallet.dat without using pywallet
Post by: nc50lc on August 30, 2022, 04:16:22 AM
root@RémiM:~# python2.7 core_decrypter.py?dl=1.1
-snip-
root@RémiM:~# pip install base58
Requirement already satisfied: base58 in /usr/local/lib/python3.9/dist-packages (2.1.1)
can you help please? Thanks
everytime i try i get thiis
Pip is installing base58 to Python 3.9 while you're using Python 2.7 for core_decrypter.py.
Try to specify the python version when using pip.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: EdouardDuval on August 30, 2022, 11:05:20 AM
root@RémiM:~# python2.7 core_decrypter.py?dl=1.1
-snip-
root@RémiM:~# pip install base58
Requirement already satisfied: base58 in /usr/local/lib/python3.9/dist-packages (2.1.1)
can you help please? Thanks
everytime i try i get thiis
Pip is installing base58 to Python 3.9 while you're using Python 2.7 for core_decrypter.py.
Try to specify the python version when using pip.
thanks. I'll try it.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: nikok on January 13, 2023, 04:39:32 AM
How hard would it be for jackjack or someone to create a standalone tool to decrypt private keys, if the correct hex strings and passphrase were inputted? Not that I'm implying he should, as he seems to be a very busy person. But If you can search out the required info with a hex editor, it would be a very flexible tool for fragmented wallet files.
Probably not very difficult... because it didn't take me too long to bang this out: https://keybase.pub/hcp/python/core_decrypter.py

It's pretty rough... but basically, if you can feed it an "encrypted master key" (or decrypted master key), "encrypted private key" and matching "public key"... it will prompt for wallet passphrase and then attempt to decrypt the master key... then use that to decrypt the private key before outputting the Address+WIF.

I've run some tests on some newly generated wallet.dat data... and the master key/priv key/pub key data from the code example in joric's post (https://bitcointalk.org/index.php?topic=34028.msg708668#msg708668) that I linked to earlier... and it seems to be working OK.

As per the comment at the top of the script, it borrows very heavily from the "Proof of Concept" code from joric's post. (https://bitcointalk.org/index.php?topic=34028.msg708668#msg708668)... full credit to them! ;)




NOTES:

- Python 2.7x compatible only for now... if there is enough interest, I'll see if I can make it Python3 compatible.
- requires a couple of libraries that you'll likely already have installed if you've been using PyWallet etc (ie. pycrypto, ecdsa etc)... if Python moans at you about modules not being found then install them with pip :P





- (For now) The encrypted master key needs to be the full 66/67 bytes (132/134 hex chars) of the mkey record in the wallet.dat... This should be of the form:

"30" - 48 byte data record indicator
"48 bytes worth of encrypted master key"
"08" - 8 byte data record indicator
"8 bytes worth of salt"
"4 bytes worth of method" - should be 0 (ie. 00000000)
"4 bytes worth of iterations" - in Little Endian (ie.  1fb80000 ==> 0x0000b8f1 ==> 47345)
"00" - 1 byte end of record indicator (optional)

for example:
Code:
3008adc5605413b38a04979bf465d0cff826a25c2c8812e582241477052c6d45c11b27690ba3bf2c1da144600789c2baaa08d8659791be653e15000000001760030000

Quote
3008adc5605413b38a04979bf465d0cff826a25c2c8812e582241477052c6d45c11b27690ba3bf2 c1da144600789c2baaa08d8659791be653e15000000001760030000

This modified version of the walletinfo.py script (original here (https://github.com/brichard19/core-decrypt)) will output the "full mkey" from a wallet.dat: https://keybase.pub/hcp/python/walletinfo.py

Usage:
Code:
python walletinfo.py wallet.dat

otherwise, you'll have to do some hexediting of the wallet.dat file to find the data you need... have fun with that :P

I am also considering modifying the script so you can supply the "parsed" master key data (ie. encrypted key, salt, iterations etc) individually... I guess it depends on what is the most likely format of the hex data extracted from the wallet.dat file. ???





On subsequent runs for private keys from the same wallet.dat (ie. encrypted with the same master key), you can just use the "decrypted master key" that is output instead of using the "encrypted" master key + walletpassphrase

Example:
Code:
C:\core_decrypter>C:\Python27\python.exe core_decrypter.py --enc_mkey 3008ADC5605413B38A04979BF465D0CFF826A25C2C8812E582241477052C6D45C11B27690BA3BF2C1DA144600789C2BAAA08D8659791BE653E150000000017600300 BF1356ABEEB7FD2C7CD6757BA4B459AF64D62A3855592B24F685F642D7143D7F6725230C8B8D9B65D42DA5634DDA9A73 020016BE1AFB579AB2EF6F57220E8946B0653FD5B883E09D70A7825F17C3B07F3D

Enter wallet passphrase:

Keys successfully decrypted:

decrypted mkey:  84d1f2f2380eb3a089ea256b851553ebfbc95555eb11b28a9eaaa7eeb97db4d6
--------------------------------------------------------------
uncomp addr:  13y8obG15gqVBmuRzD7HnokyVqGhQJZBfC
uncomp WIF :  5JXMD129XHcfpWF8hrzKG7eW4zDwZtuQ82gkwfMLz9aQRTxvsrh
--------------------------------------------------------------
comp addr  :  15V1kJedt9CJDsEYCofuvfWTyapqJPW4C9
comp WIF   :  KzLxBy64cgLSLg5P1MdybiLXJba7rC6H42SUxGGoDErSNtSKCJKP
--------------------------------------------------------------

C:\core_decrypter>

On the next run, you can just use the "decrypted mkey" that was displayed:
Code:
84d1f2f2380eb3a089ea256b851553ebfbc95555eb11b28a9eaaa7eeb97db4d6

... and remove the --enc_mkey flag from the commandline:
Code:
C:\core_decrypter>C:\Python27\python.exe core_decrypter.py 84d1f2f2380eb3a089ea256b851553ebfbc95555eb11b28a9eaaa7eeb97db4d6 ba946bb7db1a98e628d1a93104369d7cbb7a4cba9c9705223a2c7891bdc888a8b1019c27d2c17b28728513a51ba54f1e 0200cc635c13471b913e22bbe568711c19fd7bcb7449a9f09885f9ca53aff3cc6e

Keys successfully decrypted:

decrypted mkey:  84d1f2f2380eb3a089ea256b851553ebfbc95555eb11b28a9eaaa7eeb97db4d6
--------------------------------------------------------------
uncomp addr:  1K3p8CZCRZoKuXtzzawYs2LmKuN1uV2jvd
uncomp WIF :  5JsNBq7rwGPqp1jZLSgawvtusp3E47c2PjPex2QgK4Mhj4Bneuv
--------------------------------------------------------------
comp addr  :  1CVQVAeTCPhNUCcVsmSqrZoXWQCksbmgmc
comp WIF   :  L1sJWoPHQWwpSWEqipMiqSt8PGcpck9b9L6zVsDWWhpNkErSrJwf
--------------------------------------------------------------

C:\core_decrypter>
NOTE that there is no "wallet passphrase" prompt! ;)





If the walletpassphrase is not correct or the hex data is corrupt/incorrect, you will see a warning like this:
Code:
C:\core_decrypter>C:\Python27\python.exe core_decrypter.py --enc_mkey 3008ADC5605413B38A04979BF465D0CFF826A25C2C8812E582241477052C6D45C11B27690BA3BF2C1DA144600789C2BAAA08D8659791BE653E150000000017600300 BF1356ABEEB7FD2C7CD6757BA4B459AF64D62A3855592B24F685F642D7143D7F6725230C8B8D9B65D42DA5634DDA9A73 020016BE1AFB579AB2EF6F57220E8946B0653FD5B883E09D70A7825F17C3B07F3D

Enter wallet passphrase:


WARNING!!!
WARNING!!! - computed public keys DO NOT match, passphrase is probably incorrect or hex data is corrupt
WARNING!!!

C:\core_decrypter>
The script calculates the pubkey from the decrypted privkey, then compares to the user supplied "hex pub key". If both the calculated compressed and uncompressed pubkeys do not match the user provided pubkey, then either the wallet passphrase was incorrect (resulting in a bad master key decrypt) or the priv/pub key hex data could be corrupt/incorrect.





Wallet passphrase for the examples above: password123

Partial Pywallet dump (with encrypted privkeys):
Code:
keys": [
        {
            "addr": "15V1kJedt9CJDsEYCofuvfWTyapqJPW4C9",
            "compressed": true,
            "encrypted_privkey": "bf1356abeeb7fd2c7cd6757ba4b459af64d62a3855592b24f685f642d7143d7f6725230c8b8d9b65d42da5634dda9a73",
            "pubkey": "020016be1afb579ab2ef6f57220e8946b0653fd5b883e09d70a7825f17c3b07f3d",
            "reserve": 1
        },
        {
            "addr": "1CVQVAeTCPhNUCcVsmSqrZoXWQCksbmgmc",
            "compressed": true,
            "encrypted_privkey": "ba946bb7db1a98e628d1a93104369d7cbb7a4cba9c9705223a2c7891bdc888a8b1019c27d2c17b28728513a51ba54f1e",
            "pubkey": "0200cc635c13471b913e22bbe568711c19fd7bcb7449a9f09885f9ca53aff3cc6e",
            "reserve": 1
        },
        {
            "addr": "1JSo3zCQ8xaj9oGgfts8DMATtQ5ptnwigk",
            "compressed": true,
            "encrypted_privkey": "65207b28be9d6b142837e192797cc782e3c8f868fddb2fb901895dd4115c6bc1367c0787544f48bc631ec7e8fa0ebb51",
            "pubkey": "02020828662e18c691abd0ca216d655c576bbbac560a8852e7aafb42acb76ed9b9",
            "reserve": 1
        },
@HCP
Can you write a python script to decrypt only the master key, and derive all private keys from the master key according to the BIP32 path?  will consider donating to you



Title: Re: recover keys from wallet.dat without using pywallet
Post by: Marshall Chord on March 22, 2023, 09:36:30 AM
I am try this method. It is useful for me.  You also try this . If you have a wallet.dat file and need to recover the keys without using pywallet, you can use a tool like Bitcoin Core to extract the keys. Bitcoin Core is a full Bitcoin client and will attempt to recover all keys stored in your wallet.dat file. It is a bit more complicated than using pywallet, but it is an effective way to recover your keys.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: whanau on April 06, 2023, 11:43:29 PM


Quote
The passphrase is no problem as I already know it. I wonder if the salt and iteration are viewable within the wallet file? How do these various scripts find them?

I posted a script to explain what goes on. it is here
https://bitcointalk.org/index.php?topic=5331322.0

Please note this script does not match bitcoin decryption exactly (on purpose) it is for demonstration

If you want the script for bitcoin send me a pm.


Title: Re: recover keys from wallet.dat without using pywallet
Post by: dirk1101 on January 17, 2024, 07:33:25 PM
Hi, since HCP wasnt online for 2 weeks now, does someone by chance has his coredecrypter?


Title: Re: recover keys from wallet.dat without using pywallet
Post by: NotATether on January 18, 2024, 12:13:32 PM
Hi, since HCP wasnt online for 2 weeks now, does someone by chance has his coredecrypter?

The coredecryptor python script is inaccessible from a web prowser because keybase.pub shut down almost a year ago. It was a separate service from Keybase itself IIRC.

However, according to this comment: https://news.ycombinator.com/item?id=34711449 it seems that you are still able to access the directory through the Keybase program itself. I am not sure how that would work though, because I haven't used Keybase since it was acquired by Zoom.