[原创]ctf中的large bins attack及lctf2017 2ez4u writeup
前置知识
关于fd_nextsize和bk_nextsize
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *s=malloc(1008);//分配large bin的大小
char *s1=malloc(1008);
char *s2=malloc(960);
char *s3=malloc(960);
char *s4=malloc(980);
char *s5=malloc(980);
free(s);
free(s2);
free(s4);
char *s6=(char *)malloc(2000);unsorted bins里找
s6="hello,world";
printf("%s\n",s6);
}
编译:gcc -m32 fenpei.c -g -o fenpei
pwndbg> b 14 Breakpoint 1 at 0x804850a: file fenpei.c, line 14. pwndbg> r Starting program: /home/sakura/fenpei ... 14 char *s6=(char *)malloc(2000); ... pwndbg> bins fastbins 0x10: 0x0 0x18: 0x0 0x20: 0x0 0x28: 0x0 0x30: 0x0 0x38: 0x0 0x40: 0x0 unsortedbin all: 0x804bf80 —? 0x804b7f0 —? 0x804b000 ?— 0xf7fbd450 smallbins empty largebins empty
注意当14行,这条语句运行前,还没有large bins,因为会先把free的chunk加入unsorted bins,然后当再次分配时,遍历unsorted,如果没有才把free的chunk加入到其该去的bins(这里就是large bins)。
pwndbg> n
15 s6="hello,world";
...
pwndbg> bins
fastbins
0x10: 0x0
0x18: 0x0
0x20: 0x0
0x28: 0x0
0x30: 0x0
0x38: 0x0
0x40: 0x0
unsortedbin
all: 0x0
smallbins
empty
largebins
0x3c0: 0x804b000 —? 0x804bf80 —? 0x804b7f0 ?— 0xf7fbd680
0x804b000 PREV_INUSE {
prev_size = 0,
size = 1017,
fd = 0x804bf80,
bk = 0xf7fbd680 <main_arena+608>,
fd_nextsize = 0x804bf80,
bk_nextsize = 0x804b7f0
}
0x804bf80 PREV_INUSE {
prev_size = 0,
size = 985,
fd = 0x804b7f0,
bk = 0x804b000,
fd_nextsize = 0x804b7f0,
bk_nextsize = 0x804b000
}
0x804b7f0 PREV_INUSE {
prev_size = 0,
size = 969,
fd = 0xf7fbd680 <main_arena+608>,
bk = 0x804bf80,
fd_nextsize = 0x804b000,
bk_nextsize = 0x804bf80
}
结论:
- large bin里的chunk是按照从大到小排序的。
- 若chunk在large bin的末端,则其的fd_nextsize指向首部,也就是最大的chunk,否则,fd_nextsize指向的是比它小的chunk.
- 若chunk在large bin的首部,则其的bk_nextsize指向末端,也就是最小的chunk,否则,bk_nextsize指向的是比它大的chunk.
unlink

注意:上传附件及图片大小不得大于30M。
⚠️ 版权声明:
本博客所有内容(含教程、源码、工具)仅供个人技术学习与研究交流使用,严禁商用、倒卖、二次分发及非法用途。
未经作者书面授权,任何组织或个人不得转载、复制或用于其他平台,违者将追究相关责任。
复制成功
