Thursday, October 17, 2013

Brute Forcing a 32 Character Luks Password by Sequentially Iterating through a 32 Character Hex String

Just an example of iterating through a 32 character hex string.  As an example we're brute-forcing a Luks encryption password where the password is known to be a 128 bit hex string (good luck).

From irb, we find our largest number:

> "ffffffffffffffffffffffffffffffff".to_i(16)
 => 340282366920938463463374607431768211455 


Now we iterate, pad, and pass the value to luks:

(0..340282366920938463463374607431768211455).each do |num| 
  pass = sprintf("%032x", num)
  print "Passing #{pass}..."
  `echo -ne "#{pass}\r\n" | cryptsetup -q luksOpen /dev/sdb1 secureUSB`
end


Passing 00000000000000000000000000000000...No key available with this passphrase.
Passing 00000000000000000000000000000001...No key available with this passphrase.
Passing 00000000000000000000000000000002...No key available with this passphrase.
Passing 00000000000000000000000000000003...No key available with this passphrase.
Passing 00000000000000000000000000000004...No key available with this passphrase.
Passing 00000000000000000000000000000005...No key available with this passphrase.
Passing 00000000000000000000000000000006...No key available with this passphrase.
Passing 00000000000000000000000000000007...No key available with this passphrase.
Passing 00000000000000000000000000000008...No key available with this passphrase.
Passing 00000000000000000000000000000009...No key available with this passphrase.
Passing 0000000000000000000000000000000a...No key available with this passphrase.
Passing 0000000000000000000000000000000b...No key available with this passphrase.
Passing 0000000000000000000000000000000c...No key available with this passphrase.
Passing 0000000000000000000000000000000d...No key available with this passphrase.
Passing 0000000000000000000000000000000e...No key available with this passphrase.
Passing 0000000000000000000000000000000f...No key available with this passphrase.
Passing 00000000000000000000000000000010...No key available with this passphrase.
Passing 00000000000000000000000000000011...No key available with this passphrase.
Passing 00000000000000000000000000000012...No key available with this passphrase.
Passing 00000000000000000000000000000013...No key available with this passphrase.
Passing 00000000000000000000000000000014...No key available with this passphrase.
Passing 00000000000000000000000000000015...No key available with this passphrase.
Passing 00000000000000000000000000000016...No key available with this passphrase.
Passing 00000000000000000000000000000017...No key available with this passphrase.
Passing 00000000000000000000000000000018...No key available with this passphrase.
Passing 00000000000000000000000000000019...No key available with this passphrase.
Passing 0000000000000000000000000000001a...No key available with this passphrase.

Be sure to reference the appropriate Luks block device (e.g. /dev/sdc1).

Cheers!