Code Monkey home page Code Monkey logo

how2heap_zh's Introduction

简介

本项目主要为How2heap提供了一份中文翻译,尽可能的做到尊重原文,便于读者理解。

如果有帮到各位师傅,还请动动手点个Star吧!如果发现本文有任何谬误或对本文有任何建议,欢迎提交commit。

正在施工中。。。

堆利用教程

这个仓库用于学习各种堆利用技术。我们使用Ubuntu的Libc版本作为黄金标准。每种技术都经过验证的,可以在相应的Ubuntu版本上正常工作。您可以运行“apt source libc6”来下载您在基于Debian的操作系统上使用的Libc的源代码。您还可以单击:arrow_forward:使用gdb在浏览器中调试技术。

我们在黑客会议期间想出了这个想法,并实现了以下技术:

文件 ▶️ 技术概括 Glibc-版本 补丁(patch) 相关的CTF挑战
first_fit.c 展示glibc malloc使用first-fit算法的方式。
calc_tcache_idx.c 展示glibc的tcache索引计算方式。
fastbin_dup.c ▶️ 通过利用 fastbin 的 freelist 来诱骗 malloc 返回已分配的堆指针。 最新
fastbin_dup_into_stack.c ▶️ 通过利用 fastbin 的 freelist 来诱骗 malloc 返回几乎任意的指针。 最新 9447-search-engine, 0ctf 2017-babyheap
fastbin_dup_consolidate.c ▶️ 通过将指针放在 fast bin freelist 和 unsorted bin freelist 中来诱骗 malloc 返回已分配的堆指针。 最新 Hitcon 2016 SleepyHolder
unsafe_unlink.c ▶️ 利用损坏的块进行自由攻击,能够进行任意地址写入。 最新 HITCON CTF 2014-stkof, Insomni'hack 2017-Wheel of Robots
house_of_spirit.c ▶️ free 一个伪造的 fastbin chunk 使 malloc 返回一个几乎任意的指针。 最新 hack.lu CTF 2014-OREO
poison_null_byte.c ▶️ 利用单个空字节溢出。 最新 PlaidCTF 2015-plaiddb, BalsnCTF 2019-PlainNote
house_of_lore.c ▶️ 通过利用 small bin freelist 来诱骗 malloc 返回几乎任意的指针。 最新
overlapping_chunks.c ▶️ 利用 unsorted bin 中释放的区块大小的覆盖,以使新的分配与现有区块重叠 < 2.29 补丁 hack.lu CTF 2015-bookstore, Nuit du Hack 2016-night-deamonic-heap
overlapping_chunks_2.c ▶️ 覆盖正在使用的区块大小,使新的分配与现有区块重叠 < 2.29 补丁
mmap_overlapping_chunks.c 利用正在使用的 mmap 区块,使新的分配与当前 mmap 区块重叠 最新
house_of_force.c ▶️ 利用 top chunk (Wilderness)header 来让 malloc 返回几乎任意的指针 < 2.29 补丁 Boston Key Party 2016-cookbook, BCTF 2016-bcloud
unsorted_bin_into_stack.c ▶️ 覆盖 unsorted bin freelist 上的已被释放的堆块来返回几乎任意的指针。 < 2.29 补丁
unsorted_bin_attack.c ▶️ 覆盖 unsorted bin freelist 上的已被释放的堆块将一个较大的值写入任意地址 < 2.29 补丁 0ctf 2016-zerostorage
large_bin_attack.c ▶️ 覆盖 large bin freelist 上的已被释放的堆块将一个较大的值写入任意地址 最新 0ctf 2018-heapstorm2
house_of_einherjar.c ▶️ 利用单个空字节溢出诱骗 malloc 返回受控指针 最新 Seccon 2016-tinypad
house_of_orange.c ▶️ 利用 top chunk(Wilderness)来进行任意代码执行 < 2.26 补丁 Hitcon 2016 houseoforange
house_of_roman.c ▶️ 一种无泄漏技术,以通过伪造的fastbins,unsorted bin和相对覆盖来实现远程代码执行。 < 2.29 补丁
tcache_poisoning.c ▶️ 通过利用 tcache freelist 来诱骗 malloc 返回完全任意的指针。(glibc版本至少要在2.32以上并且同时需要对堆泄漏进行利用) > 2.25 补丁
tcache_house_of_spirit.c ▶️ 释放一个伪造的块,让 malloc 返回一个几乎任意的指针。 > 2.25
house_of_botcake.c ▶️ 绕过tcache的双重释放检查机制。Make tcache_dup great again! > 2.25
tcache_stashing_unlink_attack.c ▶️ 覆盖 small bin freelist 上的已被释放的块来诱骗 malloc 返回任意指针,并在 calloc 的帮助下将一个较大的值写入任意地址。 > 2.25 Hitcon 2019 one punch man
fastbin_reverse_into_tcache.c ▶️ 覆盖 fastbin 中已被释放的块将一个较大的值写入任意地址。 > 2.25
house_of_mind_fastbin.c ▶️ 利用arena处理的单字节覆盖将一个较大的值(堆指针)写入任意地址 最新
house_of_storm.c ▶️ 利用对 large bin 和unsorted bin 的 use-after-free 漏洞以从 malloc 返回任意的块 < 2.29
house_of_gods.c ▶️ 一种在 8 次分配以内劫持线程arena的技术 < 2.27
decrypt_safe_linking.c ▶️ 解密链表中的poisoned value来恢复实际指针 >= 2.32
tcache_dup.c(已废弃) 利用 tcache freelist 诱骗 malloc 返回已分配的堆指针。 2.26 - 2.28 补丁

