Rcon tests.

This commit is contained in:
momo5502 2016-02-17 22:21:42 +01:00
parent 59a00f2b0e
commit 339b05f8a7
8 changed files with 127 additions and 0 deletions

View File

@ -13,6 +13,7 @@ namespace Components
Loader::Register(new Maps()); Loader::Register(new Maps());
Loader::Register(new News()); Loader::Register(new News());
Loader::Register(new Node()); Loader::Register(new Node());
Loader::Register(new RCon());
Loader::Register(new Menus()); Loader::Register(new Menus());
Loader::Register(new Party()); Loader::Register(new Party());
Loader::Register(new Colors()); Loader::Register(new Colors());

View File

@ -39,6 +39,7 @@ namespace Components
#include "Modules\Network.hpp" #include "Modules\Network.hpp"
#include "Modules\Theatre.hpp" #include "Modules\Theatre.hpp"
#include "Modules\Node.hpp" #include "Modules\Node.hpp"
#include "Modules\RCon.hpp"
#include "Modules\Party.hpp" // Destroys the order, but requires network classes :D #include "Modules\Party.hpp" // Destroys the order, but requires network classes :D
#include "Modules\Download.hpp" #include "Modules\Download.hpp"
#include "Modules\Playlist.hpp" #include "Modules\Playlist.hpp"

View File

@ -4,6 +4,7 @@ namespace Components
{ {
std::mutex Logger::MessageMutex; std::mutex Logger::MessageMutex;
std::vector<std::string> Logger::MessageQueue; std::vector<std::string> Logger::MessageQueue;
void(*Logger::PipeCallback)(std::string) = nullptr;
bool Logger::IsConsoleReady() bool Logger::IsConsoleReady()
{ {
@ -86,6 +87,41 @@ namespace Components
Logger::MessageMutex.unlock(); 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) void Logger::EnqueueMessage(std::string message)
{ {
Logger::MessageMutex.lock(); Logger::MessageMutex.lock();
@ -95,8 +131,17 @@ namespace Components
Logger::Logger() Logger::Logger()
{ {
Logger::PipeOutput(nullptr);
Logger::PipeOutput([] (std::string data)
{
OutputDebugStringA(data.data());
});
Renderer::OnFrame(Logger::Frame); // Client Renderer::OnFrame(Logger::Frame); // Client
Dedicated::OnFrame(Logger::Frame); // Dedi Dedicated::OnFrame(Logger::Frame); // Dedi
Utils::Hook(Game::Com_PrintMessage, Logger::PrintMessageStub, HOOK_JUMP).Install()->Quick();
} }
Logger::~Logger() Logger::~Logger()

View File

@ -12,11 +12,16 @@ namespace Components
static void SoftError(const char* message, ...); static void SoftError(const char* message, ...);
static bool IsConsoleReady(); static bool IsConsoleReady();
static void PipeOutput(void(*callback)(std::string));
private: private:
static std::mutex MessageMutex; static std::mutex MessageMutex;
static std::vector<std::string> MessageQueue; static std::vector<std::string> MessageQueue;
static void(*PipeCallback)(std::string);
static void Frame(); static void Frame();
static void PrintMessageStub();
static void PrintMessagePipe(const char* data);
static void EnqueueMessage(std::string message); static void EnqueueMessage(std::string message);
}; };
} }

View File

@ -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()
{
}
}

View File

@ -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;
};
}

9
src/Proto/rcon.proto Normal file
View File

@ -0,0 +1,9 @@
syntax = "proto3";
package Proto.RCon;
message Command
{
string commands = 1;
bytes signature = 2;
}

View File

@ -64,6 +64,7 @@
// Protobuf // Protobuf
#include "proto/network.pb.h" #include "proto/network.pb.h"
#include "proto/node.pb.h" #include "proto/node.pb.h"
#include "proto/rcon.pb.h"
#pragma warning(pop) #pragma warning(pop)