#!/usr/bin/env ruby
#
# dm-crypt LUKS bruteforcing script
#
# Copyright 2009 by Rorschach (r0rschach@lavabit.com)
# Licence: GPL3
$VERBOSE=true
require 'open3'
$partition='/dev/sdXY'
$mapper='brute'
def error(msg)
puts " Error: #{msg}"
puts " Aborting now!"
exit 1
end
def check_if_correct(stderr,stdout)
return false if stderr.chomp.chomp == "Command failed: No key available with this passphrase."
return true if stdout =~ /^key\sslot\s\d\sunlocked\.$/
case stderr.chomp
when "Command failed: Device already exists"
error("#{$partition} is already unencrypted and mapped to #{$mapper}.")
when "Command failed: Can not access device"
error("Wheter #{$partition} does not exist or is already mapped to another device.")
else
error("An unknown error has occured:\n #{stderr.chomp}")
end
end
if ARGV[0]==nil
error("Not enough arguments!\n Usage: #{$0} dictionaryfile")
end
if not FileTest::exist?(ARGV[0])
error("#{ARGV[0]} doesn't exist.")
end
File.open(ARGV[0], "r").each_line do |password|
puts "Testing: #{password}"
Open3.popen3("sudo cryptsetup luksOpen #{$partition} #{$mapper}") do |stdin,stdout,stderr|
stdin.puts password.chomp
if check_if_correct(stderr.read,stdout.read)
puts "\n Correct password found: #{password.chomp}"
system("sudo cryptsetup remove #{$mapper}")
exit 0
end
end
end
puts "\n Haven't found the correct password."
exit 1