从零开始学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

相关文章

深入理解Apache Airflow 调度器(最新推荐)

《深入理解ApacheAirflow调度器(最新推荐)》ApacheAirflow调度器是数据管道管理系统的关键组件,负责编排dag中任务的执行,通过理解调度器的角色和工作方式,正确配置调度器,并... 目录什么是Airflow 调度器?Airflow 调度器工作机制配置Airflow调度器调优及优化建议最

一文带你理解Python中import机制与importlib的妙用

《一文带你理解Python中import机制与importlib的妙用》在Python编程的世界里,import语句是开发者最常用的工具之一,它就像一把钥匙,打开了通往各种功能和库的大门,下面就跟随小... 目录一、python import机制概述1.1 import语句的基本用法1.2 模块缓存机制1.

深入理解C语言的void*

《深入理解C语言的void*》本文主要介绍了C语言的void*,包括它的任意性、编译器对void*的类型检查以及需要显式类型转换的规则,具有一定的参考价值,感兴趣的可以了解一下... 目录一、void* 的类型任意性二、编译器对 void* 的类型检查三、需要显式类型转换占用的字节四、总结一、void* 的

深入理解Redis大key的危害及解决方案

《深入理解Redis大key的危害及解决方案》本文主要介绍了深入理解Redis大key的危害及解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着... 目录一、背景二、什么是大key三、大key评价标准四、大key 产生的原因与场景五、大key影响与危

深入理解C++ 空类大小

《深入理解C++空类大小》本文主要介绍了C++空类大小,规定空类大小为1字节,主要是为了保证对象的唯一性和可区分性,满足数组元素地址连续的要求,下面就来了解一下... 目录1. 保证对象的唯一性和可区分性2. 满足数组元素地址连续的要求3. 与C++的对象模型和内存管理机制相适配查看类对象内存在C++中,规

认识、理解、分类——acm之搜索

普通搜索方法有两种:1、广度优先搜索;2、深度优先搜索; 更多搜索方法: 3、双向广度优先搜索; 4、启发式搜索(包括A*算法等); 搜索通常会用到的知识点:状态压缩(位压缩,利用hash思想压缩)。

【生成模型系列(初级)】嵌入(Embedding)方程——自然语言处理的数学灵魂【通俗理解】

【通俗理解】嵌入(Embedding)方程——自然语言处理的数学灵魂 关键词提炼 #嵌入方程 #自然语言处理 #词向量 #机器学习 #神经网络 #向量空间模型 #Siri #Google翻译 #AlexNet 第一节:嵌入方程的类比与核心概念【尽可能通俗】 嵌入方程可以被看作是自然语言处理中的“翻译机”,它将文本中的单词或短语转换成计算机能够理解的数学形式,即向量。 正如翻译机将一种语言

【C++高阶】C++类型转换全攻略:深入理解并高效应用

📝个人主页🌹:Eternity._ ⏩收录专栏⏪:C++ “ 登神长阶 ” 🤡往期回顾🤡:C++ 智能指针 🌹🌹期待您的关注 🌹🌹 ❀C++的类型转换 📒1. C语言中的类型转换📚2. C++强制类型转换⛰️static_cast🌞reinterpret_cast⭐const_cast🍁dynamic_cast 📜3. C++强制类型转换的原因📝

深入理解RxJava:响应式编程的现代方式

在当今的软件开发世界中,异步编程和事件驱动的架构变得越来越重要。RxJava,作为响应式编程(Reactive Programming)的一个流行库,为Java和Android开发者提供了一种强大的方式来处理异步任务和事件流。本文将深入探讨RxJava的核心概念、优势以及如何在实际项目中应用它。 文章目录 💯 什么是RxJava?💯 响应式编程的优势💯 RxJava的核心概念

如何通俗理解注意力机制?

1、注意力机制(Attention Mechanism)是机器学习和深度学习中一种模拟人类注意力的方法,用于提高模型在处理大量信息时的效率和效果。通俗地理解,它就像是在一堆信息中找到最重要的部分,把注意力集中在这些关键点上,从而更好地完成任务。以下是几个简单的比喻来帮助理解注意力机制: 2、寻找重点:想象一下,你在阅读一篇文章的时候,有些段落特别重要,你会特别注意这些段落,反复阅读,而对其他部分