其实 对比一下 块表 挺像 linux里面的fastbin 然后 空表就像 unsortbin 这两者有一些相识之处
然后 这里学习块表
还是根据0day 安全 一书所看
实验环境 就是 windows2000 sp4 VC6.0 OD
然后下面是代码
/*****************************************************************************
To be the apostrophe which changed "Impossible" into "I'm possible"!
POC code of chapter 5 in book "Lookaside Using"
file name : heap_lookaside.c
author : failwest
date : 2010.09.04
description : demo show of how heap works
Noticed : 1 only run on windows 2000
2 complied with VC 6.0
3 build into release version
4 only used for run time debugging
version : 1.0
E-mail : [email protected]
Only for educational purposes enjoy the fun from exploiting :)
******************************************************************************/
#include <stdio.h>
#include <windows.h>
void main()
{
HLOCAL h1,h2,h3,h4;
HANDLE hp;
hp = HeapCreate(0,0,0);
__asm int 3
h1 = HeapAlloc(hp,HEAP_ZERO_MEMORY,8);
h2 = HeapAlloc(hp,HEAP_ZERO_MEMORY,8);
h3 = HeapAlloc(hp,HEAP_ZERO_MEMORY,16);
h4 = HeapAlloc(hp,HEAP_ZERO_MEMORY,24);
HeapFree(hp,0,h1);
HeapFree(hp,0,h2);
HeapFree(hp,0,h3);
HeapFree(hp,0,h4);
h2 = HeapAlloc(hp,HEAP_ZERO_MEMORY,16);
HeapFree(hp,0,h2);
}
然后开始我们的调试之旅
刚断下int 3 的样子
可以看到有几点要注意的
可以看出 尾块有0x0000022F个堆单位可分配 并且 尾块不再是偏移是 0x688了 因为 这个地方被块表霸占了
可以看到 这里的块表 是 全是空的
这里应该符合常理(毕竟单链表)
然后我们运行 查看都有什么变化
申请没有什么好讲的 就是 在 list[0]的堆块里面 割下 所需堆块
申请到堆块 如下 堆首我已经标注出来了
然后继续看 free过程 块表的变化
这里把四条free语句全部执行,
查看块表的变化 不过这里有两点疑惑。。。 为啥 块表每个项的 间隔那么大呢 中间的数据项是啥呢 ,, 还有是这里 存储的 不是堆的所有大小而是 data段的大小,,, list[0]—>数据段为 8的堆 不算堆首
然后 我们看一下,,
发现却是 是 这样,
指向了 下一个 可以发现 是把 后free的堆块 加进了链表头
那么还有一个
h2 = HeapAlloc(hp,HEAP_ZERO_MEMORY,16);
执行后
发现 fastlist[2] 已经被清空,,,
块表的性质大概就是这个样子了,,
参考资料