-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c9ab6f
commit 9a229fe
Showing
10 changed files
with
511 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#pragma once | ||
|
||
#include "crypto.h" | ||
|
||
BOOL crypto_hash(ALG_ID algid, LPCVOID data, DWORD dataLen, LPVOID hash, DWORD hashWanted) | ||
{ | ||
BOOL status = FALSE; | ||
HCRYPTPROV hProv; | ||
HCRYPTHASH hHash; | ||
DWORD hashLen; | ||
PBYTE buffer; | ||
PKERB_CHECKSUM pCheckSum; | ||
PVOID Context; | ||
|
||
if (algid == CALG_CRC32) | ||
{ | ||
if ((hashWanted == sizeof(DWORD)) && NT_SUCCESS(CDLocateCheckSum(KERB_CHECKSUM_REAL_CRC32, &pCheckSum))) | ||
{ | ||
if (NT_SUCCESS(pCheckSum->Initialize(0, &Context))) | ||
{ | ||
pCheckSum->Sum(Context, dataLen, data); | ||
status = NT_SUCCESS(pCheckSum->Finalize(Context, hash)); | ||
pCheckSum->Finish(&Context); | ||
} | ||
} | ||
} | ||
else if (CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) | ||
{ | ||
if (CryptCreateHash(hProv, algid, 0, 0, &hHash)) | ||
{ | ||
if (CryptHashData(hHash, (LPCBYTE)data, dataLen, 0)) | ||
{ | ||
if (CryptGetHashParam(hHash, HP_HASHVAL, NULL, &hashLen, 0)) | ||
{ | ||
if (buffer = (PBYTE)LocalAlloc(LPTR, hashLen)) | ||
{ | ||
status = CryptGetHashParam(hHash, HP_HASHVAL, buffer, &hashLen, 0); | ||
RtlCopyMemory(hash, buffer, min(hashLen, hashWanted)); | ||
LocalFree(buffer); | ||
} | ||
} | ||
} | ||
CryptDestroyHash(hHash); | ||
} | ||
CryptReleaseContext(hProv, 0); | ||
} | ||
return status; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#pragma once | ||
|
||
#include "globals.h" | ||
|
||
#define CALG_CRC32 (ALG_CLASS_HASH | ALG_TYPE_ANY | 0) | ||
|
||
#define MD5_DIGEST_LENGTH 16 | ||
#define LM_NTLM_HASH_LENGTH 16 | ||
|
||
#define RtlDecryptDES2blocks1DWORD SystemFunction025 | ||
#define RtlEncryptDecryptRC4 SystemFunction032 | ||
|
||
typedef NTSTATUS(WINAPI* PKERB_CHECKSUM_INITIALIZE) (DWORD unk0, PVOID* pContext); | ||
typedef NTSTATUS(WINAPI* PKERB_CHECKSUM_SUM) (PVOID pContext, DWORD Size, LPCVOID Buffer); | ||
typedef NTSTATUS(WINAPI* PKERB_CHECKSUM_FINALIZE) (PVOID pContext, PVOID Buffer); | ||
typedef NTSTATUS(WINAPI* PKERB_CHECKSUM_FINISH) (PVOID* pContext); | ||
typedef NTSTATUS(WINAPI* PKERB_CHECKSUM_INITIALIZEEX) (LPCVOID Key, DWORD KeySize, DWORD KeyUsage, PVOID* pContext); | ||
|
||
typedef struct _MD5_CTX { | ||
DWORD count[2]; | ||
DWORD state[4]; | ||
BYTE buffer[64]; | ||
BYTE digest[MD5_DIGEST_LENGTH]; | ||
} MD5_CTX, * PMD5_CTX; | ||
|
||
typedef struct _CRYPTO_BUFFER { | ||
DWORD Length; | ||
DWORD MaximumLength; | ||
PBYTE Buffer; | ||
} CRYPTO_BUFFER, * PCRYPTO_BUFFER; | ||
|
||
typedef struct _KERB_CHECKSUM { | ||
LONG Type; | ||
DWORD Size; | ||
DWORD Flag; | ||
PKERB_CHECKSUM_INITIALIZE Initialize; | ||
PKERB_CHECKSUM_SUM Sum; | ||
PKERB_CHECKSUM_FINALIZE Finalize; | ||
PKERB_CHECKSUM_FINISH Finish; | ||
PKERB_CHECKSUM_INITIALIZEEX InitializeEx; | ||
PVOID unk0_null; | ||
} KERB_CHECKSUM, * PKERB_CHECKSUM; | ||
|
||
extern VOID WINAPI MD5Init(PMD5_CTX pCtx); | ||
extern VOID WINAPI MD5Update(PMD5_CTX pCtx, LPCVOID data, DWORD cbData); | ||
extern VOID WINAPI MD5Final(PMD5_CTX pCtx); | ||
|
||
BOOL crypto_hash(ALG_ID algid, LPCVOID data, DWORD dataLen, LPVOID hash, DWORD hashWanted); |
Oops, something went wrong.