

标准堆菜单

Allocate
- void __fastcall sub_D48(__int64 a1)
- {
- int i; // [rsp+10h] [rbp-10h]
- int v2; // [rsp+14h] [rbp-Ch]
- void *v3; // [rsp+18h] [rbp-8h]
-
- for ( i = 0; i <= 15; ++i )
- {
- if ( !*(_DWORD *)(24LL * i + a1) )
- {
- printf("Size: ");
- v2 = sub_138C();
- if ( v2 > 0 )
- {
- if ( v2 > 4096 )
- v2 = 4096;
- v3 = calloc(v2, 1uLL);
- if ( !v3 )
- exit(-1);
- *(_DWORD *)(24LL * i + a1) = 1;
- *(_QWORD *)(a1 + 24LL * i + 8) = v2;
- *(_QWORD *)(a1 + 24LL * i + 16) = v3;
- printf("Allocate Index %d\n", (unsigned int)i);
- }
- return;
- }
- }
- }
分配内存,没有什么异样
Fill
- __int64 __fastcall sub_E7F(__int64 a1)
- {
- __int64 result; // rax
- int v2; // [rsp+18h] [rbp-8h]
- int v3; // [rsp+1Ch] [rbp-4h]
-
- printf("Index: ");
- result = sub_138C();
- v2 = result;
- if ( (int)result >= 0 && (int)result <= 15 )
- {
- result = *(unsigned int *)(24LL * (int)result + a1);
- if ( (_DWORD)result == 1 )
- {
- printf("Size: ");
- result = sub_138C();
- v3 = result;
- if ( (int)result > 0 )
- {
- printf("Content: ");
- return sub_11B2(*(_QWORD *)(24LL * v2 + a1 + 16), v3);
- }
- }
- }
- return result;
- }
进行填充 ,阅读代码看到fill对我们的输入没有限制,可以利用,填充过多数据造成堆溢出
Free
- __int64 __fastcall sub_F50(__int64 a1)
- {
- __int64 result; // rax
- int v2; // [rsp+1Ch] [rbp-4h]
-
- printf("Index: ");
- result = sub_138C();
- v2 = result;
- if ( (int)result >= 0 && (int)result <= 15 )
- {
- result = *(unsigned int *)(24LL * (int)result + a1);
- if ( (_DWORD)result == 1 )
- {
- *(_DWORD *)(24LL * v2 + a1) = 0;
- *(_QWORD *)(24LL * v2 + a1 + 8) = 0LL;
- free(*(void **)(24LL * v2 + a1 + 16));
- result = 24LL * v2 + a1;
- *(_QWORD *)(result + 16) = 0LL;
- }
- }
- return result;
- }
free一般出现漏洞的概率很大,在free之后没有进行置0就会出现一系列漏洞利用
但是本题进行了置0,没有利用的
Dump
- int __fastcall sub_1051(__int64 a1)
- {
- int result; // eax
- int v2; // [rsp+1Ch] [rbp-4h]
-
- printf("Index: ");
- result = sub_138C();
- v2 = result;
- if ( result >= 0 && result <= 15 )
- {
- result = *(_DWORD *)(24LL * result + a1);
- if ( result == 1 )
- {
- puts("Content: ");
- sub_130F(*(_QWORD *)(24LL * v2 + a1 + 16), *(_QWORD *)(24LL * v2 + a1 + 8));
- return puts(byte_14F1);
- }
- }
- return result;
- }
利用思路
泄露libc基址,通过伪造fake_chunk来向hook附近通过Fill函数填充溢出覆盖
malloc_hook 是一个libc上的函数指针,调用malloc时如果该指针不为空则执行它指向的函数,可以通过写malloc_hook来getshell,修改malloc_hook为某个one_gadget
这道题查阅了好多师傅们的博客
泄露libc的方法有两种
1.利用fastbin double free
babyheap_0ctf_2017——堆入门1 - PYozo_free - 博客园 (cnblogs.com)
2.利用unsorted bin
堆学习:babyheap_0ctf_2017——经典fastbin attack - 『软件调试区』 - 吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn
目前的脚本还没有打通远程
这篇博客讲述了buuctf上打不通的原因,而且师傅具体分析的也很细致,推荐学习