从零开始学howtoheap:理解fastbins的double-free攻击

2024-02-09 21:28

本文主要是介绍从零开始学howtoheap:理解fastbins的double-free攻击,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 how2heap是由shellphish团队制作的堆利用教程,介绍了多种堆利用技术,后续系列实验我们就通过这个教程来学习。环境可参见从零开始配置pwn环境:优化pwn虚拟机配置支持libc等指令-CSDN博客

1.fastbins的double-free攻击

下面的程序展示了fastbins的double-free攻击,可以泄露出一块已经被分配的内存指针。fastbins 可以看成一个后进先出的栈,使用单链表来实现,通过fastbin->fd来遍历。由于free的过程会对free list做检查,我们不能连续两次free同一个chunk,所以这里在两次free 之间,增加了一次对其他chunk的free 过程,从而绕过了检查顺利执行,然后再malloc三次,就在同一个地址malloc了两次,也就有了两个指向同一块内存区域的指针。

2.fastbin_dup程序

这个程序更具体地展示了通过欺骗 malloc 来返回一个我们可控的区域的指针(在这个例子中,我们可以返回一个栈指针)。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>int main()
{fprintf(stderr, "这个例子演示了 fastbin 的 double free\n");fprintf(stderr, "首先申请了 3 个 chunk\n");char* a = malloc(8);strcpy(a, "AAAAAAAA");char* b = malloc(8);strcpy(b, "BBBBBBBB");char* c = malloc(8);strcpy(c, "CCCCCCCC");fprintf(stderr, "第一个 malloc(8): %p\n", a);fprintf(stderr, "第二个 malloc(8): %p\n", b);fprintf(stderr, "第三个 malloc(8): %p\n", c);fprintf(stderr, "free 掉第一个\n");free(a);fprintf(stderr, "当我们再次 free %p 的时候, 程序将会崩溃因为 %p 在 free 链表的第一个位置上\n", a, a);// free(a);fprintf(stderr, "我们先 free %p.\n", b);free(b);fprintf(stderr, "现在我们就可以再次 free %p 了, 因为他现在不在 free 链表的第一个位置上\n", a);free(a);fprintf(stderr, "现在空闲链表是这样的 [ %p, %p, %p ]. 如果我们 malloc 三次, 我们会得到两次 %p \n", a, b, a, a);char* d = malloc(8);char* e = malloc(8);char* f = malloc(8);strcpy(d, "DDDDDDDD");strcpy(e, "EEEEEEEE");strcpy(f, "FFFFFFFF");fprintf(stderr, "第一次 malloc(8): %p\n", d);fprintf(stderr, "第二次 malloc(8): %p\n", e);fprintf(stderr, "第三次 malloc(8): %p\n", f);
}

3.调试fastbin_dup

3.1 获得可执行程序 

gcc -g fastbin_dup.c -o fastbin_dup

3.2 第一次调试程序

调试环境搭建可参考环境从零开始配置pwn环境:优化pwn虚拟机配置支持libc等指令-CSDN博客

root@pwn_test1604:/ctf/work/how2heap# gdb ./fastbin_dup
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
pwndbg: loaded 171 commands. Type pwndbg [filter] for a list.
pwndbg: created $rebase, $ida gdb functions (can be used with print/break)
Reading symbols from ./fastbin_dup...done.
pwndbg> r
Starting program: /ctf/work/how2heap/fastbin_dup 
这个例子演示了 fastbin 的 double free
首先申请了 3 个 chunk
第一个 malloc(8): 0x602010
第二个 malloc(8): 0x602030
第三个 malloc(8): 0x602050
free 掉第一个
当我们再次 free 0x602010 的时候, 程序将会崩溃因为 0x602010 在 free 链表的第一个位置上
我们先 free 0x602030.
现在我们就可以再次 free 0x602010 了, 因为他现在不在 free 链表的第一个位置上
现在空闲链表是这样的 [ 0x602010, 0x602030, 0x602010 ]. 如果我们 malloc 三次, 我们会得到两次 0x602010 
第一次 malloc(8): 0x602010
第二次 malloc(8): 0x602030
第三次 malloc(8): 0x602010
[Inferior 1 (process 130) exited normally]
pwndbg> 

3.3 第二次调试程序

3.3.1 下相应的断点并走起

可以看到首先分配三块内存,当free掉第一块内存之后,再free一次该内存块是不行的,因为这时候这块内存刚好在对应的free-list的顶部,再次free这块内存就会被检查到,这里就free第二块内存。现在我们再次free第一块内存,因为它已经不在链表顶部了。

这时候的 free-list 有这三块内存 [0x2502010, 0x2502030, 0x2502010],如果我们malloc三次的话,就会得到0x2502010两次。

使用pwndbg逐步调试,首先malloc 3个chunk。

