off_by_null2
继续更off_by_null,其实也就是把自己的一些总结写下来,将来方便自己回顾。
之前的一篇简单说过了off_by_null,不过在那一篇里,off_by_null的利用方式是通过边界溢出修改类似在bss段上的内容。以此来间接达到我们想要的结果。
今天这个,中心思想是通过一字节溢出,修改下一个堆块上size段上的pre_inuse位,以此欺骗分配器–“本堆块已被释放(实际并没有)”。在pre_inuse位归0后,pre_size会同时被启用,我们伪造pre_size就可以实现堆重叠。
通常目的是为了,让堆块被释放后被合并,辅助实现unlink,构成堆重叠。
大概就这个原理吧,因为我是随着wiki上的题做的。这次这例题是wiki上的,但是我个人觉得并不合适(可能是因为版本原因吧,我也不知道,后面会讲为什么)
题目链接:https://github.com/ctfs/write-ups-2015/tree/master/plaidctf-2015/pwnable/plaiddb
这个题就是,逆向有点恶心,题大体上不难,原理就是我上面说的那个,具体wiki上说得很详细了我不重复了,可以先看看Wiki,这里我就说点我的一些想法。环境是ubuntu16.04的
1 |
|
这里分开说一下,
1 | for i in range(10): |
#这里,wiki上也说了,是为了不被影响,申请多个0x38的fastbin备用,在之后申请大堆块的时候,剩余的堆块会被合并
1 | delete('5') |
这里需要说一下,在这里整道题其实和off_by_null并没有什么关系delete('a'*0x1f0 + p64(0x4e0))
wiki上说,这个操作是溢出使下一堆块pre_inuse归0,但是我反复调试了几次后发现,其实在之前delete('3')
的时候,下一堆块的pre_inuse已经被归0了。我也不知道到底是不是这样,反正这道题,我觉得没有off_by_null同样的操作,也能打。
这不是,一道讲off_by_null的好的题。
但是,还是推荐做一下。不做,有些细节可能就理解不了。有些可能出错的地方发现不了。
但是,之前说过,这个题的逆向是有那么一点恶心的,他加了一个二叉树,这个如果在比赛中出现,会比较恶心人,因为我逆向菜
但是,我发现他的getline其实抄起来,可以借鉴一下。蛮不错
1 | char * getline() |
下次用应该修修就能行