Example #1
0
#!/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')
c1, c2 = collider.get_last_coll()

postfix += c1

postfix += b"""'''

if (same == diff):
    print "good"

else:
    print "evil"

"""

# Close the 'diff' variable string and declare the 'same' variable to always have the 1st collision block
# Thus for one file: same == diff, but for the other: same != diff
collider.bincat(postfix)

# Write out the good and evil scripts
cols = collider.get_collisions()

GOOD = 'out_py_good.py'
EVIL = 'out_py_evil.py'

with open(GOOD,  'wb') as good:
    good.write(next(cols))
    
with open(EVIL, 'wb') as evil:
    evil.write(next(cols))

os.system('chmod +x {} {}'.format(GOOD, EVIL))
#!/usr/bin/env python3

from coll import Collider, md5pad, filter_disallow_binstrings

# 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('Hello world.')

# 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')
Example #4
0
            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:
    evil.write(next(cols))

os.system('chmod +x {} {}'.format(GOOD, EVIL))
os.remove(temp)