#!/usr/bin/env python # md5coll parser # by Javantea aka. Joel R. Voss """ md5coll finds an md5 collision and outputs a C formatted file. Luckily for us, it is easy to parse this file with python. This gives us a pair of binaries with the same md5. To test, we use Python's built-in md5 hash. It's easier than having to run md5sum on the two resulting files, but why not do that also. Hash collisions are cool because you can append anything to them and they still collide. cat md5coll31.bin md5coll3.py | md5sum d5dc7227898bdc128fd3fd9255d6d457 cat md5coll32.bin md5coll3.py | md5sum d5dc7227898bdc128fd3fd9255d6d457 """ import md5 import base64 import struct def parse_md5coll(filename='md5coll2a.txt', outfile='md5coll3a'): input_file = open(filename, 'r') data = input_file.read() input_file.close() lines = data.split("\n") Start1 = False Start2 = False Data1 = '' Data2 = '' for line in lines: if Start1: if line == '};': Start1 = False continue #end if Data1 += line elif Start2: if line == '};': Start2 = False continue #end if Data2 += line else: if line == 'unsigned int m0[32] = {': Start1 = True elif line == 'unsigned int m1[32] = {': Start2 = True #else: # print line #end if #end if #next line DataList1 = eval('[' + Data1 + ']') Binary1 = '' for i in DataList1: Binary1 += struct.pack("L", i) #print "Data1:", Data1, base64.b16encode(Binary1) print "md5 1:", base64.b16encode(md5.new(Binary1).digest()) d = open(outfile + '1.bin', 'wb') d.write(Binary1) d.close() DataList2 = eval('[' + Data2 + ']') Binary2 = '' for i in DataList2: Binary2 += struct.pack("L", i) #print "Data2:", Data2, base64.b16encode(Binary2) print "md5 2:", base64.b16encode(md5.new(Binary2).digest()) d = open(outfile + '2.bin', 'wb') d.write(Binary2) d.close() #end def parse_md5coll(filename, outfile) def main(): from sys import argv if len(argv) > 1: infile = argv[1] if infile == '-h' or infile == '--help': print 'Usage: python md5coll3.py infile outfile' print 'It will read infile and create two files:' print '1.bin and 2.bin' #end if else: infile = 'md5coll2a.txt' # The input file #end if if len(argv) > 2: outfile = argv[2] else: outfile = 'md5coll3' # The output file #end if try: parse_md5coll(infile, outfile) except Exception, ex: print ex #end try #end def main() if __name__ == '__main__': main() #end if