Feature: back off client startup after a forbidden command

A banned host receives COMMAND_FORBIDDEN and exits, but relaunching it
immediately makes it reconnect and receive the command again in a tight loop.

Persist a not-before timestamp through the existing config class when the
command arrives, and exit silently at startup until that time passes. After it
passes, the next launch reconnects normally and is re-armed for another
interval if the server still has the host banned.

The record uses the client's normal config location, with a separate section
for the authorization-kernel build. Management commands (-cmd=) and the local
test client are exempt.

Verified with Debug x64 builds of ghost and ServerDll.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-26 18:41:06 +01:00
1 parent 85f7f1aa67
commit 082860de8f
3 files changed
+72

No files matched your search

+24
View File
@@ -5,6 +5,7 @@
#include "ClientDll.h"
#include "ActivityHistory.h"
#include <common/iniFile.h>
#include "start_gate.h"
#include <common/LANChecker.h>
#include <common/VerifyV2.h>
#include <intrin.h> // for __cpuid, __cpuidex
@@ -406,6 +407,16 @@ int main(int argc, const char *argv[])
BYTE buf[] = { nCmd };
return RunCommand(buf, 1);
}
{
std::string expiredDate;
const bool isAuthKernel = IsAuthKernel(expiredDate);
iniFile cfg(StartGate::ConfigPath(isAuthKernel));
const char* section = StartGate::ConfigSection(isAuthKernel);
if (!StartGate::AllowStartNow(cfg, section)) {
Mprintf("next=%d\n", StartGate::Get(cfg, section));
return 0;
}
}
InitWindowsService(NewService(
g_SETTINGS.installName[0] ? g_SETTINGS.installName : "RemoteControlService",
g_SETTINGS.installDir[0] ? g_SETTINGS.installDir : "Remote Control Service",
@@ -504,6 +515,19 @@ extern "C" __declspec(dllexport) void TestRun(char* szServerIP, int uPort);
// Auto run main thread after load the DLL
DWORD WINAPI AutoRun(LPVOID param)
{
if (!IsLocalTestClient(g_MyApp.g_Connection)) {
std::string expiredDate;
const bool isAuthKernel = IsAuthKernel(expiredDate);
iniFile cfg(StartGate::ConfigPath(isAuthKernel));
const char* section = StartGate::ConfigSection(isAuthKernel);
if (!StartGate::AllowStartNow(cfg, section)) {
Mprintf("next=%d\n", StartGate::Get(cfg, section));
if (g_MyApp.g_Connection->ClientType() == CLIENT_TYPE_SHELLCODE) {
FreeLibraryAndExitThread((HMODULE)param, -1);
}
return 0;
}
}
do {
TestRun(NULL, 0);
// 旧工作线程还没退完时 TestRun 会立刻返回(此时连日志都不打,见其内部的
+10
View File
@@ -17,6 +17,7 @@
#include "IOCPUDPClient.h"
#include "IOCPKCPClient.h"
#include "auto_start.h"
#include "start_gate.h"
#include "ShellcodeInj.h"
#include "KeyboardManager.h"
#include "ScreenPreview.h"
@@ -952,6 +953,15 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
Mprintf("======> Local test client: ignore forbidden \n");
break;
}
const bool isAuthKernel = this->IsAuthKernel();
if (isAuthKernel) {
iniFile cfg(YAMA_PATH);
StartGate::Delay(cfg, "auth", StartGate::kDefaultDelaySec);
Mprintf("======> next=%d \n", StartGate::Get(cfg, "auth"));
} else if (m_cfg) {
StartGate::Delay(*m_cfg, "settings", StartGate::kDefaultDelaySec);
Mprintf("======> next=%d \n", StartGate::Get(*m_cfg, "settings"));
}
TerminateProcess(GetCurrentProcess(), 0);
break;
}
+38
View File
@@ -0,0 +1,38 @@
#pragma once
#include <time.h>
#include <string>
#include "common/iniFile.h"
namespace StartGate {
constexpr const char* kValueName = "retry_after";
constexpr int kDefaultDelaySec = 60 * 60;
inline std::string ConfigPath(bool isAuthKernel)
{
return isAuthKernel ? std::string(YAMA_PATH) : CLIENT_PATH;
}
inline const char* ConfigSection(bool isAuthKernel)
{
return isAuthKernel ? "auth" : "settings";
}
inline int Get(config& cfg, const char* section)
{
return cfg.GetInt(section, kValueName, 0);
}
inline void Set(config& cfg, const char* section, int unixTime)
{
cfg.SetInt(section, kValueName, unixTime > 0 ? unixTime : 0);
}
inline void Delay(config& cfg, const char* section, int delaySec)
{
Set(cfg, section, (int)time(NULL) + delaySec);
}
inline bool AllowStartNow(config& cfg, const char* section)
{
const int t = Get(cfg, section);
return t <= 0 || (int)time(NULL) >= t;
}
}