|
Title: Microsoft Visual C++ 8.0 standard library time functions
invalid assertion DoS (Problem 3000).
Product: Visual Studio 2005
Vendor: Microsoft
Vulnerability
class: Denial of Service
Remote: application dependant, remote vector is possible
CVE: CVE-2007-0842
Author: 3APA3A, http://SecurityVulns.com/
Advisory URL: http://SecurityVulns.com/advisories/year3000.asp
Intro:
Since Microsoft Visual Studio 5.0, Visual C++ compiler defaults time_t
type to 64 bit integer and time functions to their 64-bit variants.
Vulnerability:
64-bit versions of time functions:
localtime()
localtime_s()
gmtime()
gmtime_s()
ctime()
ctime_s()
wctime()
wctime_s()
fstat()
and may be others
incorrectly behave for a time_t argument larger than or equal to
_MAX__TIME64_T (representing January, 1 3000 00:00:00). According to
MSDN documentation, time functions must indicate error by returning NULL
pointer or EINVAL (depending on function class) and must not invoke any
invalid parameter handler. Instead, time function calls invalid
parameter assert()-like macro, terminating calling application and
creating Denial of Service condition for calling application.
An example is within localtime_s function (loctim64.c):
/*
* Check for illegal __time64_t value
*/
_VALIDATE_RETURN_ERRCODE_NOEXC( (*ptime >= 0), EINVAL);
_VALIDATE_RETURN_ERRCODE( (*ptime <= _MAX__TIME64_T), EINVAL);
Last string initiates assertion, it's invalid
_VALIDATE_RETURN_ERRCODE_NOEXC must be used for both negative and
oversized value. Valid code is:
/*
* Check for illegal __time64_t value
*/
_VALIDATE_RETURN_ERRCODE_NOEXC( (*ptime >= 0), EINVAL);
_VALIDATE_RETURN_ERRCODE_NOEXC( (*ptime <= _MAX__TIME64_T), EINVAL);
Both static and dynamic (MSVCR80.DLL) versions of C library are
vulnerable.
Who is vulnerable?
Any application compiled with Microsoft Visual C++ 8.0 compiler with
either static or dynamic libraries is vulnerable, if it uses one of
named functions with user-controlled data.
Possible attack vectors:
1. Network protocols and applications where time_t value is used and/or
transmitted as 8-octets (64 bit) in seconds or milliseconds and can be
behind January, 1, 3000. Example: different SQL databases.
2. Windows applications where time_t is result of conversion from
FILETIME or SYSTEMTIME structures. E. g. GetFileTime/SetFileTime
functions can be used to get/set NTFS file time to values behind
January, 1, 3000. You can try to exploit different applications by using
this very simple trick. This is also true for Java and JavaScript
timestamps.
3. Application where date_t is calculated as a result from user input +
some offset (e.g. timezone conversions for date December, 29 2999 23:01
GMT-01:00). An example: e-mail messages, HTTP requests, etc.
Example of vulnerable application:
/*
D:\>cl localtime_s.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
localtime_s.c
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
/out:localtime_s.exe
localtime_s.obj
D:\>localtime_s.exe
(Dr.Watson comes, expected result: "Invalid value")
*/
#include