From d786e65a9a262638e74f6ebcf1b296917897ae49 Mon Sep 17 00:00:00 2001 From: boris Date: Sun, 30 Dec 2018 15:00:51 +1300 Subject: unban marcus or suffer my wrath grr --- csgo-loader/csgo-server/Networking/TCPServer.cpp | 32 +++++------- csgo-loader/csgo-server/Networking/TCPServer.hpp | 7 +-- csgo-loader/csgo-server/Networking/WebSocket.cpp | 17 +++---- csgo-loader/csgo-server/Security/Encryption.cpp | 40 ++++++++------- csgo-loader/csgo-server/Server.cpp | 10 +--- csgo-loader/csgo-server/csgo-server.vcxproj | 65 ++++++++++++++++++++++++ 6 files changed, 111 insertions(+), 60 deletions(-) (limited to 'csgo-loader/csgo-server') diff --git a/csgo-loader/csgo-server/Networking/TCPServer.cpp b/csgo-loader/csgo-server/Networking/TCPServer.cpp index c381c85..d93a710 100644 --- a/csgo-loader/csgo-server/Networking/TCPServer.cpp +++ b/csgo-loader/csgo-server/Networking/TCPServer.cpp @@ -4,7 +4,7 @@ namespace Networking { void TCPConnection::Close() { - printf("[ <= ] disconnected\n"); + printf("[ <= ] %s disconnected!\n", m_IpAddress); if(m_Socket) closesocket(m_Socket); @@ -18,12 +18,10 @@ namespace Networking // Send data. int32_t Result = send(m_Socket, (char *)Bytes.data(), (int)Bytes.size(), 0); - if(m_IpAddress) - - printf("[ => ] %zd bytes\n", Bytes.size()); + printf("[ => ] Sending %zd bytes to %s.\n", Bytes.size(), m_IpAddress); if(Result == -1) - printf("[ => ] %zd bytes failed (%d)\n", Bytes.size(), WSAGetLastError()); + printf("[ E! ] Failed to send %zd bytes to %s. (Socket %04Ix)\n", Bytes.size(), m_IpAddress, m_Socket); } ByteArray TCPConnection::ReceiveRawBytes() @@ -43,7 +41,7 @@ namespace Networking // Emplace all received bytes. for(int n = 0; n < Received; ++n) { - ReceivedBytes.emplace_back(RecvBuffer[n]); + ReceivedBytes.push_back(RecvBuffer[n]); } // No more bytes left to receive. @@ -51,7 +49,7 @@ namespace Networking break; } - printf("[ <= ] %zd bytes\n", ReceivedBytes.size()); + printf("[ <= ] Received %zd bytes from %s.\n", ReceivedBytes.size(), m_IpAddress); return ReceivedBytes; } @@ -90,8 +88,8 @@ 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); @@ -99,7 +97,7 @@ namespace Networking return false; // Start listening. - printf("[INFO] Server listening on port %d.\n", ServerPort); + printf("[ i! ] Server listening on port %d.\n", ServerPort); listen(m_Socket, 1); return true; @@ -121,23 +119,17 @@ namespace Networking Encryption.Start(); // Attempt handshake with client. - TCPConnection Connection(IncomingSocket, inet_ntoa(IncomingConnection.sin_addr), Encryption); + const char *IpAddress = inet_ntoa(IncomingConnection.sin_addr); + TCPConnection Connection(IncomingSocket, IpAddress, Encryption); ByteArray EncryptionKey = Connection.GetEncryptionKey(); Connection.SendRawBytes(EncryptionKey); - // Print out handshake header - printf("[ => ] Handshake: "); - - for(auto &It : EncryptionKey) - printf("%02x ", It); - - printf("\n"); - // Detach a thread to handle the connection. std::thread thread([&] { - // smol fix :^) + // Fix for crashing when there is no connection handler + // (literally happened to me once) if(m_ConnectionHandler) m_ConnectionHandler(Connection); diff --git a/csgo-loader/csgo-server/Networking/TCPServer.hpp b/csgo-loader/csgo-server/Networking/TCPServer.hpp index 31beec8..a29a796 100644 --- a/csgo-loader/csgo-server/Networking/TCPServer.hpp +++ b/csgo-loader/csgo-server/Networking/TCPServer.hpp @@ -23,13 +23,14 @@ namespace Networking { SOCKET m_Socket; Wrapper::Encryption m_Encryption; - const char *m_IpAddress; + char m_IpAddress[32]; 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) { - printf("[ => ] connected\n"); + strcpy_s<32>(m_IpAddress, IpAddress); + printf("[ => ] %s connected!\n", m_IpAddress); } // Release the connection once it goes out of scope. diff --git a/csgo-loader/csgo-server/Networking/WebSocket.cpp b/csgo-loader/csgo-server/Networking/WebSocket.cpp index 75b5731..2c42001 100644 --- a/csgo-loader/csgo-server/Networking/WebSocket.cpp +++ b/csgo-loader/csgo-server/Networking/WebSocket.cpp @@ -21,30 +21,27 @@ namespace Networking // Receives a response from a request. ByteArray WebSocket::Request(const char *File, const char *Header, ByteArray &Data) { - DWORD ReceivedSize{}; ByteArray Response; InternetHandle WebRequest = HttpOpenRequestA(m_Address, "POST", File, 0, 0, 0, INTERNET_FLAG_SECURE | INTERNET_FLAG_KEEP_CONNECTION, 0); - if(!WebRequest) - return Response; - // Make connection request. bool Sent = HttpSendRequestA(WebRequest, Header, (DWORD)strlen(Header), Data.data(), (DWORD)Data.size()); if(Sent) { - // Allocate a buffer to read the response into. - uint8_t *Block = (uint8_t *)malloc(0x1000); + DWORD ReceivedSize{}; + + uint8_t *Block = (uint8_t *)malloc(4096); // Read response. - while(InternetReadFile(WebRequest, Block, 0x1000, &ReceivedSize)) + while(InternetReadFile(WebRequest, Block, 4096, &ReceivedSize)) { - const size_t RequestRange = std::min< int >(0x1000, ReceivedSize); - for(size_t n{}; n < RequestRange; ++n) + for(size_t n{}; n < std::min< int >(4096, ReceivedSize); ++n) + { Response.push_back(Block[n]); + } } - // Free the buffer to avoid leaking memory. free(Block); } diff --git a/csgo-loader/csgo-server/Security/Encryption.cpp b/csgo-loader/csgo-server/Security/Encryption.cpp index b79a1c3..f4681b8 100644 --- a/csgo-loader/csgo-server/Security/Encryption.cpp +++ b/csgo-loader/csgo-server/Security/Encryption.cpp @@ -259,7 +259,7 @@ namespace Wrapper ByteArray::size_type Aes256::decrypt_start(const ByteArray::size_type encrypted_length) { - register unsigned char j; + unsigned char j; m_remainingLength = encrypted_length; @@ -308,7 +308,7 @@ namespace Wrapper { if(!m_decryptInitialized && m_buffer_pos == m_salt.size() + 1) { - register unsigned char j; + unsigned char j; ByteArray::size_type padding; // Get salt @@ -370,7 +370,7 @@ namespace Wrapper void Aes256::expand_enc_key(unsigned char* rc) { - register unsigned char i; + unsigned char i; m_rkey[0] = m_rkey[0] ^ sbox[m_rkey[29]] ^ (*rc); m_rkey[1] = m_rkey[1] ^ sbox[m_rkey[30]]; @@ -433,7 +433,7 @@ namespace Wrapper void Aes256::sub_bytes(unsigned char* buffer) { - register unsigned char i = KEY_SIZE / 2; + unsigned char i = KEY_SIZE / 2; while(i--) buffer[i] = sbox[buffer[i]]; @@ -441,7 +441,7 @@ namespace Wrapper void Aes256::sub_bytes_inv(unsigned char* buffer) { - register unsigned char i = KEY_SIZE / 2; + unsigned char i = KEY_SIZE / 2; while(i--) buffer[i] = sboxinv[buffer[i]]; @@ -459,7 +459,7 @@ namespace Wrapper void Aes256::add_round_key(unsigned char* buffer, const unsigned char round) { - register unsigned char i = KEY_SIZE / 2; + unsigned char i = KEY_SIZE / 2; while(i--) buffer[i] ^= m_rkey[(round & 1) ? i + 16 : i]; @@ -467,7 +467,7 @@ namespace Wrapper void Aes256::shift_rows(unsigned char* buffer) { - register unsigned char i, j, k, l; /* to make it potentially parallelable :) */ + unsigned char i, j, k, l; /* to make it potentially parallelable :) */ i = buffer[1]; buffer[1] = buffer[5]; @@ -492,7 +492,7 @@ namespace Wrapper void Aes256::shift_rows_inv(unsigned char* buffer) { - register unsigned char i, j, k, l; /* same as above :) */ + unsigned char i, j, k, l; /* same as above :) */ i = buffer[1]; buffer[1] = buffer[13]; @@ -517,7 +517,7 @@ namespace Wrapper void Aes256::mix_columns(unsigned char* buffer) { - register unsigned char i, a, b, c, d, e; + unsigned char i, a, b, c, d, e; for(i = 0; i < 16; i += 4) { @@ -537,7 +537,7 @@ namespace Wrapper void Aes256::mix_columns_inv(unsigned char* buffer) { - register unsigned char i, a, b, c, d, e, x, y, z; + unsigned char i, a, b, c, d, e, x, y, z; for(i = 0; i < 16; i += 4) { @@ -581,7 +581,6 @@ namespace Wrapper // Generate random bytes to use as encryption key. if(CryptGenRandom(m_CryptProvider, RandomBytesCount, RandomBytes)) { - m_EncryptionKey.reserve(RandomBytesCount); m_EncryptionKey.insert( m_EncryptionKey.begin(), RandomBytes, @@ -598,15 +597,10 @@ namespace Wrapper { // If an encryption key is provided, initialise the wrapper with // the passed parameter. - if(!EncryptionKey.empty()) - { - m_EncryptionKey.reserve(EncryptionKey.size()); - std::copy(EncryptionKey.begin(), EncryptionKey.end(), m_EncryptionKey.begin()); - } - else - { + std::copy(EncryptionKey.begin(), EncryptionKey.end(), m_EncryptionKey.begin()); + + if(EncryptionKey.empty()) Start(); - } } ByteArray Encryption::Encrypt(ByteArray &Data) @@ -614,7 +608,11 @@ namespace Wrapper // Encrypt outgoing data. ByteArray Encrypted; + #ifdef DEBUG + Encrypted = Data; + #else Aes256::encrypt(m_EncryptionKey, Data, Encrypted); + #endif return Encrypted; } @@ -624,7 +622,11 @@ namespace Wrapper // Decrypt incoming data. ByteArray Decrypted; + #ifdef DEBUG + Decrypted = Data; + #else Aes256::decrypt(m_EncryptionKey, Data, Decrypted); + #endif return Decrypted; } diff --git a/csgo-loader/csgo-server/Server.cpp b/csgo-loader/csgo-server/Server.cpp index c475542..2f3f913 100644 --- a/csgo-loader/csgo-server/Server.cpp +++ b/csgo-loader/csgo-server/Server.cpp @@ -1,14 +1,8 @@ #include -void ConnectionHandler(Networking::TCPConnection &Connection) +void ConnectionHandler(Networking::TCPConnection &) { - ByteArray Bytes = Connection.ReceiveBytes(); - for(auto &It : Bytes) - printf("%02x ", It); - printf("\n"); - - Connection.SendBytes(Bytes); } int __stdcall WinMain(HINSTANCE, HINSTANCE, char*, int) @@ -33,7 +27,7 @@ int __stdcall WinMain(HINSTANCE, HINSTANCE, char*, int) } if(!Result) - printf("[FAIL] Failed to initialise server. (%08lx)\n", WSAGetLastError()); + printf("[ !! ] Failed to initialise server. (%08lx)\n", WSAGetLastError()); system("pause"); } \ No newline at end of file diff --git a/csgo-loader/csgo-server/csgo-server.vcxproj b/csgo-loader/csgo-server/csgo-server.vcxproj index 268a409..3bd07ca 100644 --- a/csgo-loader/csgo-server/csgo-server.vcxproj +++ b/csgo-loader/csgo-server/csgo-server.vcxproj @@ -5,6 +5,14 @@ Debug Win32 + + FuckMSVC + Win32 + + + FuckMSVC + x64 + Release Win32 @@ -59,6 +67,13 @@ true MultiByte + + Application + false + v141 + true + MultiByte + Application true @@ -72,6 +87,13 @@ true MultiByte + + Application + false + v141 + true + MultiByte + @@ -83,12 +105,18 @@ + + + + + + $(SolutionDir)bin\$(Configuration)\ @@ -102,6 +130,12 @@ $(ExecutablePath) $(ProjectDir);$(VC_IncludePath);$(WindowsSDK_IncludePath); + + $(SolutionDir)bin\$(Configuration)\ + $(SolutionDir)build\$(Configuration)\Server\ + $(ExecutablePath) + $(ProjectDir);$(VC_IncludePath);$(WindowsSDK_IncludePath); + Level3 @@ -137,6 +171,20 @@ true + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + Level4 @@ -154,6 +202,23 @@ Windows + + + Level4 + MaxSpeed + true + true + true + true + DEBUG;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NOMINMAX;_MBCS;%(PreprocessorDefinitions) + + + true + true + RequireAdministrator + Windows + + -- cgit v1.2.3