root@pwn_test1604:/ctf/work/how2heap# gdb ./fastbin_dup
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
pwndbg: loaded 171 commands. Type pwndbg [filter] for a list.
pwndbg: created $rebase, $ida gdb functions (can be used with print/break)
Reading symbols from ./fastbin_dup...done.
pwndbg> r
Starting program: /ctf/work/how2heap/fastbin_dup 
这个例子演示了 fastbin 的 double free
首先申请了 3 个 chunk
第一个 malloc(8): 0x602010
第二个 malloc(8): 0x602030
第三个 malloc(8): 0x602050
free 掉第一个
当我们再次 free 0x602010 的时候, 程序将会崩溃因为 0x602010 在 free 链表的第一个位置上
我们先 free 0x602030.
现在我们就可以再次 free 0x602010 了, 因为他现在不在 free 链表的第一个位置上
现在空闲链表是这样的 [ 0x602010, 0x602030, 0x602010 ]. 如果我们 malloc 三次, 我们会得到两次 0x602010 
第一次 malloc(8): 0x602010
第二次 malloc(8): 0x602030
第三次 malloc(8): 0x602010
[Inferior 1 (process 130) exited normally]
pwndbg> list
1       #include <stdio.h>
2       #include <stdlib.h>
3       #include <string.h>
4
5       int main()
6       {
7           fprintf(stderr, "这个例子演示了 fastbin 的 double free\n");
8
9           fprintf(stderr, "首先申请了 3 个 chunk\n");
10          char* a = malloc(8);
pwndbg> n
The program is not being run.
pwndbg> b 19
Breakpoint 1 at 0x40072d: file fastbin_dup.c, line 19.
pwndbg> b 24
Breakpoint 2 at 0x400774: file fastbin_dup.c, line 24.
pwndbg> b 29 
Breakpoint 3 at 0x4007be: file fastbin_dup.c, line 29.
pwndbg> b 31
Breakpoint 4 at 0x4007e7: file fastbin_dup.c, line 31.
pwndbg> b 36
Breakpoint 5 at 0x400840: file fastbin_dup.c, line 36.
pwndbg> r
Starting program: /ctf/work/how2heap/fastbin_dup 
这个例子演示了 fastbin 的 double free
首先申请了 3 个 chunk
第一个 malloc(8): 0x602010
第二个 malloc(8): 0x602030Breakpoint 1, main () at fastbin_dup.c:19
19          fprintf(stderr, "第三个 malloc(8): %p\n", c);
LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
───────────────────────────────────────────────────────────────────────────────────────────────────[ REGISTERS ]───────────────────────────────────────────────────────────────────────────────────────────────────RAX  0x1eRBX  0x0RCX  0x7ffff7b042c0 (__write_nocancel+7) ◂— cmp    rax, -0xfffRDX  0x7ffff7dd3770 (_IO_stdfile_2_lock) ◂— 0x0RDI  0x2RSI  0x7fffffffbf00 ◂— 0xb8e48cbae4acace7R8   0x7ffff7feb700 ◂— 0x7ffff7feb700R9   0x1eR10  0x0R11  0x246R12  0x400550 (_start) ◂— xor    ebp, ebpR13  0x7fffffffe6a0 ◂— 0x1R14  0x0R15  0x0RBP  0x7fffffffe5c0 —▸ 0x4008e0 (__libc_csu_init) ◂— push   r15RSP  0x7fffffffe590 —▸ 0x602010 ◂— 'AAAAAAAA'RIP  0x40072d (main+231) ◂— mov    rax, qword ptr [rip + 0x20092c]
────────────────────────────────────────────────────────────────────────────────────────────────────[ DISASM ]─────────────────────────────────────────────────────────────────────────────────────────────────────► 0x40072d <main+231>    mov    rax, qword ptr [rip + 0x20092c] <0x601060>0x400734 <main+238>    mov    rdx, qword ptr [rbp - 0x20]0x400738 <main+242>    mov    esi, 0x4009e60x40073d <main+247>    mov    rdi, rax0x400740 <main+250>    mov    eax, 00x400745 <main+255>    call   fprintf@plt <0x400510>0x40074a <main+260>    mov    rax, qword ptr [rip + 0x20090f] <0x601060>0x400751 <main+267>    mov    rcx, rax0x400754 <main+270>    mov    edx, 0x120x400759 <main+275>    mov    esi, 10x40075e <main+280>    mov    edi, 0x4009ff
─────────────────────────────────────────────────────────────────────────────────────────────────[ SOURCE (CODE) ]─────────────────────────────────────────────────────────────────────────────────────────────────
In file: /ctf/work/how2heap/fastbin_dup.c14     char* c = malloc(8);15     strcpy(c, "CCCCCCCC");16 17     fprintf(stderr, "第一个 malloc(8): %p\n", a);18     fprintf(stderr, "第二个 malloc(8): %p\n", b);► 19     fprintf(stderr, "第三个 malloc(8): %p\n", c);20 21     fprintf(stderr, "free 掉第一个\n");22     free(a);23 24     fprintf(stderr, "当我们再次 free %p 的时候, 程序将会崩溃因为 %p 在 free 链表的第一个位置上\n", a, a);
─────────────────────────────────────────────────────────────────────────────────────────────────────[ STACK ]─────────────────────────────────────────────────────────────────────────────────────────────────────
00:0000│ rsp  0x7fffffffe590 —▸ 0x602010 ◂— 'AAAAAAAA'
01:0008│      0x7fffffffe598 —▸ 0x602030 ◂— 'BBBBBBBB'
02:0010│      0x7fffffffe5a0 —▸ 0x602050 ◂— 'CCCCCCCC'
03:0018│      0x7fffffffe5a8 —▸ 0x400550 (_start) ◂— xor    ebp, ebp
04:0020│      0x7fffffffe5b0 —▸ 0x7fffffffe6a0 ◂— 0x1
05:0028│      0x7fffffffe5b8 ◂— 0x0
06:0030│ rbp  0x7fffffffe5c0 —▸ 0x4008e0 (__libc_csu_init) ◂— push   r15
07:0038│      0x7fffffffe5c8 —▸ 0x7ffff7a2d830 (__libc_start_main+240) ◂— mov    edi, eax
───────────────────────────────────────────────────────────────────────────────────────────────────[ BACKTRACE ]───────────────────────────────────────────────────────────────────────────────────────────────────► f 0           40072d main+231f 1     7ffff7a2d830 __libc_start_main+240
Breakpoint /ctf/work/how2heap/fastbin_dup.c:19
pwndbg> heap
heapbase : 0x602000
pwndbg> parseheap                                                                                                                                                                                                  
addr                prev                size                 status              fd                bk                
0x602000            0x0                 0x20                 Used                None              None
0x602020            0x0                 0x20                 Used                None              None
0x602040            0x0                 0x20                 Used                None              None
pwndbg> x/20gx 0x602000
0x602000:       0x0000000000000000      0x0000000000000021
0x602010:       0x4141414141414141      0x0000000000000000
0x602020:       0x0000000000000000      0x0000000000000021
0x602030:       0x4242424242424242      0x0000000000000000
0x602040:       0x0000000000000000      0x0000000000000021
0x602050:       0x4343434343434343      0x0000000000000000
0x602060:       0x0000000000000000      0x0000000000020fa1
0x602070:       0x0000000000000000      0x0000000000000000
0x602080:       0x0000000000000000      0x0000000000000000
0x602090:       0x0000000000000000      0x0000000000000000

 3.3.2 第一个free之后

chunk a被添加到fastbins中。

pwndbg> c
Continuing.
第三个 malloc(8): 0x602050
free 掉第一个Breakpoint 2, main () at fastbin_dup.c:24
24          fprintf(stderr, "当我们再次 free %p 的时候, 程序将会崩溃因为 %p 在 free 链表的第一个位置上\n", a, a);
LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
───────────────────────────────────────────────────────────────────────────────────────────────────[ REGISTERS ]───────────────────────────────────────────────────────────────────────────────────────────────────RAX  0x0RBX  0x0RCX  0x7ffff7b04200 (__openat_2+16) ◂— cmp    eax, 0x410000 /* '=' */RDX  0x0RDI  0xffffffffRSI  0x7ffff7dd1b28 (main_arena+8) —▸ 0x602000 ◂— 0x0R8   0x602010 ◂— 0x0R9   0x7ffff7dd2500 (_nl_global_locale+224) —▸ 0x7ffff7b9b997 (_nl_C_name) ◂— add    byte ptr [r15 + 0x5f], bl /* 'C' */R10  0x8b8R11  0x7ffff7a914f0 (free) ◂— push   r13R12  0x400550 (_start) ◂— xor    ebp, ebpR13  0x7fffffffe6a0 ◂— 0x1R14  0x0R15  0x0RBP  0x7fffffffe5c0 —▸ 0x4008e0 (__libc_csu_init) ◂— push   r15RSP  0x7fffffffe590 —▸ 0x602010 ◂— 0x0RIP  0x400774 (main+302) ◂— mov    rax, qword ptr [rip + 0x2008e5]
────────────────────────────────────────────────────────────────────────────────────────────────────[ DISASM ]─────────────────────────────────────────────────────────────────────────────────────────────────────► 0x400774 <main+302>    mov    rax, qword ptr [rip + 0x2008e5] <0x601060>0x40077b <main+309>    mov    rcx, qword ptr [rbp - 0x30]0x40077f <main+313>    mov    rdx, qword ptr [rbp - 0x30]0x400783 <main+317>    mov    esi, 0x400a180x400788 <main+322>    mov    rdi, rax0x40078b <main+325>    mov    eax, 00x400790 <main+330>    call   fprintf@plt <0x400510>0x400795 <main+335>    mov    rax, qword ptr [rip + 0x2008c4] <0x601060>0x40079c <main+342>    mov    rdx, qword ptr [rbp - 0x28]0x4007a0 <main+346>    mov    esi, 0x400a7d0x4007a5 <main+351>    mov    rdi, rax
─────────────────────────────────────────────────────────────────────────────────────────────────[ SOURCE (CODE) ]─────────────────────────────────────────────────────────────────────────────────────────────────
In file: /ctf/work/how2heap/fastbin_dup.c19     fprintf(stderr, "第三个 malloc(8): %p\n", c);20 21     fprintf(stderr, "free 掉第一个\n");22     free(a);23 ► 24     fprintf(stderr, "当我们再次 free %p 的时候, 程序将会崩溃因为 %p 在 free 链表的第一个位置上\n", a, a);25     // free(a);26     fprintf(stderr, "我们先 free %p.\n", b);27     free(b);28 29     fprintf(stderr, "现在我们就可以再次 free %p 了, 因为他现在不在 free 链表的第一个位置上\n", a);
─────────────────────────────────────────────────────────────────────────────────────────────────────[ STACK ]─────────────────────────────────────────────────────────────────────────────────────────────────────
00:0000│ rsp  0x7fffffffe590 —▸ 0x602010 ◂— 0x0
01:0008│      0x7fffffffe598 —▸ 0x602030 ◂— 'BBBBBBBB'
02:0010│      0x7fffffffe5a0 —▸ 0x602050 ◂— 'CCCCCCCC'
03:0018│      0x7fffffffe5a8 —▸ 0x400550 (_start) ◂— xor    ebp, ebp
04:0020│      0x7fffffffe5b0 —▸ 0x7fffffffe6a0 ◂— 0x1
05:0028│      0x7fffffffe5b8 ◂— 0x0
06:0030│ rbp  0x7fffffffe5c0 —▸ 0x4008e0 (__libc_csu_init) ◂— push   r15
07:0038│      0x7fffffffe5c8 —▸ 0x7ffff7a2d830 (__libc_start_main+240) ◂— mov    edi, eax
───────────────────────────────────────────────────────────────────────────────────────────────────[ BACKTRACE ]───────────────────────────────────────────────────────────────────────────────────────────────────► f 0           400774 main+302f 1     7ffff7a2d830 __libc_start_main+240
Breakpoint /ctf/work/how2heap/fastbin_dup.c:24
pwndbg> x/20gx 0x602000
0x602000:       0x0000000000000000      0x0000000000000021
0x602010:       0x0000000000000000      0x0000000000000000
0x602020:       0x0000000000000000      0x0000000000000021
0x602030:       0x4242424242424242      0x0000000000000000
0x602040:       0x0000000000000000      0x0000000000000021
0x602050:       0x4343434343434343      0x0000000000000000
0x602060:       0x0000000000000000      0x0000000000020fa1
0x602070:       0x0000000000000000      0x0000000000000000
0x602080:       0x0000000000000000      0x0000000000000000
0x602090:       0x0000000000000000      0x0000000000000000
pwndbg> heap
heapbase : 0x602000
pwndbg> parseheap                                                                                                                                                                                                  
addr                prev                size                 status              fd                bk                
0x602000            0x0                 0x20                 Freed                0x0              None
0x602020            0x0                 0x20                 Used                None              None
0x602040            0x0                 0x20                 Used                None              None
pwndbg> 

3.3.3第二个 free 之后

chunk b 被添加到fastbins中,可以看到在b的fd指针那里已经改成了chunk a的地址了。 

pwndbg> c
Continuing.
当我们再次 free 0x602010 的时候, 程序将会崩溃因为 0x602010 在 free 链表的第一个位置上
我们先 free 0x602030.Breakpoint 3, main () at fastbin_dup.c:29
29          fprintf(stderr, "现在我们就可以再次 free %p 了, 因为他现在不在 free 链表的第一个位置上\n", a);
LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
───────────────────────────────────────────────────────────────────────────────────────────────────[ REGISTERS ]───────────────────────────────────────────────────────────────────────────────────────────────────RAX  0x602000 ◂— 0x0RBX  0x0RCX  0x7ffff7b04200 (__openat_2+16) ◂— cmp    eax, 0x410000 /* '=' */RDX  0x602000 ◂— 0x0RDI  0xffffffffRSI  0x7ffff7dd1b28 (main_arena+8) —▸ 0x602020 ◂— 0x0R8   0x602030 —▸ 0x602000 ◂— 0x0R9   0x0R10  0x0R11  0x246R12  0x400550 (_start) ◂— xor    ebp, ebpR13  0x7fffffffe6a0 ◂— 0x1R14  0x0R15  0x0RBP  0x7fffffffe5c0 —▸ 0x4008e0 (__libc_csu_init) ◂— push   r15RSP  0x7fffffffe590 —▸ 0x602010 ◂— 0x0RIP  0x4007be (main+376) ◂— mov    rax, qword ptr [rip + 0x20089b]
────────────────────────────────────────────────────────────────────────────────────────────────────[ DISASM ]─────────────────────────────────────────────────────────────────────────────────────────────────────► 0x4007be <main+376>    mov    rax, qword ptr [rip + 0x20089b] <0x601060>0x4007c5 <main+383>    mov    rdx, qword ptr [rbp - 0x30]0x4007c9 <main+387>    mov    esi, 0x400a980x4007ce <main+392>    mov    rdi, rax0x4007d1 <main+395>    mov    eax, 00x4007d6 <main+400>    call   fprintf@plt <0x400510>0x4007db <main+405>    mov    rax, qword ptr [rbp - 0x30]0x4007df <main+409>    mov    rdi, rax0x4007e2 <main+412>    call   free@plt <0x4004f0>0x4007e7 <main+417>    mov    rax, qword ptr [rip + 0x200872] <0x601060>0x4007ee <main+424>    mov    rdi, qword ptr [rbp - 0x30]
─────────────────────────────────────────────────────────────────────────────────────────────────[ SOURCE (CODE) ]─────────────────────────────────────────────────────────────────────────────────────────────────
In file: /ctf/work/how2heap/fastbin_dup.c24     fprintf(stderr, "当我们再次 free %p 的时候, 程序将会崩溃因为 %p 在 free 链表的第一个位置上\n", a, a);25     // free(a);26     fprintf(stderr, "我们先 free %p.\n", b);27     free(b);28 ► 29     fprintf(stderr, "现在我们就可以再次 free %p 了, 因为他现在不在 free 链表的第一个位置上\n", a);30     free(a);31     fprintf(stderr, "现在空闲链表是这样的 [ %p, %p, %p ]. 如果我们 malloc 三次, 我们会得到两次 %p \n", a, b, a, a);32     33     char* d = malloc(8);34     char* e = malloc(8);
─────────────────────────────────────────────────────────────────────────────────────────────────────[ STACK ]─────────────────────────────────────────────────────────────────────────────────────────────────────
00:0000│ rsp  0x7fffffffe590 —▸ 0x602010 ◂— 0x0
01:0008│      0x7fffffffe598 —▸ 0x602030 —▸ 0x602000 ◂— 0x0
02:0010│      0x7fffffffe5a0 —▸ 0x602050 ◂— 'CCCCCCCC'
03:0018│      0x7fffffffe5a8 —▸ 0x400550 (_start) ◂— xor    ebp, ebp
04:0020│      0x7fffffffe5b0 —▸ 0x7fffffffe6a0 ◂— 0x1
05:0028│      0x7fffffffe5b8 ◂— 0x0
06:0030│ rbp  0x7fffffffe5c0 —▸ 0x4008e0 (__libc_csu_init) ◂— push   r15
07:0038│      0x7fffffffe5c8 —▸ 0x7ffff7a2d830 (__libc_start_main+240) ◂— mov    edi, eax
───────────────────────────────────────────────────────────────────────────────────────────────────[ BACKTRACE ]───────────────────────────────────────────────────────────────────────────────────────────────────► f 0           4007be main+376f 1     7ffff7a2d830 __libc_start_main+240
Breakpoint /ctf/work/how2heap/fastbin_dup.c:29
pwndbg> parseheap
addr                prev                size                 status              fd                bk                
0x602000            0x0                 0x20                 Freed                0x0              None
0x602020            0x0                 0x20                 Freed           0x602000              None
0x602040            0x0                 0x20                 Used                None              None
pwndbg> x/20gx 0x602000
0x602000:       0x0000000000000000      0x0000000000000021
0x602010:       0x0000000000000000      0x0000000000000000
0x602020:       0x0000000000000000      0x0000000000000021
0x602030:       0x0000000000602000      0x0000000000000000
0x602040:       0x0000000000000000      0x0000000000000021
0x602050:       0x4343434343434343      0x0000000000000000
0x602060:       0x0000000000000000      0x0000000000020fa1
0x602070:       0x0000000000000000      0x0000000000000000
0x602080:       0x0000000000000000      0x0000000000000000
0x602090:       0x0000000000000000      0x0000000000000000
pwndbg> 

3.3.4 第三个free之后

此时,由于chunk a处于bin中第2块的位置,不会被double-free的检查机制检查出来,所以第三个free之后,chunk a再次被添加到fastbins 中。chunk a和chunk b形成了一个环

pwndbg> c
Continuing.
现在我们就可以再次 free 0x602010 了, 因为他现在不在 free 链表的第一个位置上Breakpoint 4, main () at fastbin_dup.c:31
31          fprintf(stderr, "现在空闲链表是这样的 [ %p, %p, %p ]. 如果我们 malloc 三次, 我们会得到两次 %p \n", a, b, a, a);
LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
───────────────────────────────────────────────────────────────────────────────────────────────────[ REGISTERS ]───────────────────────────────────────────────────────────────────────────────────────────────────RAX  0x602020 ◂— 0x0RBX  0x0RCX  0x7ffff7b04200 (__openat_2+16) ◂— cmp    eax, 0x410000 /* '=' */RDX  0x602020 ◂— 0x0RDI  0xffffffffRSI  0x7ffff7dd1b28 (main_arena+8) —▸ 0x602000 ◂— 0x0R8   0x602010 —▸ 0x602020 ◂— 0x0R9   0x0R10  0xe8be93e920656572R11  0x246R12  0x400550 (_start) ◂— xor    ebp, ebpR13  0x7fffffffe6a0 ◂— 0x1R14  0x0R15  0x0RBP  0x7fffffffe5c0 —▸ 0x4008e0 (__libc_csu_init) ◂— push   r15RSP  0x7fffffffe590 —▸ 0x602010 —▸ 0x602020 ◂— 0x0RIP  0x4007e7 (main+417) ◂— mov    rax, qword ptr [rip + 0x200872]
────────────────────────────────────────────────────────────────────────────────────────────────────[ DISASM ]─────────────────────────────────────────────────────────────────────────────────────────────────────0x4007d1 <main+395>    mov    eax, 00x4007d6 <main+400>    call   fprintf@plt <0x400510>0x4007db <main+405>    mov    rax, qword ptr [rbp - 0x30]0x4007df <main+409>    mov    rdi, rax0x4007e2 <main+412>    call   free@plt <0x4004f0>► 0x4007e7 <main+417>    mov    rax, qword ptr [rip + 0x200872] <0x601060>0x4007ee <main+424>    mov    rdi, qword ptr [rbp - 0x30]0x4007f2 <main+428>    mov    rsi, qword ptr [rbp - 0x30]0x4007f6 <main+432>    mov    rcx, qword ptr [rbp - 0x28]0x4007fa <main+436>    mov    rdx, qword ptr [rbp - 0x30]0x4007fe <main+440>    mov    r9, rdi
─────────────────────────────────────────────────────────────────────────────────────────────────[ SOURCE (CODE) ]─────────────────────────────────────────────────────────────────────────────────────────────────
In file: /ctf/work/how2heap/fastbin_dup.c26     fprintf(stderr, "我们先 free %p.\n", b);27     free(b);28 29     fprintf(stderr, "现在我们就可以再次 free %p 了, 因为他现在不在 free 链表的第一个位置上\n", a);30     free(a);► 31     fprintf(stderr, "现在空闲链表是这样的 [ %p, %p, %p ]. 如果我们 malloc 三次, 我们会得到两次 %p \n", a, b, a, a);32     33     char* d = malloc(8);34     char* e = malloc(8);35     char* f = malloc(8);36     strcpy(d, "DDDDDDDD");
─────────────────────────────────────────────────────────────────────────────────────────────────────[ STACK ]─────────────────────────────────────────────────────────────────────────────────────────────────────
00:0000│ rsp  0x7fffffffe590 —▸ 0x602010 —▸ 0x602020 ◂— 0x0
01:0008│      0x7fffffffe598 —▸ 0x602030 —▸ 0x602000 ◂— 0x0
02:0010│      0x7fffffffe5a0 —▸ 0x602050 ◂— 'CCCCCCCC'
03:0018│      0x7fffffffe5a8 —▸ 0x400550 (_start) ◂— xor    ebp, ebp
04:0020│      0x7fffffffe5b0 —▸ 0x7fffffffe6a0 ◂— 0x1
05:0028│      0x7fffffffe5b8 ◂— 0x0
06:0030│ rbp  0x7fffffffe5c0 —▸ 0x4008e0 (__libc_csu_init) ◂— push   r15
07:0038│      0x7fffffffe5c8 —▸ 0x7ffff7a2d830 (__libc_start_main+240) ◂— mov    edi, eax
───────────────────────────────────────────────────────────────────────────────────────────────────[ BACKTRACE ]───────────────────────────────────────────────────────────────────────────────────────────────────► f 0           4007e7 main+417f 1     7ffff7a2d830 __libc_start_main+240
Breakpoint /ctf/work/how2heap/fastbin_dup.c:31
pwndbg> parseheap
addr                prev                size                 status              fd                bk                
0x602000            0x0                 0x20                 Freed           0x602020              None
0x602020            0x0                 0x20                 Freed           0x602000              None
0x602040            0x0                 0x20                 Used                None              None
pwndbg> x/20gx 0x602000
0x602000:       0x0000000000000000      0x0000000000000021
0x602010:       0x0000000000602020      0x0000000000000000
0x602020:       0x0000000000000000      0x0000000000000021
0x602030:       0x0000000000602000      0x0000000000000000
0x602040:       0x0000000000000000      0x0000000000000021
0x602050:       0x4343434343434343      0x0000000000000000
0x602060:       0x0000000000000000      0x0000000000020fa1
0x602070:       0x0000000000000000      0x0000000000000000
0x602080:       0x0000000000000000      0x0000000000000000
0x602090:       0x0000000000000000      0x0000000000000000
pwndbg> bin
fastbins
0x20: 0x602000 —▸ 0x602020 ◂— 0x602000
0x30: 0x0
0x40: 0x0
0x50: 0x0
0x60: 0x0
0x70: 0x0
0x80: 0x0
unsortedbin
all: 0x0
smallbins
empty
largebins
empty
pwndbg> 

 3.3.5 最后再malloc三块内存d、e、f

可以看到0x4444444444444444被改成了 0x4646464646464646,是因为后来申请的 f 跟 d 指向同一块内存区域。

pwndbg> n
37          strcpy(e, "EEEEEEEE");
LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
───────────────────────────────────────────────────────────────────────────────────────────────────[ REGISTERS ]───────────────────────────────────────────────────────────────────────────────────────────────────RAX  0x602010 ◂— 'DDDDDDDD'RBX  0x0RCX  0x4444444444444444 ('DDDDDDDD')RDX  0x602010 ◂— 'DDDDDDDD'RDI  0x0RSI  0x7ffff7dd1b20 (main_arena) ◂— 0x0R8   0x602020 ◂— 0x0R9   0x7dR10  0x0R11  0x246R12  0x400550 (_start) ◂— xor    ebp, ebpR13  0x7fffffffe6a0 ◂— 0x1R14  0x0R15  0x0RBP  0x7fffffffe5c0 —▸ 0x4008e0 (__libc_csu_init) ◂— push   r15RSP  0x7fffffffe590 —▸ 0x602010 ◂— 'DDDDDDDD'RIP  0x400855 (main+527) ◂— mov    rax, qword ptr [rbp - 0x10]
────────────────────────────────────────────────────────────────────────────────────────────────────[ DISASM ]─────────────────────────────────────────────────────────────────────────────────────────────────────0x40083c <main+502>    mov    qword ptr [rbp - 8], rax0x400840 <main+506>    mov    rax, qword ptr [rbp - 0x18]0x400844 <main+510>    movabs rcx, 0x44444444444444440x40084e <main+520>    mov    qword ptr [rax], rcx0x400851 <main+523>    mov    byte ptr [rax + 8], 0► 0x400855 <main+527>    mov    rax, qword ptr [rbp - 0x10]0x400859 <main+531>    movabs rsi, 0x45454545454545450x400863 <main+541>    mov    qword ptr [rax], rsi0x400866 <main+544>    mov    byte ptr [rax + 8], 00x40086a <main+548>    mov    rax, qword ptr [rbp - 8]0x40086e <main+552>    movabs rcx, 0x4646464646464646
─────────────────────────────────────────────────────────────────────────────────────────────────[ SOURCE (CODE) ]─────────────────────────────────────────────────────────────────────────────────────────────────
In file: /ctf/work/how2heap/fastbin_dup.c32     33     char* d = malloc(8);34     char* e = malloc(8);35     char* f = malloc(8);36     strcpy(d, "DDDDDDDD");► 37     strcpy(e, "EEEEEEEE");38     strcpy(f, "FFFFFFFF");39     fprintf(stderr, "第一次 malloc(8): %p\n", d);40     fprintf(stderr, "第二次 malloc(8): %p\n", e);41     fprintf(stderr, "第三次 malloc(8): %p\n", f);42 }
─────────────────────────────────────────────────────────────────────────────────────────────────────[ STACK ]─────────────────────────────────────────────────────────────────────────────────────────────────────
00:0000│ rsp  0x7fffffffe590 —▸ 0x602010 ◂— 'DDDDDDDD'
01:0008│      0x7fffffffe598 —▸ 0x602030 —▸ 0x602000 ◂— 0x0
02:0010│      0x7fffffffe5a0 —▸ 0x602050 ◂— 'CCCCCCCC'
03:0018│      0x7fffffffe5a8 —▸ 0x602010 ◂— 'DDDDDDDD'
04:0020│      0x7fffffffe5b0 —▸ 0x602030 —▸ 0x602000 ◂— 0x0
05:0028│      0x7fffffffe5b8 —▸ 0x602010 ◂— 'DDDDDDDD'
06:0030│ rbp  0x7fffffffe5c0 —▸ 0x4008e0 (__libc_csu_init) ◂— push   r15
07:0038│      0x7fffffffe5c8 —▸ 0x7ffff7a2d830 (__libc_start_main+240) ◂— mov    edi, eax
───────────────────────────────────────────────────────────────────────────────────────────────────[ BACKTRACE ]───────────────────────────────────────────────────────────────────────────────────────────────────► f 0           400855 main+527f 1     7ffff7a2d830 __libc_start_main+240
pwndbg> bin
fastbins
0x20: 0x602020 —▸ 0x602000 ◂— 'DDDDDDDD'
0x30: 0x0
0x40: 0x0
0x50: 0x0
0x60: 0x0
0x70: 0x0
0x80: 0x0
unsortedbin
all: 0x0
smallbins
empty
largebins
empty
pwndbg> x/20gx 0x602000
0x602000:       0x0000000000000000      0x0000000000000021
0x602010:       0x4444444444444444      0x0000000000000000
0x602020:       0x0000000000000000      0x0000000000000021
0x602030:       0x0000000000602000      0x0000000000000000
0x602040:       0x0000000000000000      0x0000000000000021
0x602050:       0x4343434343434343      0x0000000000000000
0x602060:       0x0000000000000000      0x0000000000020fa1
0x602070:       0x0000000000000000      0x0000000000000000
0x602080:       0x0000000000000000      0x0000000000000000
0x602090:       0x0000000000000000      0x0000000000000000
pwndbg> 
pwndbg> n
38          strcpy(f, "FFFFFFFF");
LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
───────────────────────────────────────────────────────────────────────────────────────────────────[ REGISTERS ]───────────────────────────────────────────────────────────────────────────────────────────────────RAX  0x602030 ◂— 'EEEEEEEE'RBX  0x0RCX  0x4444444444444444 ('DDDDDDDD')RDX  0x602010 ◂— 'DDDDDDDD'RDI  0x0RSI  0x4545454545454545 ('EEEEEEEE')R8   0x602020 ◂— 0x0R9   0x7dR10  0x0R11  0x246R12  0x400550 (_start) ◂— xor    ebp, ebpR13  0x7fffffffe6a0 ◂— 0x1R14  0x0R15  0x0RBP  0x7fffffffe5c0 —▸ 0x4008e0 (__libc_csu_init) ◂— push   r15RSP  0x7fffffffe590 —▸ 0x602010 ◂— 'DDDDDDDD'RIP  0x40086a (main+548) ◂— mov    rax, qword ptr [rbp - 8]
────────────────────────────────────────────────────────────────────────────────────────────────────[ DISASM ]─────────────────────────────────────────────────────────────────────────────────────────────────────0x400851 <main+523>    mov    byte ptr [rax + 8], 00x400855 <main+527>    mov    rax, qword ptr [rbp - 0x10]0x400859 <main+531>    movabs rsi, 0x45454545454545450x400863 <main+541>    mov    qword ptr [rax], rsi0x400866 <main+544>    mov    byte ptr [rax + 8], 0► 0x40086a <main+548>    mov    rax, qword ptr [rbp - 8]0x40086e <main+552>    movabs rcx, 0x46464646464646460x400878 <main+562>    mov    qword ptr [rax], rcx0x40087b <main+565>    mov    byte ptr [rax + 8], 00x40087f <main+569>    mov    rax, qword ptr [rip + 0x2007da] <0x601060>0x400886 <main+576>    mov    rdx, qword ptr [rbp - 0x18]
─────────────────────────────────────────────────────────────────────────────────────────────────[ SOURCE (CODE) ]─────────────────────────────────────────────────────────────────────────────────────────────────
In file: /ctf/work/how2heap/fastbin_dup.c33     char* d = malloc(8);34     char* e = malloc(8);35     char* f = malloc(8);36     strcpy(d, "DDDDDDDD");37     strcpy(e, "EEEEEEEE");► 38     strcpy(f, "FFFFFFFF");39     fprintf(stderr, "第一次 malloc(8): %p\n", d);40     fprintf(stderr, "第二次 malloc(8): %p\n", e);41     fprintf(stderr, "第三次 malloc(8): %p\n", f);42 }
─────────────────────────────────────────────────────────────────────────────────────────────────────[ STACK ]─────────────────────────────────────────────────────────────────────────────────────────────────────
00:0000│ rsp  0x7fffffffe590 —▸ 0x602010 ◂— 'DDDDDDDD'
01:0008│      0x7fffffffe598 —▸ 0x602030 ◂— 'EEEEEEEE'
02:0010│      0x7fffffffe5a0 —▸ 0x602050 ◂— 'CCCCCCCC'
03:0018│      0x7fffffffe5a8 —▸ 0x602010 ◂— 'DDDDDDDD'
04:0020│      0x7fffffffe5b0 —▸ 0x602030 ◂— 'EEEEEEEE'
05:0028│      0x7fffffffe5b8 —▸ 0x602010 ◂— 'DDDDDDDD'
06:0030│ rbp  0x7fffffffe5c0 —▸ 0x4008e0 (__libc_csu_init) ◂— push   r15
07:0038│      0x7fffffffe5c8 —▸ 0x7ffff7a2d830 (__libc_start_main+240) ◂— mov    edi, eax
───────────────────────────────────────────────────────────────────────────────────────────────────[ BACKTRACE ]───────────────────────────────────────────────────────────────────────────────────────────────────► f 0           40086a main+548f 1     7ffff7a2d830 __libc_start_main+240
pwndbg> bin
fastbins
0x20: 0x602020 ◂— 'EEEEEEEE'
0x30: 0x0
0x40: 0x0
0x50: 0x0
0x60: 0x0
0x70: 0x0
0x80: 0x0
unsortedbin
all: 0x0
smallbins
empty
largebins
empty
pwndbg> x/20gx 0x602000
0x602000:       0x0000000000000000      0x0000000000000021
0x602010:       0x4444444444444444      0x0000000000000000
0x602020:       0x0000000000000000      0x0000000000000021
0x602030:       0x4545454545454545      0x0000000000000000
0x602040:       0x0000000000000000      0x0000000000000021
0x602050:       0x4343434343434343      0x0000000000000000
0x602060:       0x0000000000000000      0x0000000000020fa1
0x602070:       0x0000000000000000      0x0000000000000000
0x602080:       0x0000000000000000      0x0000000000000000
0x602090:       0x0000000000000000      0x0000000000000000
pwndbg> n
39          fprintf(stderr, "第一次 malloc(8): %p\n", d);
LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
───────────────────────────────────────────────────────────────────────────────────────────────────[ REGISTERS ]───────────────────────────────────────────────────────────────────────────────────────────────────RAX  0x602010 ◂— 'FFFFFFFF'RBX  0x0RCX  0x4646464646464646 ('FFFFFFFF')RDX  0x602010 ◂— 'FFFFFFFF'RDI  0x0RSI  0x4545454545454545 ('EEEEEEEE')R8   0x602020 ◂— 0x0R9   0x7dR10  0x0R11  0x246R12  0x400550 (_start) ◂— xor    ebp, ebpR13  0x7fffffffe6a0 ◂— 0x1R14  0x0R15  0x0RBP  0x7fffffffe5c0 —▸ 0x4008e0 (__libc_csu_init) ◂— push   r15RSP  0x7fffffffe590 —▸ 0x602010 ◂— 'FFFFFFFF'RIP  0x40087f (main+569) ◂— mov    rax, qword ptr [rip + 0x2007da]
────────────────────────────────────────────────────────────────────────────────────────────────────[ DISASM ]─────────────────────────────────────────────────────────────────────────────────────────────────────0x400866 <main+544>    mov    byte ptr [rax + 8], 00x40086a <main+548>    mov    rax, qword ptr [rbp - 8]0x40086e <main+552>    movabs rcx, 0x46464646464646460x400878 <main+562>    mov    qword ptr [rax], rcx0x40087b <main+565>    mov    byte ptr [rax + 8], 0► 0x40087f <main+569>    mov    rax, qword ptr [rip + 0x2007da] <0x601060>0x400886 <main+576>    mov    rdx, qword ptr [rbp - 0x18]0x40088a <main+580>    mov    esi, 0x400b660x40088f <main+585>    mov    rdi, rax0x400892 <main+588>    mov    eax, 00x400897 <main+593>    call   fprintf@plt <0x400510>
─────────────────────────────────────────────────────────────────────────────────────────────────[ SOURCE (CODE) ]─────────────────────────────────────────────────────────────────────────────────────────────────
In file: /ctf/work/how2heap/fastbin_dup.c34     char* e = malloc(8);35     char* f = malloc(8);36     strcpy(d, "DDDDDDDD");37     strcpy(e, "EEEEEEEE");38     strcpy(f, "FFFFFFFF");► 39     fprintf(stderr, "第一次 malloc(8): %p\n", d);40     fprintf(stderr, "第二次 malloc(8): %p\n", e);41     fprintf(stderr, "第三次 malloc(8): %p\n", f);42 }
─────────────────────────────────────────────────────────────────────────────────────────────────────[ STACK ]─────────────────────────────────────────────────────────────────────────────────────────────────────
00:0000│ rsp  0x7fffffffe590 —▸ 0x602010 ◂— 'FFFFFFFF'
01:0008│      0x7fffffffe598 —▸ 0x602030 ◂— 'EEEEEEEE'
02:0010│      0x7fffffffe5a0 —▸ 0x602050 ◂— 'CCCCCCCC'
03:0018│      0x7fffffffe5a8 —▸ 0x602010 ◂— 'FFFFFFFF'
04:0020│      0x7fffffffe5b0 —▸ 0x602030 ◂— 'EEEEEEEE'
05:0028│      0x7fffffffe5b8 —▸ 0x602010 ◂— 'FFFFFFFF'
06:0030│ rbp  0x7fffffffe5c0 —▸ 0x4008e0 (__libc_csu_init) ◂— push   r15
07:0038│      0x7fffffffe5c8 —▸ 0x7ffff7a2d830 (__libc_start_main+240) ◂— mov    edi, eax
───────────────────────────────────────────────────────────────────────────────────────────────────[ BACKTRACE ]───────────────────────────────────────────────────────────────────────────────────────────────────► f 0           40087f main+569f 1     7ffff7a2d830 __libc_start_main+240
pwndbg> x/20gx 0x602000
0x602000:       0x0000000000000000      0x0000000000000021
0x602010:       0x4646464646464646      0x0000000000000000
0x602020:       0x0000000000000000      0x0000000000000021
0x602030:       0x4545454545454545      0x0000000000000000
0x602040:       0x0000000000000000      0x0000000000000021
0x602050:       0x4343434343434343      0x0000000000000000
0x602060:       0x0000000000000000      0x0000000000020fa1
0x602070:       0x0000000000000000      0x0000000000000000
0x602080:       0x0000000000000000      0x0000000000000000
0x602090:       0x0000000000000000      0x0000000000000000
pwndbg> bin
fastbins
0x20: 0x602020 ◂— 'EEEEEEEE'
0x30: 0x0
0x40: 0x0
0x50: 0x0
0x60: 0x0
0x70: 0x0
0x80: 0x0
unsortedbin
all: 0x0
smallbins
empty
largebins
empty
pwndbg> 

