-
Notifications
You must be signed in to change notification settings - Fork 0
/
greed_inferno_ctf.py
60 lines (51 loc) · 1.37 KB
/
greed_inferno_ctf.py
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
49
50
51
52
53
54
55
56
57
58
59
60
from pwn import *
from ctypes import CDLL
import time
libc = CDLL('libc-2.31.so')
addr = 'iitmandi.co.in'
operation = ['+', '-', '*']
s = remote(addr, 9696)
# Seed srand with time(0)
now = int(time.time())
libc.srand(now)
s.recv()
s.send(b'2\n')
def predictMath():
a = libc.rand() % 100
b = libc.rand() % 100
op = operation[libc.rand() % 3];
print("MINE {}{}{}?".format(a,op,b))
def predictSlot():
lot_chars = ['$', '%', '&', '*', '#', '?', '@']
a_lot = lot_chars[libc.rand() % 7]
b_lot = lot_chars[libc.rand() % 7]
c_lot = lot_chars[libc.rand() % 7]
print("MY PREDICTION : {} {} {}".format(a_lot,b_lot,c_lot))
return a_lot==b_lot==c_lot
predictMath()
q = s.recv().split()[-1]
print("THEIR {}".format(q.decode()))
ans = repr(eval(q[:-1]))
s.sendline(ans.encode())
for i in range(49):
predictMath()
q = s.recv().strip()
print("THEIR {}".format(q.decode()))
ans = repr(eval(q[:-1]))
s.sendline(ans.encode())
money = 1000
print(s.recv())
for i in range(20):
print(money)
pred = predictSlot()
if pred:
s.sendline('1000')
money += 1000
else:
s.sendline('-10000')
money += 10000
slot = s.recv().decode()
print(slot)
if 'Spinning the reels' not in slot:
break
#FLAG : dante{7he_h19hes7_weal7h_1s_7he_a8sence_0f_9reed}