Skip to content

Commit 453859f

Browse files
committed
Internetwache CTF 2016
1 parent f87d158 commit 453859f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2580
-0
lines changed

Internetwache/2016/code90/code90.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from pwn import *
2+
3+
class Node:
4+
def __init__(self, val):
5+
self.left = None
6+
self.right = None
7+
self.val = val
8+
9+
def add(self, val):
10+
if val <= self.val:
11+
if self.left:
12+
self.left.add(val)
13+
else:
14+
self.left = Node(val)
15+
else:
16+
if self.right:
17+
self.right.add(val)
18+
else:
19+
self.right = Node(val)
20+
21+
def traverse(self):
22+
ret = [self.val]
23+
if self.right:
24+
ret += self.right.traverse()
25+
if self.left:
26+
ret += self.left.traverse()
27+
return ret
28+
29+
def invert(text):
30+
print text[:-1]
31+
arr = list(map(int, text[1:-2].split(', ')))
32+
33+
root = Node(arr[0])
34+
35+
for t in arr[1:]:
36+
root.add(t)
37+
38+
return '['+', '.join(map(str, root.traverse()))+']'
39+
40+
p = remote('188.166.133.53', 11491)
41+
42+
for i in range(50):
43+
print p.recvuntil(': ')
44+
p.sendline(invert(p.recvline()))
45+
46+
print p.recvall()

Internetwache/2016/crypto60/1.enc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
�]�cɳ*G?�� �j���� ���ً�v

Internetwache/2016/crypto60/1.pem

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIGaAgEAAh0NVkuXj50jNQSVju2LdENzKB7RQYsp8ez6gJPYzwIDAQABAh0BAmb2
3+
MYhTAdA3AXo487MZazSRzhyXAHBV/SIAAQIPA3WskWGtfkMevd8B5RTPAg8D2uLh
4+
0oll0yiwbWFd/AECDwGvxpeBtSEO+9e49qWFxQIOEF5Y/oP242S2YGoQBAECDwDN
5+
jer8WhuTNBTaClzKlQ==
6+
-----END RSA PRIVATE KEY-----

Internetwache/2016/crypto60/2.enc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
"�y5�25�Vx����R{Vu��Gr�v

Internetwache/2016/crypto60/2.pem

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIGZAgEAAh0KIzcOfQ+wAjIWSsbWQoQPxU6SAkM/knpg61rb2QIDAQABAh0AqPhN
3+
tjDOSeZO80Fs89lRNazVYNah8coVsUMJTQIPAy414Z+b/fCjkNz8KHEzAg8DL/l+
4+
pGzenAB9MeZk1sMCDkTTwTLg2OKSsRg9KJ4JAg8CjJ9vZBFTZtCZUYzlgEMCDmNH
5+
Hcos5qItEq00hJQe
6+
-----END RSA PRIVATE KEY-----

Internetwache/2016/crypto60/3.enc

29 Bytes
Binary file not shown.

Internetwache/2016/crypto60/3.pem

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIGbAgEAAh0MW2nhl55UH4XazeKqFNJyKoRvQbPbg+Zn47PRHQIDAQABAh0L3+SV
3+
tt+dM1Wr9+FzU9xLvYnlLw0MMkxCRFZGAQIPA1fMr9PDmMNYK6oE7b1BAg8DskoJ
4+
LhXyEwsmwqXrcN0CDwIqdDbGYEcs6IcBlEfjAQIPAiHd3W/NTwg3PZO5PJitAg8D
5+
O055NebR/IYkH5ghhZk=
6+
-----END RSA PRIVATE KEY-----

Internetwache/2016/crypto60/bob1.pub

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-----BEGIN PUBLIC KEY-----
2+
MDgwDQYJKoZIhvcNAQEBBQADJwAwJAIdDVZLl4+dIzUElY7ti3RDcyge0UGLKfHs
3+
+oCT2M8CAwEAAQ==
4+
-----END PUBLIC KEY-----

Internetwache/2016/crypto60/bob2.pub

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-----BEGIN PUBLIC KEY-----
2+
MDgwDQYJKoZIhvcNAQEBBQADJwAwJAIdCiM3Dn0PsAIyFkrG1kKED8VOkgJDP5J6
3+
YOta29kCAwEAAQ==
4+
-----END PUBLIC KEY-----