3.3.6 总结

程序展示了fastbins的double-free攻击,可以泄露出一块已经被分配的内存指针。fastbins 可以看成一个后进先出的栈,使用单链表来实现,通过fastbin->fd来遍历。由于free的过程会对free list做检查,我们不能连续两次free同一个chunk,所以这里在两次free 之间,增加了一次对其他chunk的free 过程,从而绕过了检查顺利执行,然后再malloc三次,就在同一个地址malloc了两次,也就有了两个指向同一块内存区域的指针。

4.参考资料

【PWN】how2heap | 狼组安全团队公开知识库

这篇关于从零开始学howtoheap:理解fastbins的double-free攻击的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/695321

相关文章

Python结合Free Spire.PDF for Python实现PDF页面旋转

《Python结合FreeSpire.PDFforPython实现PDF页面旋转》在日常办公或文档处理中,我们经常会遇到PDF页面方向错误的问题,本文将分享如何用Python结合FreeSpir... 目录基础实现:单页PDF精准旋转完整代码代码解析进阶操作:覆盖多场景旋转需求1. 旋转指定角度(90/27

SQL 注入攻击(SQL Injection)原理、利用方式与防御策略深度解析

《SQL注入攻击(SQLInjection)原理、利用方式与防御策略深度解析》本文将从SQL注入的基本原理、攻击方式、常见利用手法,到企业级防御方案进行全面讲解,以帮助开发者和安全人员更系统地理解... 目录一、前言二、SQL 注入攻击的基本概念三、SQL 注入常见类型分析1. 基于错误回显的注入(Erro

GO语言zap日志库理解和使用方法示例

《GO语言zap日志库理解和使用方法示例》Zap是一个高性能、结构化日志库,专为Go语言设计,它由Uber开源,并且在Go社区中非常受欢迎,:本文主要介绍GO语言zap日志库理解和使用方法的相关资... 目录1. zap日志库介绍2.安装zap库3.配置日志记录器3.1 Logger3.2 Sugared

深入理解Redis线程模型的原理及使用

《深入理解Redis线程模型的原理及使用》Redis的线程模型整体还是多线程的,只是后台执行指令的核心线程是单线程的,整个线程模型可以理解为还是以单线程为主,基于这种单线程为主的线程模型,不同客户端的... 目录1 Redis是单线程www.chinasem.cn还是多线程2 Redis如何保证指令原子性2.

深入理解MySQL流模式

《深入理解MySQL流模式》MySQL的Binlog流模式是一种实时读取二进制日志的技术,允许下游系统几乎无延迟地获取数据库变更事件,适用于需要极低延迟复制的场景,感兴趣的可以了解一下... 目录核心概念一句话总结1. 背景知识:什么是 Binlog?2. 传统方式 vs. 流模式传统文件方式 (非流式)流

深入理解Go之==的使用

《深入理解Go之==的使用》本文主要介绍了深入理解Go之==的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录概述类型基本类型复合类型引用类型接口类型使用type定义的类型不可比较性谈谈map总结概述相信==判等操作,大

深入理解Mysql OnlineDDL的算法

《深入理解MysqlOnlineDDL的算法》本文主要介绍了讲解MysqlOnlineDDL的算法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小... 目录一、Online DDL 是什么?二、Online DDL 的三种主要算法2.1COPY(复制法)

C#利用Free Spire.XLS for .NET复制Excel工作表

《C#利用FreeSpire.XLSfor.NET复制Excel工作表》在日常的.NET开发中,我们经常需要操作Excel文件,本文将详细介绍C#如何使用FreeSpire.XLSfor.NET... 目录1. 环境准备2. 核心功能3. android示例代码3.1 在同一工作簿内复制工作表3.2 在不同

深入理解go中interface机制

《深入理解go中interface机制》本文主要介绍了深入理解go中interface机制,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学... 目录前言interface使用类型判断总结前言go的interface是一组method的集合,不

Java Spring的依赖注入理解及@Autowired用法示例详解

《JavaSpring的依赖注入理解及@Autowired用法示例详解》文章介绍了Spring依赖注入(DI)的概念、三种实现方式(构造器、Setter、字段注入),区分了@Autowired(注入... 目录一、什么是依赖注入(DI)?1. 定义2. 举个例子二、依赖注入的几种方式1. 构造器注入(Con