Skip to content

Commit 6a5f669

Browse files
committed
Added round key scan (w/ interrogate)
1 parent f1df684 commit 6a5f669

File tree

5 files changed

+321
-74
lines changed

5 files changed

+321
-74
lines changed

CMakeLists.txt

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.15)
22

33
set(CMAKE_SYSTEM_NAME Windows)
4-
project(KeyReaper VERSION 1.5.0)
4+
project(KeyReaper VERSION 1.6.0)
55
set(PROGRAM_NAME "KeyReaper")
66

77
set(MSVC True)
@@ -27,24 +27,13 @@ endif()
2727

2828
## Ease for includes
2929
add_library(common_includes INTERFACE)
30+
add_library(interrogate_include INTERFACE)
3031
target_include_directories(common_includes INTERFACE ${PROJECT_SOURCE_DIR}/include/keyreaper)
3132
target_include_directories(interrogate_include INTERFACE ${PROJECT_SOURCE_DIR}/include/interrogate)
3233

3334
# 3rd parties
3435
include(FetchContent)
3536

36-
# Interrogate
37-
FetchContent_Declare(
38-
interrogate
39-
URL https://sourceforge.net/projects/interrogate/files/interrogate/0.0.4/interrogate-0.0.4-source.tar.gz/download
40-
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
41-
)
42-
FetchContent_MakeAvailable(interrogate)
43-
set(FILE_PATH "${interrogate_SOURCE_DIR}/aes.c")
44-
file(READ ${FILE_PATH} FILE_CONTENT)
45-
string(REPLACE "interrogate.h" "aes.h" FILE_CONTENT "${FILE_CONTENT}")
46-
file(WRITE ${FILE_PATH} "${FILE_CONTENT}")
47-
4837
# JSON library
4938
FetchContent_Declare(
5039
json
@@ -96,7 +85,7 @@ add_executable(${EXECUTABLE_NAME}
9685
${SOURCE_BASE_DIR}/config.cc
9786
${SOURCE_BASE_DIR}/program_result.cc
9887
${SOURCE_BASE_DIR}/key.cc
99-
${interrogate_SOURCE_DIR}/aes.c
88+
${SOURCE_BASE_DIR}/interrogate/aes.cc
10089
${SOURCE_BASE_DIR}/scanners.cc
10190
${SOURCE_BASE_DIR}/key_scanner.cc
10291
${SOURCE_BASE_DIR}/injection/custom_ipc.cc

include/interrogate/aes.h

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#ifndef AES_INTERROGATE_H
22
#define AES_INTERROGATE_H
33

4+
#include <windows.h>
5+
#include <vector>
6+
#include <algorithm>
7+
48
namespace interrogate {
59

610
typedef struct {
@@ -34,57 +38,7 @@ void expand_key(unsigned char *in);
3438
void expand_key_192(unsigned char *in);
3539
void expand_key_256(unsigned char *in);
3640

37-
38-
void print_hex_array(unsigned char *buffer, int length, int columns) {
39-
int i;
40-
for (i = 0; i < length; i++) {
41-
if ((i % columns) == 0)
42-
printf("\n");
43-
printf("%02x ", buffer[i]);
44-
}
45-
printf("\n\n");
46-
}
47-
48-
std::vector<std::vector<BYTE>> aes_search(interrogate_context* ctx, unsigned char* buffer) {
49-
auto found_keys = vector<BYTE>();
50-
unsigned int i;
51-
52-
/* Set key schedule sizes */
53-
unsigned int kssize = 176;
54-
if (ctx->keysize == 192) {
55-
kssize = 208;
56-
} else if (ctx->keysize == 256) {
57-
kssize = 240;
58-
}
59-
60-
unsigned char* ks = (unsigned char*) malloc(kssize * sizeof(unsigned char));
61-
62-
for (i = ctx->from; i < ctx->filelen - kssize; i++) {
63-
/* Copy a chunk of data from buffer, expand it using AES key
64-
* schedule routines */
65-
ks = (unsigned char*) memcpy(ks, &buffer[i], kssize);
66-
if ((ctx->keysize == 128))
67-
expand_key(ks);
68-
else if ((ctx->keysize == 192))
69-
expand_key_192(ks);
70-
else
71-
expand_key_256(ks);
72-
/* Compare expanded key schedule to the data proceeding the chunk */
73-
if (memcmp(ks, &buffer[i], kssize) == 0) {
74-
ctx->count++;
75-
printf("Found (probable) AES key at offset %.8x:\n", i);
76-
print_hex_array(ks, ctx->keysize / 8, 16);
77-
printf("Expanded key:\n");
78-
print_hex_array(ks, kssize, 16);
79-
auto key = vector<BYTE>(ctx->keysize, 0);
80-
memcpy(key.data(), ks, min(key.size(), kssize));
81-
found_keys.push_back(move(key));
82-
}
83-
}
84-
if (ctx->count == 0) printf("Did not found any keys\n");
85-
86-
return found_keys;
87-
}
41+
std::vector<std::vector<BYTE>> aes_search(interrogate_context* ctx, unsigned char* buffer);
8842

8943
} // namespace interrogate
9044

src/custom-ransomware/basic-ransomware.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ void GenerateKeyChunck(HCRYPTPROV provider, ALG_ID alg, DWORD number_of_keys) {
277277
if (alg == CALG_RSA_KEYX || alg == CALG_RSA_SIGN) {
278278
printf(" [i] Asymmetric algorithm detected\n");
279279
data_len = 2048;
280-
getchar();
281280

282281
result = CryptExportKey(key, NULL, PRIVATEKEYBLOB, 0, buffer2, &data_len);
283282
if (result == 0) printf(" [x] Could not export the private pair\n");
@@ -450,7 +449,8 @@ int main(int argc, char* argv[]) {
450449

451450
// CheckAllBlockSizes(phProv);
452451
// GenerateKeyWithIV(phProv);
453-
GenerateKeyChunck(phProv, CALG_RSA_KEYX, 1);
452+
GenerateKeyChunck(phProv, CALG_AES_128, 1);
453+
getchar();
454454

455455
// create a hash object from the CSP (cryptographic service provider)
456456
HCRYPTHASH hHash;

0 commit comments

Comments
 (0)