Skip to content

Commit b796d8b

Browse files
committed
fix: minor fixes in extension_encryption.c
1 parent 72214ad commit b796d8b

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

c/meterpreter/source/metsrv/extension_encryption.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ DWORD cryptographic_manager_rc4_initialize(LPVOID* lpCryptoContext, LPVOID lpPar
3737
}
3838

3939
RC4_CTX* ctx = (RC4_CTX*)(*lpCryptoContext);
40-
InitRc4(ctx, (LPSTR)lpParams, strlen((LPSTR)lpParams));
40+
InitRc4(ctx, (unsigned char *)lpParams, KEY_SIZE_RC4);
4141
return 0;
4242
}
4343

@@ -47,7 +47,8 @@ DWORD cryptographic_manager_rc4_refresh(LPVOID lpCryptoContext, LPVOID lpParams)
4747
dprintf("[cryptographic_manager_rc4_refresh] lpCryptoContext is NULL.");
4848
return ERROR_INVALID_PARAMETER;
4949
}
50-
InitRc4(ctx, (LPSTR)lpParams, strlen((LPSTR)lpParams));
50+
InitRc4(ctx, (unsigned char *)lpParams, KEY_SIZE_RC4);
51+
dprintf("[cryptographic_manager_rc4] Refreshed RC4 Cryptographic Manager.");
5152
return 0;
5253
}
5354

@@ -93,6 +94,7 @@ BOOL cryptographic_manager_rc4(CryptographicManager* manager, LPVOID lpParams) {
9394
dprintf("[cryptographic_manager_rc4] Invalid parameters.");
9495
return FALSE;
9596
}
97+
dprintf("[cryptographic_manager_rc4] Initializing RC4 Cryptographic Manager.");
9698
manager->bInitialized = TRUE;
9799
manager->bNeedsRefresh = TRUE;
98100
manager->initialize = cryptographic_manager_rc4_initialize;
@@ -203,7 +205,13 @@ BOOL extension_encryption_add(LPVOID lpExtensionLocation, DWORD dwExtensionSize)
203205
lpExtensionStatus->lpLoc = lpExtensionLocation;
204206
lpExtensionStatus->dwSize = dwExtensionSize;
205207
lpExtensionStatus->dwLastUsedTime = GetTickCount();
208+
dprintf("[extension_encryption][extension_encryption_add] lpExtensionStatus->bEncryptable: %d", lpExtensionStatus->bEncryptable);
209+
dprintf("[extension_encryption][extension_encryption_add] lpExtensionStatus->bEncrypted: %d", lpExtensionStatus->bEncrypted);
210+
dprintf("[extension_encryption][extension_encryption_add] lpExtensionStatus->lpLoc: %p", lpExtensionStatus->lpLoc);
211+
dprintf("[extension_encryption][extension_encryption_add] lpExtensionStatus->dwSize: %u", lpExtensionStatus->dwSize);
212+
dprintf("[extension_encryption][extension_encryption_add] lpExtensionStatus->dwLastUsedTime: %u", lpExtensionStatus->dwLastUsedTime);
206213
g_ExtensionEncryptionManager->extensionStatuses[g_ExtensionEncryptionManager->dwExtensionsCount - 1] = lpExtensionStatus;
214+
dprintf("[extension_encryption][extension_encryption_add] Added extension at %p of size %u", lpExtensionLocation, dwExtensionSize);
207215
ret = TRUE;
208216
LeaveCriticalSection(&g_ExtensionEncryptionManager->cs);
209217
return ret;
@@ -313,6 +321,7 @@ BOOL extension_encryption_encrypt(ExtensionEncryptionStatus* lpExtensionStatus)
313321
}
314322

315323
lpExtensionStatus->dwLastUsedTime = GetTickCount();
324+
lpExtensionStatus->bEncrypted = TRUE;
316325
LeaveCriticalSection(&g_ExtensionEncryptionManager->cs);
317326
return ret;
318327
}
@@ -356,12 +365,11 @@ BOOL extension_encryption_decrypt(ExtensionEncryptionStatus* lpExtensionStatus)
356365

357366
if( g_ExtensionEncryptionManager->cryptoManager.bNeedsRefresh ) {
358367
if (g_ExtensionEncryptionManager->cryptoManager.refresh != NULL) {
359-
if (g_ExtensionEncryptionManager->cryptoManager.refresh(g_ExtensionEncryptionManager->cryptoManager.lpCryptoContext, g_ExtensionEncryptionManager->cryptoManager.lpCryptoParams) != 0) {
368+
if (g_ExtensionEncryptionManager->cryptoManager.refresh(g_ExtensionEncryptionManager->cryptoManager.lpCryptoContext, (LPVOID) g_ExtensionEncryptionManager->cryptoManager.lpCryptoParams) != 0) {
360369
dprintf("[extension_encryption][extension_encryption_decrypt] CryptographicManager refresh failed.");
361370
LeaveCriticalSection(&g_ExtensionEncryptionManager->cs);
362371
return FALSE;
363372
}
364-
g_ExtensionEncryptionManager->cryptoManager.bNeedsRefresh = FALSE;
365373
}
366374
}
367375

@@ -387,6 +395,7 @@ BOOL extension_encryption_decrypt(ExtensionEncryptionStatus* lpExtensionStatus)
387395
}
388396

389397
lpExtensionStatus->dwLastUsedTime = GetTickCount();
398+
lpExtensionStatus->bEncrypted = FALSE;
390399
LeaveCriticalSection(&g_ExtensionEncryptionManager->cs);
391400
return ret;
392401
}

c/meterpreter/source/metsrv/extension_encryption.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ typedef struct {
4949
BOOL (*remove)(ExtensionEncryptionStatus* lpStatus);
5050
BOOL (*encrypt)(ExtensionEncryptionStatus* lpStatus);
5151
BOOL (*decrypt)(ExtensionEncryptionStatus* lpStatus);
52-
void (*encryptUnused)(VOID);
52+
void (*encryptUnused)();
5353
};
5454
} ExtensionEncryptionManager;
5555

0 commit comments

Comments
 (0)