how2heap分析系列:2_fastbin_dup

源码

#include <stdio.h>
#include <stdlib.h>

int main()
{
    printf("This file demonstrates a simple double-free attack with fastbins.\n");

    printf("Allocating 3 buffers.\n");
    int *a = malloc(8);
    int *b = malloc(8);
    int *c = malloc(8);

    printf("1st malloc(8): %p\n", a);
    printf("2nd malloc(8): %p\n", b);
    printf("3rd malloc(8): %p\n", c);

    printf("Freeing the first one...\n");
    free(a);

    printf("If we free %p again, things will crash because %p is at the top of the free list.\n", a, a);
    // free(a);

    printf("So, instead, we‘ll free %p.\n", b);
    free(b);

    printf("Now, we can free %p again, since it‘s not the head of the free list.\n", a);
    free(a);

    printf("Now the free list has [ %p, %p, %p ]. If we malloc 3 times, we‘ll get %p twice!\n", a, b, a, a);
    printf("1st malloc(8): %p\n", malloc(8));
    printf("2nd malloc(8): %p\n", malloc(8));
    printf("3rd malloc(8): %p\n", malloc(8));
}

执行输出:

[email protected]:~/pwn/how2heap$ ./fastbin_dup
This file demonstrates a simple double-free attack with fastbins.
Allocating 3 buffers.
1st malloc(8): 0x2509420
2nd malloc(8): 0x2509440
3rd malloc(8): 0x2509460
Freeing the first one...
If we free 0x2509420 again, things will crash because 0x2509420 is at the top of the free list.
So, instead, we‘ll free 0x2509440.
Now, we can free 0x2509420 again, since it‘s not the head of the free list.
Now the free list has [ 0x2509420, 0x2509440, 0x2509420 ]. If we malloc 3 times, we‘ll get 0x2509420 twice!
1st malloc(8): 0x2509420
2nd malloc(8): 0x2509440
3rd malloc(8): 0x2509420

这一节也只是阐述了double free的概念和基本条件,没什么好说的,下一节进行利用double free技术的实战

时间: 2024-08-03 15:19:30

how2heap分析系列:2_fastbin_dup的相关文章

how2heap分析系列:1_first_fit

一些基础知识不再赘述,可以自行搜索解决 程序源码first_fit.c 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 5 int main() 6 { 7 printf("This file doesn't demonstrate an attack, but shows the nature of glibc's allocator.\n"); 8 printf

SpringMVC源码分析系列

说到java的mvc框架,struts2和springmvc想必大家都知道,struts2的设计基本上完全脱离了Servlet容器,而springmvc是依托着Servlet容器元素来设计的,同时springmvc基于Spring框架,Spring框架想必搞java的同学都很熟悉. 一进Spring的官网就发现了这样一排醒目的文字, spring可以让我们构造简单的.便携的.又快又易于扩展的基于jvm的系统和应用程序. 没错,基于Spring的MVC框架SpringMVC同样也可以构造具有这些特

Cordova Android源码分析系列一(项目总览和CordovaActivity分析)

PhoneGap/Cordova是一个专业的移动应用开发框架,是一个全面的WEB APP开发的框架,提供了以WEB形式来访问终端设备的API的功能.这对于采用WEB APP进行开发者来说是个福音,这可以避免了原生开发的某些功能.Cordova 只是个原生外壳,app的内核是一个完整的webapp,需要调用的原生功能将以原生插件的形式实现,以暴露js接口的方式调用. Cordova Android项目是Cordova Android原生部分的Java代码实现,提供了Android原生代码和上层We

jQuery源码分析系列(33) : AJAX中的前置过滤器和请求分发器

jQuery1.5以后,AJAX模块提供了三个新的方法用于管理.扩展AJAX请求,分别是: 1.前置过滤器 jQuery. ajaxPrefilter 2.请求分发器 jQuery. ajaxTransport, 3.类型转换器 ajaxConvert 源码结构: jQuery.extend({ /** * 前置过滤器 * @type {[type]} */ ajaxPrefilter: addToPrefiltersOrTransports(prefilters), /** * 请求分发器 *

java执行程序的内存分析系列专栏二之static变量和方法内存分析

昨天写了简单的聊了下java执行程序时简单的内存划分,今天我们接着往下聊,聊聊static变量和方法的内存分析. 1.static变量和方法的第一个特性内存分析 statiic变量和方法的第一个特性能通过类名.static变量和类名.static方法的形式调用,而普通只能对象的形式调用.但具体为什么是这样的,这得分析static变量和方法他们在内存中怎样分配的,因此在这里我首先建立一个学生类,里面有一个普通成员变量和一个静态成员变量以及一个普通方法和一个成员方法,然后建立了一个测试学生的类. 1

趣味分析系列 | 文胸品牌知多少(一)

一年一度的圣诞节马上就快到了,各位男神是不是又在劳神费力地给女神们准备圣诞节礼物?今年送啥呢? 送脑白金怎么样?NO,NO,NO!脑白金是送给大妈的!!! 直接给MONEY? NO,NO,NO!太俗气!!! 送鲜花与巧克力?NO,NO,NO!不实在!!! 按我说,直接送个文胸套装,有情调又贴心!!!说不定你的女神会给你个惊喜呢! 但是问题又来了,挑选哪个品牌的文胸好呢,总不能送一个层次太LOW的吧.因此,你需要对文胸的品牌有个大概的了解.简单讲,首先你得了解女生文胸品牌有多少?品牌的排名度是怎样

jQuery源码分析系列(38) : 队列操作

Queue队列,如同data数据缓存与Deferred异步模型一样,都是jQuery库的内部实现的基础设施 Queue队列是animate动画依赖的基础设施,整个jQuery中队列仅供给动画使用 Queue队列 队列是一种特殊的线性表,只允许在表的前端(队头)进行删除操作(出队),在表的后端(队尾)进行插入操作(入队).队列的特点是先进先出(FIFO-first in first out),即最先插入的元素最先被删除. 为什么要引入队列? 我们知道代码的执行流有异步与同步之分,例如 var a

jQuery源码分析系列(36) : Ajax - 类型转化器

什么是类型转化器? jQuery支持不同格式的数据返回形式,比如dataType为 xml, json,jsonp,script, or html 但是浏览器的XMLHttpRequest对象对数据的响应只有 responseText与responseXML 二种 所以现在我要定义dataType为jsonp,那么所得的最终数据是一个json的键值对,所以jQuery内部就会默认帮你完成这个转化工作 jQuery为了处理这种执行后数据的转化,就引入了类型转化器,如果没有指定类型就依据响应头Con

房卡麻将分析系列之&quot;断线重连&quot;

"房卡"麻将研发技巧,尽在"红孩儿的游戏开发之路",欢迎关注公众号! 房卡麻将分析系列之"断线重连" 大家好,我是红孩儿,"房卡"麻将分析系列继续进行中. 在进行游戏的过程中,人们往往会遇到"断线"情况,比如坐公车,地铁下班路上玩一局,下车转站时往往先关机,过一会儿再上线继续完,如果没有自动"断线重连",则对于牌局的体验感影响会非常大,在"房卡"麻将中加入"