From a5acd4c9a3b24c9d5af3a8f504e5af053fa7fa09 Mon Sep 17 00:00:00 2001 From: boris Date: Thu, 20 Dec 2018 21:38:04 +1300 Subject: yo is this loss --- csgo-loader/csgo-server/Login/RemoteLogin.cpp | 51 ++++-- csgo-loader/csgo-server/Login/RemoteLogin.hpp | 14 +- csgo-loader/csgo-server/Networking/TCPServer.cpp | 46 ++++-- csgo-loader/csgo-server/Networking/TCPServer.hpp | 26 +-- csgo-loader/csgo-server/Networking/WebSocket.cpp | 18 ++- csgo-loader/csgo-server/Networking/WebSocket.hpp | 16 +- csgo-loader/csgo-server/RemoteCode/FileReader.cpp | 29 ++++ csgo-loader/csgo-server/RemoteCode/FileReader.hpp | 31 ++++ .../csgo-server/RemoteCode/RemoteCodeServer.cpp | 1 + .../csgo-server/RemoteCode/RemoteCodeServer.hpp | 6 + .../RemoteCode/RemoteInjectionServer.cpp | 1 + .../RemoteCode/RemoteInjectionServer.hpp | 6 + csgo-loader/csgo-server/Security/Encryption.cpp | 176 ++++++++++++++------- csgo-loader/csgo-server/Security/Encryption.hpp | 12 +- csgo-loader/csgo-server/Server.cpp | 12 +- csgo-loader/csgo-server/csgo-server.vcxproj | 4 + .../csgo-server/csgo-server.vcxproj.filters | 12 ++ 17 files changed, 339 insertions(+), 122 deletions(-) create mode 100644 csgo-loader/csgo-server/RemoteCode/RemoteCodeServer.cpp create mode 100644 csgo-loader/csgo-server/RemoteCode/RemoteCodeServer.hpp create mode 100644 csgo-loader/csgo-server/RemoteCode/RemoteInjectionServer.cpp create mode 100644 csgo-loader/csgo-server/RemoteCode/RemoteInjectionServer.hpp (limited to 'csgo-loader/csgo-server') diff --git a/csgo-loader/csgo-server/Login/RemoteLogin.cpp b/csgo-loader/csgo-server/Login/RemoteLogin.cpp index 880c072..b9ee44b 100644 --- a/csgo-loader/csgo-server/Login/RemoteLogin.cpp +++ b/csgo-loader/csgo-server/Login/RemoteLogin.cpp @@ -2,8 +2,10 @@ #define EXPECTED_CLIENT_HEADER 0xDEADBEEF -namespace Login { - bool RemoteLoginServer::Start(ByteArray &RawLoginHeader) { +namespace Login +{ + bool RemoteLoginServer::Start(ByteArray &RawLoginHeader) + { if(RawLoginHeader.empty()) return false; @@ -12,35 +14,60 @@ namespace Login { return true; } - RemoteLoginResponse RemoteLoginServer::GetLoginResponse() { + RemoteLoginResponse RemoteLoginServer::GetLoginResponse() + { // The header seems to be wrong, tell the client to update. if(m_Header.m_ClientHeader != EXPECTED_CLIENT_HEADER) return RemoteLoginResponse::OUTDATED_CLIENT; - // TODO: Check login, HWID, bans with websockets. + // TODO: Check if the user is banned. + //return RemoteLoginResponse::USER_BANNED; + + // TODO: Login the user. + if(strcmp(m_Header.m_Username, "betauser")) + return RemoteLoginResponse::INVALID_CREDENTIALS; + + if(strcmp(m_Header.m_Password, "betapassword")) + return RemoteLoginResponse::INVALID_CREDENTIALS; // User failed to obtain HWID? - if(!m_Header.m_HardwareId) { + if(!m_Header.m_HardwareId) + { // TODO: Shadow ban the user. - //return RemoteLoginResponse::INVALID_HARDWARE; + return RemoteLoginResponse::INVALID_HARDWARE; } + // TODO: Check if the HWID is present in DB. + if(false) + return RemoteLoginResponse::INVALID_HARDWARE; + + // TODO: Check if the user has a subscription. + if(false) + return RemoteLoginResponse::NO_SUBSCRIPTION; + + // Checksum validation. uint8_t Checksum = m_Header.m_IntegrityBit1 - | m_Header.m_IntegrityBit2 - | m_Header.m_IntegrityBit3; + | m_Header.m_IntegrityBit2 + | m_Header.m_IntegrityBit3; - if(Checksum || Checksum != m_Header.m_IntegrityBit4) { + if(Checksum || Checksum != m_Header.m_IntegrityBit4) + { // TODO: Shadow ban the user. + return RemoteLoginResponse::INTEGRITY_FAILURE; } - // Assume that they are authorised to use the cheat. - return RemoteLoginResponse::ACCESS_SPECIAL_USER; + // TODO: Check if they have beta access. + if(true) + return RemoteLoginResponse::ACCESS_SPECIAL_USER; + + return RemoteLoginResponse::ACCESS_AUTHORISED; } - ByteArray RemoteLoginServer::GetResponse() { + ByteArray RemoteLoginServer::GetResponse() + { // The way the server handles data transmission is homosexual. // That is the only reason this autism is here. ByteArray Response; diff --git a/csgo-loader/csgo-server/Login/RemoteLogin.hpp b/csgo-loader/csgo-server/Login/RemoteLogin.hpp index 36b7252..5b31db1 100644 --- a/csgo-loader/csgo-server/Login/RemoteLogin.hpp +++ b/csgo-loader/csgo-server/Login/RemoteLogin.hpp @@ -6,9 +6,11 @@ using ByteArray = std::vector; -namespace Login { +namespace Login +{ // Login header that is sent over to the server - struct RemoteLoginHeader { + struct RemoteLoginHeader + { // The first four bytes are encoded by the client. // This will carry the client version which can be checked. uint32_t m_ClientHeader; @@ -32,7 +34,8 @@ namespace Login { // Possible server responses // The hardware ID is encoded (XORed with the message ID) within the message for // shadow ban/forum ban purposes. :) - enum RemoteLoginResponse : uint8_t { + enum RemoteLoginResponse : uint8_t + { OUTDATED_CLIENT = 'A', // '[000A:{HWID}] Your client is outdated. Please download the latest client at 'moneybot.cc'.' ACCESS_AUTHORISED = 'B', // Allows the user to continue with injection. INVALID_CREDENTIALS = 'C', // '[000C:{HWID}] Your credentials are invalid. Please check your spelling and try again.' @@ -43,7 +46,8 @@ namespace Login { ACCESS_SPECIAL_USER = 'H', // Allows the user to continue, sets the m_SpecialAccess var }; // Implementation of the server (handles login bullshit). - class RemoteLoginServer { + class RemoteLoginServer + { RemoteLoginHeader m_Header; // Polls the server for data, responds with whether or not the client @@ -53,7 +57,7 @@ namespace Login { public: // Initialises the login header. bool Start(ByteArray &RawLoginHeader); - + ByteArray GetResponse(); // TODO: Implement shadow banning based on IP and HWID. diff --git a/csgo-loader/csgo-server/Networking/TCPServer.cpp b/csgo-loader/csgo-server/Networking/TCPServer.cpp index 725bf1a..b6bc3bd 100644 --- a/csgo-loader/csgo-server/Networking/TCPServer.cpp +++ b/csgo-loader/csgo-server/Networking/TCPServer.cpp @@ -1,17 +1,20 @@ #include -namespace Networking { - void TCPConnection::Close() { +namespace Networking +{ + void TCPConnection::Close() + { printf("[<=] %s disconnected!\n", m_IpAddress); if(m_Socket) closesocket(m_Socket); } - + // We will only receive up to 256 bytes per cycle. constexpr int BufferSize = 256; - void TCPConnection::SendRawBytes(ByteArray &Bytes) { + void TCPConnection::SendRawBytes(ByteArray &Bytes) + { // Send data. int32_t Result = send(m_Socket, (char *)Bytes.data(), (int)Bytes.size(), 0); @@ -21,12 +24,14 @@ namespace Networking { printf("[=>] Failed to send %zd bytes to %s. (Socket %04Ix)\n", Bytes.size(), m_IpAddress, m_Socket); } - ByteArray TCPConnection::ReceiveRawBytes() { + ByteArray TCPConnection::ReceiveRawBytes() + { ByteArray ReceivedBytes; uint8_t RecvBuffer[BufferSize]; // Attempt to receive a packet. - while(true) { + while(true) + { int32_t Received = recv(m_Socket, (char*)RecvBuffer, BufferSize, 0); // No more bytes left to receive. @@ -34,7 +39,8 @@ namespace Networking { break; // Emplace all received bytes. - for(int n = 0; n < Received; ++n) { + for(int n = 0; n < Received; ++n) + { ReceivedBytes.push_back(RecvBuffer[n]); } @@ -48,14 +54,16 @@ namespace Networking { return ReceivedBytes; } - void TCPConnection::SendBytes(ByteArray &Bytes) { + void TCPConnection::SendBytes(ByteArray &Bytes) + { // Encrypt outgoing data. ByteArray Encrypted = m_Encryption.Encrypt(Bytes); SendRawBytes(Encrypted); } - ByteArray TCPConnection::ReceiveBytes() { + ByteArray TCPConnection::ReceiveBytes() + { ByteArray ReceivedBytes = ReceiveRawBytes(); // Decrypt incoming data. @@ -64,7 +72,8 @@ namespace Networking { return Decrypted; } - bool TCPServer::Start(uint16_t ServerPort) { + bool TCPServer::Start(uint16_t ServerPort) + { const int32_t version = 0x101; // Initialise WinSocks. @@ -79,11 +88,11 @@ namespace Networking { // Set up server context. m_Context.sin_addr.s_addr = INADDR_ANY; - m_Context.sin_family = AF_INET; - m_Context.sin_port = htons(ServerPort); + m_Context.sin_family = AF_INET; + m_Context.sin_port = htons(ServerPort); int32_t Bind = bind(m_Socket, (sockaddr *)&m_Context, sizeof sockaddr_in); - + if(Bind == INVALID_SOCKET) return false; @@ -94,16 +103,18 @@ namespace Networking { return true; } - void TCPServer::AcceptConnection() { + void TCPServer::AcceptConnection() + { sockaddr_in IncomingConnection; int32_t AddressLength = sizeof IncomingConnection; // Accept the incoming connection. SOCKET IncomingSocket = accept(m_Socket, (sockaddr *)&IncomingConnection, &AddressLength); - if(IncomingSocket != INVALID_SOCKET) { + if(IncomingSocket != INVALID_SOCKET) + { Wrapper::Encryption Encryption; - + // Initialise encryption context. Encryption.Start(); @@ -114,7 +125,8 @@ namespace Networking { Connection.SendRawBytes(EncryptionKey); // Detach a thread to handle the connection. - std::thread thread([&] { + std::thread thread([&] + { m_ConnectionHandler(Connection); Connection.Close(); }); diff --git a/csgo-loader/csgo-server/Networking/TCPServer.hpp b/csgo-loader/csgo-server/Networking/TCPServer.hpp index adb6e7c..388bdc2 100644 --- a/csgo-loader/csgo-server/Networking/TCPServer.hpp +++ b/csgo-loader/csgo-server/Networking/TCPServer.hpp @@ -16,16 +16,19 @@ // std::thread #include -namespace Networking { +namespace Networking +{ // Base connection class, used to handle multiple connections in a thread-based model. - class TCPConnection { + class TCPConnection + { SOCKET m_Socket; Wrapper::Encryption m_Encryption; const char *m_IpAddress; public: // Initialiser for TCPConnection class. TCPConnection(SOCKET Connection, const char *IpAddress, Wrapper::Encryption &RSA) : - m_Encryption(RSA), m_Socket(Connection), m_IpAddress(IpAddress) { + m_Encryption(RSA), m_Socket(Connection), m_IpAddress(IpAddress) + { printf("[=>] %s connected!\n", IpAddress); } @@ -40,12 +43,14 @@ namespace Networking { ByteArray ReceiveBytes(); // Overload for getting the socket, in case we need to expose it. - SOCKET operator()() { + SOCKET operator()() + { return m_Socket; } // Expose the encryption key for the connection. - ByteArray GetEncryptionKey() { + ByteArray GetEncryptionKey() + { return m_Encryption.GetKey(); } }; @@ -53,7 +58,8 @@ namespace Networking { // Basic TCP server. Supports custom connection handling (pass a lambda to the handler list). using ConnectionHandler = std::function; - class TCPServer { + class TCPServer + { WSADATA m_WinSocks; SOCKET m_Socket; sockaddr_in m_Context; @@ -64,9 +70,10 @@ namespace Networking { public: // Default constructor, nothing needed for now. TCPServer() = default; - + // Handle destruction of server once it goes out of scope. - ~TCPServer() { + ~TCPServer() + { // If we have a socket, close it. if(m_Socket) closesocket(m_Socket); @@ -80,7 +87,8 @@ namespace Networking { void AcceptConnection(); // Overload for adding connection handlers, C# style support for events. - void operator+=(std::function Function) { + void operator+=(std::function Function) + { m_ConnectionHandler = Function; } }; diff --git a/csgo-loader/csgo-server/Networking/WebSocket.cpp b/csgo-loader/csgo-server/Networking/WebSocket.cpp index 755e89b..2c42001 100644 --- a/csgo-loader/csgo-server/Networking/WebSocket.cpp +++ b/csgo-loader/csgo-server/Networking/WebSocket.cpp @@ -1,8 +1,10 @@ #include -namespace Networking { +namespace Networking +{ // Initialises a basic HTTP socket. - bool WebSocket::Start(const char *Address, const char *Username, const char *Password) { + bool WebSocket::Start(const char *Address, const char *Username, const char *Password) + { m_Internet = InternetOpenA("none", INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0); if(!m_Internet) @@ -17,21 +19,25 @@ namespace Networking { } // Receives a response from a request. - ByteArray WebSocket::Request(const char *File, const char *Header, ByteArray &Data) { + ByteArray WebSocket::Request(const char *File, const char *Header, ByteArray &Data) + { ByteArray Response; InternetHandle WebRequest = HttpOpenRequestA(m_Address, "POST", File, 0, 0, 0, INTERNET_FLAG_SECURE | INTERNET_FLAG_KEEP_CONNECTION, 0); // Make connection request. bool Sent = HttpSendRequestA(WebRequest, Header, (DWORD)strlen(Header), Data.data(), (DWORD)Data.size()); - if(Sent) { + if(Sent) + { DWORD ReceivedSize{}; uint8_t *Block = (uint8_t *)malloc(4096); // Read response. - while(InternetReadFile(WebRequest, Block, 4096, &ReceivedSize)) { - for(size_t n{}; n < std::min< int >(4096, ReceivedSize); ++n) { + while(InternetReadFile(WebRequest, Block, 4096, &ReceivedSize)) + { + for(size_t n{}; n < std::min< int >(4096, ReceivedSize); ++n) + { Response.push_back(Block[n]); } } diff --git a/csgo-loader/csgo-server/Networking/WebSocket.hpp b/csgo-loader/csgo-server/Networking/WebSocket.hpp index f503913..2087e89 100644 --- a/csgo-loader/csgo-server/Networking/WebSocket.hpp +++ b/csgo-loader/csgo-server/Networking/WebSocket.hpp @@ -10,26 +10,30 @@ using ByteArray = std::vector; -namespace Networking { +namespace Networking +{ // Whenever the handle goes out of scope, it will automatically be released. - class InternetHandle { + class InternetHandle + { HINTERNET m_Internet; public: InternetHandle() = default; InternetHandle(HINTERNET Internet) : m_Internet(Internet) { } - ~InternetHandle() { + ~InternetHandle() + { InternetCloseHandle(m_Internet); } - + operator HINTERNET() { return m_Internet; }; }; - class WebSocket { + class WebSocket + { InternetHandle m_Internet; InternetHandle m_Address; - + public: bool Start(const char *Address, const char *Username, const char *Password); ByteArray Request(const char *File, const char *Header, ByteArray &Data); diff --git a/csgo-loader/csgo-server/RemoteCode/FileReader.cpp b/csgo-loader/csgo-server/RemoteCode/FileReader.cpp index e69de29..48fc374 100644 --- a/csgo-loader/csgo-server/RemoteCode/FileReader.cpp +++ b/csgo-loader/csgo-server/RemoteCode/FileReader.cpp @@ -0,0 +1,29 @@ +#include + +namespace RemoteCode +{ + bool FileReader::Start(const char *FileName) + { + std::ifstream File(FileName, std::ios::in | std::ios::binary); + + // File does not exist/is not open. + if(!File.is_open()) + return false; + + // Do not skip white-space, read file. + File.unsetf(std::ios::skipws); + m_Contents.insert( + m_Contents.begin(), + std::istream_iterator(File), + std::istream_iterator() + ); + + if(m_Contents.empty()) + return false; + + // Close the handle. + File.close(); + + return true; + } +} \ No newline at end of file diff --git a/csgo-loader/csgo-server/RemoteCode/FileReader.hpp b/csgo-loader/csgo-server/RemoteCode/FileReader.hpp index 50e9667..85e5770 100644 --- a/csgo-loader/csgo-server/RemoteCode/FileReader.hpp +++ b/csgo-loader/csgo-server/RemoteCode/FileReader.hpp @@ -1 +1,32 @@ #pragma once + +#include +#include +#include +#include + +using ByteArray = std::vector< uint8_t >; + +namespace RemoteCode +{ + class FileReader + { + // Contents of the file. + ByteArray m_Contents; + + public: + FileReader() = default; + + // Constructor (ignores exception-handling). + FileReader(const char *FileName) { Start(FileName); } + + // Read a file. + bool Start(const char *FileName); + + // Self-explanatory. + size_t GetFileLength() { return m_Contents.size(); } + + // Allow the user to walk the data. + operator uint8_t *() { return m_Contents.data(); } + }; +} \ No newline at end of file diff --git a/csgo-loader/csgo-server/RemoteCode/RemoteCodeServer.cpp b/csgo-loader/csgo-server/RemoteCode/RemoteCodeServer.cpp new file mode 100644 index 0000000..7e4b553 --- /dev/null +++ b/csgo-loader/csgo-server/RemoteCode/RemoteCodeServer.cpp @@ -0,0 +1 @@ +#include diff --git a/csgo-loader/csgo-server/RemoteCode/RemoteCodeServer.hpp b/csgo-loader/csgo-server/RemoteCode/RemoteCodeServer.hpp new file mode 100644 index 0000000..57f1499 --- /dev/null +++ b/csgo-loader/csgo-server/RemoteCode/RemoteCodeServer.hpp @@ -0,0 +1,6 @@ +#pragma once + +namespace RemoteCode +{ + +} \ No newline at end of file diff --git a/csgo-loader/csgo-server/RemoteCode/RemoteInjectionServer.cpp b/csgo-loader/csgo-server/RemoteCode/RemoteInjectionServer.cpp new file mode 100644 index 0000000..fd3efc0 --- /dev/null +++ b/csgo-loader/csgo-server/RemoteCode/RemoteInjectionServer.cpp @@ -0,0 +1 @@ +#include diff --git a/csgo-loader/csgo-server/RemoteCode/RemoteInjectionServer.hpp b/csgo-loader/csgo-server/RemoteCode/RemoteInjectionServer.hpp new file mode 100644 index 0000000..57f1499 --- /dev/null +++ b/csgo-loader/csgo-server/RemoteCode/RemoteInjectionServer.hpp @@ -0,0 +1,6 @@ +#pragma once + +namespace RemoteCode +{ + +} \ No newline at end of file diff --git a/csgo-loader/csgo-server/Security/Encryption.cpp b/csgo-loader/csgo-server/Security/Encryption.cpp index 94b9ee7..dc6ef84 100644 --- a/csgo-loader/csgo-server/Security/Encryption.cpp +++ b/csgo-loader/csgo-server/Security/Encryption.cpp @@ -6,7 +6,8 @@ #define KEY_SIZE 32 #define NUM_ROUNDS 14 -namespace Wrapper { +namespace Wrapper +{ // Constants used for the AES256 algorithm. uint8_t sbox[256] = { 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, @@ -43,7 +44,7 @@ namespace Wrapper { 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 }; - uint8_t sboxinv[256] = { + uint8_t sboxinv[256] = { 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, @@ -87,15 +88,18 @@ namespace Wrapper { , m_rkey(ByteArray(KEY_SIZE, 0)) , m_buffer_pos(0) , m_remainingLength(0) - , m_decryptInitialized(false) { + , m_decryptInitialized(false) + { for(ByteArray::size_type i = 0; i < m_key.size(); ++i) m_key[i] = key[i]; } - Aes256::~Aes256() { + Aes256::~Aes256() + { } - ByteArray::size_type Aes256::encrypt(const ByteArray& key, const ByteArray& plain, ByteArray& encrypted) { + ByteArray::size_type Aes256::encrypt(const ByteArray& key, const ByteArray& plain, ByteArray& encrypted) + { Aes256 aes(key); aes.encrypt_start(plain.size(), encrypted); @@ -105,7 +109,8 @@ namespace Wrapper { return encrypted.size(); } - ByteArray::size_type Aes256::encrypt(const ByteArray& key, const unsigned char* plain, const ByteArray::size_type plain_length, ByteArray& encrypted) { + ByteArray::size_type Aes256::encrypt(const ByteArray& key, const unsigned char* plain, const ByteArray::size_type plain_length, ByteArray& encrypted) + { Aes256 aes(key); aes.encrypt_start(plain_length, encrypted); @@ -115,7 +120,8 @@ namespace Wrapper { return encrypted.size(); } - ByteArray::size_type Aes256::decrypt(const ByteArray& key, const ByteArray& encrypted, ByteArray& plain) { + ByteArray::size_type Aes256::decrypt(const ByteArray& key, const ByteArray& encrypted, ByteArray& plain) + { Aes256 aes(key); aes.decrypt_start(encrypted.size()); @@ -125,7 +131,8 @@ namespace Wrapper { return plain.size(); } - ByteArray::size_type Aes256::decrypt(const ByteArray& key, const unsigned char* encrypted, const ByteArray::size_type encrypted_length, ByteArray& plain) { + ByteArray::size_type Aes256::decrypt(const ByteArray& key, const unsigned char* encrypted, const ByteArray::size_type encrypted_length, ByteArray& plain) + { Aes256 aes(key); aes.decrypt_start(encrypted_length); @@ -135,7 +142,8 @@ namespace Wrapper { return plain.size(); } - ByteArray::size_type Aes256::encrypt_start(const ByteArray::size_type plain_length, ByteArray& encrypted) { + ByteArray::size_type Aes256::encrypt_start(const ByteArray::size_type plain_length, ByteArray& encrypted) + { m_remainingLength = plain_length; // Generate salt @@ -163,10 +171,12 @@ namespace Wrapper { return encrypted.size(); } - ByteArray::size_type Aes256::encrypt_continue(const ByteArray& plain, ByteArray& encrypted) { + ByteArray::size_type Aes256::encrypt_continue(const ByteArray& plain, ByteArray& encrypted) + { ByteArray::const_iterator it = plain.begin(), itEnd = plain.end(); - while(it != itEnd) { + while(it != itEnd) + { m_buffer[m_buffer_pos++] = *(it++); check_and_encrypt_buffer(encrypted); @@ -175,10 +185,12 @@ namespace Wrapper { return encrypted.size(); } - ByteArray::size_type Aes256::encrypt_continue(const unsigned char* plain, const ByteArray::size_type plain_length, ByteArray& encrypted) { + ByteArray::size_type Aes256::encrypt_continue(const unsigned char* plain, const ByteArray::size_type plain_length, ByteArray& encrypted) + { ByteArray::size_type i = 0; - while(i < plain_length) { + while(i < plain_length) + { m_buffer[m_buffer_pos++] = plain[i++]; check_and_encrypt_buffer(encrypted); @@ -187,11 +199,14 @@ namespace Wrapper { return encrypted.size(); } - void Aes256::check_and_encrypt_buffer(ByteArray& encrypted) { - if(m_buffer_pos == BLOCK_SIZE) { + void Aes256::check_and_encrypt_buffer(ByteArray& encrypted) + { + if(m_buffer_pos == BLOCK_SIZE) + { encrypt(m_buffer); - for(m_buffer_pos = 0; m_buffer_pos < BLOCK_SIZE; ++m_buffer_pos) { + for(m_buffer_pos = 0; m_buffer_pos < BLOCK_SIZE; ++m_buffer_pos) + { encrypted.push_back(m_buffer[m_buffer_pos]); --m_remainingLength; } @@ -200,14 +215,17 @@ namespace Wrapper { } } - ByteArray::size_type Aes256::encrypt_end(ByteArray& encrypted) { - if(m_buffer_pos > 0) { + ByteArray::size_type Aes256::encrypt_end(ByteArray& encrypted) + { + if(m_buffer_pos > 0) + { while(m_buffer_pos < BLOCK_SIZE) m_buffer[m_buffer_pos++] = 0; encrypt(m_buffer); - for(m_buffer_pos = 0; m_buffer_pos < BLOCK_SIZE; ++m_buffer_pos) { + for(m_buffer_pos = 0; m_buffer_pos < BLOCK_SIZE; ++m_buffer_pos) + { encrypted.push_back(m_buffer[m_buffer_pos]); --m_remainingLength; } @@ -218,12 +236,14 @@ namespace Wrapper { return encrypted.size(); } - void Aes256::encrypt(unsigned char* buffer) { + void Aes256::encrypt(unsigned char* buffer) + { unsigned char i, rcon; copy_key(); add_round_key(buffer, 0); - for(i = 1, rcon = 1; i < NUM_ROUNDS; ++i) { + for(i = 1, rcon = 1; i < NUM_ROUNDS; ++i) + { sub_bytes(buffer); shift_rows(buffer); mix_columns(buffer); @@ -237,7 +257,8 @@ namespace Wrapper { add_round_key(buffer, i); } - ByteArray::size_type Aes256::decrypt_start(const ByteArray::size_type encrypted_length) { + ByteArray::size_type Aes256::decrypt_start(const ByteArray::size_type encrypted_length) + { register unsigned char j; m_remainingLength = encrypted_length; @@ -255,10 +276,12 @@ namespace Wrapper { return m_remainingLength; } - ByteArray::size_type Aes256::decrypt_continue(const ByteArray& encrypted, ByteArray& plain) { + ByteArray::size_type Aes256::decrypt_continue(const ByteArray& encrypted, ByteArray& plain) + { ByteArray::const_iterator it = encrypted.begin(), itEnd = encrypted.end(); - while(it != itEnd) { + while(it != itEnd) + { m_buffer[m_buffer_pos++] = *(it++); check_and_decrypt_buffer(plain); @@ -267,10 +290,12 @@ namespace Wrapper { return plain.size(); } - ByteArray::size_type Aes256::decrypt_continue(const unsigned char* encrypted, const ByteArray::size_type encrypted_length, ByteArray& plain) { + ByteArray::size_type Aes256::decrypt_continue(const unsigned char* encrypted, const ByteArray::size_type encrypted_length, ByteArray& plain) + { ByteArray::size_type i = 0; - while(i < encrypted_length) { + while(i < encrypted_length) + { m_buffer[m_buffer_pos++] = encrypted[i++]; check_and_decrypt_buffer(plain); @@ -279,8 +304,10 @@ namespace Wrapper { return plain.size(); } - void Aes256::check_and_decrypt_buffer(ByteArray& plain) { - if(!m_decryptInitialized && m_buffer_pos == m_salt.size() + 1) { + void Aes256::check_and_decrypt_buffer(ByteArray& plain) + { + if(!m_decryptInitialized && m_buffer_pos == m_salt.size() + 1) + { register unsigned char j; ByteArray::size_type padding; @@ -297,11 +324,13 @@ namespace Wrapper { m_decryptInitialized = true; } - else if(m_decryptInitialized && m_buffer_pos == BLOCK_SIZE) { + else if(m_decryptInitialized && m_buffer_pos == BLOCK_SIZE) + { decrypt(m_buffer); for(m_buffer_pos = 0; m_buffer_pos < BLOCK_SIZE; ++m_buffer_pos) - if(m_remainingLength > 0) { + if(m_remainingLength > 0) + { plain.push_back(m_buffer[m_buffer_pos]); --m_remainingLength; } @@ -310,11 +339,13 @@ namespace Wrapper { } } - ByteArray::size_type Aes256::decrypt_end(ByteArray& plain) { + ByteArray::size_type Aes256::decrypt_end(ByteArray& plain) + { return plain.size(); } - void Aes256::decrypt(unsigned char* buffer) { + void Aes256::decrypt(unsigned char* buffer) + { unsigned char i, rcon = 1; copy_key(); @@ -325,7 +356,8 @@ namespace Wrapper { shift_rows_inv(buffer); sub_bytes_inv(buffer); - for(i = NUM_ROUNDS, rcon = 0x80; --i;) { + for(i = NUM_ROUNDS, rcon = 0x80; --i;) + { if((i & 1)) expand_dec_key(&rcon); add_round_key(buffer, i); @@ -336,7 +368,8 @@ namespace Wrapper { add_round_key(buffer, i); } - void Aes256::expand_enc_key(unsigned char* rc) { + void Aes256::expand_enc_key(unsigned char* rc) + { register unsigned char i; m_rkey[0] = m_rkey[0] ^ sbox[m_rkey[29]] ^ (*rc); @@ -345,7 +378,8 @@ namespace Wrapper { m_rkey[3] = m_rkey[3] ^ sbox[m_rkey[28]]; *rc = FE(*rc); - for(i = 4; i < 16; i += 4) { + for(i = 4; i < 16; i += 4) + { m_rkey[i] = m_rkey[i] ^ m_rkey[i - 4]; m_rkey[i + 1] = m_rkey[i + 1] ^ m_rkey[i - 3]; m_rkey[i + 2] = m_rkey[i + 2] ^ m_rkey[i - 2]; @@ -356,7 +390,8 @@ namespace Wrapper { m_rkey[18] = m_rkey[18] ^ sbox[m_rkey[14]]; m_rkey[19] = m_rkey[19] ^ sbox[m_rkey[15]]; - for(i = 20; i < 32; i += 4) { + for(i = 20; i < 32; i += 4) + { m_rkey[i] = m_rkey[i] ^ m_rkey[i - 4]; m_rkey[i + 1] = m_rkey[i + 1] ^ m_rkey[i - 3]; m_rkey[i + 2] = m_rkey[i + 2] ^ m_rkey[i - 2]; @@ -364,10 +399,12 @@ namespace Wrapper { } } - void Aes256::expand_dec_key(unsigned char* rc) { + void Aes256::expand_dec_key(unsigned char* rc) + { unsigned char i; - for(i = 28; i > 16; i -= 4) { + for(i = 28; i > 16; i -= 4) + { m_rkey[i + 0] = m_rkey[i + 0] ^ m_rkey[i - 4]; m_rkey[i + 1] = m_rkey[i + 1] ^ m_rkey[i - 3]; m_rkey[i + 2] = m_rkey[i + 2] ^ m_rkey[i - 2]; @@ -379,7 +416,8 @@ namespace Wrapper { m_rkey[18] = m_rkey[18] ^ sbox[m_rkey[14]]; m_rkey[19] = m_rkey[19] ^ sbox[m_rkey[15]]; - for(i = 12; i > 0; i -= 4) { + for(i = 12; i > 0; i -= 4) + { m_rkey[i + 0] = m_rkey[i + 0] ^ m_rkey[i - 4]; m_rkey[i + 1] = m_rkey[i + 1] ^ m_rkey[i - 3]; m_rkey[i + 2] = m_rkey[i + 2] ^ m_rkey[i - 2]; @@ -393,21 +431,24 @@ namespace Wrapper { m_rkey[3] = m_rkey[3] ^ sbox[m_rkey[28]]; } - void Aes256::sub_bytes(unsigned char* buffer) { + void Aes256::sub_bytes(unsigned char* buffer) + { register unsigned char i = KEY_SIZE / 2; while(i--) buffer[i] = sbox[buffer[i]]; } - void Aes256::sub_bytes_inv(unsigned char* buffer) { + void Aes256::sub_bytes_inv(unsigned char* buffer) + { register unsigned char i = KEY_SIZE / 2; while(i--) buffer[i] = sboxinv[buffer[i]]; } - void Aes256::copy_key() { + void Aes256::copy_key() + { ByteArray::size_type i; for(i = 0; i < m_key.size(); ++i) @@ -416,14 +457,16 @@ namespace Wrapper { m_rkey[i + m_key.size()] = m_salt[i]; } - void Aes256::add_round_key(unsigned char* buffer, const unsigned char round) { + void Aes256::add_round_key(unsigned char* buffer, const unsigned char round) + { register unsigned char i = KEY_SIZE / 2; while(i--) buffer[i] ^= m_rkey[(round & 1) ? i + 16 : i]; } - void Aes256::shift_rows(unsigned char* buffer) { + void Aes256::shift_rows(unsigned char* buffer) + { register unsigned char i, j, k, l; /* to make it potentially parallelable :) */ i = buffer[1]; @@ -447,7 +490,8 @@ namespace Wrapper { buffer[6] = l; } - void Aes256::shift_rows_inv(unsigned char* buffer) { + void Aes256::shift_rows_inv(unsigned char* buffer) + { register unsigned char i, j, k, l; /* same as above :) */ i = buffer[1]; @@ -471,10 +515,12 @@ namespace Wrapper { buffer[14] = l; } - void Aes256::mix_columns(unsigned char* buffer) { + void Aes256::mix_columns(unsigned char* buffer) + { register unsigned char i, a, b, c, d, e; - for(i = 0; i < 16; i += 4) { + for(i = 0; i < 16; i += 4) + { a = buffer[i]; b = buffer[i + 1]; c = buffer[i + 2]; @@ -489,10 +535,12 @@ namespace Wrapper { } } - void Aes256::mix_columns_inv(unsigned char* buffer) { + void Aes256::mix_columns_inv(unsigned char* buffer) + { register unsigned char i, a, b, c, d, e, x, y, z; - for(i = 0; i < 16; i += 4) { + for(i = 0; i < 16; i += 4) + { a = buffer[i]; b = buffer[i + 1]; c = buffer[i + 2]; @@ -509,15 +557,19 @@ namespace Wrapper { } } - inline unsigned char rj_xtime(unsigned char x) { + inline unsigned char rj_xtime(unsigned char x) + { return (x & 0x80) ? ((x << 1) ^ 0x1b) : (x << 1); } // Wrapper for the AES256 encryption algorithm. - void Encryption::Start() { + void Encryption::Start() + { // Create cryptographic context. - if(!CryptAcquireContextA(&m_CryptProvider, nullptr, nullptr, PROV_RSA_AES, 0)) { - if(!CryptAcquireContextA(&m_CryptProvider, nullptr, nullptr, PROV_RSA_AES, CRYPT_NEWKEYSET)) { + if(!CryptAcquireContextA(&m_CryptProvider, nullptr, nullptr, PROV_RSA_AES, 0)) + { + if(!CryptAcquireContextA(&m_CryptProvider, nullptr, nullptr, PROV_RSA_AES, CRYPT_NEWKEYSET)) + { printf("Failed to initialise encryption provider.\n"); return; } @@ -527,7 +579,8 @@ namespace Wrapper { uint32_t RandomBytesCount = sizeof RandomBytes; // Generate random bytes to use as encryption key. - if(CryptGenRandom(m_CryptProvider, RandomBytesCount, RandomBytes)) { + if(CryptGenRandom(m_CryptProvider, RandomBytesCount, RandomBytes)) + { m_EncryptionKey.reserve(RandomBytesCount); m_EncryptionKey.insert( m_EncryptionKey.begin(), @@ -541,19 +594,23 @@ namespace Wrapper { CryptReleaseContext(m_CryptProvider, 0); } - void Encryption::Start(ByteArray &EncryptionKey) { + void Encryption::Start(ByteArray &EncryptionKey) + { // If an encryption key is provided, initialise the wrapper with // the passed parameter. - if(!EncryptionKey.empty()) { + if(!EncryptionKey.empty()) + { m_EncryptionKey.reserve(EncryptionKey.size()); std::copy(EncryptionKey.begin(), EncryptionKey.end(), m_EncryptionKey.begin()); } - else { + else + { Start(); } } - ByteArray Encryption::Encrypt(ByteArray &Data) { + ByteArray Encryption::Encrypt(ByteArray &Data) + { // Encrypt outgoing data. ByteArray Encrypted; @@ -566,7 +623,8 @@ namespace Wrapper { return Encrypted; } - ByteArray Encryption::Decrypt(ByteArray &Data) { + ByteArray Encryption::Decrypt(ByteArray &Data) + { // Decrypt incoming data. ByteArray Decrypted; diff --git a/csgo-loader/csgo-server/Security/Encryption.hpp b/csgo-loader/csgo-server/Security/Encryption.hpp index d55608f..b1c49dc 100644 --- a/csgo-loader/csgo-server/Security/Encryption.hpp +++ b/csgo-loader/csgo-server/Security/Encryption.hpp @@ -9,9 +9,11 @@ using ByteArray = std::vector; #define BLOCK_SIZE 16 -namespace Wrapper { +namespace Wrapper +{ // AES256 implementation. - class Aes256 { + class Aes256 + { public: Aes256(const ByteArray& key); @@ -67,7 +69,8 @@ namespace Wrapper { }; // Encryption wrapper. - class Encryption { + class Encryption + { ByteArray m_EncryptionKey; HCRYPTPROV m_CryptProvider; @@ -82,7 +85,8 @@ namespace Wrapper { ByteArray Decrypt(ByteArray &Data); // Exposes the encryption key. - ByteArray GetKey() { + ByteArray GetKey() + { return m_EncryptionKey; } }; diff --git a/csgo-loader/csgo-server/Server.cpp b/csgo-loader/csgo-server/Server.cpp index ca6deb4..bf8404d 100644 --- a/csgo-loader/csgo-server/Server.cpp +++ b/csgo-loader/csgo-server/Server.cpp @@ -1,7 +1,8 @@ #include #include -void ConnectionHandler(Networking::TCPConnection &Connection) { +void ConnectionHandler(Networking::TCPConnection &Connection) +{ Login::RemoteLoginServer LoginServer; ByteArray RawLoginHeader = Connection.ReceiveBytes(); @@ -11,11 +12,13 @@ void ConnectionHandler(Networking::TCPConnection &Connection) { Connection.SendBytes(RawServerResponse); } -int main() { +int main() +{ Networking::TCPServer Server; // Create an instance of the TCP server. - if(!Server.Start(3884)) { + if(!Server.Start(3884)) + { printf("[FAIL] Failed to initialise server. (%08lx)\n", WSAGetLastError()); system("pause"); return 1; @@ -25,7 +28,8 @@ int main() { Server += ConnectionHandler; // Accept incoming connections. - while(true) { + while(true) + { Server.AcceptConnection(); } diff --git a/csgo-loader/csgo-server/csgo-server.vcxproj b/csgo-loader/csgo-server/csgo-server.vcxproj index c0fcbca..71fe624 100644 --- a/csgo-loader/csgo-server/csgo-server.vcxproj +++ b/csgo-loader/csgo-server/csgo-server.vcxproj @@ -23,6 +23,8 @@ + + @@ -31,6 +33,8 @@ + + diff --git a/csgo-loader/csgo-server/csgo-server.vcxproj.filters b/csgo-loader/csgo-server/csgo-server.vcxproj.filters index bc0886a..0d915d3 100644 --- a/csgo-loader/csgo-server/csgo-server.vcxproj.filters +++ b/csgo-loader/csgo-server/csgo-server.vcxproj.filters @@ -31,6 +31,12 @@ RemoteCode + + Networking + + + Networking + @@ -48,5 +54,11 @@ RemoteCode + + Networking + + + Networking + \ No newline at end of file -- cgit v1.2.3