#!/usr/bin/env python3 from coll import Collider, md5pad, filter_disallow_binstrings file = open("../files/grade.txt", "r") # Generate a 213-way collision as a test c = Collider(pad=b' ', blockfilter=filter_disallow_binstrings([b'\0'])) # begin the output files with hello world text c.strcat(file.read()) # Diverge 8 times. That means 2^8 possibilities for i in range(8): print('Stage {} of 8'.format(i+1)) # we fork into 2 different possibilities of collision blocks (128 byte garbage each) here c.diverge() # place some text in the middle of each divergence c.strcat('More text: {}\n'.format(i)) c.strcat('\nFinal.') # Select the first 213 collisions to output to file for i,data in enumerate(c.get_collisions(count=213)): with open('out_test_%03d.txt' % i, 'wb') as f: f.write(data) print('Done')
if compdata[q] == ord('+') or compdata[q] == ord('-'): startchars = q - (64 * 3) if not first: first = i offset = i - startchars else: second = startchars + offset compdata[q] = 0 break if not (first and second): raise Exception('error: did not find marker strings') # Splice in the collision blocks according to the obtained offsets collider = Collider(blockfilter=filter_disallow_binstrings([b'\0'])) collider.bincat(compdata[:first]) collider.safe_diverge() c1, c2 = collider.get_last_coll() collider.bincat(compdata[first + 128:second] + c1 + compdata[second + 128:]) # Write out good and evil binaries cols = collider.get_collisions() GOOD = 'out_c_good' EVIL = 'out_c_evil' with open(GOOD, 'wb') as good: good.write(next(cols)) with open(EVIL, 'wb') as evil: