Rcon tests.
This commit is contained in:
parent
59a00f2b0e
commit
339b05f8a7
@ -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());
|
||||
|
@ -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"
|
||||
|
@ -4,6 +4,7 @@ namespace Components
|
||||
{
|
||||
std::mutex Logger::MessageMutex;
|
||||
std::vector<std::string> 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()
|
||||
|
@ -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<std::string> MessageQueue;
|
||||
static void(*PipeCallback)(std::string);
|
||||
|
||||
static void Frame();
|
||||
static void PrintMessageStub();
|
||||
static void PrintMessagePipe(const char* data);
|
||||
static void EnqueueMessage(std::string message);
|
||||
};
|
||||
}
|
||||
|
43
src/Components/Modules/RCon.cpp
Normal file
43
src/Components/Modules/RCon.cpp
Normal 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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
22
src/Components/Modules/RCon.hpp
Normal file
22
src/Components/Modules/RCon.hpp
Normal 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
9
src/Proto/rcon.proto
Normal file
@ -0,0 +1,9 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package Proto.RCon;
|
||||
|
||||
message Command
|
||||
{
|
||||
string commands = 1;
|
||||
bytes signature = 2;
|
||||
}
|
@ -64,6 +64,7 @@
|
||||
// Protobuf
|
||||
#include "proto/network.pb.h"
|
||||
#include "proto/node.pb.h"
|
||||
#include "proto/rcon.pb.h"
|
||||
|
||||
#pragma warning(pop)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user