mirror of
https://github.com/yuanyuanxiang/SimpleRemoter.git
synced 2026-01-23 15:53:10 +08:00
Improve: Ask for running master with administrator
This commit is contained in:
@@ -232,8 +232,45 @@ static BOOL IsAgentMode()
|
|||||||
|
|
||||||
// CMy2015RemoteApp 初始化
|
// CMy2015RemoteApp 初始化
|
||||||
|
|
||||||
|
BOOL IsRunningAsAdmin()
|
||||||
|
{
|
||||||
|
BOOL isAdmin = FALSE;
|
||||||
|
PSID administratorsGroup = NULL;
|
||||||
|
|
||||||
|
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
|
||||||
|
if (AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
|
||||||
|
0, 0, 0, 0, 0, 0, &administratorsGroup)) {
|
||||||
|
if (!CheckTokenMembership(NULL, administratorsGroup, &isAdmin)) {
|
||||||
|
isAdmin = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
FreeSid(administratorsGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
return isAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL LaunchAsAdmin(const char* szFilePath, const char* verb)
|
||||||
|
{
|
||||||
|
SHELLEXECUTEINFOA shExecInfo;
|
||||||
|
ZeroMemory(&shExecInfo, sizeof(SHELLEXECUTEINFOA));
|
||||||
|
shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOA);
|
||||||
|
shExecInfo.fMask = SEE_MASK_DEFAULT;
|
||||||
|
shExecInfo.hwnd = NULL;
|
||||||
|
shExecInfo.lpVerb = verb;
|
||||||
|
shExecInfo.lpFile = szFilePath;
|
||||||
|
shExecInfo.nShow = SW_NORMAL;
|
||||||
|
|
||||||
|
return ShellExecuteExA(&shExecInfo);
|
||||||
|
}
|
||||||
|
|
||||||
BOOL CMy2015RemoteApp::InitInstance()
|
BOOL CMy2015RemoteApp::InitInstance()
|
||||||
{
|
{
|
||||||
|
char curFile[MAX_PATH] = { 0 };
|
||||||
|
GetModuleFileNameA(NULL, curFile, MAX_PATH);
|
||||||
|
if (!IsRunningAsAdmin() && LaunchAsAdmin(curFile, "runas"))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
// 首先处理服务命令行参数
|
// 首先处理服务命令行参数
|
||||||
if (HandleServiceCommandLine()) {
|
if (HandleServiceCommandLine()) {
|
||||||
return FALSE; // 服务命令已处理,退出
|
return FALSE; // 服务命令已处理,退出
|
||||||
|
|||||||
@@ -1030,6 +1030,12 @@ BOOL CMy2015RemoteDlg::OnInitDialog()
|
|||||||
AUTO_TICK(500, "");
|
AUTO_TICK(500, "");
|
||||||
CDialogEx::OnInitDialog();
|
CDialogEx::OnInitDialog();
|
||||||
|
|
||||||
|
UPDATE_SPLASH(15, "正在注册主控信息...");
|
||||||
|
THIS_CFG.SetStr("settings", "MainWnd", std::to_string((uint64_t)GetSafeHwnd()));
|
||||||
|
THIS_CFG.SetStr("settings", "SN", getDeviceID(getHwFallback));
|
||||||
|
THIS_CFG.SetStr("settings", "PwdHash", GetPwdHash());
|
||||||
|
THIS_CFG.SetStr("settings", "MasterHash", GetMasterHash());
|
||||||
|
|
||||||
UPDATE_SPLASH(20, "正在初始化文件上传模块...");
|
UPDATE_SPLASH(20, "正在初始化文件上传模块...");
|
||||||
int ret = InitFileUpload(GetHMAC());
|
int ret = InitFileUpload(GetHMAC());
|
||||||
g_hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, AfxGetInstanceHandle(), 0);
|
g_hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, AfxGetInstanceHandle(), 0);
|
||||||
@@ -1199,10 +1205,6 @@ BOOL CMy2015RemoteDlg::OnInitDialog()
|
|||||||
OnCancel();
|
OnCancel();
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
THIS_CFG.SetStr("settings", "MainWnd", std::to_string((uint64_t)GetSafeHwnd()));
|
|
||||||
THIS_CFG.SetStr("settings", "SN", getDeviceID());
|
|
||||||
THIS_CFG.SetStr("settings", "PwdHash", GetPwdHash());
|
|
||||||
THIS_CFG.SetStr("settings", "MasterHash", GetMasterHash());
|
|
||||||
|
|
||||||
UPDATE_SPLASH(100, "启动完成!");
|
UPDATE_SPLASH(100, "启动完成!");
|
||||||
CloseSplash();
|
CloseSplash();
|
||||||
@@ -1790,7 +1792,7 @@ bool CMy2015RemoteDlg::CheckValid(int trail)
|
|||||||
auto settings = "settings", pwdKey = "Password";
|
auto settings = "settings", pwdKey = "Password";
|
||||||
// 验证口令
|
// 验证口令
|
||||||
CPasswordDlg dlg(this);
|
CPasswordDlg dlg(this);
|
||||||
static std::string hardwareID = getHardwareID();
|
static std::string hardwareID = getHardwareID(getHwFallback);
|
||||||
static std::string hashedID = hashSHA256(hardwareID);
|
static std::string hashedID = hashSHA256(hardwareID);
|
||||||
static std::string deviceID = getFixedLengthID(hashedID);
|
static std::string deviceID = getFixedLengthID(hashedID);
|
||||||
CString pwd = THIS_CFG.GetStr(settings, pwdKey, "").c_str();
|
CString pwd = THIS_CFG.GetStr(settings, pwdKey, "").c_str();
|
||||||
@@ -2771,7 +2773,7 @@ LRESULT CMy2015RemoteDlg::ShareClient(WPARAM wParam, LPARAM lParam)
|
|||||||
void CMy2015RemoteDlg::OnToolAuth()
|
void CMy2015RemoteDlg::OnToolAuth()
|
||||||
{
|
{
|
||||||
CPwdGenDlg dlg;
|
CPwdGenDlg dlg;
|
||||||
std::string hardwareID = getHardwareID();
|
std::string hardwareID = getHardwareID(getHwFallback);
|
||||||
std::string hashedID = hashSHA256(hardwareID);
|
std::string hashedID = hashSHA256(hardwareID);
|
||||||
std::string deviceID = getFixedLengthID(hashedID);
|
std::string deviceID = getFixedLengthID(hashedID);
|
||||||
dlg.m_sDeviceID = deviceID.c_str();
|
dlg.m_sDeviceID = deviceID.c_str();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "afxcmn.h"
|
#include "afxcmn.h"
|
||||||
#include "TrueColorToolBar.h"
|
#include "TrueColorToolBar.h"
|
||||||
#include "IOCPServer.h"
|
#include "IOCPServer.h"
|
||||||
|
#include <common/location.h>
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// 以下为特殊需求使用
|
// 以下为特殊需求使用
|
||||||
@@ -106,6 +107,11 @@ enum {
|
|||||||
|
|
||||||
class CSplashDlg; // 前向声明
|
class CSplashDlg; // 前向声明
|
||||||
|
|
||||||
|
inline std::string getHwFallback() {
|
||||||
|
IPConverter cvt;
|
||||||
|
return cvt.getPublicIP();
|
||||||
|
}
|
||||||
|
|
||||||
// CMy2015RemoteDlg 对话框
|
// CMy2015RemoteDlg 对话框
|
||||||
class CMy2015RemoteDlg : public CDialogEx
|
class CMy2015RemoteDlg : public CDialogEx
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "pwd_gen.h"
|
#include "pwd_gen.h"
|
||||||
#include "2015Remote.h"
|
#include "2015Remote.h"
|
||||||
#include "common/skCrypter.h"
|
#include "common/skCrypter.h"
|
||||||
|
#include "2015RemoteDlg.h"
|
||||||
|
|
||||||
// CPasswordDlg 对话框
|
// CPasswordDlg 对话框
|
||||||
|
|
||||||
@@ -196,7 +197,7 @@ void CPwdGenDlg::OnBnClickedButtonGenkey()
|
|||||||
getFixedLengthID(finalKey);
|
getFixedLengthID(finalKey);
|
||||||
m_sPassword = fixedKey.c_str();
|
m_sPassword = fixedKey.c_str();
|
||||||
m_EditPassword.SetWindowTextA(fixedKey.c_str());
|
m_EditPassword.SetWindowTextA(fixedKey.c_str());
|
||||||
std::string hardwareID = getHardwareID();
|
std::string hardwareID = getHardwareID(getHwFallback);
|
||||||
std::string hashedID = hashSHA256(hardwareID);
|
std::string hashedID = hashSHA256(hardwareID);
|
||||||
std::string deviceID = getFixedLengthID(hashedID);
|
std::string deviceID = getFixedLengthID(hashedID);
|
||||||
std::string hmac = genHMAC(pwdHash, m_sUserPwd.GetString());
|
std::string hmac = genHMAC(pwdHash, m_sUserPwd.GetString());
|
||||||
|
|||||||
@@ -89,13 +89,16 @@ std::string execCommand(const char* cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// <20><>ȡӲ<C8A1><D3B2> ID<49><44>CPU + <20><><EFBFBD><EFBFBD> + Ӳ<>̣<EFBFBD>
|
// <20><>ȡӲ<C8A1><D3B2> ID<49><44>CPU + <20><><EFBFBD><EFBFBD> + Ӳ<>̣<EFBFBD>
|
||||||
std::string getHardwareID()
|
std::string getHardwareID(fallback fb)
|
||||||
{
|
{
|
||||||
std::string cpuID = execCommand("wmic cpu get processorid");
|
std::string cpuID = execCommand("wmic cpu get processorid");
|
||||||
std::string boardID = execCommand("wmic baseboard get serialnumber");
|
std::string boardID = execCommand("wmic baseboard get serialnumber");
|
||||||
std::string diskID = execCommand("wmic diskdrive get serialnumber");
|
std::string diskID = execCommand("wmic diskdrive get serialnumber");
|
||||||
|
|
||||||
std::string combinedID = cpuID + "|" + boardID + "|" + diskID;
|
std::string combinedID = cpuID + "|" + boardID + "|" + diskID;
|
||||||
|
if (fb && combinedID.find("ERROR") != std::string::npos) {
|
||||||
|
return fb();
|
||||||
|
}
|
||||||
return combinedID;
|
return combinedID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,9 +147,9 @@ std::string deriveKey(const std::string& password, const std::string& hardwareID
|
|||||||
return hashSHA256(password + " + " + hardwareID);
|
return hashSHA256(password + " + " + hardwareID);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getDeviceID()
|
std::string getDeviceID(fallback fb)
|
||||||
{
|
{
|
||||||
static std::string hardwareID = getHardwareID();
|
static std::string hardwareID = getHardwareID(fb);
|
||||||
static std::string hashedID = hashSHA256(hardwareID);
|
static std::string hashedID = hashSHA256(hardwareID);
|
||||||
static std::string deviceID = getFixedLengthID(hashedID);
|
static std::string deviceID = getFixedLengthID(hashedID);
|
||||||
return deviceID;
|
return deviceID;
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
typedef std::string(*fallback)();
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><C9B7><EFBFBD><EFBFBD>˹<EFBFBD><CBB9>ܽ<EFBFBD><DCBD>м<EFBFBD><D0BC><EFBFBD>
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><C9B7><EFBFBD><EFBFBD>˹<EFBFBD><CBB9>ܽ<EFBFBD><DCBD>м<EFBFBD><D0BC><EFBFBD>
|
||||||
|
|
||||||
std::string getHardwareID();
|
std::string getHardwareID(fallback fb = NULL);
|
||||||
|
|
||||||
std::string hashSHA256(const std::string& data);
|
std::string hashSHA256(const std::string& data);
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ std::string getFixedLengthID(const std::string& hash);
|
|||||||
|
|
||||||
std::string deriveKey(const std::string& password, const std::string& hardwareID);
|
std::string deriveKey(const std::string& password, const std::string& hardwareID);
|
||||||
|
|
||||||
std::string getDeviceID();
|
std::string getDeviceID(fallback fb = NULL);
|
||||||
|
|
||||||
// Use HMAC to sign a message.
|
// Use HMAC to sign a message.
|
||||||
uint64_t SignMessage(const std::string& pwd, BYTE* msg, int len);
|
uint64_t SignMessage(const std::string& pwd, BYTE* msg, int len);
|
||||||
|
|||||||
Reference in New Issue
Block a user