-
Notifications
You must be signed in to change notification settings - Fork 15
/
hash.c
61 lines (53 loc) · 1008 Bytes
/
hash.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
*
* Captures incoming Net-NTLMv1/v2 hashes
* for incoming authentication attempts
* via NTLM.
*
* GuidePoint Security LLC
* Threat and Attack Simulation
*
**/
#include "common.h"
/**
*
* @brief: Hashes an input buffer of the specified length.
*
* @param: Pointer to the start of the buffer.
* @param: Length of the buffer.
*
**/
D_SEC( E ) ULONG HashString( _In_ PVOID Buffer, _In_ ULONG Length )
{
UCHAR Chr = 0 ;
UINT32 Djb = 0 ;
PUCHAR Ptr = NULL ;
Djb = 5381;
Ptr = Buffer;
while ( TRUE ) {
/* Parse the current character */
Chr = * Ptr;
/* \0 terminated? */
if ( ! Length ) {
if ( ! * Ptr ) {
break;
};
} else {
/* End of string? */
if ( ( ULONG )( Ptr - ( PUCHAR ) Buffer ) >= Length ) {
break;
};
/* Not null? Next! */
if ( ! * Ptr ) {
++Ptr; continue;
};
};
/* Uppercase */
if ( Chr >= 'a' ) {
Chr -= 0x20 ;
};
/* Create hash */
Djb = ( ( Djb << 5 ) + Djb ) + Chr; Ptr++;
};
return Djb;
};