require 'pbkdf2.rb' args = ARGV # arguments in the following order: salt hash iterations samples.txt transformations.txt -v if !args.empty? salt = args[0] hash = args[1] iterations = Integer(args[2]) rescue Integer(0) if iterations <= 0 puts "Iterations \" #{args[2]} \" has to be a number > 0" puts "Exiting..." exit end samplesTxt = args[3] transformsTxt = args[4] else puts "Run this program with the following command line arguments" puts "Following order required: \"salt hash iterations samples.txt transformations.txt -v\" -v is optional." puts "Example usage: kikugalanet 7d69838932ccb599fe218f896e23dc8934b297736cf9be1ac3a5d4cc7a223beb 10000 bullshit.txt transformations.txt -v" end if ARGV.include? "-v" debug = true end # Guess by file approach if debug puts "Testing words from #{samplesTxt}" sleep(3) end if File.exist?(samplesTxt) samplesFile = File.new(samplesTxt, "r") else puts "File #{samplesTxt} doesn't exist. Exiting now..." exit end IO.foreach(samplesFile){|sampleLine| temp_password = PBKDF2.new(:password=>sampleLine.chomp, :salt=>salt, :iterations=>iterations) if hash == temp_password.hex_string puts "PASSWORD FOUND: #{sampleLine}" exit else if debug puts "Failed: #{sampleLine}" end end } # Tranformations approach if debug puts "Testing permutations using #{transformsTxt}" sleep(3) end if File.exist?(transformsTxt) transformsFile = File.new(transformsTxt, "r") else puts "File #{transformsTxt} doesn't exist. Exiting now..." exit end IO.foreach(samplesFile){|sampleLine| temp = sampleLine.chomp IO.foreach(transformsFile){|transformLine| split = transformLine.chomp.split temp = temp.gsub(split[0].match(/(?<=\/)(.*?)(?=\/)/).to_s, split[1].match(/(?<=\')(.*?)(?=\')/).to_s) } temp_password = PBKDF2.new(:password=>temp, :salt=>salt, :iterations=>iterations) if hash == temp_password.hex_string puts "PASSWORD FOUND: #{temp}" exit else if debug puts "Failed: #{temp}" end end } # Brute Force approach if debug puts "Last Method: \"Brute Force\" initialized" sleep(3) end chars = (0000..9999).to_a + ("aaaa".."zzzz").to_a ctr = 0 chars.each {|elem| ctr = ctr + 1 temp_password = PBKDF2.new(:password=>elem.to_s, :salt=>salt, :iterations=>iterations) if hash == temp_password.hex_string puts "PASSWORD FOUND: #{temp_password.password}" exit else if debug puts "Try No.: #{ctr} of #{chars.length} Failed: #{temp_password.password}" end end } puts "Passwort couldn't be found. Try again later."