From 1b7783f8e0b864d81c8ab7bb4d83cd2f789b0d48 Mon Sep 17 00:00:00 2001
From: auth12 <67507608+auth12@users.noreply.github.com>
Date: Fri, 28 Aug 2020 17:02:54 +0100
Subject: Added version checks on server. Changed main thread behaviour. Fixed
events bug where packet seq would get corrupted. Changed session packet
behaviour.
---
client/client.sln | 10 ++++
client/client.vcxproj | 82 +++++++++++++++++++++++++++++
client/client.vcxproj.filters | 12 ++---
client/src/client/client.h | 17 +++---
client/src/client/packet.h | 1 +
client/src/main.cpp | 105 +++++++++++++++++++++----------------
client/src/security/security.cpp | 34 +++---------
client/src/ui/ui.cpp | 4 +-
client/src/util/events.h | 4 +-
client/src/util/io.cpp | 2 -
client/src/util/io.h | 13 ++---
client/src/util/util.cpp | 5 --
client/wolfssl | 2 +-
server/src/client/client.h | 8 ++-
server/src/main.cpp | 108 +++++++++++++++++++++++++++++++++------
server/src/server/packet.h | 1 +
server/src/server/server.cpp | 2 +-
17 files changed, 286 insertions(+), 124 deletions(-)
diff --git a/client/client.sln b/client/client.sln
index f4f8604..54dd02b 100644
--- a/client/client.sln
+++ b/client/client.sln
@@ -18,6 +18,8 @@ Global
DLL Debug|x86 = DLL Debug|x86
DLL Release|x64 = DLL Release|x64
DLL Release|x86 = DLL Release|x86
+ Production|x64 = Production|x64
+ Production|x86 = Production|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
@@ -34,6 +36,10 @@ Global
{AB29EDA2-1C4F-4476-945B-AC08756EED67}.DLL Release|x64.Build.0 = Release|x64
{AB29EDA2-1C4F-4476-945B-AC08756EED67}.DLL Release|x86.ActiveCfg = Release|Win32
{AB29EDA2-1C4F-4476-945B-AC08756EED67}.DLL Release|x86.Build.0 = Release|Win32
+ {AB29EDA2-1C4F-4476-945B-AC08756EED67}.Production|x64.ActiveCfg = Production|x64
+ {AB29EDA2-1C4F-4476-945B-AC08756EED67}.Production|x64.Build.0 = Production|x64
+ {AB29EDA2-1C4F-4476-945B-AC08756EED67}.Production|x86.ActiveCfg = Production|Win32
+ {AB29EDA2-1C4F-4476-945B-AC08756EED67}.Production|x86.Build.0 = Production|Win32
{AB29EDA2-1C4F-4476-945B-AC08756EED67}.Release|x64.ActiveCfg = Release|x64
{AB29EDA2-1C4F-4476-945B-AC08756EED67}.Release|x64.Build.0 = Release|x64
{AB29EDA2-1C4F-4476-945B-AC08756EED67}.Release|x86.ActiveCfg = Release|Win32
@@ -50,6 +56,10 @@ Global
{73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Release|x64.Build.0 = DLL Release|x64
{73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Release|x86.ActiveCfg = DLL Release|Win32
{73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Release|x86.Build.0 = DLL Release|Win32
+ {73973223-5EE8-41CA-8E88-1D60E89A237B}.Production|x64.ActiveCfg = Production|x64
+ {73973223-5EE8-41CA-8E88-1D60E89A237B}.Production|x64.Build.0 = Production|x64
+ {73973223-5EE8-41CA-8E88-1D60E89A237B}.Production|x86.ActiveCfg = Release|Win32
+ {73973223-5EE8-41CA-8E88-1D60E89A237B}.Production|x86.Build.0 = Release|Win32
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Release|x64.ActiveCfg = Release|x64
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Release|x64.Build.0 = Release|x64
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Release|x86.ActiveCfg = Release|Win32
diff --git a/client/client.vcxproj b/client/client.vcxproj
index ac79152..d891f0d 100644
--- a/client/client.vcxproj
+++ b/client/client.vcxproj
@@ -5,6 +5,14 @@
Debug
Win32
+
+ Production
+ Win32
+
+
+ Production
+ x64
+
Release
Win32
@@ -39,6 +47,13 @@
true
Unicode
+
+ Application
+ false
+ v142
+ true
+ Unicode
+
Application
true
@@ -52,6 +67,13 @@
true
MultiByte
+
+ Application
+ false
+ v142
+ true
+ Unicode
+
@@ -63,12 +85,18 @@
+
+
+
+
+
+
true
@@ -76,6 +104,9 @@
false
+
+ false
+
true
@@ -85,6 +116,12 @@
$(SolutionDir)obj\$(ProjectName)\$(Platform)\$(Configuration)\
false
+
+ false
+ $(SolutionDir)bin\$(Platform)\$(Configuration)\
+ $(SolutionDir)obj\$(ProjectName)\$(Platform)\$(Configuration)\
+ false
+
Level3
@@ -113,6 +150,22 @@
true
+
+
+ Level3
+ true
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+ true
+ true
+
+
Level3
@@ -152,6 +205,35 @@
+
+
+ TurnOffAllWarnings
+ true
+ true
+ true
+ NDEBUG;_CONSOLE;NOMINMAX;WIN32_LEAN_AND_MEAN;_WINSOCK_DEPRECATED_NO_WARNINGS;FMT_HEADER_ONLY;IMGUI_DISABLE_INCLUDE_IMCONFIG_H;_REL;JM_XORSTR_DISABLE_AVX_INTRINSICS;%(PreprocessorDefinitions)
+ true
+ stdcpplatest
+ $(DXSDK_DIR)include\;$(SolutionDir);$(SolutionDir)wolfssl;$(SolutionDir)..\shared;$(SolutionDir)..\shared\spdlog\include;$(IncludePath)
+ MultiThreaded
+ Sync
+ Full
+ true
+ Speed
+
+
+ Windows
+ true
+ true
+ false
+ wolfssl.lib;ws2_32.lib;d3d9.lib;%(AdditionalDependencies)
+ $(DXSDK_DIR)Lib\x64\;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+ RequireAdministrator
+ false
+
+
+
+
diff --git a/client/client.vcxproj.filters b/client/client.vcxproj.filters
index 8b22397..3fd52a6 100644
--- a/client/client.vcxproj.filters
+++ b/client/client.vcxproj.filters
@@ -51,9 +51,6 @@
src\client
-
- src\util
-
src\injection
@@ -114,6 +111,9 @@
src\ui\imgui
+
+ src\util
+
@@ -140,9 +140,6 @@
src\util\apiset
-
- src\security
-
src\ui\imgui
@@ -164,5 +161,8 @@
src\ui\imgui
+
+ src\security
+
\ No newline at end of file
diff --git a/client/src/client/client.h b/client/src/client/client.h
index 372affc..bc87414 100644
--- a/client/src/client/client.h
+++ b/client/src/client/client.h
@@ -24,7 +24,7 @@ struct game_data_t {
namespace tcp {
enum client_state {
- connecting = 0, idle, logging_in, logged_in, imports_ready, waiting, image_ready, injected
+ connecting = 0, idle, logging_in, logged_in, imports_ready, waiting, image_ready, injected, blacklisted
};
enum login_result {
@@ -35,10 +35,11 @@ namespace tcp {
server_error = 98679
};
- enum session_result {
- hwid_fail = 4567,
+ enum hwid_result {
+ hwid_fail = 5671,
+ hwid_blacklisted = 4567,
version_mismatch = 5472,
- session_ok = 3247
+ ok = 3247
};
class client {
@@ -47,13 +48,10 @@ namespace tcp {
WOLFSSL* m_server_ssl;
WOLFSSL_CTX* m_ssl_ctx;
-
- std::mutex write_lock;
-
public:
int state;
int login_result;
- int session_result;
+ int hwid_result;
mapper_data_t mapper_data;
std::vector games;
game_data_t selected_game;
@@ -64,7 +62,7 @@ namespace tcp {
uint16_t ver = 4672;
- client() : m_socket{ -1 }, m_active{ false }, state{ client_state::connecting }, m_server_ssl{ nullptr }, m_ssl_ctx{ nullptr }, login_result{ -1 }, session_result{ -1 } {}
+ client() : m_socket{ -1 }, m_active{ false }, state{ client_state::connecting }, m_server_ssl{ nullptr }, m_ssl_ctx{ nullptr }, login_result{ -1 }, hwid_result{ -1 } {}
void start(const std::string_view server_ip, const uint16_t port);
@@ -74,7 +72,6 @@ namespace tcp {
}
__forceinline int write(const void* data, int size) {
- std::lock_guard lock(write_lock);
return wolfSSL_write(m_server_ssl, data, size);
}
diff --git a/client/src/client/packet.h b/client/src/client/packet.h
index fa119ef..1039249 100644
--- a/client/src/client/packet.h
+++ b/client/src/client/packet.h
@@ -12,6 +12,7 @@ namespace tcp {
enum packet_id {
message = 0,
hwid,
+ hwid_resp,
session,
login_req,
login_resp,
diff --git a/client/src/main.cpp b/client/src/main.cpp
index d7427cb..bc1c52d 100644
--- a/client/src/main.cpp
+++ b/client/src/main.cpp
@@ -11,7 +11,9 @@
#include "ui/ui.h"
void add_handlers(tcp::client& client) {
- client.connect_event.add([&]() { io::log("connected."); });
+ client.connect_event.add([&]() {
+ io::log("connected.");
+ });
client.receive_event.add([&](tcp::packet_t packet) {
if (!packet) return;
@@ -20,25 +22,6 @@ void add_handlers(tcp::client& client) {
if (id == tcp::packet_id::session) {
client.session_id = packet.session_id;
-
- uint16_t ver{ 0 };
- for (int i = 0; i < message.size(); ++i) {
- if (i % 2) { // skip characters in between
- continue;
- }
-
- ver += static_cast(message[i]) << 5;
- }
-
- if (client.ver != ver) {
- client.session_result = tcp::session_result::version_mismatch;
-
- std::this_thread::sleep_for(std::chrono::seconds(5));
-
- client.shutdown();
- return;
- }
-
/*hwid::hwid_data_t data;
if (!hwid::fetch(data)) {
client.session_result = tcp::session_result::hwid_fail;
@@ -49,21 +32,29 @@ void add_handlers(tcp::client& client) {
return;
}*/
+ nlohmann::json hwid_data;
+ hwid_data["uid"] = 0;
+
nlohmann::json json;
- json["uid"] = 0;
- //json["gpu"] = data.gpu;
+ json["hwid"] = hwid_data.dump();
+ json["ver"] = client.ver;
+
int ret = client.write(tcp::packet_t(json.dump(), tcp::packet_type::write, client.session_id, tcp::packet_id::hwid));
if (ret <= 0) {
- client.session_result = tcp::session_result::hwid_fail;
+ client.hwid_result = tcp::hwid_result::hwid_fail;
std::this_thread::sleep_for(std::chrono::seconds(5));
client.shutdown();
return;
}
+ }
+
+ if (id == tcp::packet_id::hwid_resp) {
+ auto j = nlohmann::json::parse(message);
- client.state = tcp::client_state::idle;
+ client.hwid_result = j["status"];
}
if (id == tcp::packet_id::login_resp) {
@@ -110,20 +101,24 @@ void add_handlers(tcp::client& client) {
}
if (id == tcp::packet_id::ban) {
+ client.state = tcp::client_state::blacklisted;
+
client.shutdown();
return;
}
io::log("{}:{}->{} {}", packet.seq, packet.session_id, message, id);
- });
+ });
}
int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
+#ifndef _REL
AllocConsole();
FILE* fp = nullptr;
freopen_s(&fp, "CONOUT$", "w", stdout);
+#endif
g_syscalls.init();
@@ -173,6 +168,9 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
MSG msg;
std::memset(&msg, 0, sizeof(msg));
+
+ bool stop = false;
+
while (msg.message != WM_QUIT) {
if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) {
TranslateMessage(&msg);
@@ -180,8 +178,13 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
continue;
}
- if (!client)
+ if (stop) {
+ client.shutdown();
+
+ std::this_thread::sleep_for(std::chrono::seconds(3));
+
break;
+ }
ImGui_ImplDX9_NewFrame();
ImGui_ImplWin32_NewFrame();
@@ -217,17 +220,38 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
SetWindowPos(hwnd, nullptr, point.x - offset_x, point.y - offset_y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
+ if (client.state == tcp::client_state::blacklisted) {
+ ImGui::Text("your computer has been blacklisted.");
+ }
+
if (client.state == tcp::client_state::connecting) {
- if (client.session_result == -1) {
+ if (client.hwid_result == -1) {
ImGui::Text("connecting...");
}
- if (client.session_result == tcp::session_result::hwid_fail) {
+ if (client.hwid_result == tcp::hwid_result::hwid_fail) {
ImGui::Text("internal client error.");
+
+ stop = true;
}
- if (client.session_result == tcp::session_result::version_mismatch) {
+ if (client.hwid_result == tcp::hwid_result::version_mismatch) {
ImGui::Text("please update your client.");
+
+ stop = true;
+ }
+
+
+ if (client.hwid_result == tcp::hwid_result::hwid_blacklisted) {
+ ImGui::Text("your computer is blacklisted.");
+
+ stop = true;
+ }
+
+ if (client.hwid_result == tcp::hwid_result::ok) {
+ ImGui::Text("connected.");
+
+ client.state = tcp::client_state::idle;
}
}
@@ -256,7 +280,7 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
}
if (ImGui::Button("exit")) {
- client.shutdown();
+ stop = true;
}
}
@@ -269,10 +293,7 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
if (res == tcp::login_result::banned) {
ImGui::Text("your account is banned.");
- std::this_thread::sleep_for(std::chrono::seconds(5));
-
- client.shutdown();
- break;
+ stop = true;
}
if (res == tcp::login_result::login_fail) {
@@ -282,19 +303,13 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
if (res == tcp::login_result::hwid_mismatch) {
ImGui::Text("please reset your hwid on the forums.");
- std::this_thread::sleep_for(std::chrono::seconds(5));
-
- client.shutdown();
- break;
+ stop = true;
}
if (res == tcp::login_result::server_error) {
ImGui::Text("internal server error, please contact a developer.");
- std::this_thread::sleep_for(std::chrono::seconds(5));
-
- client.shutdown();
- break;
+ stop = true;
}
if (res == tcp::login_result::login_success) {
@@ -342,7 +357,7 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
ImGui::EndChild();
if (ImGui::Button("exit")) {
- client.shutdown();
+ stop = true;
}
ImGui::EndGroup();
}
@@ -362,6 +377,8 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
if (client.state == tcp::client_state::injected) {
ImGui::Text("done.");
+
+ stop = true;
}
ImGui::End();
@@ -373,7 +390,7 @@ int WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPSTR cmd_args, int show_cmd) {
ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
ui::device->EndScene();
}
-
+
HRESULT result = ui::device->Present(0, 0, 0, 0);
if (result == D3DERR_DEVICELOST && ui::device->TestCooperativeLevel() == D3DERR_DEVICENOTRESET) {
diff --git a/client/src/security/security.cpp b/client/src/security/security.cpp
index b1e2b93..abe9db2 100644
--- a/client/src/security/security.cpp
+++ b/client/src/security/security.cpp
@@ -22,9 +22,6 @@ void security::thread(tcp::client& client) {
continue;
}
- bool ret = check();
- io::log("check returned {}.", ret);
-
std::unordered_map loaded_images;
if (!pe::get_all_modules(loaded_images)) {
io::log_error("failed to get loaded modules.");
@@ -34,7 +31,7 @@ void security::thread(tcp::client& client) {
break;
}
- std::vector patches;
+ int i = 0;
for (auto& [name, limage] : loaded_images) {
auto& parsed = parsed_images[name];
if (parsed.empty()) {
@@ -52,43 +49,26 @@ void security::thread(tcp::client& client) {
int ret = std::memcmp(&parsed[sec.va], reinterpret_cast(start + sec.va), sec.size);
if (ret != 0) {
+ ++i;
io::log("found patch in {}.", name);
}
-
- /*auto sec_start = reinterpret_cast(start + sec.va);
- auto sec_len = sec.size;
-
- for (size_t i = 0; i < sec_len; ++i) {
- auto va = start + sec.va + i;
- auto og_op = uint8_t(parsed[sec.va + i]);
- auto cur_op = sec_start[i];
-
- if (og_op != cur_op) {
- patch_t patch;
- patch.va = va;
- patch.original_op = og_op;
- patch.patched_op = cur_op;
- patch.module = name;
-
- patches.emplace_back(patch);
- }
- }*/
}
}
nlohmann::json j;
- j["patches"] = patches.size();
+ j["patches"] = i;
+ j["check"] = check();
- /*const auto ret = client.write(tcp::packet_t(j.dump(), tcp::packet_type::write, client.session_id, tcp::packet_id::security_report));
+ const auto ret = client.write(tcp::packet_t(j.dump(), tcp::packet_type::write, client.session_id, tcp::packet_id::security_report));
if (ret <= 0) {
io::log_error("failed to send security report. {}", ret);
client.shutdown();
break;
- }*/
+ }
- std::this_thread::sleep_for(std::chrono::seconds(5));
+ std::this_thread::sleep_for(std::chrono::seconds(10));
}
}
diff --git a/client/src/ui/ui.cpp b/client/src/ui/ui.cpp
index 3ef383d..277aeba 100644
--- a/client/src/ui/ui.cpp
+++ b/client/src/ui/ui.cpp
@@ -30,14 +30,14 @@ HWND ui::create_window(HINSTANCE instance, const std::pair size, const
wc.hInstance = instance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = 0;
- wc.lpszClassName = "LoaderClass";
+ wc.lpszClassName = L"LoaderClass";
RegisterClassEx(&wc);
auto flag = WS_POPUP;
/*flag &= ~WS_MAXIMIZEBOX;
flag &= ~WS_SIZEBOX;*/
- return CreateWindowEx(WS_EX_TOPMOST, wc.lpszClassName, "client", flag, pos.first, pos.second, size.first, size.second, 0, 0, wc.hInstance, 0);
+ return CreateWindowEx(WS_EX_TOPMOST, wc.lpszClassName, L"client", flag, pos.first, pos.second, size.first, size.second, 0, 0, wc.hInstance, 0);
}
bool ui::create_device(HWND hwnd) {
diff --git a/client/src/util/events.h b/client/src/util/events.h
index 67c4b1f..ffad3c6 100644
--- a/client/src/util/events.h
+++ b/client/src/util/events.h
@@ -5,13 +5,13 @@ class event {
using func_type = std::function;
std::mutex event_lock;
- std::list m_funcs;
+ std::vector m_funcs;
public:
void add(const func_type& func) {
std::lock_guard lock(event_lock);
- m_funcs.push_back(std::move(func));
+ m_funcs.emplace_back(func);
}
void call(Args... params) {
diff --git a/client/src/util/io.cpp b/client/src/util/io.cpp
index bfd58db..47d9dbe 100644
--- a/client/src/util/io.cpp
+++ b/client/src/util/io.cpp
@@ -1,8 +1,6 @@
#include "../include.h"
#include "io.h"
-std::mutex io::file_mutex;
-
bool io::read_file(const std::string_view path, std::vector& out) {
std::ifstream file(path.data(), std::ios::binary);
if (!file.good()) {
diff --git a/client/src/util/io.h b/client/src/util/io.h
index 2b99434..99339c5 100644
--- a/client/src/util/io.h
+++ b/client/src/util/io.h
@@ -5,36 +5,37 @@
#include "../client/enc.h"
-
-
namespace io {
- extern std::mutex file_mutex;
template
void log(const std::string_view str, Args... params) {
+#ifndef _REL
static auto handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_GREEN);
fmt::print("$> ");
SetConsoleTextAttribute(handle, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
- std::string msg{str};
+ std::string msg{ str };
msg.append("\n");
fmt::print(msg, std::forward(params)...);
+#endif
}
template
void log_error(const std::string_view str, Args... params) {
+#ifndef _REL
static auto handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_RED);
fmt::print("$> ");
SetConsoleTextAttribute(handle, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
- std::string msg{str};
+ std::string msg{ str };
msg.append("\n");
fmt::print(msg, std::forward(params)...);
- }
+#endif
+}
bool read_file(const std::string_view path, std::vector& out);
}; // namespace io
diff --git a/client/src/util/util.cpp b/client/src/util/util.cpp
index 7103604..b78d616 100644
--- a/client/src/util/util.cpp
+++ b/client/src/util/util.cpp
@@ -39,11 +39,6 @@ std::wstring util::multibyte_to_wide(const std::string& str) {
}
bool util::close_handle(HANDLE handle) {
- if (!handle) {
- io::log_error("invalid handle to close.");
- return false;
- }
-
static auto nt_close = g_syscalls.get("NtClose");
auto status = nt_close(handle);
diff --git a/client/wolfssl b/client/wolfssl
index 5015ddb..13fb320 160000
--- a/client/wolfssl
+++ b/client/wolfssl
@@ -1 +1 @@
-Subproject commit 5015ddb9b1eee748efc24056e46f81888c975f7a
+Subproject commit 13fb320bf0bb6e3bf2d921c9044c373379ebaf1b
diff --git a/server/src/client/client.h b/server/src/client/client.h
index 857ea50..1a37193 100644
--- a/server/src/client/client.h
+++ b/server/src/client/client.h
@@ -13,6 +13,12 @@ enum client_response {
server_error = 98679
};
+enum hwid_result {
+ blacklisted = 4567,
+ version_mismatch = 5472,
+ ok = 3247
+ };
+
class client {
int m_socket;
SSL* m_ssl;
@@ -57,7 +63,7 @@ class client {
bool timeout() { return std::difftime(std::time(nullptr), m_time) >= 300; }
- bool security_timeout() { return std::difftime(std::time(nullptr), security_time) >= 10; }
+ bool security_timeout() { return std::difftime(std::time(nullptr), security_time) >= 30; }
int write(const packet_t& packet) {
if (!packet) return 0;
diff --git a/server/src/main.cpp b/server/src/main.cpp
index 2fcd42f..07b728c 100644
--- a/server/src/main.cpp
+++ b/server/src/main.cpp
@@ -11,10 +11,10 @@ int main(int argc, char* argv[]) {
tcp::server client_server("6666");
// id 0 : notepad test dll
- client_server.images["notepad++.exe"] = pe::image("img.dll");
+ client_server.images["csgo.exe"] = pe::image("img.dll");
// x64 image test
- client_server.images64["sublime_text.exe"] = pe::image("img64.dll");
+ client_server.images64["notepad.exe"] = pe::image("img64.dll");
client_server.start();
@@ -26,6 +26,7 @@ int main(int argc, char* argv[]) {
ver += static_cast(version[i]) << 5;
}
+
io::logger->info("client version {}.", ver);
client_server.connect_event.add([&](tcp::client& client) {
@@ -87,27 +88,100 @@ int main(int argc, char* argv[]) {
return;
}
auto j = nlohmann::json::parse(message);
- if (j.contains("uid")) client.hwid = j["uid"];
+ if(!j.contains("ver") || !j.contains("hwid")) {
+ io::logger->warn(
+ "json hwid packet doesn't contain required fields!!");
+
+ client_server.disconnect_event.call(client);
+ return;
+ }
- client.hwid_data = message;
+ nlohmann::json response;
- io::logger->info("got hwid from {} : {}", ip, client.hwid);
+ int client_version = j["ver"];
+ if(client_version != ver) {
+ response["status"] = tcp::hwid_result::version_mismatch;
- client.reset_security_time();
+ io::logger->warn("{} has an outdated client version.", ip);
+
+ client.write(tcp::packet_t(response.dump(), tcp::packet_type::write,
+ session, tcp::packet_id::hwid_resp));
+
+ client_server.disconnect_event.call(client);
+ return;
+ }
+
+ auto hwid_data = nlohmann::json::parse(j["hwid"].get());
+
+ if(j.contains("uid")) client.hwid = hwid_data["uid"];
+
+ client.hwid_data = hwid_data.dump();
if (client_server.bl().find(client.hwid)) {
io::logger->warn("{} is hwid banned.", ip);
- client.write(tcp::packet_t(message, tcp::packet_type::write, session,
- tcp::packet_id::ban));
+ response["status"] = tcp::hwid_result::blacklisted;
+
+ client.write(tcp::packet_t(response.dump(), tcp::packet_type::write,
+ session, tcp::packet_id::hwid_resp));
client_server.disconnect_event.call(client);
return;
}
+
+ response["status"] = tcp::hwid_result::ok;
+
+ client.write(tcp::packet_t(response.dump(), tcp::packet_type::write,
+ session, tcp::packet_id::hwid_resp));
+
+ client.reset_security_time();
}
if (id == tcp::packet_id::security_report) {
+ if (!nlohmann::json::accept(message)) {
+ io::logger->warn("{} sent invalid security report packet.", ip);
+
+ client_server.disconnect_event.call(client);
+ return;
+ }
+
+ auto j = nlohmann::json::parse(message);
+
+ if (!j.contains("check") || !j.contains("patches")) {
+ io::logger->warn(
+ "json security report doesn't contain required fields!!");
+
+ client_server.disconnect_event.call(client);
+ return;
+ }
+
client.reset_security_time();
+
+ bool ret = j["check"];
+ if (ret) {
+ client_server.bl().add(client.hwid);
+
+ io::logger->warn("blacklisted {} due to failed security check.", ip,
+ ret);
+
+ client.write(tcp::packet_t("check", tcp::packet_type::write,
+ session, tcp::packet_id::ban));
+
+ client_server.disconnect_event.call(client);
+ return;
+ }
+
+ int patches = j["patches"];
+ if (patches > 0) {
+ client_server.bl().add(client.hwid);
+
+ io::logger->warn("blacklisted {}, found {} patches.", ip, patches);
+
+ client.write(tcp::packet_t("patch", tcp::packet_type::write,
+ session, tcp::packet_id::ban));
+
+ client_server.disconnect_event.call(client);
+ }
}
if (id == tcp::packet_id::login_req) {
@@ -180,14 +254,14 @@ int main(int argc, char* argv[]) {
}
json["result"] = tcp::client_response::login_success;
+ json["games"]["csgo"] = {{"version", 1},
+ {"id", 0},
+ {"process", "csgo.exe"},
+ {"x64", false}};
json["games"]["notepad"] = {{"version", 1},
- {"id", 0},
- {"process", "notepad++.exe"},
- {"x64", false}};
- json["games"]["sublime text"] = {{"version", 1},
- {"id", 1},
- {"process", "sublime_text.exe"},
- {"x64", true}};
+ {"id", 1},
+ {"process", "notepad.exe"},
+ {"x64", true}};
client.write(tcp::packet_t(json.dump(), tcp::packet_type::write,
session, tcp::packet_id::login_resp));
@@ -396,10 +470,10 @@ int main(int argc, char* argv[]) {
client_server().erase(it);
}
- /*if (client.security_timeout()) {
+ if (client.security_timeout()) {
io::logger->warn("{} failed to send security packet in time, dropping...",
client.get_ip());
- }*/
+ }
io::logger->info("{} timed out.", client.get_ip());
});
diff --git a/server/src/server/packet.h b/server/src/server/packet.h
index a2545e7..09cec7c 100644
--- a/server/src/server/packet.h
+++ b/server/src/server/packet.h
@@ -12,6 +12,7 @@ enum packet_type { write = 0, read };
enum packet_id {
message = 0,
hwid,
+ hwid_resp,
session,
login_req,
login_resp,
diff --git a/server/src/server/server.cpp b/server/src/server/server.cpp
index 898d6fe..204ee17 100644
--- a/server/src/server/server.cpp
+++ b/server/src/server/server.cpp
@@ -155,7 +155,7 @@ void tcp::server::receive() {
void tcp::server::check_timeout() {
auto it = std::find_if(client_stack.begin(), client_stack.end(),
- [&](client& c) { return c.timeout() /*|| c.security_timeout()*/; });
+ [&](client& c) { return c.timeout() || c.security_timeout(); });
if (it != client_stack.end()) {
timeout_event.call(*it);
--
cgit v1.2.3