Scripting with cardano-cli and writing to stdin

A friend of mine lost one of his 12 mnemonics, so I am trying a brute-force recovery of his wallet. when i manually recover a wallet with 12 existing mnemonics, the cli works as expected. however when i try to automatize this part and when prompted write the mnemonics to stdin, the cli crashes or doesn’t receive the input as expected. before i dive too deep into rust and the cli source, any idea how to solve this?

cardano-cli wallet recover --daedalus-seed --derivation-scheme=v1 --mnemonics-length=12 --wallet-scheme=random_index_2levels MyWallet <<<"my 12 private words"
Please enter all your 12 mnemonics: my 12 private words
Set a wallet password. This is for local usage only, allows you to protect your cached private key and prevent from creating non desired transactions.
spending password: thread ‘main’ panicked at ‘called Result::unwrap() on an Err value: Os { code: 9, kind: Other, message: “Bad file descriptor” }’, src/libcore/result.rs:1165:5
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace.

Hi,

If he lost it, and no any long part of it with the correct order is known, then you CANNOT brute force it.
I mean you can try but it won’t happen in your and in long deep generations of your anchestors’ life.

Cheers,

Pal

Ok, but why stop at brute forcing only your friend’s wallet? I would go for the whales - obviously :slight_smile:
As @_ilap mentionned, good luck to you and your grand, grand, grand-kids

he lost the last one of 12 words, so there are just around 120 possibilities left.
Please, if you don’t know anything about my actual problem, which is piping stdin to cardano-cli, don’t respond to this thread, thank you!

oups sorry - one is ok then :slight_smile:

Cardano-cli; as other commands that use password inputs; dynamically opens new file descriptors for those password inputs (it does not use stdin a.k.a. fd=0 for passwords), therefore piping and redirecting wont work. However, you can try an expect script for redirecting the mnemonics, see below:

#!/usr/bin/expect
spawn cardano-cli-Darwin --quiet wallet recover --daedalus-seed --derivation-scheme=v1 --mnemonics-length=12 --wallet-scheme=random_index_2levels MyWallet[lrange $argv 0 0]
send "[lrange $argv 1 12]\n"
interact

From here you can create a bash scripts calling that expect script /w the index and mnemonics and then push the enter two times
The 0 is the postfix for the MyWallet e.g. MyWallet0

expect.sh 0 abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about 
3 Likes

Please let me know if you succeed…Because Sebastian basically said it is impossibe

See Bruteforce Password Protection

This is different, Grumpy. :grinning:

Only one word is missing, and the order is known, so the odds are reduced to 1 in 120.

My bad…thought it were 12 :slight_smile:

1 Like

Thank you very much, this is exactly what i was looking for!
It took my script 3 days and after 1112 combinations i found the right word :star_struck:

1 Like

That’s different, that’s for spending password. For wallet recovery you do not need the spending password, but only the recovery phrases.

Hi @Frigus , what are the chances you can provide the script? A friend of mine is missing the final two words. Looks like his hands might become a bit sore around attempt #10,000