Post
Topic
Board Bitcoin Technical Support
Re: Encrypted wallet.dat, lost password, any solutions?
by
ihatepasswords
on 28/12/2013, 00:07:30 UTC
I ran it from the command prompt, it gave me a password instantly and said it found it but its not the right one, i tried to send coin to myself and electrum said it was invalid.

edit: i added some random word in the initial password and it did the same thing, said found it! but of course it was the wrong password. It seems to think the first guess is the right one.

edit2: for the record im running windows 7x64 + electrum standalone 1.9.5 + ruby 1.9.3.

edit3: this is the script im using

Code:
#!/usr/bin/ruby
require 'base64'
require 'digest/sha2'
require 'open3'
require 'openssl'

# Double substitution for Electrum

# Put your best guess at your passphrase here
passphrase = '****************'

# The full path to your electrum.dat or default_wallet
wallet_file = 'C:\Users\Admin\Desktop\Brute\wallet.dat'

# Where to find Electrum.  Use 1.9.2!  Older versions may be incompatible.
$electrum = 'C:\Users\Admin\Desktop\Brute\electrum-1.9.5.exe'


def test(phrase)
  $cipher.reset
  $cipher.key = Digest::SHA256.digest(Digest::SHA256.digest(phrase))
  $cipher.update $seed
  $cipher.final
  puts phrase
  i,o,t = Open3.popen2e($electrum, "-o", "getseed")
  i.puts(phrase)
  i.close
  if t.value.success?
    puts "Found it! #{phrase}"
    exit
  end
rescue OpenSSL::Cipher::CipherError
end

def scramble(passphrase)
  characters = " !$'(),.ABCDEFGHIJKLMNOPQRSTUVWXYZ^abcdefghijklmnopqrstuvwxyz"
  list = []

  # transpose adjacent chars
  (passphrase.length - 1).times do |i|
    testphrase = passphrase.dup
    testphrase[i] = passphrase[i+1]
    testphrase[i+1] = passphrase[i]
    list << testphrase
  end

  # delete one char
  passphrase.length.times do |i|
    testphrase = passphrase.dup
    testphrase = testphrase[0,i] + testphrase[(i+1)..-1]
    list << testphrase
  end

  # substitutute one char
  passphrase.length.times do |i|
    characters.chars.each do |c|
      testphrase = passphrase.dup
      testphrase[i] = c
      list << testphrase
    end
  end

  # insert one char
  (passphrase.length + 1).times do |i|
    characters.chars.each do |c|
      testphrase = passphrase.dup
      testphrase.insert(i, c)
      list << testphrase
    end
  end

  return list.uniq
end

wallet = File.read(wallet_file)
seed_base64 = wallet.match(/'seed': '([^']+)'/).captures.first
$seed = Base64.decode64(seed_base64)
$cipher = OpenSSL::Cipher.new('aes-256-cbc')
$cipher.iv = $seed.slice!(0,16)
Dir.chdir File.dirname $electrum
list1 = scramble(passphrase)
list1.each { |i| test i }
list1.each { |i| scramble(i).each { |j| test j }}
puts "No luck."
exit 1