上一篇,大家详细介绍了一种Double free技术性。而且完成了对malloc_hook的fastbin_attack。
此次将详细介绍怎样利用malloc中的consolidate体制来完成double free。文中会涉及到一些源码,若有表述不正确,恳求诸位高手纠正。
0x01 利用consolidate的Double Free
1.1 fastbin_dup_consolidate剖析
更先剖析一下实例编码
#include
#include
#include
int main(){
void* p1=malloc(0x40);
void* p2=malloc(0x40);
fprintf(stderr, "Allocated two fastbins: p1=%p p2=%pn", p1, p2);
fprintf(stderr, "Now free p1!n");
free(p1);
void* p3=malloc(0x400);
fprintf(stderr, "Allocated large bin to trigger malloc_consolidate(): p3=%pn", p3);
fprintf(stderr, "In malloc_consolidate(), p1 is moved to the unsorted bin.n");
free(p1);
fprintf(stderr, "Trigger the double free vulnerability!n");
fprintf(stderr, "We can pass the check in malloc() since p1 is not fast top.n");
fprintf(stderr, "Now p1 is in unsorted bin and fast bin. So we'will get it twice: %p %pn", malloc(0x40), malloc(0x40));
}
编译程序时刻加-g主要参数,动态性调节中能够同歩源代码开展剖析。
1.2步骤剖析
程序流程更先malloc分派了2个0x40的运行内存p1和p2,随后free掉chunk_p1,低于64的chunkp1会被链入fastbins中。
gef? x/40gx 0x602010-0x10
0x602000: 0x0000000000000000 0x0000000000000051
0x602010: 0x0000000000000000 0x0000000000000000
0x602020: 0x0000000000000000 0x0000000000000000
0x602030: 0x0000000000000000 0x0000000000000000
0x602040: 0x0000000000000000 0x0000000000000000
0x602050: 0x0000000000000000 0x0000000000000051
0x602060: 0x0000000000000000 0x0000000000000000
0x602070: 0x0000000000000000 0x0000000000000000
0x602080: 0x0000000000000000 0x0000000000000000
0x602090: 0x0000000000000000 0x0000000000000000
0x6020a0: 0x0000000000000000 0x0000000000020f61
查询快表,能够见到被释放出来的chunk_p1
gef? heap bins fast
─────[ Fastbins for arena 0x7ffff7dd1b20 ]─────
Fastbin[3]→ UsedChunk(addr=0x602010,size=0x50)
实行分派0x400运行内存,这时看fastbin,发觉chunk_p1早已被从快表中卸掉了。而我们在 *** all bins中找到它。
gef? heap bins fast
────[ Fastbins for arena 0x7ffff7dd1b20 ]───
Fastbin[0]0x00
Fastbin[1]0x00
Fastbin[2]0x00
Fastbin[3]0x00
gef? heap bins *** all
───[ Small Bins for arena 'main_arena' ]────
[ ]Found base for bin(4): fw=0x602000, bk=0x602000
→ FreeChunk(addr=0x602010,size=0x50)
glibc在分派large chunk(>1024字节数)时,更先实际操作是分辨fast bins是不是包括chunk。假如包括,则应用malloc_consolidate涵数将fastbin中的chunk合拼,并放进unsortbins。依据尺寸放进 *** all bins/large bins。
要我根据glibc源代码开展阅读文章剖析 ,FTP下载链接,malloc的完成在/malloc/malloc.c
malloc.c在1055行各自界定了malloc free realloc涵数
static void* _int_malloc(mstate, size_t);
static void _int_free(mstate, mchunkptr, int);
static void* _int_realloc(mstate, mchunkptr, INTERNAL_SIZE_T,
? INTERNAL_SIZE_T);
在_int_malloc的Define下寻找开启consolidate的编码一部分。
更先根据have_fastchunks分辨fastbins是不是链有空余堆。
have_fastchunks的宏定义即是分辨fastbin中是不是包括chunk,flag为0的情况下表明存有chunk。
#define have_fastchunks(M) (((M)->flags & FASTCHUNKS_BIT)==0)
假如包括chunk,可能启用consolidate来合拼fastbins中的chunk,并将这种空余的chunk添加unsorted bin中。
本实例开启consolidate的源代码
/*
? If this is a large request, consolidate fastbins before continuing.
? While it might look excessive to kill all fastbins before
? even seeing if there is space available, this avoids
? fragmentation problems normally associated with fastbins.
? Also, in practice, programs tend to have runs of either *** all or
? large requests, but less often mixtures, so consolidation is not
? invoked all that often in most programs. And the programs that
指神技的使用次数,一般为2次,粉钻可能是三次。每使用一次龙脉则会减少一个。这是腾讯为了不要神级太强,太过广泛(因为只要打巡海夜叉获得天地宝鉴第一。 楼主您好龙脉这个是不能人为激活什么的等以后2哥更新出...
黑客微信号定位软件(微信定位找人)近期,不少定位App打着“只要输入手机号就能确定对方位置”的旗号,通过让消费者充值购买会员服务的形式获利。然而,很多消费者表示,这项功能并没有那么神奇。 输入手机号...
本文导读目录: 1、什么是钩子程序?c/c++如何实现? 2、c系统盘下面有一个JMSOFT文件夹,请问高手这是干什么的? 3、安装消息钩子是什么意思 4、黑客3号钓鲫鱼好用吗? 5、...
同步带规格型号表示方法(5m同步带规格型号表) 1.同步带节线长度 同步带工作时,其承重绳的中心线长度应保持不变,因此该中心线称为同步带的节线,节线的周长作为皮带的标称长皮,称为节线长度。在同步带...
新人入市,第一件事就是得先开个户。如何用手机办理股票开户手续?下面小编就为大家讲述一下。 手机开户炒股有两个途径,一个是用手机在搜索引擎上搜索券商网站下载开户APP;还有一个是用电脑访问券商网站,扫...
若磁盘空间足够,则会经过动态获取的办法加载后续操作所需求的函数,以此来逃避杀毒软件的静态查杀。 下图仅列出一部分22.88 设置 PostmanAndroid Pie中引进了BiometricProm...