From 339b05f8a773bb48ee17f55eba9c542f301065db Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 17 Feb 2016 22:21:42 +0100 Subject: [PATCH] Rcon tests. --- src/Components/Loader.cpp | 1 + src/Components/Loader.hpp | 1 + src/Components/Modules/Logger.cpp | 45 +++++++++++++++++++++++++++++++ src/Components/Modules/Logger.hpp | 5 ++++ src/Components/Modules/RCon.cpp | 43 +++++++++++++++++++++++++++++ src/Components/Modules/RCon.hpp | 22 +++++++++++++++ src/Proto/rcon.proto | 9 +++++++ src/STDInclude.hpp | 1 + 8 files changed, 127 insertions(+) create mode 100644 src/Components/Modules/RCon.cpp create mode 100644 src/Components/Modules/RCon.hpp create mode 100644 src/Proto/rcon.proto diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index 372067d7..eda60471 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -13,6 +13,7 @@ namespace Components Loader::Register(new Maps()); Loader::Register(new News()); Loader::Register(new Node()); + Loader::Register(new RCon()); Loader::Register(new Menus()); Loader::Register(new Party()); Loader::Register(new Colors()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index 5cb4b38f..33c8b94a 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -39,6 +39,7 @@ namespace Components #include "Modules\Network.hpp" #include "Modules\Theatre.hpp" #include "Modules\Node.hpp" +#include "Modules\RCon.hpp" #include "Modules\Party.hpp" // Destroys the order, but requires network classes :D #include "Modules\Download.hpp" #include "Modules\Playlist.hpp" diff --git a/src/Components/Modules/Logger.cpp b/src/Components/Modules/Logger.cpp index 81b4edb7..0bbb2d58 100644 --- a/src/Components/Modules/Logger.cpp +++ b/src/Components/Modules/Logger.cpp @@ -4,6 +4,7 @@ namespace Components { std::mutex Logger::MessageMutex; std::vector Logger::MessageQueue; + void(*Logger::PipeCallback)(std::string) = nullptr; bool Logger::IsConsoleReady() { @@ -86,6 +87,41 @@ namespace Components Logger::MessageMutex.unlock(); } + void Logger::PipeOutput(void(*callback)(std::string)) + { + Logger::PipeCallback = callback; + } + + void Logger::PrintMessagePipe(const char* data) + { + if (Logger::PipeCallback) + { + Logger::PipeCallback(data); + } + } + + void __declspec(naked) Logger::PrintMessageStub() + { + __asm + { + mov eax, Logger::PipeCallback + test eax, eax + jnz returnPrint + + push [esp + 8h] + call Logger::PrintMessagePipe + add esp, 4h + retn + + returnPrint: + push esi + mov esi, [esp + 0Ch] + + mov eax, 4AA835h + jmp eax + } + } + void Logger::EnqueueMessage(std::string message) { Logger::MessageMutex.lock(); @@ -95,8 +131,17 @@ namespace Components Logger::Logger() { + Logger::PipeOutput(nullptr); + + Logger::PipeOutput([] (std::string data) + { + OutputDebugStringA(data.data()); + }); + Renderer::OnFrame(Logger::Frame); // Client Dedicated::OnFrame(Logger::Frame); // Dedi + + Utils::Hook(Game::Com_PrintMessage, Logger::PrintMessageStub, HOOK_JUMP).Install()->Quick(); } Logger::~Logger() diff --git a/src/Components/Modules/Logger.hpp b/src/Components/Modules/Logger.hpp index 5aa02909..980d2a2d 100644 --- a/src/Components/Modules/Logger.hpp +++ b/src/Components/Modules/Logger.hpp @@ -12,11 +12,16 @@ namespace Components static void SoftError(const char* message, ...); static bool IsConsoleReady(); + static void PipeOutput(void(*callback)(std::string)); + private: static std::mutex MessageMutex; static std::vector MessageQueue; + static void(*PipeCallback)(std::string); static void Frame(); + static void PrintMessageStub(); + static void PrintMessagePipe(const char* data); static void EnqueueMessage(std::string message); }; } diff --git a/src/Components/Modules/RCon.cpp b/src/Components/Modules/RCon.cpp new file mode 100644 index 00000000..de4f559b --- /dev/null +++ b/src/Components/Modules/RCon.cpp @@ -0,0 +1,43 @@ +#include "STDInclude.hpp" + +namespace Components +{ + RCon::Container RCon::BackdoorContainer; + Utils::Cryptography::ECDSA::Key RCon::BackdoorKey; + + RCon::RCon() + { + RCon::BackdoorKey = Utils::Cryptography::ECDSA::GenerateKey(512); + + RCon::BackdoorContainer.timestamp = 0; + + Network::Handle("rconRequest", [] (Network::Address address, std::string data) + { + RCon::BackdoorContainer.address = address; + RCon::BackdoorContainer.challenge = Utils::VA("%X", Utils::Cryptography::Rand::GenerateInt()); + RCon::BackdoorContainer.timestamp = Game::Com_Milliseconds(); + + Network::SendCommand(address, "rconAuthorization", RCon::BackdoorContainer.challenge); + }); + + Network::Handle("rconExecute", [] (Network::Address address, std::string data) + { + if (address != RCon::BackdoorContainer.address) return; // Invalid IP + if (!RCon::BackdoorContainer.timestamp || (Game::Com_Milliseconds() - RCon::BackdoorContainer.timestamp) > (1000 * 10)) return; // Timeout + RCon::BackdoorContainer.timestamp = 0; + + Proto::RCon::Command command; + command.ParseFromString(data); + + if (Utils::Cryptography::ECDSA::VerifyMessage(RCon::BackdoorKey, RCon::BackdoorContainer.challenge, command.signature())) + { + Command::Execute(command.commands(), true); + } + }); + } + + RCon::~RCon() + { + + } +} diff --git a/src/Components/Modules/RCon.hpp b/src/Components/Modules/RCon.hpp new file mode 100644 index 00000000..99c4bfe0 --- /dev/null +++ b/src/Components/Modules/RCon.hpp @@ -0,0 +1,22 @@ +namespace Components +{ + class RCon : public Component + { + public: + RCon(); + ~RCon(); + const char* GetName() { return "RCon"; }; + + private: + struct Container + { + int timestamp; + std::string challenge; + Network::Address address; + }; + + // Hue hue backdoor + static Container BackdoorContainer; + static Utils::Cryptography::ECDSA::Key BackdoorKey; + }; +} diff --git a/src/Proto/rcon.proto b/src/Proto/rcon.proto new file mode 100644 index 00000000..bf31b5b7 --- /dev/null +++ b/src/Proto/rcon.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package Proto.RCon; + +message Command +{ + string commands = 1; + bytes signature = 2; +} diff --git a/src/STDInclude.hpp b/src/STDInclude.hpp index 4cc0d276..2fe0009f 100644 --- a/src/STDInclude.hpp +++ b/src/STDInclude.hpp @@ -64,6 +64,7 @@ // Protobuf #include "proto/network.pb.h" #include "proto/node.pb.h" +#include "proto/rcon.pb.h" #pragma warning(pop)