Created
January 2, 2021 19:35
-
-
Save julik/a821886356a802050284c2a37aa2f3df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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