-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsomnia2016_crypto_solution.py
More file actions
48 lines (43 loc) · 1.11 KB
/
insomnia2016_crypto_solution.py
File metadata and controls
48 lines (43 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import struct
import os
import hashlib
from binascii import hexlify
import socket
import itertools
serv='bringthenoise.insomnihack.ch'
port=1111
buffer2=1024
POWLEN=5
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((serv, port))
sock.send('')
data = sock.recv(buffer2)[12:17]
print "Hash to process: %s" % data
rdata=0
while (hashlib.md5(str(rdata).encode('ascii')).hexdigest().strip()[:5] != data):
rdata=rdata+1
print "Success! %s" % str(rdata).encode('ascii')
sock.send(str(rdata).encode('ascii')+'\n')
data = sock.recv(buffer2)
data = data + sock.recv(buffer2)
coefs = data.split('\n')
coefs = coefs[0:-2]
eq = [map(lambda x: int(x), e.split(', ')) for e in coefs]
print "eq:"
print eq
for s in itertools.product(range(8), repeat=6):
allok = True
for e in eq:
result = sum(s[i]*e[i] for i in range(6)) % 8
thisok=False
for v in [-1,0,1]:
thisok = thisok or (e[6] == (result + 8 + v) % 8)
allok = allok and thisok
if allok:
print "PWNZ"
print s
sock.send(str(s)[1:-1]+'\n')
data = sock.recv(buffer2)
print data
break
sock.close()