Internetwache/2016/crypto60/bob3.pub

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-----BEGIN PUBLIC KEY-----
2+
MDgwDQYJKoZIhvcNAQEBBQADJwAwJAIdDFtp4ZeeVB+F2s3iqhTSciqEb0Gz24Pm
3+
Z+Oz0R0CAwEAAQ==
4+
-----END PUBLIC KEY-----

Internetwache/2016/crypto60/decode.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import sys
2+
sys.stdout.write(raw_input().decode('base64'))

Internetwache/2016/crypto60/memo.txt

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<check public key information>
2+
openssl rsa -pubin -inform PEM -text -noout < bob1.pub
3+
4+
<check private key information>
5+
openssl rsa -inform PEM -text -noout < 1.pem
6+
7+
<decrypt>
8+
openssl rsautl -decrypt -inkey 1.pem -in 1.enc
9+
10+
e is all 0x10001
11+
12+
bob1.pub
13+
0d:56:4b:97:8f:9d:23:35:04:95:8e:ed:8b:74:43:73:28:1e:d1:41:8b:29:f1:ec:fa:80:93:d8:cf
14+
359567260516027240236814314071842368703501656647819140843316303878351
15+
16+
17963604736595708916714953362445519
17+
20016431322579245244930631426505729
18+
19+
bob2.pub
20+
0a:23:37:0e:7d:0f:b0:02:32:16:4a:c6:d6:42:84:0f:c5:4e:92:02:43:3f:92:7a:60:eb:5a:db:d9
21+
273308045849724059815624389388987562744527435578575831038939266472921
22+
23+
16514150337068782027309734859141427
24+
16549930833331357120312254608496323
25+
26+
bob3.pub
27+
0c:5b:69:e1:97:9e:54:1f:85:da:cd:e2:aa:14:d2:72:2a:84:6f:41:b3:db:83:e6:67:e3:b3:d1:1d
28+
333146335555060589623326457744716213139646991731493272747695074955549
29+
30+
17357677172158834256725194757225793
31+
19193025210159847056853811703017693
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
DK9dt2MTybMqRz/N2RUMq2qauvqFIOnQ89mLjXY=
2+
3+
AK/WPYsK5ECFsupuW98bCFKYUApgrQ6LTcm3KxY=
4+
5+
CiLSeTUCCKkyNf8NVnifGKKS2FJ7VnWKnEdygXY=
+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
from pwn import *
2+
import hashlib
3+
import binascii
4+
import textwrap
5+
import random
6+
7+
def binary_string(s):
8+
return bin(int(binascii.hexlify(s),16)).lstrip("0b")
9+
10+
def te(s):
11+
p = 1 << 7
12+
return s + "0" * (p-len(s)%p)
13+
14+
def wrap64(s):
15+
return textwrap.wrap(s, 64) #64
16+
17+
def wrap16(s):
18+
return textwrap.wrap(s, 16) #16
19+
20+
def ti(l):
21+
return int(l,2)
22+
23+
def tr(x,y):
24+
return (x<< y) or (x >> (16-y));
25+
26+
def th(x):
27+
return "{0:#0{1}x}".format(x,8)
28+
29+
def tp(x,y):
30+
s = th(x) + th(y)
31+
s = s.replace("0x","")
32+
return s
33+
34+
def myhash(text):
35+
36+
b = binary_string(text)
37+
38+
p = te(b)
39+
40+
bl = wrap64(p)
41+
42+
t11 = 3
43+
q2 = 5
44+
45+
tu = [ y**2 for y in range(16)]
46+
to = [2, 7, 8, 2, 5, 3, 7, 8, 9, 4, 11, 13, 5, 8, 14, 15]
47+
48+
for i in bl:
49+
t1 = t11
50+
t2 = q2
51+
52+
tl = wrap16(i)
53+
tq = map(ti, tl)
54+
55+
for j in range(16):
56+
if(j >= 12 ):
57+
tz = (tq[0] & tq[1]) | ~tq[2]
58+
elif(j >= 8):
59+
tz = (tq[3] | tq[2])
60+
elif(j >= 4):
61+
tz = (~tq[2] & tq[0]) & (tq[1] | ~tq[0])
62+
elif(j >= 0):
63+
tz = (tq[0] | ~tq[2]) | tq[1]
64+
else:
65+
pass
66+
67+
t1 = t1 + tr(tz + tu[j] + tq[j%(16>>2)],to[j])
68+
t2 = t1 + tr(t2,to[j]) %t1
69+
70+
t11 += t1
71+
q2 += t2
72+
73+
t11 = t11 % 0xFF # Should be 0xFFFFFFFF, right?
74+
q2 = q2 % 0xFF # Same here... 0xFFFFFFFF
75+
76+
return tp(t11,q2)
77+
78+
p = remote('188.166.133.53', 10009)
79+
80+
p.recvuntil('It has ')
81+
prefix = p.recvn(8)
82+
log.info('prefix is %s' % prefix)
83+
84+
now = 0
85+
while 1:
86+
cand = prefix + '%07x' % now
87+
m = hashlib.sha1()
88+
m.update(cand)
89+
h = m.digest().encode('hex')
90+
if h[-4:] == '0000':
91+
log.info('string is %s' % cand)
92+
log.info('hash is %s' % h)
93+
break
94+
now += 1
95+
96+
p.sendline(cand)
97+
98+
now = 0
99+
while 1:
100+
cand = ''
101+
for i in range(18):
102+
cand += random.choice('0123456789abcdefghijklmnopqrstuvwxyz')
103+
h = myhash(cand)
104+
log.info('string %s - hash %s' % (cand, h))
105+
if h == '00006800007d':
106+
break
107+
now += 1
108+
109+
log.info(cand)
110+
log.info(myhash(cand))
111+
p.interactive()
112+

