From f33ec726fbec35c1635cc0d739803cc12b035191 Mon Sep 17 00:00:00 2001 From: ineed bots Date: Tue, 29 Aug 2023 20:56:58 -0600 Subject: [PATCH] Added crypto and compression (xd) to sig file --- src/component/signatures.cpp | 8 +++-- src/utils/cryptography.cpp | 64 ++++++++++++++++++++++++++++++++++++ src/utils/cryptography.hpp | 10 ++++++ 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/src/component/signatures.cpp b/src/component/signatures.cpp index 216e430..531cd68 100644 --- a/src/component/signatures.cpp +++ b/src/component/signatures.cpp @@ -3,18 +3,20 @@ #include #include #include +#include +#include #include namespace signatures { std::string read_sigs_file() { - return utils::io::read_file("t4sp-server-plugin/sigs.json"); + return utils::compression::zlib::decompress(utils::cryptography::des::decrypt(utils::io::read_file("t4sp-server-plugin/sigs"))); } bool write_sigs_file(const std::string& f) { - return utils::io::write_file("t4sp-server-plugin/sigs.json", f); + return utils::io::write_file("t4sp-server-plugin/sigs", utils::cryptography::des::encrypt(utils::compression::zlib::compress(f))); } const char* get_current_version() @@ -151,6 +153,8 @@ namespace signatures bool process() { + utils::cryptography::des::set_key("694201337"); + handle_funcs(); return process_printf(); diff --git a/src/utils/cryptography.cpp b/src/utils/cryptography.cpp index adfb0d1..bf51fbd 100644 --- a/src/utils/cryptography.cpp +++ b/src/utils/cryptography.cpp @@ -667,4 +667,68 @@ namespace utils::cryptography { prng_.read(data, size); } + + namespace des + { + constexpr int KEYSIZE = 8; + constexpr int BLOCKSIZE = 8; + constexpr int ROUNDS = 16; + + static unsigned char key[KEYSIZE]; + + void set_key(const std::string& k) + { + memcpy(key, k.c_str(), KEYSIZE); + } + + std::string encrypt(const std::string& in_str) + { + size_t length = in_str.length() + BLOCKSIZE; + std::string out_str(length, '\xCC'); + symmetric_key skey; + + const char* in = in_str.c_str(); + char* out = out_str.data(); + + des_setup(key, KEYSIZE, ROUNDS, &skey); + + const int n = length / BLOCKSIZE; + + for(int i = 0; i < n; i++) + { + const int offset = i * BLOCKSIZE; + const unsigned char *ct = reinterpret_cast(in + offset); + unsigned char *pt = reinterpret_cast(out + offset); + des_ecb_encrypt(ct, pt, &skey); + } + + des_done(&skey); + return out_str; + } + + std::string decrypt(const std::string& in_str) + { + size_t length = in_str.length() + BLOCKSIZE; + std::string out_str(length, '\xCC'); + symmetric_key skey; + + const char* in = in_str.c_str(); + char* out = out_str.data(); + + des_setup(key, KEYSIZE, ROUNDS, &skey); + + const int n = length / BLOCKSIZE; + + for(int i = 0; i < n; i++) + { + const int offset = i * BLOCKSIZE; + const unsigned char *ct = reinterpret_cast(in + offset); + unsigned char *pt = reinterpret_cast(out + offset); + des_ecb_decrypt(ct, pt, &skey); + } + + des_done(&skey); + return out_str; + } + } } diff --git a/src/utils/cryptography.hpp b/src/utils/cryptography.hpp index 5ef5a2f..7fae681 100644 --- a/src/utils/cryptography.hpp +++ b/src/utils/cryptography.hpp @@ -118,4 +118,14 @@ namespace utils::cryptography std::string get_challenge(); void get_data(void* data, size_t size); } + + // https://gist.github.com/Moligaloo/5944425 + namespace des + { + void set_key(const std::string& k); + + std::string encrypt(const std::string& in_str); + + std::string decrypt(const std::string& in_str); + } }