SIPp / sipp

The SIPp testing tool
https://sipp.readthedocs.io
Other
916 stars 380 forks source link

[SECURITY] heap-buffer-overflow in message.cpp #727

Closed RootUp closed 3 weeks ago

RootUp commented 5 months ago

Summary

While fuzzing sipp (0254e2fa771f331053f8190280b6baf27927b574) it was found that the application suffers from out-of-bound via crafted XML files with a valid scenario, leading to denial or service or code execution.

ASAN

==3891007==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6160000002b7 at pc 0x000000582825 bp 0x7fffffffb6d0 sp 0x7fffffffb6c8
READ of size 1 at 0x6160000002b7 thread T0
    #0 0x582824 in quoted_strchr(char const*, int) /sipp/src/message.cpp:130:17
    #1 0x582824 in SendingMessage::SendingMessage(scenario*, char const*, bool) /sipp/src/message.cpp:227:20
    #2 0x5b6712 in scenario::scenario(char*, int) /sipp/src/scenario.cpp:848:45
    #3 0x63a0f9 in main /sipp/src/sipp.cpp:1706:41
    #4 0x7ffff764a082 in __libc_start_main /build/glibc-e2p3jK/glibc-2.31/csu/../csu/libc-start.c:308:16
    #5 0x426a7d in _start (/sipp/build/sipp+0x426a7d)

0x6160000002b7 is located 0 bytes to the right of 567-byte region [0x616000000080,0x6160000002b7)
allocated by thread T0 here:
    #0 0x48b564 in strdup (/sipp/build/sipp+0x48b564)
    #1 0x57f308 in SendingMessage::SendingMessage(scenario*, char const*, bool) /sipp/src/message.cpp:142:18
    #2 0x5b6712 in scenario::scenario(char*, int) /sipp/src/scenario.cpp:848:45
    #3 0x63a0f9 in main /sipp/src/sipp.cpp:1706:41
    #4 0x7ffff764a082 in __libc_start_main /build/glibc-e2p3jK/glibc-2.31/csu/../csu/libc-start.c:308:16

SUMMARY: AddressSanitizer: heap-buffer-overflow /sipp/src/message.cpp:130:17 in quoted_strchr(char const*, int)
Shadow bytes around the buggy address:
  0x0c2c7fff8000: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c2c7fff8010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c2c7fff8020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c2c7fff8030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c2c7fff8040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c2c7fff8050: 00 00 00 00 00 00[07]fa fa fa fa fa fa fa fa fa
  0x0c2c7fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c2c7fff8070: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2c7fff8080: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2c7fff8090: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2c7fff80a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
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
  Shadow gap:              cc
==3891007==ABORTING

Code Snippet

https://github.com/SIPp/sipp/blob/master/src/message.cpp#L130

static char* quoted_strchr(const char* s, int c)
{
    const char* p;

    for (p = s; *p && *p != c; p++) {
        if (*p == '"') {
            p++;
            p += strcspn(p, "\"");
        }
    }

    return *p == c ? const_cast<char*>(p) : nullptr;
}

The quoted_strchr function is iterating over a string s and incrementing the pointer p until it finds the character c or a null character (\0). However, it appears that the function is not handling the case properly where the character c is not found in the string, leading to an out-of-bounds read beyond the end of the string demonstrating heap overflow.

Proof-of-concept: hof.zip

orgads commented 3 weeks ago

Thank you! Will push a fix shortly.