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

程序源码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. 空中网招聘Java架构师、数据库开发等各类人才

    爱好网络游戏吗?爱好网站开发技术吗? 有没有想过可以成为史诗级MMO RPG<激战2>运营团队中的一员? 如果下面的职位有合适你的,加入我们吧! http://gw2.kongzhong. ...

  2. Ajax 加载数据 练习 自我有些迷糊了,写的大概请谅解 ^ _ ^

    查询表的显示,查询显示如果不嵌入PHP代码的话,用ajax怎么实现?   <h1>显示数据</h1> <table width="100%" bord ...

  3. .Net使用system.Security.Cryptography.RNGCryptoServiceProvider类与System.Random类生成随机数

    .Net中我们通常使用Random类生成随机数,在一些场景下,我却发现Random生成的随机数并不可靠,在下面的例子中我们通过循环随机生成10个随机数: ; i < ; i++) { Rando ...

  4. SqlService过期的解决方案

    看图吧,不喜欢说话,图里面我都打备注了 0SQLService异常 1找到安装中心 2升级版本 3监测ing 4输入升级key 5同意并下一步 6下一步 7下一步 8下一步 9收工 10可以打开了

  5. GC使用注意

    GC.Collect() GC.WaitForPendingFinallizers() GC.KeepAlive 尽量不要new很大的Object 不要频繁的new生命周期很短的Object,这样会导 ...

  6. ASP.NET MVC5+EF6+EasyUI 后台管理系统(62)-EF链接串加密

    系列目录 前言: 这一节提供一个简单的功能,这个功能看似简单,找了一下没找到EF链接数据库串的加密帮助文档,只能自己写了,这样也更加符合自己的加密要求 有时候我们发布程序为了避免程序外的SQL链接串明 ...

  7. SQL Server-交叉联接、内部联接基础回顾(十二)

    前言 本节开始我们进入联接学习,关于连接这一块涉及的内容比较多,我们一步一步循序渐进学习,简短内容,深入的理解,Always to review the basics. 交叉联接(CROSS JOIN ...

  8. DDD 领域驱动设计-谈谈 Repository、IUnitOfWork 和 IDbContext 的实践(2)

    上一篇:<DDD 领域驱动设计-谈谈 Repository.IUnitOfWork 和 IDbContext 的实践(1)> 阅读目录: 抽离 IRepository 并改造 Reposi ...

  9. 1元搭建自己的云服务器&解析域名

    最近在学做微信开发,没有自己的域名和服务器就不得不寄人篱下,索性自己就到云主机上搭建了个服务器,但是水平有限弄了一个下午~~有自己的域名和服务器的好处相信不用我多说了.比如日后可以有自己域名的个性博客 ...

  10. 13.JAVA之GUI编程将程序打包jar

    jar基本命令: 目标:将下列MyMenuDemo.java代码打包成jar. 方法如下: 1.把java代码放到d:\myclass目录下. 2.按下快捷键ctrl+r,打开运行窗口,输入cmd后回 ...