Closed randomssr closed 1 year ago
Hi!
I can confirm this issue. Above commit should get rid of it.
Thanks for the bugreport!
Hello, I hope you're doing well,
When I use this POC it's not give me the same result. you @Kaian can shear whit us the result after this POC Thank you!
I reproduced the vulnerability with the following command: sngrep:v1.6.0
CC=gcc CXX=g++ CFLAGS="-g -fsanitize=address" CXXFLAGS="-g -fsanitize=address" ./configure make I can get the above results. This stack-buffer-overflow bug happens in capture.c:147. The program does not check the length of "payload".
When I use this POC it's not give me the same result. you @Kaian can shear whit us the result after this POC
Sure!
Before 038a658
➜ # CC=gcc CXX=g++ CFLAGS="-g -fsanitize=address" CXXFLAGS="-g -fsanitize=address" ./configure
➜ # make
➜ # src/sngrep -N -R -I ~/Downloads/id0-stack-overflow
Dialog count: 0=================================================================
==10730==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fa3ad404040 at pc 0x7fa3b1461013 bp 0x7fa3addf9ae0 sp 0x7fa3addf9288
READ of size 57344 at 0x7fa3ad404040 thread T1
#0 0x7fa3b1461012 in __interceptor_memcpy /usr/src/debug/gcc/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:899
#1 0x5558a72925cb in packet_set_payload /home/kaian/Projects/sngrep/src/packet.c:147
#2 0x5558a728bc74 in parse_packet /home/kaian/Projects/sngrep/src/capture.c:430
#3 0x7fa3b1b7f8d2 (/usr/lib/libpcap.so.1+0x2c8d2) (BuildId: b1d10ed2f42804ba91995b233589e17e715d4218)
#4 0x7fa3b1b60b96 in pcap_loop (/usr/lib/libpcap.so.1+0xdb96) (BuildId: b1d10ed2f42804ba91995b233589e17e715d4218)
#5 0x5558a728f15a in capture_thread /home/kaian/Projects/sngrep/src/capture.c:1042
#6 0x7fa3b129d44a (/usr/lib/libc.so.6+0x8744a) (BuildId: 2f005a79cd1a8e385972f5a102f16adba414d75e)
#7 0x7fa3b1320e3f (/usr/lib/libc.so.6+0x10ae3f) (BuildId: 2f005a79cd1a8e385972f5a102f16adba414d75e)
Address 0x7fa3ad404040 is located in stack of thread T1 at offset 20544 in frame
#0 0x5558a728b316 in parse_packet /home/kaian/Projects/sngrep/src/capture.c:321
This frame has 3 object(s):
[32, 36) 'size_capture' (line 337)
[48, 52) 'size_payload' (line 339)
[64, 20544) 'data' (line 333) <== Memory access at offset 20544 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
(longjmp and C++ exceptions *are* supported)
Thread T1 created by T0 here:
#0 0x7fa3b144a4a7 in __interceptor_pthread_create /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_interceptors.cpp:208
#1 0x5558a728f045 in capture_launch_thread /home/kaian/Projects/sngrep/src/capture.c:1027
#2 0x5558a729bbdd in main /home/kaian/Projects/sngrep/src/main.c:451
#3 0x7fa3b123984f (/usr/lib/libc.so.6+0x2384f) (BuildId: 2f005a79cd1a8e385972f5a102f16adba414d75e)
SUMMARY: AddressSanitizer: stack-buffer-overflow /usr/src/debug/gcc/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:899 in __interceptor_memcpy
Shadow bytes around the buggy address:
0x7fa3ad403d80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7fa3ad403e00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7fa3ad403e80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7fa3ad403f00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7fa3ad403f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x7fa3ad404000: 00 00 00 00 00 00 00 00[f3]f3 f3 f3 f3 f3 f3 f3
0x7fa3ad404080: f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3
0x7fa3ad404100: f3 f3 f3 f3 f3 f3 f3 f3 00 00 00 00 00 00 00 00
0x7fa3ad404180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7fa3ad404200: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7fa3ad404280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
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
==10730==ABORTING
After 038a658
➜ # CC=gcc CXX=g++ CFLAGS="-g -fsanitize=address" CXXFLAGS="-g -fsanitize=address" ./configure
➜ # make
➜ # src/sngrep -N -R -I ~/Downloads/id0-stack-overflow
Dialog count: 0
=================================================================
==11703==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 664 byte(s) in 1 object(s) allocated from:
#0 0x7f2bcc4e0cd1 in __interceptor_calloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:77
#1 0x7f2bccb205e8 (/usr/lib/libpcap.so.1+0x295e8) (BuildId: b1d10ed2f42804ba91995b233589e17e715d4218)
Direct leak of 40 byte(s) in 1 object(s) allocated from:
#0 0x7f2bcc4e1369 in __interceptor_malloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:69
#1 0x55916acdbac6 in vector_create /home/kaian/Projects/sngrep/src/vector.c:40
#2 0x55916acc0244 in capture_offline /home/kaian/Projects/sngrep/src/capture.c:311
#3 0x55916acd079c in main /home/kaian/Projects/sngrep/src/main.c:390
#4 0x7f2bcc23984f (/usr/lib/libc.so.6+0x2384f) (BuildId: 2f005a79cd1a8e385972f5a102f16adba414d75e)
Direct leak of 40 byte(s) in 1 object(s) allocated from:
#0 0x7f2bcc4e1369 in __interceptor_malloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:69
#1 0x55916acdbac6 in vector_create /home/kaian/Projects/sngrep/src/vector.c:40
#2 0x55916acc0202 in capture_offline /home/kaian/Projects/sngrep/src/capture.c:310
#3 0x55916acd079c in main /home/kaian/Projects/sngrep/src/main.c:390
#4 0x7f2bcc23984f (/usr/lib/libc.so.6+0x2384f) (BuildId: 2f005a79cd1a8e385972f5a102f16adba414d75e)
Direct leak of 40 byte(s) in 1 object(s) allocated from:
#0 0x7f2bcc4e1369 in __interceptor_malloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:69
#1 0x55916acdbac6 in vector_create /home/kaian/Projects/sngrep/src/vector.c:40
#2 0x55916accfbb2 in main /home/kaian/Projects/sngrep/src/main.c:142
#3 0x7f2bcc23984f (/usr/lib/libc.so.6+0x2384f) (BuildId: 2f005a79cd1a8e385972f5a102f16adba414d75e)
Indirect leak of 96 byte(s) in 1 object(s) allocated from:
#0 0x7f2bcc4e1369 in __interceptor_malloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:69
#1 0x7f2bccb20868 (/usr/lib/libpcap.so.1+0x29868) (BuildId: b1d10ed2f42804ba91995b233589e17e715d4218)
SUMMARY: AddressSanitizer: 880 byte(s) leaked in 5 allocation(s).
I found a stack buffer overflow in sngrep. Please confirm. Thanks!
Test Environment Ubuntu 20.04, 64 bit sngrep (version: v1.6.0 ;5089514)
How to trigger Compile the program with AddressSanitizer Run command $ ./sngrep -N -R -I $PoC Details ASAN report $./sngrep -N -R -I $PoC
The URL of PoC is PoC