Internetwache/2016/crypto70/myhash.py

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/python2
2+
import binascii
3+
import textwrap
4+
5+
def binary_string(s):
6+
return bin(int(binascii.hexlify(s),16)).lstrip("0b")
7+
8+
def te(s):
9+
p = 1 << 7
10+
return s + "0" * (p-len(s)%p)
11+
12+
def wrap64(s):
13+
return textwrap.wrap(s, 64) #64
14+
15+
def wrap16(s):
16+
return textwrap.wrap(s, 16) #16
17+
18+
def ti(l):
19+
return int(l,2)
20+
21+
def tr(x,y):
22+
return (x<< y) or (x >> (16-y));
23+
24+
def th(x):
25+
return "{0:#0{1}x}".format(x,8)
26+
27+
def tp(x,y):
28+
s = th(x) + th(y)
29+
s = s.replace("0x","")
30+
return s
31+
32+
def myhash(text):
33+
34+
b = binary_string(text)
35+
36+
p = te(b) # 뒤에 0을 붙여 길이를 128의 배수로 만듦
37+
38+
bl = wrap64(p)
39+
40+
t11 = 3
41+
q2 = 5
42+
43+
tu = [ y**2 for y in range(16)]
44+
to = [2, 7, 8, 2, 5, 3, 7, 8, 9, 4, 11, 13, 5, 8, 14, 15]
45+
46+
for i in bl:
47+
t1 = t11
48+
t2 = q2
49+
50+
tl = wrap16(i)
51+
tq = map(ti, tl)
52+
53+
for j in range(16):
54+
if(j >= 12 ):
55+
tz = (tq[0] & tq[1]) | ~tq[2]
56+
elif(j >= 8):
57+
tz = (tq[3] | tq[2])
58+
elif(j >= 4):
59+
tz = (~tq[2] & tq[0]) & (tq[1] | ~tq[0])
60+
elif(j >= 0):
61+
tz = (tq[0] | ~tq[2]) | tq[1]
62+
else:
63+
pass
64+
65+
t1 = t1 + tr(tz + tu[j] + tq[j%(16>>2)],to[j])
66+
t2 = t1 + tr(t2,to[j]) %t1
67+
68+
t11 += t1
69+
q2 += t2
70+
71+
t11 = t11 % 0xFF # Should be 0xFFFFFFFF, right?
72+
q2 = q2 % 0xFF # Same here... 0xFFFFFFFF
73+
74+
return tp(t11,q2)
75+
76+
77+
while 1:
78+
r = raw_input("Text: ")
79+
print myhash(r)

0 commit comments

Comments
 (0)