用法

获取仓库

$ git clone https://github.com/ffreeez/how2heap_zh
$ cd ./how2heap_zh
$ git submodule update --init --recursive

在根目录下直接make即可

$ cd ./how2heap_zh
$ make

使用glibc_run.sh来执行可执行文件,可以更方便的替换glibc 在使用这个脚本之前,需要安装patchelf,并且要在glibc-all-in-one项目中更新可下载的列表

$ sudo apt install patchelf
$ cd ./how2heap_zh/glibc-all-in-one
$ chmod +x ./*
$ ./update_list

执行update_list时,可能会提示-bash: ./update_list: /usr/bin/python: bad interpreter: No such file or directory ,在文本编辑器中把update_list文件中的第一行#!/usr/bin/python改为#!/usr/bin/python3即可

[用法] ./glibc_run.sh <glibc版本号> <可执行文件> [-h] [-i686] [-u] [-r] [-gdb | -r2 | -p]
-i686 -使用32位的libc
-u 在glibc-all-in-one中更新libc列表
-r 在glibc-all-in-one中下载libc
-gdb -在gdb中执行目标文件
-r2 -在radare2中执行目标文件
-p -只在可执行文件中修改interpreter和rpath来指向对应的glibc并且不执行

eg: ./glibc_run.sh 2.23 ./first_fit

Gnu Libc 正在不断发展,上面的几种技术已经允许在 malloc/free 逻辑中引入一致性检查。 因此,这些检查会定期破坏某些技术,并需要进行调整以绕过它们(如果可能)。 我们通过为每个需要调整的 Glibc 版本保留相同技术的多个版本来解决此问题。 项目结构为glibc_<version>/技术名称.c

堆利用工具

这里有一些广为流传的堆利用工具,具体内容暂不做翻译(懒懒。

shadow

jemalloc exploitation framework: https://github.com/CENSUS/shadow

libheap

Examine the glibc heap in gdb: https://github.com/cloudburst/libheap

heap-viewer

Examine the glibc heap in IDA Pro: https://github.com/danigargu/heap-viewer

heapinspect

A Python based heap playground with good visualization for educational purposes: https://github.com/matrix1001/heapinspect

Forkever

Debugger that lets you set "checkpoints" as well as view and edit the heap using a hexeditor: https://github.com/haxkor/forkever

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

heaptrace

Helps you visualize heap operations by replacing addresses with symbols: https://github.com/Arinerron/heaptrace

Heap Search

Search for applicable heap exploitation techniques based on primitive requirements: https://kissprogramming.com/heap/heap-search

Other resources

Some good heap exploitation resources, roughly in order of their publication, are:

Hardening

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.

how2heap_zh's People

Contributors

kyle-kyle avatar m1ghtym0 avatar zardus avatar antoniobianchi333 avatar fr0ster avatar mdulin2 avatar salls avatar ffreeez avatar crowell avatar danigargu avatar sajjadium avatar grazfather avatar htejeda avatar nickstephens avatar eterna1 avatar jkrshnmenon avatar cyanboy avatar n132 avatar degrigis avatar andigena avatar milo-d avatar kevinbackhouse avatar cloudburst avatar xmzyshypnc avatar junmoxiao avatar owlz avatar n30m1nd avatar jacopo avatar insuyun avatar rhelmot avatar

Stargazers

 avatar Jolene avatar CDDG avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.