diff --git a/include/winpr/sysinfo.h b/include/winpr/sysinfo.h index 85ba5bdc4..efb97e715 100644 --- a/include/winpr/sysinfo.h +++ b/include/winpr/sysinfo.h @@ -145,6 +145,8 @@ WINPR_API BOOL GetVersionExW(LPOSVERSIONINFOW lpVersionInformation); #define GetVersionEx GetVersionExA #endif +WINPR_API VOID GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime); + #endif #endif /* WINPR_SYSINFO_H */ diff --git a/include/winpr/wtypes.h b/include/winpr/wtypes.h index 1311132e2..f84710fb9 100644 --- a/include/winpr/wtypes.h +++ b/include/winpr/wtypes.h @@ -143,6 +143,23 @@ typedef LPSTR LPTSTR; typedef LPCSTR LPCTSTR; #endif +typedef union _ULARGE_INTEGER +{ + struct + { + DWORD LowPart; + DWORD HighPart; + }; + + struct + { + DWORD LowPart; + DWORD HighPart; + } u; + + ULONGLONG QuadPart; +} ULARGE_INTEGER, *PULARGE_INTEGER; + typedef struct _FILETIME { DWORD dwLowDateTime; diff --git a/winpr/sspi/NTLM/ntlm.c b/winpr/sspi/NTLM/ntlm.c index a74cb0e10..a0a545829 100644 --- a/winpr/sspi/NTLM/ntlm.c +++ b/winpr/sspi/NTLM/ntlm.c @@ -85,7 +85,7 @@ NTLM_CONTEXT* ntlm_ContextNew() if (context != NULL) { - context->ntlm_v2 = 0; + context->ntlm_v2 = FALSE; context->NegotiateFlags = 0; context->SendVersionInfo = 0; context->LmCompatibilityLevel = 3; diff --git a/winpr/sspi/NTLM/ntlm_compute.c b/winpr/sspi/NTLM/ntlm_compute.c index 5fcb53311..df5f11215 100644 --- a/winpr/sspi/NTLM/ntlm_compute.c +++ b/winpr/sspi/NTLM/ntlm_compute.c @@ -166,13 +166,15 @@ void ntlm_output_channel_bindings(NTLM_CONTEXT* context) void ntlm_current_time(BYTE* timestamp) { - UINT64 time64; + FILETIME filetime; + ULARGE_INTEGER time64; - /* Timestamp (8 bytes), represented as the number of tenths of microseconds since midnight of January 1, 1601 */ - time64 = time(NULL) + 11644473600LL; /* Seconds since January 1, 1601 */ - time64 *= 10000000; /* Convert timestamp to tenths of a microsecond */ + GetSystemTimeAsFileTime(&filetime); - CopyMemory(timestamp, &time64, 8); /* Copy into timestamp in little-endian */ + time64.LowPart = filetime.dwLowDateTime; + time64.HighPart = filetime.dwHighDateTime; + + CopyMemory(timestamp, &(time64.QuadPart), 8); } /** @@ -191,6 +193,13 @@ void ntlm_generate_timestamp(NTLM_CONTEXT* context) CopyMemory(context->av_pairs->Timestamp.value, context->Timestamp, 8); return; } + else + { + context->ntlm_v2 = FALSE; + context->av_pairs->Timestamp.length = 8; + context->av_pairs->Timestamp.value = malloc(context->av_pairs->Timestamp.length); + CopyMemory(context->av_pairs->Timestamp.value, context->Timestamp, 8); + } } else { @@ -279,23 +288,23 @@ void ntlm_compute_ntlm_v2_response(NTLM_CONTEXT* context) sspi_SecBufferAlloc(&ntlm_v2_temp, context->TargetInfo.cbBuffer + 28); - memset(ntlm_v2_temp.pvBuffer, '\0', ntlm_v2_temp.cbBuffer); + ZeroMemory(ntlm_v2_temp.pvBuffer, ntlm_v2_temp.cbBuffer); blob = (BYTE*) ntlm_v2_temp.pvBuffer; /* Compute the NTLMv2 hash */ ntlm_compute_ntlm_v2_hash(context, (char*) ntlm_v2_hash); #ifdef WITH_DEBUG_NTLM - printf("Password (length = %d)\n", context->identity.PasswordLength); - winpr_HexDump((BYTE*) context->identity.Password, context->identity.PasswordLength); + printf("Password (length = %d)\n", context->identity.PasswordLength * 2); + winpr_HexDump((BYTE*) context->identity.Password, context->identity.PasswordLength * 2); printf("\n"); - printf("Username (length = %d)\n", context->identity.UserLength); - winpr_HexDump((BYTE*) context->identity.User, context->identity.UserLength); + printf("Username (length = %d)\n", context->identity.UserLength * 2); + winpr_HexDump((BYTE*) context->identity.User, context->identity.UserLength * 2); printf("\n"); - printf("Domain (length = %d)\n", context->identity.DomainLength); - winpr_HexDump((BYTE*) context->identity.Domain, context->identity.DomainLength); + printf("Domain (length = %d)\n", context->identity.DomainLength * 2); + winpr_HexDump((BYTE*) context->identity.Domain, context->identity.DomainLength * 2); printf("\n"); printf("Workstation (length = %d)\n", context->WorkstationLength); diff --git a/winpr/sspi/NTLM/ntlm_message.c b/winpr/sspi/NTLM/ntlm_message.c index cb8cedcf0..d55e3b575 100644 --- a/winpr/sspi/NTLM/ntlm_message.c +++ b/winpr/sspi/NTLM/ntlm_message.c @@ -381,8 +381,8 @@ SECURITY_STATUS ntlm_read_ChallengeMessage(NTLM_CONTEXT* context, PSecBuffer buf winpr_HexDump(context->ChallengeMessage.pvBuffer, context->ChallengeMessage.cbBuffer); printf("\n"); #endif - /* AV_PAIRs */ + if (context->ntlm_v2) ntlm_populate_av_pairs(context); diff --git a/winpr/sysinfo/sysinfo.c b/winpr/sysinfo/sysinfo.c index fb1e5d02a..feadc8986 100644 --- a/winpr/sysinfo/sysinfo.c +++ b/winpr/sysinfo/sysinfo.c @@ -63,6 +63,7 @@ #ifndef _WIN32 +#include #include #include @@ -152,4 +153,17 @@ BOOL GetVersionExW(LPOSVERSIONINFOW lpVersionInformation) return 1; } +VOID GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime) +{ + ULARGE_INTEGER time64; + + /* time represented in tenths of microseconds since midnight of January 1, 1601 */ + + time64.QuadPart = time(NULL) + 11644473600LL; /* Seconds since January 1, 1601 */ + time64.QuadPart *= 10000000; /* Convert timestamp to tenths of a microsecond */ + + lpSystemTimeAsFileTime->dwLowDateTime = time64.LowPart; + lpSystemTimeAsFileTime->dwHighDateTime = time64.HighPart; +} + #endif