Class: Analyzers::PaddingOracle::Analyzer

Inherits:
Object
  • Object
show all
Includes:
Utils::Reporting::Console
Defined in:
lib/crypto-toolbox/analyzers/padding_oracle/analyzer.rb

Defined Under Namespace

Classes: FailedAnalysis

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Reporting::Console

#jot, #print_delimiter_line, #print_nice, #print_raw

Constructor Details

#initialize(oracle = CryptoToolbox::Oracles::PaddingOracle::TcpOracle.new) ⇒ Analyzer

Returns a new instance of Analyzer.



10
11
12
13
# File 'lib/crypto-toolbox/analyzers/padding_oracle/analyzer.rb', line 10

def initialize(oracle = CryptoToolbox::Oracles::PaddingOracle::TcpOracle.new)
  @result      = [ ]
  @oracle      = oracle
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



7
8
9
# File 'lib/crypto-toolbox/analyzers/padding_oracle/analyzer.rb', line 7

def result
  @result
end

Instance Method Details

#analyze(cipher) ⇒ Object

start with the second to last block to manipulate the final block ( cbc xor behaviour ) from there on we move to the left until we have used the first block (iv) to decrypt the second blick ( first plain text block )

we have to manipulate the block before the one we want to change xxxxxxxxx xxxxxxxxx xxxxxxxxxx changing this byte ^- will change ^- this byte at decryption



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/crypto-toolbox/analyzers/padding_oracle/analyzer.rb', line 22

def analyze(cipher)
  blocks = CryptBuffer.from_hex(cipher).chunks_of(16)

  # ranges cant be from high to low
  (1..(blocks.length() -1)).reverse_each do |block_index|
    result.unshift analyse_block(blocks,block_index)
  end

  plaintext = CryptBuffer(result.flatten)
  report_result(plaintext)
  plaintext.strip_padding
end