Skip to content

Instantly share code, notes, and snippets.

@budanthara
Last active April 27, 2016 18:08
Show Gist options
  • Save budanthara/4da07d80a868e145cb911e37715df5c9 to your computer and use it in GitHub Desktop.
Save budanthara/4da07d80a868e145cb911e37715df5c9 to your computer and use it in GitHub Desktop.
...
# Usage: python filename.py originalfile collisionfile
# snoww0lf
import sys
from hashlib import *
coll_find = [19, 45, 59, 83, 109, 123]
d_out = []
def to_hex_conversion(data):
return hex(ord(data))
def find_coll(data, data_l):
return ((data + data_l) & 0xff)
def colliding(recv_data, c_file):
out = []
for i in range(0, len(recv_data)):
out.append(hex(int(recv_data[i])))
for j in range(0, len(out)):
d_out[coll_find[j]] = out[j]
final = []
w_final = ""
for i in range(0, len(d_out)):
v = "%s" % (''.join(d_out[i]))
final.append(int(v, 16))
for j in range(0, len(final)):
w_final += chr(final[j])
# Integrity.
print "MD5 =>", md5(w_final).hexdigest()
print "SHA256 =>", sha256(w_final).hexdigest()
w_collision_file = open(c_file,'w')
w_collision_file.write(w_final)
return out
def collision_check(recv_data, data_l, c_file):
_hex = []
for i in range(0, len(coll_find)):
v = "%s" % (recv_data[coll_find[i]])
d_str = int(v, 16)
_hex.append(find_coll(d_str, data_l))
#print v
return colliding(_hex, c_file)
def main():
global d_out
try:
original_file = sys.argv[1]
collision_file = sys.argv[2]
op = open(original_file,'r')
for p_data in op.read():
d_out.append(''.join(to_hex_conversion(p_data)).split(","))
origin = []
for i in range(0, len(d_out)):
origin.append(''.join(d_out[i]))
collision_check(origin, len(open(original_file,'r').read()), collision_file)
except Exception, e:
print e
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment