================================================================= ==3116373==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffdd404f9b4 at pc #可以看到ASAN给我们定位到了栈溢出地址在0x7ffdd404f9b4,同时也给了bp,sp的值 0x55d2ab84708d bp 0x7ffdd404f7f0 sp 0x7ffdd404f7e8 READ of size 4 at 0x7ffdd404f9b4 thread T0 #00x55d2ab84708c in main /home/osaa/桌面/fuzz/asan_lab/stackover.cpp:4:10 #10x7f2f7af6f189 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #20x7f2f7af6f244 in __libc_start_main csu/../csu/libc-start.c:381:3 #30x55d2ab789300 in _start (/home/osaa/桌面/fuzz/asan_lab/stackover+0x20300) (BuildId: 70598e6f1fc76855f20289da2c89caf8155ace14) #还表示了采用read操作和给了函数栈 Address 0x7ffdd404f9b4 is located in stack of thread T0 at offset 436 in frame #00x55d2ab846eaf in main /home/osaa/桌面/fuzz/asan_lab/stackover.cpp:1 #标记漏洞在溢出的地址(0x7ffdd404f9b4)偏移436处 This frame has 1object(s): [32, 432) 'osaa' (line 2) <== Memory access at offset 436 overflows this variable HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext orvfork (longjmp and C++ exceptions *are* supported) SUMMARY: AddressSanitizer: stack-buffer-overflow /home/osaa/桌面/fuzz/asan_lab/stackover.cpp:4:10 in main Shadow bytes around the buggy address: 0x10003a801ee0: 00000000000000000000000000000000 0x10003a801ef0: 00000000000000000000000000000000 0x10003a801f00: f1 f1 f1 f1 000000000000000000000000 0x10003a801f10: 00000000000000000000000000000000 0x10003a801f20: 00000000000000000000000000000000 =>0x10003a801f30: 000000000000[f3]f3 f3 f3 f3 f3 f3 f3 f3 f3 0x10003a801f40: 00000000000000000000000000000000 0x10003a801f50: 00000000000000000000000000000000 0x10003a801f60: 00000000000000000000000000000000 0x10003a801f70: 00000000000000000000000000000000 0x10003a801f80: 00000000000000000000000000000000 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01020304050607 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb ==3116373==ABORTING #这一部分给出了一个内存中的示意图
==3118611==ERROR: AddressSanitizer: global-buffer-overflow on address 0x55d8fd970cf4 at pc 0x55d8fd93bedc bp 0x7fff2488bba0 sp 0x7fff2488bb98 READ of size 4 at 0x55d8fd970cf4 thread T0 #00x55d8fd93bedb in main /home/osaa/桌面/fuzz/asan_lab/global_buf_ex.cpp:4:10 #10x7fcefdc2d189 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #20x7fcefdc2d244 in __libc_start_main csu/../csu/libc-start.c:381:3 #30x55d8fd87e300 in _start (/home/osaa/桌面/fuzz/asan_lab/global_buf_ex+0x20300) (BuildId: e514f816b4c9a8607c4d2cac83c6aa6c8e736afc)
0x55d8fd970cf4 is located 4 bytes to the right of global variable 'osaa' defined in 'global_buf_ex.cpp:2:5' (0x55d8fd970b60) of size 400 SUMMARY: AddressSanitizer: global-buffer-overflow /home/osaa/桌面/fuzz/asan_lab/global_buf_ex.cpp:4:10 in main Shadow bytes around the buggy address: 0x0abb9fb26140: 00000000000000000000000000000000 0x0abb9fb26150: 00000000000000000000000000000000 0x0abb9fb26160: 00000000000000000000000000000000 0x0abb9fb26170: 00000000000000000000000000000000 0x0abb9fb26180: 00000000000000000000000000000000 =>0x0abb9fb26190: 0000000000000000000000000000[f9]f9 0x0abb9fb261a0: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 0x0abb9fb261b0: f9 f9 f9 f9 000000000000000000000000 0x0abb9fb261c0: 00000000000000000000000000000000 0x0abb9fb261d0: 00000000000000000000000000000000 0x0abb9fb261e0: 00000000000000000000000000000000 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01020304050607 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb ==3118611==ABORTING
==3121967==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7ffc8dec3ee0 at pc 0x5601e8037fbe bp 0x7ffc8dec3eb0 sp 0x7ffc8dec3ea8 WRITE of size 4 at 0x7ffc8dec3ee0 thread T0 #00x5601e8037fbd in main /home/osaa/桌面/fuzz/asan_lab/stack_use_after_sc.cpp:9:6 #10x7f56074d9189 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #20x7f56074d9244 in __libc_start_main csu/../csu/libc-start.c:381:3 #30x5601e7f7a300 in _start (/home/osaa/桌面/fuzz/asan_lab/stack_use_after_sc+0x20300) (BuildId: ddeb341fa724c7fc4aaf3a36d7181f1af9aaeabc)
Address 0x7ffc8dec3ee0 is located in stack of thread T0 at offset 32 in frame #00x5601e8037eaf in main /home/osaa/桌面/fuzz/asan_lab/stack_use_after_sc.cpp:4
This frame has 1object(s): [32, 36) 'osaa' (line 6) <== Memory access at offset 32 is inside this variable HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext orvfork (longjmp and C++ exceptions *are* supported) SUMMARY: AddressSanitizer: stack-use-after-scope /home/osaa/桌面/fuzz/asan_lab/stack_use_after_sc.cpp:9:6 in main Shadow bytes around the buggy address: 0x100011bd0780: 00000000000000000000000000000000 0x100011bd0790: 00000000000000000000000000000000 0x100011bd07a0: 00000000000000000000000000000000 0x100011bd07b0: 00000000000000000000000000000000 0x100011bd07c0: 00000000000000000000000000000000 =>0x100011bd07d0: 0000000000000000 f1 f1 f1 f1[f8]f3 f3 f3 0x100011bd07e0: 00000000000000000000000000000000 0x100011bd07f0: 00000000000000000000000000000000 0x100011bd0800: 00000000000000000000000000000000 0x100011bd0810: 00000000000000000000000000000000 0x100011bd0820: 00000000000000000000000000000000 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01020304050607 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb ==3121967==ABORTING
================================================================= ==3128767==ERROR: AddressSanitizer: stack-use-after-return on address 0x7f5e6c000024 at pc 0x55b0a492f06c bp 0x7fffa9f65d40 sp 0x7fffa9f65d38 READ of size 4 at 0x7f5e6c000024 thread T0 #00x55b0a492f06b in main /home/osaa/桌面/fuzz/asan_lab/stack_after_return.cpp:12:10 #10x7f5e6db2b189 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #20x7f5e6db2b244 in __libc_start_main csu/../csu/libc-start.c:381:3 #30x55b0a4871300 in _start (/home/osaa/桌面/fuzz/asan_lab/stack_use_after_return+0x20300) (BuildId: 17029a1a9d90225c3fcd1f3ca22844d46ab77b87)
Address 0x7f5e6c000024 is located in stack of thread T0 at offset 36 in frame #00x55b0a492eeaf in FunctionA() /home/osaa/桌面/fuzz/asan_lab/stack_after_return.cpp:5
This frame has 1object(s): [32, 432) 'osaa' (line 6) <== Memory access at offset 36 is inside this variable HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext orvfork (longjmp and C++ exceptions *are* supported) SUMMARY: AddressSanitizer: stack-use-after-return /home/osaa/桌面/fuzz/asan_lab/stack_after_return.cpp:12:10 in main Shadow bytes around the buggy address: 0x0fec4d7f7fb0: 00000000000000000000000000000000 0x0fec4d7f7fc0: 00000000000000000000000000000000 0x0fec4d7f7fd0: 00000000000000000000000000000000 0x0fec4d7f7fe0: 00000000000000000000000000000000 0x0fec4d7f7ff0: 00000000000000000000000000000000 =>0x0fec4d7f8000: f5 f5 f5 f5[f5]f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 0x0fec4d7f8010: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 0x0fec4d7f8020: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 0x0fec4d7f8030: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 0x0fec4d7f8040: 00000000000000000000000000000000 0x0fec4d7f8050: 00000000000000000000000000000000 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01020304050607 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb ==3128767==ABORTING
================================================================= ==3132691==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6140000001d4 at pc 0x5608f3bcf1fd bp 0x7ffda8f2f3b0 sp 0x7ffda8f2f3a8 READ of size 4 at 0x6140000001d4 thread T0 #00x5608f3bcf1fc in main /home/osaa/桌面/fuzz/asan_lab/uaf.cpp:5 #10x7f9a24c46189 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 #20x7f9a24c46244 in __libc_start_main_impl ../csu/libc-start.c:381 #30x5608f3bcf0c0 in _start (/home/osaa/桌面/fuzz/asan_lab/uaf+0x10c0)
0x6140000001d4 is located 4 bytes to the right of 400-byte region [0x614000000040,0x6140000001d0) allocated by thread T0 here: #00x7f9a24eb00c7 in operatornew[](unsignedlong) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:102 #10x5608f3bcf195 in main /home/osaa/桌面/fuzz/asan_lab/uaf.cpp:3
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/osaa/桌面/fuzz/asan_lab/uaf.cpp:5 in main Shadow bytes around the buggy address: 0x0c287fff7fe0: 00000000000000000000000000000000 0x0c287fff7ff0: 00000000000000000000000000000000 0x0c287fff8000: fa fa fa fa fa fa fa fa 0000000000000000 0x0c287fff8010: 00000000000000000000000000000000 0x0c287fff8020: 00000000000000000000000000000000 =>0x0c287fff8030: 00000000000000000000[fa]fa fa fa fa fa 0x0c287fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c287fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c287fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c287fff8070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c287fff8080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01020304050607 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb Shadow gap: cc ==3132691==ABORTING
==3133335==ERROR: AddressSanitizer: heap-use-after-free on address 0x614000000044 at pc 0x55f3fd3f41cb bp 0x7fff942f74c0 sp 0x7fff942f74b8 READ of size 4 at 0x614000000044 thread T0 #00x55f3fd3f41ca in main /home/osaa/桌面/fuzz/asan_lab/uaf.cpp:5 #10x7fecac046189 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 #20x7fecac046244 in __libc_start_main_impl ../csu/libc-start.c:381 #30x55f3fd3f40b0 in _start (/home/osaa/桌面/fuzz/asan_lab/uaf+0x10b0)
0x614000000044 is located 4 bytes inside of 400-byte region [0x614000000040,0x6140000001d0) freed by thread T0 here: #00x7fecac2b0a87 in operatordelete[](void*) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:163 #10x55f3fd3f4195 in main /home/osaa/桌面/fuzz/asan_lab/uaf.cpp:4
previously allocated by thread T0 here: #00x7fecac2b00c7 in operatornew[](unsignedlong) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:102 #10x55f3fd3f418a in main /home/osaa/桌面/fuzz/asan_lab/uaf.cpp:3
SUMMARY: AddressSanitizer: heap-use-after-free /home/osaa/桌面/fuzz/asan_lab/uaf.cpp:5 in main Shadow bytes around the buggy address: 0x0c287fff7fb0: 00000000000000000000000000000000 0x0c287fff7fc0: 00000000000000000000000000000000 0x0c287fff7fd0: 00000000000000000000000000000000 0x0c287fff7fe0: 00000000000000000000000000000000 0x0c287fff7ff0: 00000000000000000000000000000000 =>0x0c287fff8000: fa fa fa fa fa fa fa fa[fd]fd fd fd fd fd fd fd 0x0c287fff8010: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c287fff8020: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c287fff8030: fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa 0x0c287fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c287fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01020304050607 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb Shadow gap: cc ==3133335==ABORTING
下面一种是内存泄露漏洞,即一个指针指向一块内容后,指针不在调用,内容停留在堆区无法改变
1 2 3 4 5 6 7 8 9
==3134055==ERROR: LeakSanitizer: detected memory leaks Direct leak of 8byte(s) in 1object(s) allocated from: #00x55571255914e in __interceptor_malloc (/home/osaa/桌面/fuzz/asan_lab/mem_leak+0xa314e) (BuildId: 2acd876452190a500971caf36fe487f749e427eb) #10x555712593eb8 in main /home/osaa/桌面/fuzz/asan_lab/mem_leak.cpp:8:10 #20x7f9182d8c189 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
SUMMARY: AddressSanitizer: 8byte(s) leaked in 1allocation(s).
================================================================= ==2688234==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000071 at pc 0x55ec6f1d24e1 bp 0x7ffceb971fb0 sp 0x7ffceb971778 READ of size 2 at 0x602000000071 thread T0 #00x55ec6f1d24e0 in fputs (/home/osaa/桌面/fuzz/fuzzing_tiff/install/bin/tiffinfo+0x614e0) (BuildId: 09ddfdfe67d478d303d725e7968d407c632d1072) #10x55ec6f2c5051 in _TIFFPrintField /home/osaa/桌面/fuzz/fuzzing_tiff/tiff-4.0.4/libtiff/tif_print.c:127:4 #20x55ec6f2c5051 in TIFFPrintDirectory /home/osaa/桌面/fuzz/fuzzing_tiff/tiff-4.0.4/libtiff/tif_print.c:641:5 #30x55ec6f273e38 in tiffinfo /home/osaa/桌面/fuzz/fuzzing_tiff/tiff-4.0.4/tools/tiffinfo.c:449:2 #40x55ec6f2737e6 in main /home/osaa/桌面/fuzz/fuzzing_tiff/tiff-4.0.4/tools/tiffinfo.c:152:6 #50x7f41f3241189 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #60x7f41f3241244 in __libc_start_main csu/../csu/libc-start.c:381:3 #70x55ec6f1b5570 in _start (/home/osaa/桌面/fuzz/fuzzing_tiff/install/bin/tiffinfo+0x44570) (BuildId: 09ddfdfe67d478d303d725e7968d407c632d1072)
0x602000000071 is located 0 bytes to the right of 1-byte region [0x602000000070,0x602000000071) allocated by thread T0 here: #00x55ec6f2383be in __interceptor_malloc (/home/osaa/桌面/fuzz/fuzzing_tiff/install/bin/tiffinfo+0xc73be) (BuildId: 09ddfdfe67d478d303d725e7968d407c632d1072) #10x55ec6f27b674 in setByteArray /home/osaa/桌面/fuzz/fuzzing_tiff/tiff-4.0.4/libtiff/tif_dir.c:51:19
SUMMARY: AddressSanitizer: heap-buffer-overflow (/home/osaa/桌面/fuzz/fuzzing_tiff/install/bin/tiffinfo+0x614e0) (BuildId: 09ddfdfe67d478d303d725e7968d407c632d1072) in fputs Shadow bytes around the buggy address: 0x0c047fff7fb0: 00000000000000000000000000000000 0x0c047fff7fc0: 00000000000000000000000000000000 0x0c047fff7fd0: 00000000000000000000000000000000 0x0c047fff7fe0: 00000000000000000000000000000000 0x0c047fff7ff0: 00000000000000000000000000000000 =>0x0c047fff8000: fa fa 0000 fa fa fd fa fa fa fd fa fa fa[01]fa 0x0c047fff8010: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fa 0x0c047fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c047fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01020304050607 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb ==2688234==ABORTING
Fuzzing101 - tiff
本次练习在之前的基础上,教会了我们使用lcov来查看代码覆盖率,调整fuzz的覆盖和变异种子,记住使用lcov之前要调整环境变量export LDFLAGS=”–coverage” export CFLAGS=”–coverage” make clean以后重新make
1 2 3
sudo su echo core >/proc/sys/kernel/core_pattern exit
调整崩溃处理后进行fuzz,之后可以看到由于我fuzz了3分钟就停止了 覆盖率是很低的
1 2 3 4 5 6 7 8 9 10 11
Current view: top level Hit Total Coverage Test: app2.info Lines: 1229 11796 10.4 % Date: 2023-02-27 16:09:56 Functions: 91 560 16.2 % Legend: Rating: low: < 75 % medium: >= 75 % high: >= 90 %
Directory Sort by name Line Coverage Sort by line coverage Functions Sort by function coverage libtiff 10.0%10.0% 10.0 % 1159 / 11545 15.9 % 87 / 546 tools 27.9%27.9 27.9 % 70 / 251 28.6 % 4 / 14