Class: CryptoToolchain::Tools::CbcIvEqualsKeyAttack

Inherits:
Object
  • Object
show all
Defined in:
lib/crypto_toolchain/tools/cbc_iv_equals_key_attack.rb

Instance Method Summary collapse

Constructor Details

#initialize(target: CryptoToolchain::BlackBoxes::CbcIvEqualsKeyTarget.new, message_prefix: "Invalid byte in ") ⇒ CbcIvEqualsKeyAttack

Returns a new instance of CbcIvEqualsKeyAttack.



6
7
8
9
10
# File 'lib/crypto_toolchain/tools/cbc_iv_equals_key_attack.rb', line 6

def initialize(target: CryptoToolchain::BlackBoxes::CbcIvEqualsKeyTarget.new,
               message_prefix: "Invalid byte in ")
  @target = target
  @message_prefix = message_prefix
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/crypto_toolchain/tools/cbc_iv_equals_key_attack.rb', line 12

def execute
  initial = ("A" * CryptoToolchain::AES_BLOCK_SIZE * 3)
  blocks = target.encrypt(initial).in_blocks(CryptoToolchain::AES_BLOCK_SIZE)
  mal = blocks[0] + (0.chr * 16) + blocks[0]
  begin
    target.is_admin?(mal)
  rescue RuntimeError => e
    blocks = e.message[(message_prefix.length)..-1].in_blocks(CryptoToolchain::AES_BLOCK_SIZE)
    blocks[0] ^ blocks[2]
  end
end