/
exp.py
137 lines (122 loc) · 2.83 KB
/
exp.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import copy
import string
import itertools as it
from pwn import *
import json
FLAG_FORMAT = b'TQLCTF{.+}'
context(log_level='info', os='linux', arch='amd64')
if args.REMOTE:
r = remote('47.106.193.146', 41245)
else:
r = remote('localhost', 65101)
def move(direction):
r.sendlineafter(b'>', direction)
return r.recvline().decode().strip()
def up(aim=None):
global X, Y
with log.progress(f'U {aim}'):
if aim is None:
times = 0
while times < 20:
ret = move(b'w')
if ret == 'Cannot be moved':
times += 1
else:
times = 0
else:
while int(X) != aim:
ret = move(b'w')
if ret != 'Cannot be moved':
X -= float(ret.split(' ')[-1])
log.success(f'{X} {Y}')
def down(aim=None):
global X, Y
with log.progress(f'D {aim}'):
if aim is None:
times = 0
while times < 20:
ret = move(b's')
if ret == 'Cannot be moved':
times += 1
else:
times = 0
else:
while int(X) != aim:
ret = move(b's')
if ret != 'Cannot be moved':
X += float(ret.split(' ')[-1])
log.success(f'{X} {Y}')
def left(aim=None):
global X, Y
with log.progress(f'L {aim}'):
if aim is None:
times = 0
while times < 20:
ret = move(b'a')
if ret == 'Cannot be moved':
times += 1
else:
times = 0
else:
while int(Y) != aim:
ret = move(b'a')
if ret != 'Cannot be moved':
Y -= float(ret.split(' ')[-1])
if Y < 0:
Y += 75
log.success(f'{X} {Y}')
def right(aim=None):
global X, Y
with log.progress(f'R {aim}'):
if aim is None:
times = 0
while times < 20:
ret = move(b'd')
if ret == 'Cannot be moved':
times += 1
else:
times = 0
else:
while int(Y) != aim:
ret = move(b'd')
if ret != 'Cannot be moved':
Y += float(ret.split(' ')[-1])
log.success(f'{X} {Y}')
up()
right()
X = 2
Y = 8
left(10)
down(17)
right(16)
down(19)
right(34)
up(10)
right(39)
down(14)
right(43)
down(19)
right(52)
up(7)
right(65)
down(28)
left(61)
down(30)
left(52)
down(35)
right(57)
down(42)
left(44)
up(37)
left(34)
down(40)
left(21)
up(34)
left(15)
down(40)
left(8)
down(45)
right(41)
r.recvuntil(b'Here is your flag: ')
flag = r.recvregexS(FLAG_FORMAT)
log.success(f'Flag: {flag}')