Skip to content

Instantly share code, notes, and snippets.

@julik
Created January 2, 2021 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julik/a821886356a802050284c2a37aa2f3df to your computer and use it in GitHub Desktop.
Save julik/a821886356a802050284c2a37aa2f3df to your computer and use it in GitHub Desktop.
require 'zlib'
# A fairly naive generator of payloads which, having the same size, will produce an identical CRC32 checksum
def produce_bytes_at_iteration(bytebag_size, random_seed, iter)
rng = Random.new(random_seed)
iter.times do
rng.bytes(bytebag_size)
end
rng.bytes(bytebag_size)
end
def collider(bytebag_size, random_seed)
rng = Random.new(random_seed)
computed = {}
10_000_000.times do |iter|
bytes = rng.bytes(bytebag_size)
len_before = computed.length
crc = Zlib.crc32(bytes)
if previous = computed[crc]
# Reproduce the first colliding payload
previous_colliding = produce_bytes_at_iteration(bytebag_size, random_seed, previous)
File.open("crc_#{crc}_collision_payload_a.bin", "wb") {|f| f << previous_colliding }
File.open("crc_#{crc}_collision_payload_b.bin", "wb") {|f| f << bytes }
else
computed[crc] = iter
end
end
end
collider(3 * 1024, 123)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment