一些基础知识不再赘述,可以自行搜索解决

程序源码first_fit.c

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

 int main()
 {
 printf("This file doesn't demonstrate an attack, but shows the nature of glibc's allocator.\n");
 printf("glibc uses a first-fit algorithm to select a free chunk.\n");
 printf("If a chunk is free and large enough, malloc will select this chunk.\n");
 printf("This can be exploited in a use-after-free situation.\n");

 printf("Allocating 2 buffers. They can be large, don't have to be fastbin.\n");
 );
 );
 char* c;

 printf("1st malloc(512): %p\n", a);
 printf("2nd malloc(256): %p\n", b);
 printf("we could continue mallocing here...\n");
 printf("now let's put a string at a that we can read later \"this is A!\"\n");
 strcpy(a, "this is A!");
 printf("first allocation %p points to %s\n", a, a);

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

 printf("We don't need to free anything again. As long as we allocate less than 512, it will end up at %p\n", a);

 printf("So, let's allocate 500 bytes\n");
 c = );
 printf("3rd malloc(500): %p\n", c);
 printf("And put a different string here, \"this is C!\"\n");
 strcpy(c, "this is C!");
 printf("3rd allocation %p points to %s\n", c, c);
 printf("first allocation %p points to %s\n", a, a);
 printf("If we reuse the first allocation, it now holds the data from the third allocation.");
 }

执行程序后的输出

junmoxiao@ubuntu:~/pwn/how2heap$ ./first_fit
This file doesn't demonstrate an attack, but shows the nature of glibc's allocator.
glibc uses a first-fit algorithm to select a free chunk.
If a chunk is free and large enough, malloc will select this chunk.
This can be exploited in a use-after-free situation.
Allocating  buffers. They can be large, don't have to be fastbin.
1st ): 0x245b420
2nd ): 0x245b630
we could continue mallocing here...
now let's put a string at a that we can read later "this is A!"
first allocation 0x245b420 points to this is A!
Freeing the first one...
We don't need to free anything again. As long as we allocate less than 512, it will end up at 0x245b420
So, let's allocate 500 bytes
3rd ): 0x245b420
And put a different string here, "this is C!"
3rd allocation 0x245b420 points to this is C!
first allocation 0x245b420 points to this is C!
If we reuse the first allocation, it now holds the data from the third allocation.

这个案例只是讲了glibc分配chunk时的first fit原则,可以用于use after free漏洞,比较简单,对照看看源码和输出即可,

how2heap分析系列:1_first_fit的更多相关文章

  1. how2heap分析系列:0

    新学期到了,给学弟们写点东西, https://github.com/shellphish/how2heap 这个how2heap挺不错的,讲述了heap上几种不同的漏洞利用技术,在后面发的几篇中我会 ...

  2. how2heap分析系列:2_fastbin_dup

    源码 #include <stdio.h> #include <stdlib.h> int main() { printf("This file demonstrat ...

  3. ENode框架Conference案例分析系列之 - 文章索引

    ENode框架Conference案例分析系列之 - 业务简介 ENode框架Conference案例分析系列之 - 上下文划分和领域建模 ENode框架Conference案例分析系列之 - 架构设 ...

  4. jQuery源码分析系列

    声明:本文为原创文章,如需转载,请注明来源并保留原文链接Aaron,谢谢! 版本截止到2013.8.24 jQuery官方发布最新的的2.0.3为准 附上每一章的源码注释分析 :https://git ...

  5. jQuery-1.9.1源码分析系列完毕目录整理

    jQuery 1.9.1源码分析已经完毕.目录如下 jQuery-1.9.1源码分析系列(一)整体架构 jQuery-1.9.1源码分析系列(一)整体架构续 jQuery-1.9.1源码分析系列(二) ...

  6. MyCat源码分析系列之——结果合并

    更多MyCat源码分析,请戳MyCat源码分析系列 结果合并 在SQL下发流程和前后端验证流程中介绍过,通过用户验证的后端连接绑定的NIOHandler是MySQLConnectionHandler实 ...

  7. MyCat源码分析系列之——SQL下发

    更多MyCat源码分析,请戳MyCat源码分析系列 SQL下发 SQL下发指的是MyCat将解析并改造完成的SQL语句依次发送至相应的MySQL节点(datanode)的过程,该执行过程由NonBlo ...

  8. MyCat源码分析系列之——BufferPool与缓存机制

    更多MyCat源码分析,请戳MyCat源码分析系列 BufferPool MyCat的缓冲区采用的是java.nio.ByteBuffer,由BufferPool类统一管理,相关的设置在SystemC ...

  9. MyCat源码分析系列之——前后端验证

    更多MyCat源码分析,请戳MyCat源码分析系列 MyCat前端验证 MyCat的前端验证指的是应用连接MyCat时进行的用户验证过程,如使用MySQL客户端时,$ mysql -uroot -pr ...

随机推荐

  1. 【Win 10 应用开发】TCP通信过程

    基于TCP协议的通信,估计大伙儿都不陌生的,以前玩.net或玩C++的时候应该玩得很多吧.现在老周简单介绍一下在RT中如何用. TCP是基于连接的,所以,肯定有一方是监听者,通常称服务端或服务器,它负 ...

  2. 总结一下CSS中的定位 Position 属性

    在CSS中,Position 属性经常会用到,主要是绝对定位和相对定位,简单的使用都没有问题,尤其嵌套起来,就会有些混乱,今记录总结一下,防止久而忘之. CSS position 属性值: absol ...

  3. 查看当前数据库正在运行的Session

    当数据库运行比较缓慢时,我们需要实时查看当前有什么Session在运行,获得信息越完整,对于分析低性能的原因越有帮助.根据之前调优的经历,简单几步分析如下: 1.通过SQL Server内置的Sp_w ...

  4. 2016网易春招Java在线笔试回忆录

    别看是在线笔试,但是非常严格,全称窗口不得最小化和关闭,转移,全称需要打开摄像头监控,使用草稿纸需要摄像头对准……反正2个小时,题量在那儿摆着,有作弊的功夫不如好好做做最后的编程题呢……网易不让泄漏原 ...

  5. 【NLP】揭秘马尔可夫模型神秘面纱系列文章(五)

    向前向后算法解决隐马尔可夫模型机器学习问题 作者:白宁超 2016年7月12日14:28:10 摘要:最早接触马尔可夫模型的定义源于吴军先生<数学之美>一书,起初觉得深奥难懂且无什么用场. ...

  6. [入门级] visual studio 2010 mvc4开发,用ibatis作为数据库访问媒介(一)

    [入门级] visual studio 2010 mvc4开发,用ibatis作为数据库访问媒介(一) Date  周二 06 一月 2015 By 钟谢伟 Tags mvc4 / asp.net 示 ...

  7. 匹夫细说C#:庖丁解牛聊委托,那些编译器藏的和U3D给的

    0x00 前言 由于工作繁忙所以距离上一篇博客已经过去一个多月的时间了,因此决心这个周末无论如何也得写点东西出来,既是总结也是分享.那么本文主要的内容集中在了委托的使用以及内部结构(当然还有事件了,但 ...

  8. 使用h5的history改善ajax列表请求体验

    信息比较丰富的网站通常会以分页显示,在点“下一页”时,很多网站都采用了动态请求的方式,避免页面刷新.虽然大家都是ajax,但是从一些小的细节还是 可以区分优劣.一个小的细节是能否支持浏览器“后退”和“ ...

  9. StackExchange.Redis客户端读写主从配置,以及哨兵配置。

    今天简单分享一下StackExchange.Redis客户端中配置主从分离以及哨兵的配置. 关于哨兵如果有不了解的朋友,可以看我之前的一篇分享,当然主从复制文章也可以找到.http://www.cnb ...

  10. Navisworks Api Tool

    用Google 翻译的..做个参考 None  无有效的选择  Select  选择 SelectBox 选择框 RedlineFreehand  红线写意 RedlineLine 红线线 Redli ...