Một mục mã nguồn mở trong kho dữ liệu GitHub của TopGit: shellphish/how2heap, 8.8k sao, C. A repository for learning various heap exploitation techniques.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
This repo is for learning various heap exploitation techniques.
We use Ubuntu's Libc releases as the gold-standard. Each technique is verified to work on corresponding Ubuntu releases.
You can run apt source libc6 to download the source code of the Libc you are using on a Debian-based operating system. You can also click :arrow_forward: to debug the technique in your browser using gdb.
We came up with the idea during a hack meeting, and have implemented the following techniques:
File
:arrow_forward:
Technique
Glibc-Version
Patch
Applicable CTF Challenges
first_fit.c
Demonstrating glibc malloc's first-fit behavior.
calc_tcache_idx.c
Demonstrating glibc's tcache index calculation.
fastbin_dup.c
:arrow_forward:
Tricking malloc into returning an already-allocated heap pointer by abusing the fastbin freelist.
< 2.43
patch
fastbin_dup_into_stack.c
:arrow_forward:
Tricking malloc into returning a nearly-arbitrary pointer by abusing the fastbin freelist.
< 2.43
patch
9447-search-engine, 0ctf 2017-babyheap
fastbin_dup_consolidate.c
:arrow_forward:
Tricking malloc into returning an already-allocated heap pointer by putting a pointer on both fastbin freelist and the top chunk.
< 2.43
patch
Hitcon 2016 SleepyHolder
unsafe_unlink.c
:arrow_forward:
Exploiting free on a corrupted chunk to get arbitrary write.
latest
HITCON CTF 2014-stkof, Insomni'hack 2017-Wheel of Robots
house_of_spirit.c
:arrow_forward:
Frees a fake fastbin chunk to get malloc to return a nearly-arbitrary pointer.
latest
hack.lu CTF 2014-OREO
poison_null_byte.c
:arrow_forward:
Exploiting a single null byte overflow.
latest
PlaidCTF 2015-plaiddb, BalsnCTF 2019-PlainNote
house_of_lore.c
:arrow_forward:
Tricking malloc into returning a nearly-arbitrary pointer by abusing the smallbin freelist.
latest
overlapping_chunks.c
:arrow_forward:
Exploit the overwrite of a freed chunk size in the unsorted bin in order to make a new allocation overlap with an existing chunk
< 2.29
patch
hack.lu CTF 2015-bookstore, Nuit du Hack 2016-night-deamonic-heap
overlapping_chunks_2.c
:arrow_forward:
Exploit the overwrite of an in use chunk size in order to make a new allocation overlap with an existing chunk
< 2.29
patch
mmap_overlapping_chunks.c
Exploit an in use mmap chunk in order to make a new allocation overlap with a current mmap chunk
latest
house_of_force.c
:arrow_forward:
Exploiting the Top Chunk (Wilderness) header in order to get malloc to return a nearly-arbitrary pointer
< 2.29
patch
Boston Key Party 2016-cookbook, BCTF 2016-bcloud
unsorted_bin_into_stack.c
:arrow_forward:
Exploiting the overwrite of a freed chunk on unsorted bin freelist to return a nearly-arbitrary pointer.
< 2.29
patch
unsorted_bin_attack.c
:arrow_forward:
Exploiting the overwrite of a freed chunk on unsorted bin freelist to write a large value into arbitrary address
< 2.29
patch
0ctf 2016-zerostorage
large_bin_attack.c
:arrow_forward:
Exploiting the overwrite of a freed chunk on large bin freelist to write a large value into arbitrary address
< 2.42
patch
0ctf 2018-heapstorm2
house_of_einherjar.c
:arrow_forward:
Exploiting a single null byte overflow to trick malloc into returning a controlled pointer
latest
Seccon 2016-tinypad
house_of_water.c
Exploit a UAF or double free to gain leakless control of the t-cache metadata and a leakless way to link libc in t-cache
latest
37c3 Potluck - Tamagoyaki
sysmalloc_int_free.c
Demonstrating freeing the nearly arbitrary sized Top Chunk (Wilderness) using malloc (sysmalloc _int_free() )
latest
house_of_orange.c
:arrow_forward:
Exploiting the Top Chunk (Wilderness) in order to gain arbitrary code execution
< 2.26
patch
Hitcon 2016 houseoforange
house_of_tangerine.c
Exploiting the Top Chunk (Wilderness) in order to trick malloc into returning a completely arbitrary pointer by abusing the tcache freelist
>= 2.26
PicoCTF 2024- high frequency troubles
house_of_roman.c
:arrow_forward:
Leakless technique in order to gain remote code execution via fake fastbins, the unsorted_bin attack and relative overwrites.
< 2.29
patch
tcache_poisoning.c
:arrow_forward:
Tricking malloc into returning a completely arbitrary pointer by abusing the tcache freelist. (requires heap leak on and after 2.32)
> 2.25
patch
tcache_house_of_spirit.c
:arrow_forward:
Frees a fake chunk to get malloc to return a nearly-arbitrary pointer.
> 2.25
house_of_botcake.c
:arrow_forward:
Bypass double free restriction on tcache. Make tcache_dup great again.
> 2.25
tcache_stashing_unlink_attack.c
:arrow_forward:
Exploiting the overwrite of a freed chunk on small bin freelist to trick malloc into returning an arbitrary pointer and write a large value into arbitraty address with the help of calloc.
> 2.25
Hitcon 2019 one punch man
fastbin_reverse_into_tcache.c
:arrow_forward:
Exploiting the overwrite of a freed chunk in the fastbin to write a large value into an arbitrary address.
2.26 - 2.42
patch
house_of_mind_fastbin.c
:arrow_forward:
Exploiting a single byte overwrite with arena handling to write a large value (heap pointer) to an arbitrary address
< 2.43
patch
house_of_storm.c
:arrow_forward:
Exploiting a use after free on both a large and unsorted bin chunk to return an arbitrary chunk from malloc
< 2.29
house_of_gods.c
:arrow_forward:
A technique to hijack a thread's arena within 8 allocations
< 2.27
decrypt_safe_linking.c
:arrow_forward:
Decrypt the poisoned value in linked list to recover the actual pointer
>= 2.32
safe_link_double_protect.c
Leakless bypass for PROTECT_PTR by protecting a pointer twice, allowing for arbitrary pointer linking in t-cache
>= 2.32
37c3 Potluck - Tamagoyaki
tcache_dup.c(obsolete)
Tricking malloc into returning an already-allocated heap pointer by abusing the tcache freelist.
2.26 - 2.28
patch
tcache_metadata_poisoning.c
Trick the tcache into providing arbitrary pointers by manipulating the tcache metadata struct
>= 2.26
house_of_io.c
Tricking malloc into return a pointer to arbitrary memory by manipulating the tcache management struct by UAF in a free'd tcache chunk.
2.31 - 2.33
tcache_relative_write.c
Arbitrary decimal value and chunk pointer writing in heap by out-of-bounds tcache metadata writing
2.30-2.41
patch
tcache_metadata_hijacking
Arbitrary allocation by overflow into tcache metadata
>= 2.42
The GnuLibc is under constant development and several of the techniques above have let to consistency checks introduced in the malloc/free logic.
Consequently, these checks regularly break some of the techniques and require adjustments to bypass them (if possible).
We address this issue by keeping multiple versions of the same technique for each Glibc-release that required an adjustment.
The structure is glibc_<version>/technique.c.
Have a good example?
Add it here!
Try to inline the whole technique in a single .c -- it's a lot easier to learn that way.
Get Started
Quick Setup
make sure you have the following packages/tools installed: patchelf zstd wget (of course also build-essential or similar for compilers, make, ...)
also, /usr/bin/python must be/point to your python binary (e. g. /usr/bin/python3)
git clone https://github.com/shellphish/how2heap
cd how2heap
make clean base
./malloc_playground
Notice that this will link the binaries with your system libc. If you want to play with other libc versions. Please refer to Complete Setup.
Complete Setup
You will encounter symbol versioning issues (see this) if you try to LD_PRELOAD libcs to a binary that's compiled on your host machine.
We have two ways to bypass it.
Method 1: link against older libc
This one tells linker to link the target binary with the target libc.
git clone https://github.com/shellphish/how2heap
cd how2heap
H2H_USE_SYSTEM_LIBC=N make v2.23
This will link all the binaries against corresponding libcs. What's better is that it comes with debug symbols. Now you can play with any libc versions on your host machine.
In this example, it will compile all glibc-2.23 binaries and link them with libc-2.23. You can change the number to play with other libc versions.
Method 2: use docker
This uses Docker-based approach to complie binaries inside an old ubuntu container so it is runnable with the target libc version.
git clone https://github.com/shellphish/how2heap
cd how2heap
# the next command will prepare the target binary so it runs with
# the expected libc version
make base
./glibc_run.sh 2.30 ./malloc_playground -d -p
# now you can play with the binary with glibc-2.30
# and even debug it with the correct symbols
readelf -d -W malloc_playground | grep RUNPATH # or use checksec
readelf -l -W malloc_playground | grep interpreter
gdb -q -ex "start" ./malloc_playground
Heap Exploitation Tools
There are some heap exploitation tools floating around.
Malloc Playground
The malloc_playground.c file given is the source for a program that prompts the user for commands to allocate and free memory interactively.
Pwngdb
Examine the glibc heap in gdb: https://github.com/scwuaptx/Pwngdb
pwndbg
An exploitation-centric gdb plugin that provides the ability to view/tamper with the glibc heap: https://github.com/pwndbg/pwndbg
gef
Another excellent gdb plugin that provides the ability to examine the glibc heap: https://github.com/hugsy/gef
heap-viewer
Examine the glibc heap in IDA Pro: https://github.com/danigargu/heap-viewer
heaptrace
Helps you visualize heap operations by replacing addresses with symbols: https://github.com/Arinerron/heaptrace
Other resources
Some good heap exploitation resources, roughly in reverse order of their publication, are:
Useful heap exploitation tutorials
Overview of GLIBC heap exploitation techniques (https://0x434b.dev/overview-of-glibc-heap-exploitation-techniques/)
glibc in-depth tutorial (https://heap-exploitation.dhavalkapil.com/) - book and exploit samples
Heap exploitation techniques that work on glibc-2.31 (https://github.com/StarCross-Tech/heap_exploit_2.31)
Painless intro to the Linux userland heap (https://sensepost.com/blog/2017/painless-intro-to-the-linux-userland-heap/)
ptmalloc fanzine, a set of resources and examples related to meta-data attacks on ptmalloc (http://tukan.farm/2016/07/26/ptmalloc-fanzine/)
Glibc Adventures: The Forgotten Chunk (https://github.com/bash-c/slides/blob/master/pwn_heap/Glibc%20Adventures:%20The%20forgotten%20chunks.pdf) - advanced heap exploitation
The House Of Lore: Reloaded (http://phrack.org/issues/67/8.html)
Malloc Des-Maleficarum (http://phrack.org/issues/66/10.html) - some malloc exploitation techniques
Yet another free() exploitation technique (http://phrack.org/issues/66/6.html)
The use of set_head to defeat the wilderness (http://phrack.org/issues/64/9.html)
Understanding the heap by breaking it (https://www.blackhat.com/presentations/bh-usa-07/Ferguson/Whitepaper/bh-usa-07-ferguson-WP.pdf) - explains heap implementation and a couple exploits
OS X heap exploitation techniques (http://phrack.org/issues/63/5.html)
The Malloc Maleficarum (http://seclists.org/bugtraq/2005/Oct/118)
Exploiting The Wilderness (http://seclists.org/vuln-dev/2004/Feb/25)
There are a couple of "hardening" measures embedded in glibc, like export MALLOC_CHECK_=1 (enables some checks), export MALLOC_PERTURB_=1 (data is overwritten), export MALLOC_MMAP_THRESHOLD_=1 (always use mmap()), ...
More info: mcheck(), mallopt().
There's also some tracing support as mtrace(), malloc_stats(), malloc_info(), memusage, and in other functions in this family.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/shellphish/how2heap là nguồn chính thức.
shellphish/how2heap có bao nhiêu sao?
shellphish/how2heap có 8.8k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/shellphish/how2heap. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
shellphish/how2heap có phải mã nguồn mở không?
Có — shellphish/how2heap phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/shellphish/how2heap.
shellphish/how2heap còn đang phát triển không?
Commit gần nhất trên shellphish/how2heap là 3 tháng trước (theo timestamp GitHub). Repo có 1.3k fork — một chỉ báo về mức độ quan tâm của cộng đồng.
shellphish/how2heap dùng license gì?
shellphish/how2heap phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
shellphish/how2heap là gì?
shellphish/how2heap (shellphish/how2heap) là dự án C trên GitHub. Theo mô tả gốc: A repository for learning various heap exploitation techniques.
shellphish/how2heap viết bằng ngôn ngữ gì?
shellphish/how2heap chủ yếu viết bằng C. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc how2heap có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về how2heap.