How2Heap堆利用学习心得(二)

访客4年前黑客资讯850

上一篇,大家详细介绍了一种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

相关文章

黑客网站,没经过别人同意通过黑客查微信聊天,黑客黑长生网站

n";先看一看陈述供给的要害数据,一共包括六个方面。 FireEye 的终究方针是证明一个要挟是否能够兼并到现有组中,或许清晰它代表一个新的共同的要挟安排。 迄今为止,FireEye关于APT安排的聚...

众人帮被黑客攻击(众人帮被黑客攻击怎么办)

众人帮被黑客攻击(众人帮被黑客攻击怎么办)

本文目录一览: 1、众人帮实名认证任务有风险吗? 2、在众人帮做任务个人信息会被泄漏吗 3、众人帮平台是个骗子平台,大家有玩的吗?赚不了几个钱,还会骗取个人信息,非常恶心的一个平台,别下载...

支付宝实名号自助购买

  如果大家每个人都有支付宝账号的话,就会明白所有的账号几乎都已经实名认证了。如果说没有办法消除这一个号码,那么就会一直保留着。而且每一个号几乎都是实名制的,一旦是被不法人员给利用了,那么我们的信息也...

如何查兄弟和别人的开房记录

. 有研究结果证明,孩子太干净更容易得白血病,这主要是因为孩子太干净,与外界接触的免疫力较低,有部分家长总是认为孩子越干净越好,但不小心却造成了过度清洁,那么,孩子太干净有什么危害呢?接下来友谊长存...

如何查询老公在酒店开房记录

泰国Mistine这个牌子的东西还是很好用的,他家的睫毛膏,粉饼很多人都安利,不过眼线笔也是很多人的刚需,不过泰国Mistine眼线笔买到后怎么知道自己买的是真的还是假的呢,友谊长存小编就来说说吧。...

黑客游戏攻略详解(黑客网络攻略)

黑客游戏攻略详解(黑客网络攻略)

本文目录一览: 1、黑客帝国(尼奥之路)游戏全攻略 2、黑客游戏hacked 黑客平板第四关怎么过? 3、黑客帝国(就是和CS特像那个)动作攻略 黑客帝国(尼奥之路)游戏全攻略 《尼奥之路》...