Class: CryptoToolbox::Analyzers::CbcMutatingEncryption

Inherits:
Object
  • Object
show all
Defined in:
lib/crypto-toolbox/analyzers/cbc_mutating_encryption.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oracle) ⇒ CbcMutatingEncryption

Returns a new instance of CbcMutatingEncryption.



5
6
7
# File 'lib/crypto-toolbox/analyzers/cbc_mutating_encryption.rb', line 5

def initialize(oracle)
  @oracle = oracle
end

Instance Attribute Details

#oracleObject (readonly)

Returns the value of attribute oracle.



4
5
6
# File 'lib/crypto-toolbox/analyzers/cbc_mutating_encryption.rb', line 4

def oracle
  @oracle
end

Instance Method Details

#assemble_attack_messageObject



9
10
11
12
13
14
15
16
17
# File 'lib/crypto-toolbox/analyzers/cbc_mutating_encryption.rb', line 9

def assemble_attack_message
  # we are lazy thus we use 0 as a byte which is neutral to xor,
  # thus we dont have to cancel it before adding admin=true. 
  input = "\0" * 32
  blocks = @oracle.encrypted_message_for(input).chunks_of(16)
  fake   = blocks[2].xor(";admin=true;",expand_input: false )
  blocks[2] = fake
  ciphertext = blocks.map(&:str).join
end