Exploit › Module 3 › Lesson 2
Heap Basics Named
Heap allocations from malloc/free live in dynamic memory — name chunks and lifetime on $PWN_LAB; defenders use ASan and safe alloc discipline.
Visual · pwn_heap_basics_named
Heap literacy. $PWN_LAB only. Original Cyberlium.
Opening
The heap is not one blob — allocations, frees, and reuse explain UAF and overflow impact.
malloc requests a size; the allocator returns a pointer into a heap arena. free returns the chunk to allocator bookkeeping — it may be cached or coalesced. Adjacent chunks can neighbor in memory; overflow corrupts neighbors; UAF touches recycled slots. Cyberlium names heap basics for reading ASan reports on YOUR toy C at $PWN_LAB — not heap exploit shaping tutorials. Next: Why Corruption Matters.
1. malloc/free lifecycle (named)
malloc(n) yields n bytes (with alignment padding). Caller owns pointer until free(ptr). Double-free and invalid free are error classes ASan flags.
On $PWN_LAB, trace one allocate-use-free sequence in gdb or source — document states, not grooming steps.
Command guide
Try these commands — malloc/free lifecycle (named)
═══ TOOLS & WEBSITES ═══ Browse / read these (authorized learning only — stay in YOUR lab / program scope)
Heap basics — https://man7.org/linux/man-pages/man3/malloc.3.html (allocator literacy) CWE-122 — https://cwe.mitre.org/data/definitions/122.html (heap-based overflow) pwn.college — https://pwn.college/ (heap module literacy on authorized platform)
═══ INSTALL ═══
Linux (Debian/Ubuntu):
Command — copy this
sudo apt install binutils sudo apt install curl
macOS:
Command — copy this
brew install binutils
Windows: Use WSL binutils Built-in (PowerShell: Invoke-WebRequest)
═══ LINUX / macOS ═══
Command — copy this
export LAB_PWN=${LAB_PWN:-$HOME/cyberlium-lab/t24-pwn}
readelf -S "$LAB_PWN/bin/uaf_named" | grep -E '\.data|\.bss|\.heap' | head -6
nm "$LAB_PWN/bin/uaf_named" | grep -E ' main| malloc| free' | head -6
curl -sS https://pwn.college/ | grep -i heap | head -3 || echo 'heap literacy: malloc/free live in libc — UAF corrupts allocator metadata'Primary tools to practice this lesson: readelf, curl. Reference sites: Heap basics (https://man7.org/linux/man-pages/man3/malloc.3.html); CWE-122 (https://cwe.mitre.org/data/definitions/122.html); pwn.college (https://pwn.college/). Run every command in the box — install first, then the usage lines — only on YOUR lab / program scope.
2. Heap vs stack (when each matters)
Stack: automatic locals, frame-bound lifetime. Heap: dynamic size or cross-function lifetime. Large buffers and long-lived objects often land on heap.
Corruption classes appear on both — BOF on stack locals vs heap chunks; UAF on freed heap pointers.
3. Defender observation habits
Run tests with ASan/LSan. Valgrind (where available) catches leaks and invalid access. Prefer std containers or Rust for new modules to reduce manual free mistakes.
Ship: heap lifecycle table — malloc, use, free, invalid use — with one ASan quote from YOUR toy. Next: Why Corruption Matters.
4. What you ship: heap basics table for $PWN_LAB
malloc/free lifecycle rows. Stack vs heap one-liner. ASan quote from toy. NO heap exploit recipe. chmod 600.
5. What you record before the next lesson
Date. Heap basics table. $PWN_LAB named. File t24-m03-l02-heap-basics-named.txt chmod 600.
6. Wrong vs right: weaponized exploits vs memory-safety literacy
Worked failure — same MSF word, opposite target. Right never needs a café Wi-Fi or classmate laptop.
Wrong
Heap feng shui tutorial on live service. Ignore double-free ASan report.
Right
Write heap basics table with ASan note from YOUR toy. Next: Why Corruption Matters.
Mission: name heap lifecycle
1) Write malloc/use/free/invalid-use rows. 2) Contrast stack vs heap lifetime. 3) Paste one ASan line from toy. 4) chmod 600.
Stuck? Ask Cyberlium AI Mentor
ASan turns opaque heap bugs into readable reports.
Knowledge Check
APPLY: Heap literacy on Cyberlium means:
Multiple choice
Knowledge Check
APPLY: True or False: free(ptr) returns memory to allocator bookkeeping.
True or False
Knowledge Check
APPLY: Use-after-free commonly involves:
Multiple choice