class CryptoToolchain::Tools::EcbCutAndPasteAttack

Attributes

initial[R]
oracle[R]
replace[R]
replacement[R]

Public Class Methods

new(replace: "user", with: "admin", oracle: CryptoToolchain::BlackBoxes::EcbCutAndPasteTarget.new, initial: "charlesisagood@dog.com" ) click to toggle source
# File lib/crypto_toolchain/tools/ecb_cut_and_paste_attack.rb, line 5
def initialize(replace: "user",
               with: "admin",
               oracle: CryptoToolchain::BlackBoxes::EcbCutAndPasteTarget.new,
               initial: "charlesisagood@dog.com"
              )
  @oracle = oracle
  @replace = replace
  @replacement = with
  @initial = initial
end

Public Instance Methods

execute() click to toggle source
# File lib/crypto_toolchain/tools/ecb_cut_and_paste_attack.rb, line 16
def execute
  without_text_to_change + replaced_text_only
end

Private Instance Methods

replaced_text_only() click to toggle source
# File lib/crypto_toolchain/tools/ecb_cut_and_paste_attack.rb, line 35
def replaced_text_only
  (0...Float::INFINITY).each do |i|
    input = initial + "X" * i + replacement
    oracle.profile_for(input).in_blocks(blocksize).each_with_index do |block, bi|
      if block.start_with?(replacement)
        return oracle.encrypt(input).in_blocks(blocksize)[bi]
      end
    end
  end
end
without_text_to_change() click to toggle source
# File lib/crypto_toolchain/tools/ecb_cut_and_paste_attack.rb, line 24
def without_text_to_change
  (0...Float::INFINITY).each do |i|
    input = initial + "X" * i
    oracle.profile_for(input).in_blocks(blocksize).each do |block|
      if block.start_with?(replace)
        return oracle.encrypt(input).in_blocks(blocksize)[0..-2].join
      end
    end
  end
end