From bf689eca5945b92b69b1fd72f4c1247b067083d4 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Fri, 24 Jan 2020 02:40:30 +0100 Subject: [PATCH] Removed stuff which hasn't been used anymore --- CMakeLists.txt | 7 +- client/CMakeLists.txt | 79 -- client/HideString.h | 29 - client/changes.md | 27 - client/identityHash.cpp | 63 - client/main.cpp | 1176 ----------------- client/proto/LicenseKey.proto | 17 - client/src/Identity.cpp | 218 --- client/src/Identity.h | 44 - client/src/MultithreadedIdentity.cpp | 189 --- client/src/TinySHA1.hpp.h | 196 --- client/src/protocol/Connection.cpp | 454 ------- client/src/protocol/Connection.h | 139 -- client/src/protocol/ConnectionHandschake.cpp | 361 ----- .../src/protocol/ConnectionPacketHandler.cpp | 158 --- client/src/protocol/HandshakeNew.cpp | 154 --- .../src/protocol/socket/FilteredUDPSocket.cpp | 115 -- .../src/protocol/socket/FilteredUDPSocket.h | 27 - client/src/protocol/socket/RawUDPSocket.cpp | 151 --- client/src/protocol/socket/RawUDPSocket.h | 28 - flooder/CMakeLists.txt | 25 - flooder/main.cpp | 81 -- flooder/src/PorxiedClientSock5.cpp | 111 -- flooder/src/ProxiedClient.cpp | 175 --- flooder/src/ProxiedClient.h | 72 - flooder/src/TSClient.cpp | 108 -- flooder/src/TSClient.h | 36 - server/src/client/SpeakingClient.cpp | 25 +- 28 files changed, 15 insertions(+), 4250 deletions(-) delete mode 100644 client/CMakeLists.txt delete mode 100644 client/HideString.h delete mode 100644 client/changes.md delete mode 100644 client/identityHash.cpp delete mode 100644 client/main.cpp delete mode 100644 client/proto/LicenseKey.proto delete mode 100644 client/src/Identity.cpp delete mode 100644 client/src/Identity.h delete mode 100644 client/src/MultithreadedIdentity.cpp delete mode 100644 client/src/TinySHA1.hpp.h delete mode 100644 client/src/protocol/Connection.cpp delete mode 100644 client/src/protocol/Connection.h delete mode 100644 client/src/protocol/ConnectionHandschake.cpp delete mode 100644 client/src/protocol/ConnectionPacketHandler.cpp delete mode 100644 client/src/protocol/HandshakeNew.cpp delete mode 100644 client/src/protocol/socket/FilteredUDPSocket.cpp delete mode 100644 client/src/protocol/socket/FilteredUDPSocket.h delete mode 100644 client/src/protocol/socket/RawUDPSocket.cpp delete mode 100644 client/src/protocol/socket/RawUDPSocket.h delete mode 100644 flooder/CMakeLists.txt delete mode 100644 flooder/main.cpp delete mode 100644 flooder/src/PorxiedClientSock5.cpp delete mode 100644 flooder/src/ProxiedClient.cpp delete mode 100644 flooder/src/ProxiedClient.h delete mode 100644 flooder/src/TSClient.cpp delete mode 100644 flooder/src/TSClient.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 42bcb7b..a0053f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,11 @@ cmake_minimum_required(VERSION 3.6) project(TeaSpeak-Parent) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") +set(CMAKE_CXX_STANDARD 20) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules") set(TEASPEAK_SERVER ON) - +set(CMAKE_VERBOSE_MAKEFILE ON) #end now #set(MEMORY_DEBUG_FLAGS " -fsanitize=leak -fsanitize=address -fstack-protector-all ") #set(MEMORY_DEBUG_FLAGS "-fsanitize=address") @@ -71,9 +70,7 @@ set(LIBRARY_PATH_GLIBC "${GLIBC_LIB_DIR}/libgio-2.0.a;${GLIBC_LIB_DIR}/libgmodul add_definitions(-DINET -DINET6) add_subdirectory(shared/) -add_subdirectory(client/) add_subdirectory(server/) add_subdirectory(license/) -add_subdirectory(flooder/) add_subdirectory(MusicBot/) add_subdirectory(music/) \ No newline at end of file diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt deleted file mode 100644 index d33843f..0000000 --- a/client/CMakeLists.txt +++ /dev/null @@ -1,79 +0,0 @@ -cmake_minimum_required(VERSION 3.6) -project(TeamSpeak) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -static-libgcc -static-libstdc++ -pthread ${MEMORY_DEBUG_FLAGS}") - -include_directories(../shared/src) -add_definitions(-DLTM_DESC) - -set(SOURCE_FILES - main.cpp - src/protocol/Connection.cpp - src/protocol/ConnectionHandschake.cpp - src/protocol/ConnectionPacketHandler.cpp - - src/protocol/socket/FilteredUDPSocket.cpp - src/protocol/socket/RawUDPSocket.cpp - - src/Identity.cpp - src/MultithreadedIdentity.cpp - src/protocol/HandshakeNew.cpp - - ../shared/src/License.cpp -) - -find_package(Protobuf REQUIRED) -include_directories(${Protobuf_INCLUDE_DIRS}) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) -protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS proto/LicenseKey.proto) - -add_executable(TeamSpeakClient ${SOURCE_FILES} ${PROTO_SRCS}) -target_link_libraries(TeamSpeakClient - ${LIBRARY_PATH_THREAD_POOL} #Static - TeaSpeak #Static - TeaLicenseHelper #Static - TeaMusic #Static - ${LIBRARY_PATH_TERMINAL} #Static - ${LIBRARY_PATH_VARIBALES} - ${LIBRARY_PATH_YAML} - pthread - stdc++fs - ${LIBEVENT_PATH}/libevent.a - ${LIBEVENT_PATH}/libevent_pthreads.a - opus.a - ${LIBRARY_PATH_JSON} - ${LIBRARY_PATH_PROTOBUF} - - DataPipes - #${LIBWEBRTC_LIBRARIES} #ATTENTIAN! WebRTC does not work with crypto! (Already contains a crypto version) - ${LIBRARY_TOM_CRYPT} - ${LIBRARY_TOM_MATH} - - #We're forsed to use boringssl caused by the fact that boringssl is already within webrtc! - - #Require a so - sqlite3 - ${LIBRARY_PATH_ED255} - - ${LIBRARY_PATH_BREAKPAD} - ${LIBRARY_PATH_JDBC} - ${LIBRARY_PATH_PROTOBUF} - - ${LIBRARY_PATH_BORINGSSL_SSL} - ${LIBRARY_PATH_BORINGSSL_CRYPTO} -) - -#strip -s -p -v TeamSpeakHash -add_executable(TeamSpeakHash src/Identity.cpp src/MultithreadedIdentity.cpp identityHash.cpp) -#set_target_properties(TeamSpeakHash PROPERTIES CMAKE_CXX_FLAGS "-o1") - -target_link_libraries(TeamSpeakHash - TeaSpeak - ThreadPoolStatic - pthread - ${TOM_LIBRARIES} - ${LIBRARY_TOM_CRYPT} - ${LIBRARY_TOM_MATH} - ${LIBRARY_PATH_BORINGSSL_SSL} - ${LIBRARY_PATH_BORINGSSL_CRYPTO} -) \ No newline at end of file diff --git a/client/HideString.h b/client/HideString.h deleted file mode 100644 index 2acf4f4..0000000 --- a/client/HideString.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include -#include - -#define CRYPT_MACRO(r, d, i, elem) ( elem ^ ( d - i ) ) - -#define DEFINE_HIDDEN_STRING(NAME, SEED, SEQ)\ -static const char* BOOST_PP_CAT(Get, NAME)()\ -{\ - static char data[] = {\ - BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_FOR_EACH_I(CRYPT_MACRO, SEED, SEQ)),\ - '\0'\ - };\ -\ - static bool isEncrypted = true;\ - if ( isEncrypted )\ - {\ - for (unsigned i = 0; i < ( sizeof(data) / sizeof(data[0]) ) - 1; ++i)\ - {\ - data[i] = CRYPT_MACRO(_, SEED, i, data[i]);\ - }\ -\ - isEncrypted = false;\ - }\ -\ - return data;\ -} \ No newline at end of file diff --git a/client/changes.md b/client/changes.md deleted file mode 100644 index 990b822..0000000 --- a/client/changes.md +++ /dev/null @@ -1,27 +0,0 @@ -[OUT] clientinitiv alpha=kXZSTZ7qaOhblA== omega=MEwDAgcAAgEgAiA5+ycSoMRRdugndbohYtH7PqS6Q6h3TV1VnGRKoZNMsQIhANn2rszHVipB13LBcY2Zf3APg7HX7ix3WWiaT5hjQrUv ot=1 ip=84.200.62.248 -[ IN] initivexpand2 l=AQCBIiOUkbXLeQ\/6UhNB+8iJnwLYGZJglZoDFSTt+7awWgAJFtlwLxmo8AAAACVUZWFtU3BlYWsgU3lzdGVtcyBHbWJIAADtwskuiFg0FkafvNvS1uwz67b2lEhMnOkAygPvo0waGAAJQrh2HBxqvQAAACRUZWFtU3BlYWsgc3lzdGVtcyBHbWJIAADd85KDiA8UeqB5G9MBtNZ879CYBnfbjc\/OVj0j0xMcqQIJQ7qACi5lgAYAAAAAVGVhbVNwZWFrIFN5c3RlbXMgR21iSAAAitZK9P6JEXiiy+uERaapfw\/I5na7S5M+Se5IoOb\/24kgCV6OnAlfN1w= beta=5cB\/vUHLQ7GbVPNRStMLnZlyo572IFPzdgTTgxJ3zF4JBehh7nLudpdzk1hdbcglx4n3JmqX omega=MEwDAgcAAgEgAiEA83r2Er9vHr5sSEcm9g\/\/rdLjOdTMtwX\/Lkbi02+24FkCIB2P804l26yketcG8WxZQJ1z4ukU0e3SqEzm4pKHzMRY ot=1 proof=MEUCIAgYSvrPo0OKKD8aRmjeKVS1EVF6L\/DXLBT+XFkZlMVPAiEAnSMVOp8DOEMzcE42hna72+aWr+Z4+a76x23hmDJa4Uk= tvd=AQAAAABaQjKEblQQgGczKfB+CSS7IY5qli8LRS9jDltkab8leo6ltwQH82VUU\/WwnpCbazVbnh4iNbcobdxv\/MTX5Y3+6xpqDgEAEa1\/SLpE\/CIg2X7GX9mtDCCvP1KdQGaT\/RKoofPSsTkACRbZcAr4DPAAAAASVGVhbVNwZWFrIFN5c3RlbXMgR21iSAAAPgFaQLsu0h3FTQax+i0qXFXX\/Bn7VcGJH8SE5AOAiuQECVvUYwlenQk= time=1514211836 -[OUT] clientek ek=n4+LesWAJf+8ha6LlF5kWilUbj59qX+zV31asaniK8U= proof=MEQCIC+NxeqTNUQWqHz914BHkFfC3LTF8BkYAYktMB62sET7AiBPmnfN6yoB381g\/GAnZVwMkeCPIjKi9vHUk15yOdT5FQ== -[OUT] clientinit client_nickname=P3nisBaum client_version=3.1.7\s[Build:\s1513163251] client_platform=Windows client_input_hardware=1 client_output_hardware=1 client_default_channel client_default_channel_password client_server_password client_meta_data client_version_sign=tdNngCAZ1ImAf7BxJzO4RXv5nBRsUERsrSOnMKVUFNQg6BS4Bzag0RFgLVzs2DRj19AC8+q5cXgH+5Ms50mTCA== client_key_offset=15848377 client_nickname_phonetic client_default_token client_badges=Overwolf=0 hwid=3036580947951600a7de06cd796bb0f1,7209e96ac1f60ff7772b7301919e0878 -[OUT] clientinit client_nickname=P3nisBaum client_version=3.1.7\s[Build:\s1513163251] client_platform=Windows client_input_hardware=1 client_output_hardware=1 client_default_channel client_default_channel_password client_server_password client_meta_data client_version_sign=tdNngCAZ1ImAf7BxJzO4RXv5nBRsUERsrSOnMKVUFNQg6BS4Bzag0RFgLVzs2DRj19AC8+q5cXgH+5Ms50mTCA== client_key_offset=15848377 client_nickname_phonetic client_default_token client_badges=Overwolf=0 hwid=3036580947951600a7de06cd796bb0f1,7209e96ac1f60ff7772b7301919e0878 -[ IN] error id=521 msg=too\smany\sclones\salready\sconnected - - - --> ot & ip needs to be set --> ack needs to be unencripted as look clientinitiv not done - - -initivexpand2 l=AQCBIiOUkbXLeQ\/6UhNB+8iJnwLYGZJglZoDFSTt+7awWgAJFtlwLxmo8AAAACVUZWFtU3BlYWsgU3lzdGVtcyBHbWJIAADtwskuiFg0FkafvNvS1uwz67b2lEhMnOkAygPvo0waGAAJQrh2HBxqvQAAACRUZWFtU3BlYWsgc3lzdGVtcyBHbWJIAADd85KDiA8UeqB5G9MBtNZ879CYBnfbjc\/OVj0j0xMcqQIJQ7qACi5lgAYAAAAAVGVhbVNwZWFrIFN5c3RlbXMgR21iSAAA5Szd\/YkuL5NUF7SeHfvSKi5byOOMvYME0\/WRwlTHK8ogCV6hYglfSiI= beta=W\/D9NTwuZi6L1sbFpA+KiDBMSgl8y6Jy6vFVSGszJy1BPy8zEhNDQ62msazyAgk0CdbY0B+E omega=MEwDAgcAAgEgAiEA83r2Er9vHr5sSEcm9g\/\/rdLjOdTMtwX\/Lkbi02+24FkCIB2P804l26yketcG8WxZQJ1z4ukU0e3SqEzm4pKHzMRY ot=1 proof=MEUCIA3dgrIlXFIjkLrxJ1Yni7OqQYwPing03Xz\/zkQFrmdHAiEA8a0delCktJ21TIrj91QZbA76vtZUL38XVm+P2bR9M7c= tvd=AQAAAABaQjKEblQQgGczKfB+CSS7IY5qli8LRS9jDltkab8leo6ltwQH82VUU\/WwnpCbazVbnh4iNbcobdxv\/MTX5Y3+6xpqDgEAEa1\/SLpE\/CIg2X7GX9mtDCCvP1KdQGaT\/RKoofPSsTkACRbZcAr4DPAAAAASVGVhbVNwZWFrIFN5c3RlbXMgR21iSAAAPgFaQLsu0h3FTQax+i0qXFXX\/Bn7VcGJH8SE5AOAiuQECVvUYwlenQk= time=1514216642 - - -Nr 1 -[OUT] clientinitiv alpha=DBiidVqi8kTYAQ== omega=MEwDAgcAAgEgAiA5+ycSoMRRdugndbohYtH7PqS6Q6h3TV1VnGRKoZNMsQIhANn2rszHVipB13LBcY2Zf3APg7HX7ix3WWiaT5hjQrUv ot=1 ip=84.200.62.248 -[ IN] initivexpand2 l=AQCBIiOUkbXLeQ\/6UhNB+8iJnwLYGZJglZoDFSTt+7awWgAJFtlwLxmo8AAAACVUZWFtU3BlYWsgU3lzdGVtcyBHbWJIAADtwskuiFg0FkafvNvS1uwz67b2lEhMnOkAygPvo0waGAAJQrh2HBxqvQAAACRUZWFtU3BlYWsgc3lzdGVtcyBHbWJIAADd85KDiA8UeqB5G9MBtNZ879CYBnfbjc\/OVj0j0xMcqQIJQ7qACi5lgAYAAAAAVGVhbVNwZWFrIFN5c3RlbXMgR21iSAAALYVev\/rqwinxd2zrGZla8+69t03410Iyo9N6lV7bajMgCV6ioQlfS2E= beta=\/Eg8SA2j45sSVi28kVwBVpxT98G1w0tlenDVYuKy\/7Cn1ZZiNiwu8Z9XhGBxwrzPXrMHPEMJ omega=MEwDAgcAAgEgAiEA83r2Er9vHr5sSEcm9g\/\/rdLjOdTMtwX\/Lkbi02+24FkCIB2P804l26yketcG8WxZQJ1z4ukU0e3SqEzm4pKHzMRY ot=1 proof=MEUCIFFa+q1zdgA0OtXgdgn9gxSOMp7GBvc3vPW0YDTU2+e6AiEA8sjW3XDikxQADPoSaSw7lwL6gfXr6gwO0Hvro3RZBHU= tvd=AQAAAABaQjKEblQQgGczKfB+CSS7IY5qli8LRS9jDltkab8leo6ltwQH82VUU\/WwnpCbazVbnh4iNbcobdxv\/MTX5Y3+6xpqDgEAEa1\/SLpE\/CIg2X7GX9mtDCCvP1KdQGaT\/RKoofPSsTkACRbZcAr4DPAAAAASVGVhbVNwZWFrIFN5c3RlbXMgR21iSAAAPgFaQLsu0h3FTQax+i0qXFXX\/Bn7VcGJH8SE5AOAiuQECVvUYwlenQk= time=1514216961 -[OUT] clientek ek=19doGY4WwwAeW\/zHnmFJTpnE8h9MUJZSYFNpz4aUabs= proof=MEUCIGTwtZ1E+HjDPLqlyTuaHtvWmjYW\/\/tnQgugaC5u1swtAiEA9DN+kuwxuXG80FDzKnICGQYQGZZBySQv8Nhflg\/1FwQ= - - -[OUT] clientinitiv alpha=3Pcn19zISkIB5g== omega=MEwDAgcAAgEgAiA5+ycSoMRRdugndbohYtH7PqS6Q6h3TV1VnGRKoZNMsQIhANn2rszHVipB13LBcY2Zf3APg7HX7ix3WWiaT5hjQrUv ot=1 ip=84.200.62.248 -[ IN] initivexpand2 l=AQCBIiOUkbXLeQ\/6UhNB+8iJnwLYGZJglZoDFSTt+7awWgAJFtlwLxmo8AAAACVUZWFtU3BlYWsgU3lzdGVtcyBHbWJIAADtwskuiFg0FkafvNvS1uwz67b2lEhMnOkAygPvo0waGAAJQrh2HBxqvQAAACRUZWFtU3BlYWsgc3lzdGVtcyBHbWJIAADd85KDiA8UeqB5G9MBtNZ879CYBnfbjc\/OVj0j0xMcqQIJQ7qACi5lgAYAAAAAVGVhbVNwZWFrIFN5c3RlbXMgR21iSAAASpEEQfPJOP8aeecPLtzcu8iYmtqBJn8MWq+8lSQljYcgCV6iyAlfS4g= beta=JLFcgyWwlYNzy5lsTGJKGz6rvmShHrb6YEZfq4TXwTLSiWDGqckf6ywiMOP2MGAc1y1yQsEi omega=MEwDAgcAAgEgAiEA83r2Er9vHr5sSEcm9g\/\/rdLjOdTMtwX\/Lkbi02+24FkCIB2P804l26yketcG8WxZQJ1z4ukU0e3SqEzm4pKHzMRY ot=1 proof=MEYCIQCpKZJCmQCHyC2PLIleZVAl1fSTdnzqcNxhiXxVAHtUHgIhAPvPfziHtiqn36nB7KSVuKV+gMA29OL87bI1HP6CJNw2 tvd=AQAAAABaQjKEblQQgGczKfB+CSS7IY5qli8LRS9jDltkab8leo6ltwQH82VUU\/WwnpCbazVbnh4iNbcobdxv\/MTX5Y3+6xpqDgEAEa1\/SLpE\/CIg2X7GX9mtDCCvP1KdQGaT\/RKoofPSsTkACRbZcAr4DPAAAAASVGVhbVNwZWFrIFN5c3RlbXMgR21iSAAAPgFaQLsu0h3FTQax+i0qXFXX\/Bn7VcGJH8SE5AOAiuQECVvUYwlenQk= time=1514217000 -[OUT] clientek ek=yGZb1Qp0Y\/V7T+rMwcqtzUeOTIGgE6+7gcKxAw2OMPU= proof=MEQCIHdgsGlufstf\/ab1TvvM740Azs56jyGFmo93ijr53k1FAiBHNhWkV9xLUG19jpZGGe86SgCDli7GdSrv61ZGr3jD9g== - -bM5HB+Ox/Wht38dd6/VeB7L76ebcpP9YgKzWAk4lmQ8= \ No newline at end of file diff --git a/client/identityHash.cpp b/client/identityHash.cpp deleted file mode 100644 index dd2d6ab..0000000 --- a/client/identityHash.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include -#include "HideString.h" -DEFINE_HIDDEN_STRING(HeaderMessage, 0x44, ('#')('#')('#')('#')('#')('#')('#')('#')('#')('#')('#')('#')('#')('#')('#')('#')('#')(' ')('T')('S')('3')(' ')('H')('a')('s')('h')(' ')('b')('y')(' ')('W')('o')('l')('v')('e')('r')('i')('n')('D')('E')('V')(' ')('#')('#')('#')('#')('#')('#')('#')('#')('#')('#')('#')('#')('#')('#')('#')('#')('#')); - -using namespace ts; -using namespace std; - -inline string crypt(string in){ - stringstream result; - result << "DEFINE_HIDDEN_STRING(EncryptionKey, 0xA5, "; - - for(char c : in) - result << "('" << c << "')"; - - result << ");"; - return result.str(); -} - -int main(int argc, char** argv) { - cout << GetHeaderMessage() << endl; - if(argc < 3) { - cerr << "Invalid arguments. ./TSHash [ = 1.000.000]" << endl; - return 0; - } - - init_LTM(); - if(register_prng(&sprng_desc) == -1) { - cerr << "could not setup prng" << endl; - return EXIT_FAILURE; - } - if (register_cipher(&rijndael_desc) == -1) { - cerr << "could not setup rijndael" << endl; - return EXIT_FAILURE; - } - - int threads = atoi(argv[1]); - int level = atoi(argv[2]); - int blockSize = argc > 3 ? atoi(argv[3]) : 1 * 1000 * 1000; - - cout << "# Creating new identity (Threads: " << threads << " Level: " << level << " Size: " << blockSize << ")" << endl; - auto identity = Identity::createNew(); - cout << "IDENTITY: " << identity->exportIdentity() << endl; - cout << "# Start hashing" << endl; - if(!identity->improveSecurityLevelMultithreaded(level, threads, blockSize, 0, true)) { - cout << "ERROR: Could not improve identity!" << endl; - return 1; - } - cout << "INFO: Found identity!" << endl; - cout << "IDENTITY: " << identity->exportIdentity() << endl; - cout << "LEVEL: " << identity->getSecurityLevel() << endl; - return 0; -} -/* -#IDENTITY: 5513931022VPXfjXSN1qRa2IZvTpS3xs+L7YvcBI2lTfXgOWAkaAQwQVgR8BXtWJ1MKUSh/HGNGNgdVGWYHcCg1BgQie3pValZZB39hVE4HBStcAA5SUz9Tf1JbXVABBVUJUwFmFkJZLlZUfCtaZXFBaUVBZ1poOXlQd09KSzN6ejYxMjVnaGN3bmtSKzRPOXdvZWJObVpaT3gyOTA3ND0= -#LEVEL: 36 - -#IDENTITY: 0VdYzXyIWNlPR991zQZLQoGLDYA4JvCX9GQ3MAYzpBRABWAHZTAmJvNQUAMxEEKGQDJVlnanF1YDdQQn0GewlXVWoAQmVMLX9FVyZaMAI7KlAIeXpPKGMCJ3BTVAJHLGlUHARbBlpqSUNJUURISXY1UXJCYmlBMHlZOVV3dFdRRXovM0lkU1hzNFJvWTkwT1JienA5bVRRPT0= -Current level = 41 at 1233527956186 -Current offset index: 3750576000000 block size: 1000000 - -*/ \ No newline at end of file diff --git a/client/main.cpp b/client/main.cpp deleted file mode 100644 index 9281ef0..0000000 --- a/client/main.cpp +++ /dev/null @@ -1,1176 +0,0 @@ -#include -#include -#include -#include -#include -#include "src/Identity.h" -#include "src/protocol/Connection.h" -#include -#include -#include -#include -#include -#include -#include - -#define QLZ_COMPRESSION_LEVEL 3 -#include "qlz/QuickLZ.h" - -using namespace std; -using namespace ts; -using namespace license::teamspeak; -void hexout(std::ostream& os, unsigned char c) -{ - unsigned char uc = static_cast(c); - os << std::setw(2) << std::setfill('0') << (unsigned int)uc << ' '; -} - -void hexdump(std::ostream& outs, const std::string& s, size_t line_len = 16) -{ - std::ostringstream os; - const std::string::size_type slen(s.size()); - int i(0); - std::string::size_type pos(0); - const std::streamsize lines(slen / line_len); - const std::streamsize chars(slen % line_len); - std::ios::fmtflags f(os.flags()); - - os << "Length: " << s.length() << "/" << std::hex << "0x" << s.length() << endl; - for(std::streamsize line = 0; line <= lines - (chars == 0 ? 1 : 0); ++line) - { - os << std::hex << setfill('0') << setw(3) << line * line_len << " | "; - for(i = 0; i < line_len; ++i) - { - if(pos < s.length()) - hexout(os, s[pos]); - else os << " "; - pos++; - } - os << " | "; - if(pos - line_len < s.length()){ - auto av = s.substr(pos - line_len); - for(char c : av.substr(0, min(av.length(), line_len))){ - if(isprint(c)) - os << c << " "; - else - os << "." << " "; - } - } - os << '\n'; - } - os.flags(f); - outs << os.str() << endl; -} -//This RSA puzzel crashes the manager -//545333494e49543100658803ffED1eBAACDe66bd212F3B91A0C1dbd65b374F1FCEe353A74C78eB99B5b8B2e0eC7DC9Ce7bCdfcFE97622AbD015B4EBCB3fecc7D23bBfaA2B15DBBBBC1d009DBcd924B06Eb2e0CBCD0AfBbadc2ecbb812C47d5dcAA4BcFdaF73ACe89A106c98f6c0DBeac8e8FeF9d6d836Bd1Cd791f376452Cff581400ed760acB2deAE1Be53E98152AbaBfaC823e3e4FACdaAf69E977C8dE328ECDA5FEE3c327FfCf9228caf8D761aeF7bAdbebe5eAcda87Eba61F09D7AEC9D4EeBa763cFE3c9cE718d37dd4F73CA10ffB4127d15Bee7cF9Edc644b4be06f0F9C4aEb2FBDd9549e215959FaFea57b5B7900000000 - -/* - auto parent = import((char*) root); - fe_neg(parent.X, parent.X); -fe_neg(parent.T, parent.T); -char buf[32]; -ge_p3_tobytes((u_char*) buf, &parent); -return string(buf, 32); - */ -using namespace std::chrono; -inline std::string keyMul(const char* publicKey /* compressed */, char* privateKey /* uncompressed */, bool negate){ - ge_p3 keyA{}; - ge_p2 result{}; - - ge_frombytes_negate_vartime(&keyA, (u_char*) publicKey); - if(negate) { - fe_neg(keyA.X, keyA.X); /* undo negate */ - fe_neg(keyA.T, keyA.T); /* undo negate */ - } - ge_scalarmult_vartime(&result, (u_char*) privateKey, &keyA); - - char buffer[32]; - ge_tobytes((u_char*) buffer, &result); - return string(buffer, 32); -} - -#include "ed25519/sha512.h" -static int consttime_equal(const unsigned char *x, const unsigned char *y) { - unsigned char r = 0; - - r = x[0] ^ y[0]; - #define F(i) r |= x[i] ^ y[i] - F(1); - F(2); - F(3); - F(4); - F(5); - F(6); - F(7); - F(8); - F(9); - F(10); - F(11); - F(12); - F(13); - F(14); - F(15); - F(16); - F(17); - F(18); - F(19); - F(20); - F(21); - F(22); - F(23); - F(24); - F(25); - F(26); - F(27); - F(28); - F(29); - F(30); - F(31); - #undef F - - return !r; -} - -int ed25519_verify(bool do_hash, const unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key) { - unsigned char h[64]; - unsigned char checker[32]; - sha512_context hash; - ge_p3 A; - ge_p2 R; - - if (signature[63] & 224) { - return 0; - } - - if (ge_frombytes_negate_vartime(&A, public_key) != 0) { - return 0; - } - - if(do_hash) { - //sha512_init(&hash); - //sha512_update(&hash, signature, 32); - //sha512_update(&hash, public_key, 32); - //sha512_update(&hash, message, message_len); - //sha512_final(&hash, h); - assert(false); - } else { - memcpy(h, message, 64); - } - - sc_reduce(h); - ge_double_scalarmult_vartime(&R, h, &A, signature + 32); - ge_tobytes(checker, &R); - - if (!consttime_equal(checker, signature)) { - return 0; - } - - return 1; -} - -/* - char seed[64]; - - LicenseChain chain; - //E813384CE058BA63F5792D16A093B0C503D2C51FD19A1DC36FD613EFB88E7334 - u_char publicKey[32]; - u_char privateKey[32] = {0xE8, 0x13, 0x38, 0x4C, 0xE0, 0x58, 0xBA, 0x63, 0xF5, 0x79, 0x2D, 0x16, 0xA0, 0x93, 0xB0, 0xC5, 0x03, 0xD2, 0xC5, 0x1F, 0xD1, 0x9A, 0x1D, 0xC3, 0x6F, 0xD6, 0x13, 0xEF, 0xB8, 0x8E, 0x73, 0x34}; - //privateKey[0] &= 248; - //privateKey[31] &= 63; - //privateKey[31] |= 64; - ge_p3 A; - ge_scalarmult_base(&A, privateKey); - ge_p3_tobytes(publicKey, &A); - hexDump((char*) publicKey, 32, 32, 32); - - cout << "A: " << base64::encode(keyMul((char*) chain.generatePublicKey(public_tea_root).data(), (char*) chain.generatePrivateKey((u_char*) privateKey).data(), true)) << endl; - cout << "A: " << base64::encode(keyMul((char*) chain.generatePublicKey((u_char*) publicKey).data(), (char*) chain.generatePrivateKey((u_char*) private_tea_root).data(), true)) << endl; - /* - for(char& c : seed) - c = rand(); - ed25519_create_keypair((u_char*) publicKey, (u_char*) privateKey, (u_char*) seed); - cout << "A: " << base64::encode(keyMul((char*) public_tea_root, privateKey, true)) << endl; - cout << "B: " << base64::encode(keyMul(publicKey, (char*) private_tea_root, true)) << endl; - - chain.addServerEntry(7, "TeaSpeak"); - chain.addEphemeralEntry(); - / - - istringstream is(chain.exportChain()); - auto c2 = LicenseChain::parse(is, error); - - chain.print(); - c2->print(); - cout << "A: " << base64::encode(keyMul((char*) c2->generatePublicKey(public_tea_root).data(), (char*) chain.generatePrivateKey((u_char*) privateKey).data(), true)) << endl; - cout << "A: " << base64::encode(keyMul((char*) c2->generatePublicKey((u_char*) publicKey).data(), (char*) chain.generatePrivateKey((u_char*) private_tea_root).data(), true)) << endl; - cout << "Chain: " << base64::encode(chain.exportChain()) << endl; - */ - -inline std::string parseHex(const std::string& in) { - char buffer[(in.length() + 1) / 2]; - memset(buffer, 0, sizeof(buffer)); - size_t nibble_index = 0; - - for(auto c : in) { - if(c == '\n' || c == ' ') continue; - - uint8_t nibble = 0; - if(c >= 'A' && c <= 'F') - nibble = c - 'A' + 10; - else if(c >= 'a' && c <= 'f') - nibble = c - 'a' + 10; - else if(c >= '0' && c <= '9') - nibble = c - '0'; - - if(nibble_index % 2 == 0) - nibble <<= 4; - else - nibble &= 0xF; - buffer[nibble_index / 2] |= nibble; - nibble_index++; - } - - return string(buffer, (nibble_index + 1) / 2); -} - -bool read_crypted_string(std::string& result, const char* buffer, int length) { - char tmp[264]; - char current; - int index = 0; - - do { - //cout << "Read: " << ((index & 0x1F) - length) << " | " << index << endl; - tmp[index] = length ^ buffer[index] ^ buffer[(index & 0x1F) - length]; - } while(tmp[index++]); - result = string(tmp, index - 1); - return true; -} - -void print_dec_teamspeak() { - auto bin = parseHex("3EF0E405913439B81A2D60D467C04D11\n" - "8E7D6C6CC8DC2B8B8F62FD30F7027393\n" - "29B7A64DC47E7BAD0E6A788E7E881805\n" - "9D373E29D0FC5FAFBC57C8757C8E4CA7\n" - "B44ED70A35E78019D531CBC8299A2E34\n" - "F107D5C124B35F47C62A1F52EA43FF68\n" - "29B14B0F13EDE81BB7AD43C900CD7D41\n" - "AD02A125F7E306917D65E40B3F70CC61\n" - "C35F019E616A71CFC6369FCE3FFA26E5\n" - "1C739028E2FC58812827CBF0051EFC66\n" - "CA8257EE96943F9935D6F23B22C352F0\n" - "F432D2E6A915ED1E889B48BEABAF1613\n" - "E50143BD39F929C1B657F53627DB429E\n" - "874E42B42D8D8D48B999DB24C369EDA4\n" - "7ECBD3C97668FBAA7368C21ABABD3A93\n" - "B9E213EE48DED608F6E7E4585EA86C8D\n" - "66789F00B8AF2982F2D645FE50C08310\n" - "F6FAFC5923638A8264E1532C71A8B319\n" - "4D948F08FE727FF4536325F45E9D8609\n" - "F17176F1587229F848A7B210F97E6EE6\n" - "4B6178A0369B1047C520543DD4DC3AFA\n" - "2F009C270F4FFA5EAB4A33A6534954E6\n" - "971EF2F10D86342CB0142221F96FC249\n" - "1E9C790D04EBB03D8C2328A21D3C1408\n" - "E1ED1B822222E7293B7CCE76CC576EF0\n" - "1105FF7FD79676F6D6862D893BABF16F\n" - "D2AF8A2436CA7765EDD62C39C457EFF9\n" - "6BD6E0E929AB0889EB57B1A4AE413DED\n" - "5152A23AFE7EFBA855E13029C94A9D9E\n" - "5D58A5329E8212F58EC678CD61F1BB61\n" - "C6DAD36233822B35C356FFBC75798F16\n" - "B6B6739DAFE85AE258C3DA11EFF7E203\n" - "51AF150AED16549F8166F9415ADA3C5F\n" - "09F241E66B37A85B506A50938E7AAB0E\n" - "038220175AEE5DFA772BB4474C7663AA\n" - "AB59CB7379F114672F8E2CCE431F8073\n" - "784219DCC22EBD115B9E391B47B605A2\n" - "2F73EC1F142E05C7CA73B10B1D9A391A\n" - "5AF154E46D22AA58003A39FBF64F8832\n" - "3CA603672A9E2D8A075BC4373C0603E1\n" - "EF178B6A29A910737DC577D0560C8423\n" - "667D96C336969E69ED3AE0126ACD33EB\n" - "E80D8A3867A702277BD839D34603846A\n" - "627ED38234818579EE3EFD0F21CD33E6\n" - "EF0F9B2329A1443771DD779E400A8275\n" - "7760B6B44C42A4628B8308AC90C06294\n" - "64FFB17DDBCFDB7A7B9D3C7CD357C350\n" - "B9C560814A54B32C948305AEDEC062C6\n" - "65FBB05D769D8364FB43589C576D6454\n" - "879B63EC5E52B77C899270EA460EDB62\n" - "1A14AC1EB93F65ED4A0F14FFAA5FFFF7\n" - "008453897B03A45A828164E3512E66A1\n" - "AF55CB2A68EA403332833A9B1D5CD56F\n" - "723699957BD9DE3DA767A75B6DC365B9\n" - "FA57C66962E857765E6AA4E609816F6D\n" - "EC732AE3FF1B86226BA6073E76CF7BD5\n" - "1F0F956C7B70C9CB78F9D8130DEA75CD\n" - "D612F9D4CA3FCD26A2FC65949FC62E3F\n" - "C2646B9B12BAF43F21C659E1FA3ED5F8\n" - "E61BAF108ADB41BFEBCAC22B37D34EEA\n" - "A36ECFF6BE07B31DD7CF51A1B7A31E12\n" - "B15D5CBB22E43EDDE94FED263B9E2BA7\n" - "4E52B62B8FC600A09CDA79D96BFBA036\n" - "82C7DB656C837431CA439608B1C52F84\n" - "4148BF6FEB4D9C9374E150509D6C4D17\n" - "A707B7687DEF784094D360F34D40C663\n" - "5D57A61CA43F71F10F091EF3EB4FF4ED\n" - "019E4E8E7244E046909D33866BBFF85D\n" - "D87869ED4570288D3FDC18439232313D\n" - "91C07ED9C02AA062A85B638F71A4AD4D\n" - "D9616BE30675339F35DD7121F4E04E97\n" - "3E3CAA513062CD78DE471696737571C6\n" - "C533C0967CF835F5077FD475E8E71B8E\n" - "2B3BBD16666FD07BC5077AD10410BE67\n" - "CECC5AA1C597208828F6E27A95839237\n" - "6B90637C8C12DF05F78F28C10408F02B\n" - "AF8A5F4EAA3F829659BE9ED37AD42DAC\n" - "A327C9D9D960738D6A2ACC4B9F17C38D\n" - "4658BF20988347AB9DCB2BCE7EFEA735\n" - "82CAD6632FD42738C8569B41B3CB6C85\n" - "404CB46FEB579C8265FA42599D7A5015\n" - "B810A02C38AB0B011CB9AD47E0ED479C\n" - "5A856957967AB9B345D57565BD4C7C24\n" - "8336800C188B2B213C998D67C0CD67BC\n" - "7AA54977B615DAD560A7051D8F2B0D41\n" - "BD02F66021BF4C4047EAB90AA1BD4999\n" - "752CF4F712952778B0086C63D967C247\n" - "1C866F7968CD916A998676E825FF0D75\n" - "D23BFEF20AD155D01915E37ADADA1FF1\n" - "C384368E34AFB6629F92C76F28C4797C\n" - "9113D917A5907BCE194282F9342CCF56\n" - "BFF370D2E9BE11B80288DD05A4A2B70C\n" - "05F45304A838BB3DC5AA5DF43F368E48\n" - "EAFC7DD8E8AC5FA50595CE44B8A4A24F\n" - "57E94E57BD37F53FCCF84FFC37238E49\n" - "F7E767D5E9BC11CCB1696FDD1AB8A032\n" - "96B0FC0CEB57DAC91BE4FAED1050BA1E\n" - "12E925A161DAEA4BA56D6E8908A5AF60\n" - "96BCF549BF48D09B1FEAF0B8104DBD00\n" - "03FB6BAB6ADAFC02AA643C8E01B9B524\n" - "8DA2F62C1CD5C92DB0145D88314956F5\n" - "44ED7A21AF4B0844E3FB0EA3EB47DA17\n" - "DC3359A313DAC761A6150F8A370A4190\n" - "22EFF7148D6428AB093265CA63D95306\n" - "DE7E796ECEC5389EDF7FE433EA137780\n" - "2680CA031FFB66C28B5EE79F87369133\n" - "ABE63C83919D3B2299787E9300D70BE4\n" - "886FCB4205F271D0C249EDBFC6293ED8\n" - "58E4F124EAF8BF0DB50F94AD9E534BA8\n" - "31D8811DBB848C71D82CEEBB24C2C5D4\n" - "24729E6766DB59DC1EBBD271F2BF726A\n" - "8910F9A03C9AA5AD56EC4BD39917B0E8\n" - "F20545A90942E371AF7D8AB25EA0757C\n" - "9C08B0BA32D7A4E24EE40CA04E859B7C\n" - "E34B408463490CA109B93521B2121805\n" - "A0B45EF9F45E85439C704E8F6EA5BB5C\n" - "C36B60A443692C812999020DDB2F5019\n" - "D0DE38AD5A762DD4C03CB54218862517\n" - "53A246E47233B1455D1AF0EF0AFDB55D\n" - "C803CF2740E50ECFDE36EB421C86390F\n" - "42EB5FF13B23B75C541B9EF0091DE168\n" - "9FC55BF8CA8E7F9E2EA7FE6C9880E741\n" - "7373657274696F6E20226D5F74696D65\n" - "725265736F6C7574696F6E20213D2030\n" - "22206661696C6564206174202E2E2F2E\n" - "2E2F2E2E2F2E2E2F732F646570732F74\n" - "65616D737065616B5F7365727665725F\n" - "6C69622F7372632F74735F7365727665\n" - "722F616E7469666C6F6F642E6370703A\n" - "00416E7469466C6F6F64004173736572\n" - "74696F6E20226D5F706F696E74735469\n" - "636B5261746520213D20302220666169\n" - "6C6564206174202E2E2F2E2E2F2E2E2F\n" - "2E2E2F732F646570732F7465616D7370\n" - "65616B5F7365727665725F6C69622F73\n" - "72632F74735F7365727665722F616E74\n" - "69666C6F6F642E6370703A0052656765\n" - "7870206572726F7220666F7220495020\n" - "65787072657373696F6E202200222C20\n" - "6572726F723A200042616E4D616E6167\n" - "657200526567657870206572726F7220\n" - "666F72204E616D652065787072657373\n" - "696F6E20220054686973206E616D6520\n" - "69732000596F7520617265200062616E\n" - "6E6564207065726D616E656E746C792E\n" - "0062616E6E65642074656D706F726172\n" - "696C792E0020526561736F6E3A202200\n" - "0A54727920616761696E20696E20006E\n" - "6F7469667962616E6C697374006C6173\n" - "746E69636B6E616D6500696E766F6B65\n" - "72636C6462696400656E666F7263656D\n" - "656E74730062616E5F696E736572742E\n" - "73716C0062616E5F69700062616E5F6E\n" - "616D650062616E5F7569640062616E5F\n" - "74696D657374616D700062616E5F6C65\n" - "6E6774680062616E5F696E766F6B6572\n" - "5F636C69656E745F69640062616E5F69\n" - "6E766F6B65725F7569640062616E5F69\n" - "6E766F6B65725F6E616D650062616E5F\n" - "726561736F6E0062616E5F6861736800\n" - "62616E5F64656C6574652E73716C0062\n" - "616E5F696400417373657274696F6E20\n" - "226572726F72203D3D204552524F525F\n" - "6F6B22206661696C6564206174202E2E\n" - "2F2E2E2F2E2E2F2E2E2F732F64657073\n" - "2F7465616D737065616B5F7365727665\n" - "725F6C69622F7372632F74735F736572\n" - "7665722F62616E6D616E616765722E63\n" - "70703A0062616E2064656C6574656420\n" - "28657870697265642920726561736F6E\n" - "3D0062616E5F6C6973742E73716C0069\n" - "6E76616C69642062616E206974656D20\n" - "776974682069643A2000000000000000\n" - "4E5374335F5F3132315F5F656D707479\n" - "5F6E6F6E5F6F776E5F73746174654963\n" - "45450000000000000000000000000000\n" - "4E5374335F5F3131355F5F6861735F6F\n" - "6E655F73746174654963454500000000\n" - "4E5374335F5F31365F5F6E6F64654963\n" - "45450000000000000000000000000000\n" - "4E5374335F5F3131315F5F616C746572\n" - "6E617465496345450000000000000000\n" - "4E5374335F5F3131375F5F6F776E735F\n" - "74776F5F737461746573496345450000\n" - "4E5374335F5F3131365F5F6F776E735F\n" - "6F6E655F737461746549634545000000\n" - "4E5374335F5F3131375F5F7265706561\n" - "745F6F6E655F6C6F6F70496345450000\n" - "4E5374335F5F31365F5F6C6F6F704963\n" - "45450000000000000000000000000000\n" - "4E5374335F5F3132365F5F656E645F6D\n" - "61726B65645F73756265787072657373\n" - "696F6E49634545000000000000000000\n" - "4E5374335F5F3132385F5F626567696E\n" - "5F6D61726B65645F7375626578707265\n" - "7373696F6E4963454500000000000000\n" - "4E5374335F5F3131305F5F725F616E63\n" - "686F7249634545000000000000000000\n" - "4E5374335F5F3131305F5F6C5F616E63\n" - "686F7249634545000000000000000000\n" - "4E5374335F5F3131325F5F6D61746368\n" - "5F636861724963454500000000000000\n" - "4E5374335F5F3132305F5F6D61746368\n" - "5F636861725F636F6C6C61746549634E\n" - "535F313272656765785F747261697473\n" - "49634545454500000000000000000000\n" - "4E5374335F5F3131385F5F6D61746368\n" - "5F636861725F696361736549634E535F\n" - "313272656765785F7472616974734963\n" - "45454545000000000000000000000000\n" - "4E5374335F5F3132305F5F627261636B\n" - "65745F65787072657373696F6E49634E\n" - "535F313272656765785F747261697473\n" - "49634545454500000000000000000000\n" - "4E5374335F5F3131315F5F6D61746368\n" - "5F616E79496345450000000000000000\n" - "4E5374335F5F3131305F5F6261636B5F\n" - "72656649634545000000000000000000\n" - "4E5374335F5F3131385F5F6261636B5F\n" - "7265665F636F6C6C61746549634E535F\n" - "313272656765785F7472616974734963\n" - "45454545000000000000000000000000\n" - "4E5374335F5F3131365F5F6261636B5F\n" - "7265665F696361736549634E535F3132\n" - "72656765785F74726169747349634545\n" - "45450000000000000000000000000000\n" - "4E5374335F5F3132335F5F6D61746368\n" - "5F616E795F6275745F6E65776C696E65\n" - "49634545000000000000000000000000\n" - "4E5374335F5F3131315F5F6C6F6F6B61\n" - "6865616449634E535F31327265676578\n" - "5F747261697473496345454545000000\n" - "4E5374335F5F3131355F5F776F72645F\n" - "626F756E6461727949634E535F313272\n" - "656765785F7472616974734963454545\n" - "45000000000000000000000000000000\n" - "4E5374335F5F3131335F5F656D707479\n" - "5F737461746549634545000000000000\n" - "4E5374335F5F3132305F5F7368617265\n" - "645F7074725F706F696E74657249504E\n" - "535F31335F5F656D7074795F73746174\n" - "65496345454E535F313464656661756C\n" - "745F64656C6574654953325F45454E53\n" - "5F39616C6C6F6361746F724953325F45\n" - "45454500000000000000000000000000\n" - "4E5374335F5F31313464656661756C74\n" - "5F64656C657465494E535F31335F5F65\n" - "6D7074795F7374617465496345454545\n" - "00000000000000000000000000000000\n" - "4E5374335F5F3131315F5F656E645F73\n" - "74617465496345450041737365727469\n" - "6F6E20226D5F705669727475616C5365\n" - "7276657220213D205F5F6E756C6C2220\n" - "6661696C6564206174202E2E2F2E2E2F\n" - "2E2E2F2E2E2F732F646570732F746561\n" - "6D737065616B5F7365727665725F6C69\n" - "622F7372632F74735F7365727665722F\n" - "6368616E636C69656E74736361636865\n" - "2E6370703A004368616E436C69656E43\n" - "6163686500417373657274696F6E2022\n" - "6D5F5468726561644944203D3D207374\n" - "643A3A746869735F7468726561643A3A\n" - "6765745F6964282922206661696C6564\n" - "206174202E2E2F2E2E2F2E2E2F2E2E2F\n" - "732F646570732F7465616D737065616B\n" - "5F7365727665725F6C69622F7372632F\n" - "74735F7365727665722F6368616E636C\n" - "69656E747363616368652E6370703A00\n" - "636F6D706C61696E5F696E736572742E\n" - "73716C00636F6D706C61696E5F66726F\n" - "6D5F636C69656E745F696400636F6D70\n" - "6C61696E5F746F5F636C69656E745F69\n" - "6400636F6D706C61696E5F6D65737361\n" - "676500636F6D706C61696E5F74696D65\n" - "7374616D7000636F6D706C61696E5F68\n" - "61736800636F6D706C61696E5F64656C\n" - "6574652E73716C00636F6D706C61696E\n" - "5F64656C6574655F616C6C2E73716C00\n" - "636F6D706C61696E5F64656C6574655F\n" - "7072756E652E73716C00636F6D706C61\n" - "696E5F6765745F62795F736572766572\n" - "69642E73716C00536F6D6520636F6D70\n" - "6C61696E7420656E7472696573206672\n" - "6F6D2074686520646174616261736520\n" - "77657265206E6F74206C6F6164656420\n" - "62656361757365207468657920776572\n" - "65206475706C696361746573206F6620\n" - "616C7265616479206C6F61646564206F\n" - "6E657300436F6D706C61696E4D677200\n" - "6368616E6E656C5F696E736572745F62\n" - "756C6B2E73716C006F72675F6368616E\n" - "6E656C5F6964006368616E6E656C5F69\n" - "6E736572745F62756C6B5F6669787570\n" - "2E73716C006368616E6E656C5F696E73\n" - "6572745F62756C6B5F6D617070696E67\n" - "2E73716C006368616E6E656C5F70726F\n" - "706572746965735F62756C6B5F696E73\n" - "6572742E73716C006368616E6E656C5F\n" - "64656C6574652E73716C006368616E6E\n" - "656C5F696E736572742E73716C006368\n" - "616E6E656C5F7570646174655F706172\n" - "656E7469642E73716C00536572766572\n" - "517565727920477565737400636C6965\n" - "6E745F696E736572742E73716C00636C\n" - "69656E745F696E736572745F62756C6B\n" - "2E73716C006F72675F636C69656E745F\n" - "696400636C69656E745F696E73657274\n" - "5F62756C6B5F6D617070696E672E7371\n" - "6C00636C69656E745F70726F70657274\n" - "6965735F62756C6B5F696E736572742E\n" - "73716C00636C69656E745F6765745F62\n" - "795F7569642E73716C00636C69656E74\n" - "5F6D6F6E74685F75706C6F616400636C\n" - "69656E745F746F74616C5F75706C6F61\n" - "6400636C69656E745F6D6F6E74685F64\n" - "6F776E6C6F616400636C69656E745F74\n" - "6F74616C5F646F776E6C6F616400636C\n" - "69656E745F64656C6574652E73716C00\n" - "636C69656E745F7570646174655F6C6F\n" - "67696E5F696E666F2E73716C00636C69\n" - "656E745F7570646174655F6E616D652E\n" - "73716C00636C69656E745F7570646174\n" - "655F73746174732E73716C00636C6965\n" - "6E745F7570646174655F747261666669\n" - "635F73746174732E73716C006D657373\n" - "6167655F6765745F756E726561645F62\n" - "795F636C69656E7469642E73716C0075\n" - "6E72656164002E736F006C6962007761\n" - "6974696E6720666F7220636F6E6E6563\n" - "74696F6E20617661696C61626C650064\n" - "6174616261736520636F6E6E65637469\n" - "6F6E206E6F7420666F756E6400417373\n" - "657274696F6E20226572726F72203D3D\n" - "204552524F525F6F6B22206661696C65\n" - "64206174202E2E2F2E2E2F2E2E2F2E2E\n" - "2F732F646570732F7465616D73706561\n" - "6B5F7365727665725F6C69622F737263\n" - "2F74735F7365727665722F6461746162\n" - "6173652F64625F64617461626173652E\n" - "6370703A00506C65617365206D616B65\n" - "207375726520796F7520757365207468\n" - "6520737570706C696564207473337365\n" - "727665725F6D696E696D616C5F72756E\n" - "7363726970742E736820746F2072756E\n" - "20746865207365727665722C206F7220\n" - "736574204C445F4C4942524152595F50\n" - "41544820796F757273656C6600756E61\n" - "626C6520746F206C6F61642064617461\n" - "6261736520706C7567696E206C696272\n" - "617279202200222C2068616C74696E67\n" - "21007473336462706C7567696E5F696E\n" - "6974007473336462706C7567696E5F73\n" - "687574646F776E007473336462706C75\n" - "67696E5F636F6E6E6563740074733364\n" - "62706C7567696E5F646973636F6E6E65\n" - "6374007473336462706C7567696E5F65\n" - "786563007473336462706C7567696E5F\n" - "6F70656E007473336462706C7567696E\n" - "5F62756C6B5F696E7365727400747333\n" - "6462706C7567696E5F6765746C617374\n" - "696E736572746964007473336462706C\n" - "7567696E5F6765746D6F646966696564\n" - "726F77636F756E74007473336462706C\n" - "7567696E5F7461626C65657869737473\n" - "007473336462706C7567696E5F766572\n" - "73696F6E007473336462706C7567696E\n" - "5F6E616D65007473336462706C756769\n" - "6E5F73686F72746E616D650074733364\n" - "62706C7567696E5F6170697665727369\n" - "6F6E007473336462706C7567696E5F67\n" - "65746C6173746572726F72004661696C\n" - "656420746F20696D706F727420220022\n" - "2066726F6D202200436F756C64206E6F\n" - "74206C6F616420646174616261736520\n" - "706C7567696E006462506C7567696E20\n" - "6E616D653A20202020006462506C7567\n" - "696E2076657273696F6E3A2000506C75\n" - "67696E206170692076657273696F6E20\n" - "69732000207768696C65200020697320\n" - "72657175697265640064625F65786563\n" - "2829200064625F62756C6B5F696E7365\n" - "72742829200064625F6F70656E282920\n" - "00646174616261736520627573792C20\n" - "77616974696E6720666F722066696E69\n" - "7368696E6720696E646578207461736B\n" - "732C206D61792074616B6520736F6D65\n" - "2074696D65210073657453514C66726F\n" - "6D46696C65282066696C653A00726570\n" - "206669656C6473202F20696E73657274\n" - "20706F696E742073697A65206E6F7420\n" - "73616D6520666F722073716C20616E64\n" - "20726570656174207061727400417373\n" - "657274696F6E2022737472696E675F66\n" - "69656C645F636F756E74203D3D207374\n" - "72696E675F6669656C645F6E616D6573\n" - "2E73697A65282922206661696C656420\n" - "6174202E2E2F2E2E2F2E2E2F2E2E2F73\n" - "2F646570732F7465616D737065616B5F\n" - "7365727665725F6C69622F7372632F74\n" - "735F7365727665722F64617461626173\n" - "652F64625F64617461626173652E6370\n" - "703A00696E76616C696420706172616D\n" - "6574657220666F756E6420005C5B5C5B\n" - "5C5B282E2A3F295C5D5C5D5C5D005C3A\n" - "285B5E5C3A5D2A3F5C2A295C3A003A24\n" - "3031303A003A24303100417373657274\n" - "696F6E2022216D5F73746F726167652E\n" - "656F66282922206661696C6564206174\n" - "202E2E2F2E2E2F2E2E2F2E2E2F732F64\n" - "6570732F7465616D737065616B5F7365\n" - "727665725F6C69622F7372632F74735F\n" - "7365727665722F64617461626173652F\n" - "64625F64617461626173652E6370703A\n" - "00756E6B6E6F776E207461626C652066\n" - "69656C64207265717565737465643A20\n" - "00417373657274696F6E2022636F756E\n" - "74203C3D20363422206661696C656420\n" - "6174202E2E2F2E2E2F2E2E2F2E2E2F73\n" - "2F646570732F7465616D737065616B5F\n" - "7365727665725F6C69622F7372632F74\n" - "735F7365727665722F64617461626173\n" - "652F64625F64617461626173652E6370\n" - "703A00417373657274696F6E20227369\n" - "7A65735B695D203C3D207374643A3A6E\n" - "756D657269635F6C696D6974733C756E\n" - "7369676E656420696E743E3A3A6D6178\n" - "282922206661696C6564206174202E2E\n" - "2F2E2E2F2E2E2F2E2E2F732F64657073\n" - "2F7465616D737065616B5F7365727665\n" - "725F6C69622F7372632F74735F736572\n" - "7665722F64617461626173652F64625F\n" - "64617461626173652E6370703A005C3A\n" - "285B612D7A412D5A302D395F2D5D2A3F\n" - "295C3A005C3A285B612D7A412D5A302D\n" - "395F2D5D2A3F295C2A303F5C3A000000\n" - "3134437573746F6D4461746162617365\n" - "00000000000000000000000000000000\n" - "3134506C7567696E4461746162617365\n" - "0064625F4372656174655461626C6573\n" - "282920756E61626C6520746F206C6F61\n" - "6420696E7374616E6365206465666175\n" - "6C742076616C7565730053514C006372\n" - "656174655F7461626C65732E73716C00\n" - "64625F4372656174655461626C657328\n" - "2920756E61626C6520746F2063726561\n" - "7465207461626C65730064625F437265\n" - "6174655461626C65732829207461626C\n" - "65732063726561746564006465666175\n" - "6C74732E73716C0064625F4372656174\n" - "655461626C6573282920756E61626C65\n" - "20746F20696E73657274206465666175\n" - "6C742076616C7565730064625F437265\n" - "6174655461626C6573282920666F756E\n" - "6420696E76616C696420646174616261\n" - "73652076657273696F6E0064625F4372\n" - "656174655461626C6573282920756E61\n" - "626C6520746F207361766520696E7374\n" - "616E63652064656661756C742076616C\n" - "7565730064625F437265617465546162\n" - "6C6573282920756E61626C6520746F20\n" - "696E7365727420646174616261736520\n" - "76657273696F6E0064726F705F746162\n" - "6C65732E73716C0064625F4372656174\n" - "655461626C65732829207461626C6573\n" - "2064726F7065640064625F4372656174\n" - "655461626C6573282920756E61626C65\n" - "20746F2064726F70207461626C657300\n" - "7570646174655F64617461626173655F\n" - "76657273696F6E2E73716C0043524954\n" - "4943414C206572726F72207768696C65\n" - "207570646174696E6720646174616261\n" - "73652076657273696F6E007570646174\n" - "655F0064617461626173652075706461\n" - "746564207375636365737366756C6C79\n" - "20746F207265766973696F6E3A200075\n" - "70646174655461626C6573282920756E\n" - "61626C6520746F207570646174652064\n" - "617461626173652076657273696F6E00\n" - "64617461626173652075706461746520\n" - "746F207265766973696F6E3A20006375\n" - "73746F6D5F696E736572742E73716C00\n" - "637573746F6D5F64656C6574655F6279\n" - "5F636C69656E7469642E73716C00636C\n" - "69656E745F64656C6574655F7072756E\n" - "652E73716C0067726F7570735F736572\n" - "7665720067726F7570735F6368616E6E\n" - "656C007065726D5F696E736572742E73\n" - "716C007065726D5F6964007065726D5F\n" - "76616C7565007065726D5F6E65676174\n" - "6564007065726D5F736B697000706572\n" - "6D5F64656C6574655F62795F67726F75\n" - "7069642E73716C007065726D5F64656C\n" - "6574655F62795F7065726D69642E7371\n" - "6C007065726D5F696E736572745F6275\n" - "6C6B2E73716C0067726F75705F6D656D\n" - "6265725F696E736572745F62756C6B2E\n" - "73716C0067726F75705F696E73657274\n" - "2E73716C0067726F75705F696E736572\n" - "745F62756C6B5F736E617073686F742E\n" - "73716C006F72675F67726F75705F6964\n" - "0067726F75705F696E736572745F6275\n" - "6C6B5F736E617073686F745F6765745F\n" - "6D617070696E672E73716C0067726F75\n" - "705F64656C6574652E73716C00746162\n" - "6C6567726F7570007461626C65706572\n" - "6D73007461626C656D656D6265727300\n" - "67726F75705F72656E616D652E73716C\n" - "0067726F7570735F6765745F62795F73\n" - "657276657269645F747970652E73716C\n" - "0067726F75705F69645F6765745F6279\n" - "5F6E616D652E73716C007065726D5F75\n" - "70646174655F6765745F67726F757073\n" - "2E73716C006661696C656420746F2075\n" - "7064617465207065726D697373696F6E\n" - "732C2068616C74656421007065726D5F\n" - "72656E616D652E73716C006F6C645F70\n" - "65726D5F6E616D65006E65775F706572\n" - "6D5F6E616D6500756E61626C6520746F\n" - "2072656E616D65207065726D69737369\n" - "6F6E2C2068616C74656421007065726D\n" - "5F636F70795F64656661756C745F7065\n" - "726D697373696F6E732E73716C00756E\n" - "61626C6520746F20636F707920646566\n" - "61756C74207065726D697373696F6E73\n" - "2C2068616C74656421006661696C6564\n" - "20746F20726574726965766520766972\n" - "7475616C736572766572732C2068616C\n" - "74656421007065726D5F736572766572\n" - "5F67726F757000695F636C69656E745F\n" - "6D6F646966795F706F77657200695F6E\n" - "65656465645F6D6F646966795F706F77\n" - "65725F636C69656E745F6D6F64696679\n" - "5F706F77657200695F636C69656E745F\n" - "6E65656465645F6D6F646966795F706F\n" - "77657200695F6E65656465645F6D6F64\n" - "6966795F706F7765725F636C69656E74\n" - "5F6E65656465645F6D6F646966795F70\n" - "6F776572007570646174656420706572\n" - "6D697373696F6E7320746F2076657273\n" - "696F6E2031007065726D5F6368616E6E\n" - "656C5F67726F75707300757064617465\n" - "64207065726D697373696F6E7320746F\n" - "2076657273696F6E2032007570646174\n" - "6564207065726D697373696F6E732074\n" - "6F2076657273696F6E20330075706461\n" - "746564207065726D697373696F6E7320\n" - "746F2076657273696F6E203400757064\n" - "61746564207065726D697373696F6E73\n" - "20746F2076657273696F6E2035007570\n" - "6461746564207065726D697373696F6E\n" - "7320746F2076657273696F6E20360075\n" - "706461746564207065726D697373696F\n" - "6E7320746F2076657273696F6E203700\n" - "695F6368616E6E656C5F6D6F64696679\n" - "5F6D616B655F636F6465635F656E6372\n" - "79707465640075706461746564207065\n" - "726D697373696F6E7320746F20766572\n" - "73696F6E203800757064617465642070\n" - "65726D697373696F6E7320746F207665\n" - "7273696F6E2039007570646174656420\n" - "7065726D697373696F6E7320746F2076\n" - "657273696F6E20313000695F636C6965\n" - "6E745F6D61785F636C6F6E657300695F\n" - "6E65656465645F6D6F646966795F706F\n" - "7765725F636C69656E745F6D61785F63\n" - "6C6F6E65730075706461746564207065\n" - "726D697373696F6E7320746F20766572\n" - "73696F6E203131007570646174655F70\n" - "65726D697373696F6E735F31322E7371\n" - "6C006661696C656420746F2075706772\n" - "616465207065726D697373696F6E732C\n" - "2068616C746564210075706461746564\n" - "207065726D697373696F6E7320746F20\n" - "76657273696F6E203132007570646174\n" - "6564207065726D697373696F6E732074\n" - "6F2076657273696F6E20313300757064\n" - "61746564207065726D697373696F6E73\n" - "20746F2076657273696F6E2031340075\n" - "706461746564207065726D697373696F\n" - "6E7320746F2076657273696F6E203135\n" - "0075706461746564207065726D697373\n" - "696F6E7320746F2076657273696F6E20\n" - "31360075706461746564207065726D69\n" - "7373696F6E7320746F2076657273696F\n" - "6E20313700625F7669727475616C7365\n" - "727665725F6D6F646966795F64656661\n" - "756C745F74656D705F6368616E6E656C\n" - "5F64656C6574655F64656C617900695F\n" - "6E65656465645F6D6F646966795F706F\n" - "7765725F7669727475616C7365727665\n" - "725F6D6F646966795F64656661756C74\n" - "5F74656D705F6368616E6E656C5F6465\n" - "6C6574655F64656C617900695F636861\n" - "6E6E656C5F6372656174655F6D6F6469\n" - "66795F74656D705F64656C6574655F64\n" - "656C617900695F6E65656465645F6D6F\n" - "646966795F706F7765725F6368616E6E\n" - "656C5F6372656174655F6D6F64696679\n" - "5F74656D705F64656C6574655F64656C\n" - "61790075706461746564207065726D69\n" - "7373696F6E7320746F2076657273696F\n" - "6E203138007570646174656420706572\n" - "6D697373696F6E7320746F2076657273\n" - "696F6E20313900757064617465506572\n" - "6D697373696F6E73282920756E61626C\n" - "6520746F20696E736572742064617461\n" - "626173652076657273696F6E00736572\n" - "7665725F696E736572742E73716C0073\n" - "65727665725F64656C6574652E73716C\n" - "0062696E64696E67735F6C6973742E73\n" - "716C007365727665725F757064617465\n" - "5F747261666669635F73746174732E73\n" - "716C007365727665725F757064617465\n" - "5F706F72742E73716C00736572766572\n" - "5F7570646174655F6175746F73746172\n" - "742E73716C007365727665725F676574\n" - "5F6279706F72742E73716C0073657276\n" - "65725F7570646174655F6D616368696E\n" - "655F69642E73716C007265766F636174\n" - "696F6E735F696E736572745F62756C6B\n" - "2E73716C007265766F636174696F6E5F\n" - "74797065007265766F636174696F6E5F\n" - "65787069726174696F6E007265766F63\n" - "6174696F6E5F6B6579007265766F6361\n" - "74696F6E735F6765746C6973742E7371\n" - "6C00496E76616C6964207265766F6361\n" - "74696F6E206B657920007265766F6361\n" - "74696F6E735F64656C6574652E73716C\n" - "003B20726561736F6E3A200046696C65\n" - "4D616E6167657200436F756C64206E6F\n" - "742062696E642066696C657472616E73\n" - "666572206C697374656E20706F727420\n" - "6F6E2064656661756C74206164647265\n" - "737365730066696C657472616E736665\n" - "722062696E64206661696C6564206F6E\n" - "20004572726F72207768696C65206765\n" - "7474696E67206C697374656E696E6720\n" - "6164647265737365732E200041737365\n" - "7274696F6E20226D5F62616E64776964\n" - "74685F6C696D69745F73657276657273\n" - "2E66696E64287365727665725F696429\n" - "203D3D206D5F62616E6477696474685F\n" - "6C696D69745F736572766572732E656E\n" - "64282922206661696C6564206174202E\n" - "2E2F2E2E2F2E2E2F2E2E2F732F646570\n" - "732F7465616D737065616B5F73657276\n" - "65725F6C69622F7372632F74735F7365\n" - "727665722F66696C657472616E736665\n" - "722F73657276657266696C656D616E61\n" - "6765722E6370703A0041737365727469\n" - "6F6E2022697420213D206D5F62616E64\n" - "77696474685F6C696D69745F73657276\n" - "6572732E656E64282922206661696C65\n" - "64206174202E2E2F2E2E2F2E2E2F2E2E\n" - "2F732F646570732F7465616D73706561\n" - "6B5F7365727665725F6C69622F737263\n" - "2F74735F7365727665722F66696C6574\n" - "72616E736665722F7365727665726669\n" - "6C656D616E616765722E6370703A0045\n" - "72726F7220616363657074696E672066\n" - "696C657472616E736665722000417373\n" - "657274696F6E202262775F7365727665\n" - "7220213D206D5F62616E647769647468\n" - "5F6C696D69745F736572766572732E65\n" - "6E64282922206661696C656420617420\n" - "2E2E2F2E2E2F2E2E2F2E2E2F732F6465\n" - "70732F7465616D737065616B5F736572\n" - "7665725F6C69622F7372632F74735F73\n" - "65727665722F66696C657472616E7366\n" - "65722F73657276657266696C656D616E\n" - "616765722E6370703A00417373657274\n" - "696F6E202262775F636C69656E742021\n" - "3D2062775F7365727665722D3E736563\n" - "6F6E642E6D5F636C69656E745F62616E\n" - "647769647468732E656E642829222066\n" - "61696C6564206174202E2E2F2E2E2F2E\n" - "2E2F2E2E2F732F646570732F7465616D\n" - "737065616B5F7365727665725F6C6962\n" - "2F7372632F74735F7365727665722F66\n" - "696C657472616E736665722F73657276\n" - "657266696C656D616E616765722E6370\n" - "703A0046696C654D616E616765722054\n" - "696D657220657870697265735F66726F\n" - "6D5F6E6F772072657475726E65642065\n" - "72726F723A2000747269656420746F20\n" - "72656D6F766520697020746861742077\n" - "6173206E6F7420696E206C6973742120\n" - "00636C6F7365006C6F63616C5F656E64\n" - "706F696E740000000000000000000000\n" - "1E000000000000001E00000000000000\n" - "0A00000000000000C800000000000000\n" - "F4010000000000000000000000000000\n" - "25000000000000000000000000000000\n" - "00000000000000000000000000000000\n" - "0000000000000080FFFFFFFFFFFFFF7F\n" - "0100000000000080FDFFFFFFFFFFFF7F"); - cout << "Bin length: " << bin.length() << endl; - //0x33E 0x43C - //cout << "Str: " << read_crypted_string(bin.data() + 0x3BA, 0x3BA) << endl; - //cout << "Str: " << read_crypted_string(bin.data() + 0x3DF, 0x3DF) << endl; - //cout << "Str: " << read_crypted_string(bin.data() + 0x405, 0x405) << endl; => virtual server id - //cout << "Str: " << read_crypted_string(bin.data() + 0x43C, 0x43C) << endl; => is duplicated in same instance, shutting down! - - for(int index = 0x3E; index < bin.length() + 1; ) { - string str; - read_crypted_string(str, bin.data() + index, index); - cout << "Hex: 0x" << hex << setfill('0') << setw(3) << index << " => " << str << endl; - index += str.length() + 1; - } -} - -int main(int argc, char** argv){ - threads::timer t(""); - - srand(system_clock::now().time_since_epoch().count()); - init_LTM(); - if(register_prng(&sprng_desc) == -1) { - cerr << "could not setup prng" << endl; - return EXIT_FAILURE; - } - if (register_cipher(&rijndael_desc) == -1) { - cerr << "could not setup rijndael" << endl; - return EXIT_FAILURE; - } - string error; - - - if(false) { - auto base64_tvd = base64::decode("AQCvbHFTQDY/terPeilrp/ECU9xCH5U3xC92lYTNaY/0KQAJFueAazbsgAAAACVUZWFtU3BlYWsgU3lzdGVtcyBHbWJIAADmqdzhKVTai5ZX3LMCOmhH4wOWa7Jrb27PTN6XJSvOaAAKcspvMINAZwAAACRUZWFtU3BlYWsgc3lzdGVtcyBHbWJIAADRNBxg9GPfGFpwf0akzRQs4B/VhIvD+cKAC7vzRAys/AIKfC4AC27CAAYAAAAAW09EQU5JIEHDhyBUQUtJTF0gVHMzLkFtYWNpT2xtYXlhblRheWZhLkNPTSB8IFdFQkRpeW8uQ09NAA=="); - istringstream s(base64_tvd); - auto result = LicenseChain::parse(s, error); - if(!result) { - cerr << error << endl; - return 0; - } - - result->print(); - return 0; - } - - - cout << base64::encode(license::teamspeak::Anonymous::chain->exportChain()) << endl; - cout << base64::encode(reinterpret_cast(license::teamspeak::Anonymous::root_key), 32) << endl; - - if(false) { - auto key_plk = license::teamspeak::Anonymous::chain->generatePublicKey(); - auto key_prv = license::teamspeak::Anonymous::chain->generatePrivateKey((u_char*) license::teamspeak::Anonymous::root_key, license::teamspeak::Anonymous::root_index); - - u_char sign[64]; - string message = "Hello World"; - ed25519_sign(sign, (u_char*) message.data(), message.length(), (u_char*) key_plk.data(), (u_char*) key_prv.data()); - assert(ed25519_verify(sign, (const u_char*) message.data(), message.length(), (u_char*) key_plk.data())); - } -#if false - auto base64_license = "Co4CCsQBAQCvbHFTQDY/terPeilrp/ECU9xCH5U3xC92lYTNaY/0KQAJFueAazbsgAAAACVUZWFtU3BlYWsgU3lzdGVtcyBHbWJIAABVa/g1Aa+EhqDv4a+FKZ+nhnzgNNoG5LZZDMbWP1rUJwAJjrHNL59A2wAAACRUZWFtU3BlYWsgc3lzdGVtcyBHbWJIAAAY8GKBKoLJ2NJT15WG1E3GQ0vl0Ju29Oq3KqYAeEH9GQIJmBqACpU6gAQAAAIAVG9tIFdlYmVyABIgwLAWtDC3hSt8KzSBEksYyaYXxrIybtV207ImV+ugSWkYgAQgCioeVGVhbVNwZWFrIDMgTm9uLVByb2ZpdCBMaWNlbnNlErUBAQCvbHFTQDY/terPeilrp/ECU9xCH5U3xC92lYTNaY/0KQAJFueAazbsgAAAACVUZWFtU3BlYWsgU3lzdGVtcyBHbWJIAABVa/g1Aa+EhqDv4a+FKZ+nhnzgNNoG5LZZDMbWP1rUJwAJjrHNL59A2wAAACRUZWFtU3BlYWsgc3lzdGVtcyBHbWJIAACWjeLEq44YFFAhN9aie2W8g7q3LO2UN/FiHtoGxOoiKAUJjrHNL59A2xpARpdAlulkIKm793JIeJcyxYvvc/tdj4Bx45qcLMISR8qdAOjtgTAV2fWbkdjx0roelL6EAubc3HPij+5Xny1UDw=="; - ts::proto::license::teamspeak::License license; - license.ParseFromString(base64::decode(base64_license)); - - auto chain_sign = LicenseChain::parse(license.sign_chain(), error); - auto chain_license = LicenseChain::parse(license.license().chain(), error); - - { - auto key = chain_sign->generatePublicKey(); - auto signature = license.license_sign(); - auto message = license.license().SerializeAsString(); - - assert(ed25519_verify((const u_char*) signature.data(), (const u_char*) message.data(), message.length(), (u_char*) key.data())); - } - { - auto key_plk = chain_license->generatePublicKey(); - auto key_prv = chain_license->generatePrivateKey((u_char*) license.license().root().data(), 3); - - u_char sign[64]; - string message = "Hello World"; - ed25519_sign(sign, (u_char*) message.data(), message.length(), (u_char*) key_plk.data(), (u_char*) key_prv.data()); - assert(ed25519_verify(sign, (const u_char*) message.data(), message.length(), (u_char*) key_plk.data())); - } - chain_sign->print(); - chain_license->print(); - - cout << "version:0" << endl; - cout << "chain:" << base64::encode(chain_license->exportChain()) << endl; - cout << "root_key_prv:" << base64::encode(license.license().root()) << endl; - cout << "root_key_pbl:" << base64::encode((const char*) public_root, 32) << endl; - cout << "root_prv_index:" << to_string(3) << endl; -#endif - //return 0; - - /** - * DONT DELET! - */ - //Last checked offset was 1591824411998 - //Level 39 - //ts::Identity* id = new ts::Identity("4161411998Vginro7hE2a4haFhxRR5+Q1aknrR8Nn1iYAAUZldWVn8XZFVVUnUOVBFeMQJ9HHZaOVh3fEhLShwdXHkie2lza1gDWQltMwhROBNeVTQ2GS5EeFNbA2dBE3QvXU9jJ0VKMXd4YkpxU0tFQUlnYVZaeVVTTTYzSldSLzBRT3Nqd3hSelJBYmRpZ2xsaFhsVTF5L3hVYWgxWT0="); - - //Last checked offset was 1330241596003 - //Level 48 535525596003 - //ts::Identity* id = new ts::Identity("535525596003VMXsJbBqTW70w6dnQUt/X/CiIeth9DEVcVEVUUxBjXUY9RGxSeVN+OhYDHjJSFRoCJHIDd3FjXCgSdH0Gf3RhBlJ0SGYbIEBCVzNcAAITKD9yY30aAgBqOnQIQmVdVQB5L3NVWnZkQUNJUUR2dG5ScnNYdHVWZkFhem9OYVNxTGhjZ2ZwVXhVelFpcGMrSDFSbkIrL3dRPT0="); - - /* - for(int i = 0; ltc_ecc_sets[i].size != 0; i++){ - cout << " -> " << ltc_ecc_sets[i].name << endl; - } - int targetLevel = 20; - if(argc > 1){ - targetLevel = atoi(argv[1]); - } - - cout << "Try to find security level " << targetLevel << endl; - ts::Identity* id = new ts::Identity("30895417VvPSPlSzA2mTBpjn7RrJYEq/PmZcNAmhDCXkVdStbXUU2bVxBQ0IHNVAGNTR/CXplN2Z/AwRASSFTQn0GV3NTGX18dXENB2laLQJHKVFUKgl/VHRgD21LUlAHVk18FQcEMGpAXTBxUUNJSEtnTCtOcXJhZDRUSTlKNk04clZXMHkxQjcwWnNsanNsbldOOWo5cjBObA=="); - id->improveSecurityLevelMultithreaded(targetLevel, 16, 1000000, 10 * 1000 * 1000U, true); - cout << "New string: " << id->exportIdentity() << endl; - - if(true) return false; - */ - - /* - string error; - //auto stream = stringstream(base64::decode("AQCvbHFTQDY/terPeilrp/ECU9xCH5U3xC92lYTNaY/0KQAJFueAazbsgAAAACVUZWFtU3BlYWsgU3lzdGVtcyBHbWJIAABhl9gwla/UJp2Eszst9TRVXO/PeE6a6d+CTI6Pg7OEVgAJc5CrL4Nh8gAAACRUZWFtU3BlYWsgc3lzdGVtcyBHbWJIAACvTQIgpv6zmLZq3znh7ygmOSokGFkFjz4bTigrOnetrgIJdIIACdS/gAYAAAAAU29zc2VuU3lzdGVtcy5iaWQAADY7+uV1CQ1niOvYSdGzsu83kPTNWijovr3B78eHGeePIAm98vQJvpu0")); - auto stream = stringstream(base64::decode("AQA1hUFJiiSs0wFXkYuPUJVcDa6XCrZTcsvkB0Ffzz4CmwIITRXgCqeTYAcAAAAgQW5vbnltb3VzAAC4R+5mos+UQ/KCbkpQLMI5WRp4wkQu8e5PZY4zU+/FlyAJwaE8CcJJ/A==")); - auto chain = LicenseChain::parse(stream, error); - if(!chain) { - cerr << "Could not parse: " << error << endl; - return 0; - } - chain->print(); - cout << chain->exportChain() << endl; - - auto key = chain->generateKey(); - cout << " -> " << base64::encode(key) << endl; - cout << hex; - for(const auto& c : key) - cout << " " << (uint32_t) (uint8_t) c << endl; - if(true) return 0; - */ - - ts::Identity* identity; - //identity = new ts::Identity("30895417VvPSPlSzA2mTBpjn7RrJYEq/PmZcNAmhDCXkVdStbXUU2bVxBQ0IHNVAGNTR/CXplN2Z/AwRASSFTQn0GV3NTGX18dXENB2laLQJHKVFUKgl/VHRgD21LUlAHVk18FQcEMGpAXTBxUUNJSEtnTCtOcXJhZDRUSTlKNk04clZXMHkxQjcwWnNsanNsbldOOWo5cjBObA=="); - identity = new ts::Identity("4161411998Vginro7hE2a4haFhxRR5+Q1aknrR8Nn1iYAAUZldWVn8XZFVVUnUOVBFeMQJ9HHZaOVh3fEhLShwdXHkie2lza1gDWQltMwhROBNeVTQ2GS5EeFNbA2dBE3QvXU9jJ0VKMXd4YkpxU0tFQUlnYVZaeVVTTTYzSldSLzBRT3Nqd3hSelJBYmRpZ2xsaFhsVTF5L3hVYWgxWT0="); - cout << "Private key: " << identity->privateKey() << endl; - cout << "Public key: " << identity->publicKey() << endl; - - { - auto hash = digest::sha256("Hello World"); - auto sign_rfc = base64::decode("kjEYFcZ4iDxosbhi7bV04nRu0c0JzEIKAACSpLo9G1cJX60Ta46QpoPXTpMg9E8z5pHeZXPVUx75zmWE/LQTuQ=="); - int state; - auto result = ecc_verify_hash_rfc7518((u_char*) sign_rfc.data(), sign_rfc.length(), (u_char*) hash.data(), hash.length(), &state, identity->getKeyPair()); - __asm__("nop"); - } - - //identity = ts::Identity::createNew(); - //identity->improveSecurityLevel(9); - /* - identity = ts::Identity::createNew(); - cout << "Improve" << endl; - identity->improveSecurityLevelMultithreaded(24, 12); - cout << "Got level: " << identity->getSecurityLevel() << " at " << identity->lastValidKeyOffset() << " - " << identity->privateKey() << " - " << identity->publicKey() << endl; - return 0; - */ - - auto lastConnect = time_point(); - for(int i = 0; i < 1; i++){ - //identity = ts::Identity::createNew(); - //identity->improveSecurityLevel(9); - - //identity = new ts::Identity("4161411998Vginro7hE2a4haFhxRR5+Q1aknrR8Nn1iYAAUZldWVn8XZFVVUnUOVBFeMQJ9HHZaOVh3fEhLShwdXHkie2lza1gDWQltMwhROBNeVTQ2GS5EeFNbA2dBE3QvXU9jJ0VKMXd4YkpxU0tFQUlnYVZaeVVTTTYzSldSLzBRT3Nqd3hSelJBYmRpZ2xsaFhsVTF5L3hVYWgxWT0="); - //identity = new ts::Identity("8008VgvLYFzLLe4lE6oTKyMBPViPHzJVdCGVqAGc7VQQJXkcIRUZcCkFzMDJmHCYBMF1kWmdzRwlQBy4PT3Eie2lzVmUCd39bD3RnNC9gAyRQFh14Z0YGEHJHDg4nGkceNgdWBH9RAE1ZTjlqUUlnV1hUck5vZVdUQ21sNkVYeDNMUm80M0pMU0ZDdkRzWUorR0VkeDE3ZDJLST0="); - //identity = identity->createNew(); - //cout << "Improve" << endl; - //identity->improveSecurityLevelMultithreaded(10, 12); - //cout << "Using identity: " << identity->exportIdentity() << endl; - auto connection = new ts::connection::ServerConnection(); - - while(system_clock::now() - lastConnect < milliseconds(250)) usleep(1000); - lastConnect = system_clock::now(); - - string host = - "127.0.0.1" - //"51.255.133.2" - //"79.133.54.198" - //"51.255.133.6" - //"79.133.54.207" //GommeHD.net - //"79.133.54.202" //Rewi - //"79.133.54.210" //minesucht.net:9988 - //"91.134.112.225" //The Beast (NOT 3.1!) - //"79.133.54.198" //Grifer games:9180 - //"52.63.60.28" - //"87.106.252.164" - //"5.1.80.215" //Twerion - //"212.114.60.36" //Domies ts - //"54.36.90.72" - //"87.106.252.164" - //"84.200.62.248" - //"79.133.54.198" //Durchrasten.de:9122 - "" - ; - string port = "9987"; - if(argc > 2) { - host = argv[1]; - port = argv[2]; - } - - threads::Thread([connection, host, port, identity]() { - string error; - cout << host << ":" << port << endl; - if(!connection->connect(host, port, identity)){ - cerr << "Cant connect!" << endl; - goto sleep; - } - - if(!connection->handshake(error)){ - cerr << "Cant handschake: " << error << endl; - goto sleep; - } - - threads::self::sleep_for(seconds(10 + rand() % 10)); - sleep:; - //connection->disconnect(); - //delete connection; - }).detach(); - //connection->disconnect(); - usleep(1000 * 1000); - } - cout << "Done!" << endl; - - while(true) usleep(1000 * 2000); -} \ No newline at end of file diff --git a/client/proto/LicenseKey.proto b/client/proto/LicenseKey.proto deleted file mode 100644 index e4f83de..0000000 --- a/client/proto/LicenseKey.proto +++ /dev/null @@ -1,17 +0,0 @@ -syntax = "proto2"; - -package ts.proto.license.teamspeak; - -message LicenseData { //_ZTIN3com10teamspeak310accounting8protobuf19Signed_License_InfoE => Signed_License_Info - required bytes chain = 1; - required bytes root = 2; - required int32 slots = 3; - required int32 servers = 4; - required string type = 5; -} - -message License { - required LicenseData license = 1; - required bytes sign_chain = 2; - required bytes license_sign = 3; -} diff --git a/client/src/Identity.cpp b/client/src/Identity.cpp deleted file mode 100644 index caf3ff9..0000000 --- a/client/src/Identity.cpp +++ /dev/null @@ -1,218 +0,0 @@ -// -// Created by wolverindev on 07.10.17. -// - -#include -#include -#include "misc/base64.h" -#include "Identity.h" - -#define ECC_TYPE_INDEX 5 - -using namespace std; - -static const char *TSKEY = - "b9dfaa7bee6ac57ac7b65f1094a1c155" - "e747327bc2fe5d51c512023fe54a2802" - "01004e90ad1daaae1075d53b7d571c30" - "e063b5a62a4a017bb394833aa0983e6e"; - -static int obfuscateInplace(char *data, uint32_t length) { - int dataSize = min((uint32_t) 100, length); - for (int i = 0; i < dataSize; i++) { - data[i] ^= TSKEY[i]; - } - - char hash[20]; - hash_state ctx; - if (sha1_init(&ctx) != CRYPT_OK) - { return -1; } - if (sha1_process(&ctx, (uint8_t*)data + 20, strlen(data + 20)) != CRYPT_OK) - { return -1; } - if (sha1_done(&ctx, (uint8_t*)hash) != CRYPT_OK) - { return -1; } - - for (int i = 0; i < 20; i++) { - data[i] ^= hash[i]; - } - - return 0; -} - -static int deObfuscateInplace(char *data, uint32_t length) { - char hash[20]; - hash_state ctx; - if (sha1_init(&ctx) != CRYPT_OK) - { return -1; } - if (sha1_process(&ctx, (uint8_t*)data + 20, strlen(data + 20)) != CRYPT_OK) - { return -1; } - if (sha1_done(&ctx, (uint8_t*)hash) != CRYPT_OK) - { return -1; } - - for (int i = 0; i < 20; i++) { - data[i] ^= hash[i]; - } - - int dataSize = min((uint32_t) 100, length); - for (int i = 0; i < dataSize; i++) { - data[i] ^= TSKEY[i]; - } - return 0; -} - -namespace ts { - Identity* Identity::createNew() { - auto result = new Identity(); - - prng_state rndState{}; - memset(&rndState, 0, sizeof(prng_state)); - int err; - - result->keyPair = new ecc_key; - - cout << " -> " << find_prng("sprng") << endl; - if((err = ecc_make_key_ex(&rndState, find_prng("sprng"), result->keyPair, <c_ecc_sets[ECC_TYPE_INDEX])) != CRYPT_OK) { - cerr << "Cant create a new identity (Keygen)" << endl; - cerr << "Message: " << error_to_string(err) << endl; - delete result; - return nullptr; - } - - return result; - } - - Identity::Identity(std::string asnStruct, int64_t keyOffset, int64_t lastCheckedOffset) { - this->keyOffset = keyOffset; - this->lastCheckedOffset = lastCheckedOffset; - importKey(asnStruct); - } - - Identity::Identity(std::string data) : Identity() { - int vindex = data.find('V'); - assert(vindex > 0); - - auto slevel = data.substr(0, vindex); - assert(slevel.find_first_not_of("0123456789") == std::string::npos); - this->keyOffset = stol(slevel); - - data = data.substr(vindex + 1); - data = base64::decode(data); - if(deObfuscateInplace((char *) data.data(), data.length()) < 0) { - cerr << "Cand decript identitry data" << endl; - return; - } - importKey(base64::decode(data)); - } - - Identity::Identity() { - this->keyOffset = 0; - this->lastCheckedOffset = 0; - this->keyPair = nullptr; - } - - Identity::~Identity() { - delete this->keyPair; - this->keyPair = nullptr; - } - - void Identity::importKey(std::string asnStruct) { - this->keyPair = new ecc_key; - int err; - if((err = ecc_import_ex((const unsigned char *) asnStruct.data(), asnStruct.length(), this->keyPair, <c_ecc_sets[ECC_TYPE_INDEX])) != CRYPT_OK){ - delete this->keyPair; - this->keyPair = nullptr; - - cerr << "Cant import identity from asn structure" << endl; - cerr << "Message: " << error_to_string(err) << endl; - return; - } - } - - std::string Identity::exportIdentity() { - string data = privateKey(); - obfuscateInplace((char *) data.data(), data.length()); - return to_string(this->lastValidKeyOffset()) + "V" + base64_encode(data); - } - - std::string Identity::publicKey() { - assert(this->keyPair); - - size_t bufferLength = 1028; - char buffer[bufferLength]; - ecc_export((unsigned char *) buffer, &bufferLength, PK_PUBLIC, this->keyPair); - - return base64_encode(string(buffer, bufferLength)); - } - - std::string Identity::privateKey() { - assert(this->keyPair); - - size_t bufferLength = 1028; - char buffer[bufferLength]; - ecc_export((unsigned char *) buffer, &bufferLength, PK_PRIVATE, this->keyPair); - - return base64_encode(string(buffer, bufferLength)); - } - - ecc_key& Identity::getPrivateKey() { - return *keyPair; - } - - #define MaxUlongString 20 - - bool Identity::improveSecurityLevel(int target) { - auto publicKey = this->publicKey(); - char hashBuffer[publicKey.length() + MaxUlongString]; - memcpy(hashBuffer, publicKey.data(), publicKey.length()); - - this->lastCheckedOffset = max(this->lastCheckedOffset, this->keyOffset); - int best = getSecurityLevel(hashBuffer, publicKey.length(), this->lastCheckedOffset); - while(true){ - if(best >= target) return true; - - int currentLevel = getSecurityLevel(hashBuffer, publicKey.length(), this->lastCheckedOffset); - if(currentLevel >= best){ - this->keyOffset = this->lastCheckedOffset; - best = currentLevel; - } - this->lastCheckedOffset++; - } - } - - int Identity::getSecurityLevel() { - auto length = publicKey().length(); - char hashBuffer[length + MaxUlongString]; - - auto publicKey = this->publicKey(); - memcpy(hashBuffer, publicKey.data(), publicKey.length()); - - return getSecurityLevel(hashBuffer, publicKey.length(), this->keyOffset); - } - - int Identity::getSecurityLevel(char *hashBuffer, size_t keyLength, int64_t offset) { - char numBuffer[MaxUlongString]; - int numLen = 0; - do { - numBuffer[numLen] = '0' + (offset % 10); - offset /= 10; - numLen++; - } while(offset > 0); - for(int i = 0; i < numLen; i++) - hashBuffer[keyLength + i] = numBuffer[numLen - (i + 1)]; - - char shaBuffer[SHA_DIGEST_LENGTH]; - SHA1((const unsigned char *) hashBuffer, keyLength + numLen, (unsigned char *) shaBuffer); - - //Leading zero bits - register int zeroBits = 0; - register int i; - for(i = 0; i < SHA_DIGEST_LENGTH; i++) - if(shaBuffer[i] == 0) zeroBits += 8; - else break; - if(i < SHA_DIGEST_LENGTH) - for(int bit = 0; bit < 8; bit++) - if((shaBuffer[i] & (1 << bit)) == 0) zeroBits++; - else break; - return zeroBits; - } -} \ No newline at end of file diff --git a/client/src/Identity.h b/client/src/Identity.h deleted file mode 100644 index a6eb2e0..0000000 --- a/client/src/Identity.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#include -#include - -namespace ts { - class Identity { - public: - static Identity* createNew(); - - explicit Identity(std::string data); - Identity(std::string asnStruct,int64_t keyOffset,int64_t lastCheckedOffset); - ~Identity(); - - bool valid(){ return keyPair != nullptr; } - - std::string publicKey(); - std::string privateKey(); - std::string exportIdentity(); - - ecc_key* getKeyPair(){ - return keyPair; - } - - ecc_key& getPrivateKey(); - - bool improveSecurityLevel(int target); - bool improveSecurityLevelMultithreaded(int target, int nthread = 4, size_t nblockSize = 1000, size_t baseOffset = 0, bool verbose = false); - - int getSecurityLevel(); - - int64_t lastValidKeyOffset(){ return keyOffset; } - int64_t lastTestedKeyOffset(){ return lastCheckedOffset; } - private: - Identity(); - - int getSecurityLevel(char* hasBuffer, size_t keyLength, int64_t offset); - void importKey(std::string asn1); - - ecc_key* keyPair = nullptr; - size_t keyOffset; - size_t lastCheckedOffset; - }; -} \ No newline at end of file diff --git a/client/src/MultithreadedIdentity.cpp b/client/src/MultithreadedIdentity.cpp deleted file mode 100644 index c9b8136..0000000 --- a/client/src/MultithreadedIdentity.cpp +++ /dev/null @@ -1,189 +0,0 @@ -// -// Created by wolverindev on 14.10.17. -// - -#include -#include -#include -#include -#include -#include -#include "misc/base64.h" -#include "Identity.h" - -#define ECC_TYPE_INDEX 5 - -#define USE_OPENSSL_SHA1 -using namespace std::chrono; -using namespace std; -namespace ts { - - inline int calculateSecutityLevel(uint8_t* hashBuffer, uint8_t* bufferToHash, int length){ - register int zeroBits = 0; - register int bit; - register int i; - - SHA1(bufferToHash, length, hashBuffer); - - //Leading zero bits - for(i = 0; i < SHA_DIGEST_LENGTH; i++) - if(hashBuffer[i] == 0) zeroBits += 8; - else break; - if(i < SHA_DIGEST_LENGTH) - for(bit = 0; bit < 8; bit++) - if((hashBuffer[i] & (1 << bit)) == 0) zeroBits++; - else break; - - return zeroBits; - } - - inline void increaseNumBuffer(char* buffer, int numOffset, int* length){ - int index = *length - 1; - - while(true){ - if(buffer[index] == '9'){ - if(index - 1 < numOffset) { - buffer[index] = '1'; - buffer[*length] = '0'; - *length += 1; - return; - } - buffer[index--] = '0'; - } else { - buffer[index] += 1; - return; - } - } - } - -#define MaxUlongString 20 - bool Identity::improveSecurityLevelMultithreaded(int target, int nthread, size_t nblockSize, size_t baseOffset, bool verbose) { - if(this->getSecurityLevel() >= target) - return false; - - vector threads; - - auto publicKey = this->publicKey(); - - size_t currentBlockIndex = max(max(this->lastCheckedOffset, this->keyOffset), baseOffset); - threads::Mutex blockIndexLock; - - auto activeDigging = new bool(true); - threads::Thread* thread; - for(int threadId = 0; threadId < nthread; threadId++){ - thread = new threads::Thread([&](){ - size_t offset = 0; - size_t endOffset = 0; - size_t bestOffset = 0; - - char shaHashBuffer[SHA_DIGEST_LENGTH]; - char hashBuffer[publicKey.length() + MaxUlongString]; - memcpy(hashBuffer, publicKey.data(), publicKey.length()); - -#ifndef SLOW - //Setup some stuff - size_t pubKeyLength = publicKey.length(); - -#endif - while(*activeDigging){ - //Get next range - blockIndexLock.lock(); - offset = currentBlockIndex; - endOffset = currentBlockIndex + nblockSize; - currentBlockIndex += nblockSize; - blockIndexLock.unlock(); - - int bestLevel = this->getSecurityLevel(hashBuffer, publicKey.length(), this->keyOffset); -#ifdef SLOW - while(offset < endOffset){ - int currentLevel = getSecurityLevel(hashBuffer, publicKey.length(), offset); - if(currentLevel >= best){ - bestOffset = offset; - best = currentLevel; - } - offset++; - } - blockIndexLock.lock(); - if(best > this->getSecurityLevel()){ - if(verbose) cout << "Improved -> " << best << "/" << target << endl; - this->lastCheckedOffset = bestOffset; - this->keyOffset = bestOffset; - cout << "Got level: " << best << endl; - - if(best >= target){ - cout << "Done!" << endl; - *activeDigging = false; - } - } - blockIndexLock.unlock(); - if(verbose) cout << "round done: highest -> " << best << endl; -#else - - string strStartOffset = to_string(offset); - ssize_t roundsLeft = nblockSize; - - auto hashBufferLength = static_cast(publicKey.length() + strStartOffset.length()); - memcpy(&hashBuffer[pubKeyLength], strStartOffset.c_str(), strStartOffset.length()); - - while(roundsLeft-- >= 0){ - auto level = calculateSecutityLevel(reinterpret_cast(shaHashBuffer), reinterpret_cast(hashBuffer), hashBufferLength); - if(level > bestLevel){ - { - threads::MutexLock l(blockIndexLock); - - auto strOffset = string(&hashBuffer[pubKeyLength], hashBufferLength - pubKeyLength); - bestOffset = stoull(strOffset); - auto got = this->getSecurityLevel(); - if(got >= level) { - cout << "Already got bedder level! (" << got << ")" << endl; - bestLevel = got; - continue; - } - - if(verbose) cout << "Improved -> " << level << "/" << target << " [" << strOffset << "]" << endl; - this->lastCheckedOffset = bestOffset; - this->keyOffset = bestOffset; - bestLevel = level; - - if(bestLevel >= target){ - cout << "Done! (" << bestLevel << ")" << endl; - *activeDigging = false; - } - } - } - increaseNumBuffer(hashBuffer, pubKeyLength + 1, &hashBufferLength); - } -#endif - } - }); - thread->name("IdentityHashDigger #" + to_string(threadId)); - threads.push_back(thread); - } - - if(verbose){ - thread = new threads::Thread([&](){ - auto lastIndex = currentBlockIndex; - while(*activeDigging){ - for(int count = 0; count < 1000 && *activeDigging; count++) - usleep(1000); - - blockIndexLock.lock(); - cout << "Current level = " << this->getSecurityLevel() << " at " << this->keyOffset << endl; - cout << "Current offset index: " << currentBlockIndex << " block size: " << nblockSize << endl; - cout << "speed: " << (currentBlockIndex - lastIndex) / 1000 / 1000.f << " Mio. attemps/sec" << endl; - lastIndex = currentBlockIndex; - blockIndexLock.unlock(); - } - }); - thread->name("Status printer"); - threads.push_back(thread); - } - - for(auto elm : threads){ - if(elm->state() == threads::ThreadState::RUNNING) - elm->join(); - delete elm; - } - return true; - } -} \ No newline at end of file diff --git a/client/src/TinySHA1.hpp.h b/client/src/TinySHA1.hpp.h deleted file mode 100644 index a53decd..0000000 --- a/client/src/TinySHA1.hpp.h +++ /dev/null @@ -1,196 +0,0 @@ -/* - * - * TinySHA1 - a header only implementation of the SHA1 algorithm in C++. Based - * on the implementation in boost::uuid::details. - * - * SHA1 Wikipedia Page: http://en.wikipedia.org/wiki/SHA-1 - * - * Copyright (c) 2012-22 SAURAV MOHAPATRA - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -#ifndef _TINY_SHA1_HPP_ -#define _TINY_SHA1_HPP_ -#include -#include -#include -#include -namespace sha1 -{ - class SHA1 - { - public: - typedef uint32_t digest32_t[5]; - typedef uint8_t digest8_t[20]; - inline static uint32_t LeftRotate(uint32_t value, size_t count) { - return (value << count) ^ (value >> (32-count)); - } - SHA1(){ reset(); } - virtual ~SHA1() {} - SHA1(const SHA1& s) { *this = s; } - const SHA1& operator = (const SHA1& s) { - memcpy(m_digest, s.m_digest, 5 * sizeof(uint32_t)); - memcpy(m_block, s.m_block, 64); - m_blockByteIndex = s.m_blockByteIndex; - m_byteCount = s.m_byteCount; - return *this; - } - SHA1& reset() { - m_digest[0] = 0x67452301; - m_digest[1] = 0xEFCDAB89; - m_digest[2] = 0x98BADCFE; - m_digest[3] = 0x10325476; - m_digest[4] = 0xC3D2E1F0; - m_blockByteIndex = 0; - m_byteCount = 0; - return *this; - } - SHA1& processByte(uint8_t octet) { - this->m_block[this->m_blockByteIndex++] = octet; - ++this->m_byteCount; - if(m_blockByteIndex == 64) { - this->m_blockByteIndex = 0; - processBlock(); - } - return *this; - } - SHA1& processBlock(const void* const start, const void* const end) { - const uint8_t* begin = static_cast(start); - const uint8_t* finish = static_cast(end); - while(begin != finish) { - processByte(*begin); - begin++; - } - return *this; - } - SHA1& processBytes(const void* const data, size_t len) { - const uint8_t* block = static_cast(data); - processBlock(block, block + len); - return *this; - } - const uint32_t* getDigest(digest32_t digest) { - size_t bitCount = this->m_byteCount * 8; - processByte(0x80); - if (this->m_blockByteIndex > 56) { - while (m_blockByteIndex != 0) { - processByte(0); - } - while (m_blockByteIndex < 56) { - processByte(0); - } - } else { - while (m_blockByteIndex < 56) { - processByte(0); - } - } - processByte(0); - processByte(0); - processByte(0); - processByte(0); - processByte( static_cast((bitCount>>24) & 0xFF)); - processByte( static_cast((bitCount>>16) & 0xFF)); - processByte( static_cast((bitCount>>8 ) & 0xFF)); - processByte( static_cast((bitCount) & 0xFF)); - - memcpy(digest, m_digest, 5 * sizeof(uint32_t)); - return digest; - } - const uint8_t* getDigestBytes(digest8_t digest) { - digest32_t d32; - getDigest(d32); - size_t di = 0; - digest[di++] = ((d32[0] >> 24) & 0xFF); - digest[di++] = ((d32[0] >> 16) & 0xFF); - digest[di++] = ((d32[0] >> 8) & 0xFF); - digest[di++] = ((d32[0]) & 0xFF); - - digest[di++] = ((d32[1] >> 24) & 0xFF); - digest[di++] = ((d32[1] >> 16) & 0xFF); - digest[di++] = ((d32[1] >> 8) & 0xFF); - digest[di++] = ((d32[1]) & 0xFF); - - digest[di++] = ((d32[2] >> 24) & 0xFF); - digest[di++] = ((d32[2] >> 16) & 0xFF); - digest[di++] = ((d32[2] >> 8) & 0xFF); - digest[di++] = ((d32[2]) & 0xFF); - - digest[di++] = ((d32[3] >> 24) & 0xFF); - digest[di++] = ((d32[3] >> 16) & 0xFF); - digest[di++] = ((d32[3] >> 8) & 0xFF); - digest[di++] = ((d32[3]) & 0xFF); - - digest[di++] = ((d32[4] >> 24) & 0xFF); - digest[di++] = ((d32[4] >> 16) & 0xFF); - digest[di++] = ((d32[4] >> 8) & 0xFF); - digest[di++] = ((d32[4]) & 0xFF); - return digest; - } - - protected: - void processBlock() { - uint32_t w[80]; - for (size_t i = 0; i < 16; i++) { - w[i] = (m_block[i*4 + 0] << 24); - w[i] |= (m_block[i*4 + 1] << 16); - w[i] |= (m_block[i*4 + 2] << 8); - w[i] |= (m_block[i*4 + 3]); - } - for (size_t i = 16; i < 80; i++) { - w[i] = LeftRotate((w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16]), 1); - } - - uint32_t a = m_digest[0]; - uint32_t b = m_digest[1]; - uint32_t c = m_digest[2]; - uint32_t d = m_digest[3]; - uint32_t e = m_digest[4]; - - for (std::size_t i=0; i<80; ++i) { - uint32_t f = 0; - uint32_t k = 0; - - if (i<20) { - f = (b & c) | (~b & d); - k = 0x5A827999; - } else if (i<40) { - f = b ^ c ^ d; - k = 0x6ED9EBA1; - } else if (i<60) { - f = (b & c) | (b & d) | (c & d); - k = 0x8F1BBCDC; - } else { - f = b ^ c ^ d; - k = 0xCA62C1D6; - } - uint32_t temp = LeftRotate(a, 5) + f + e + k + w[i]; - e = d; - d = c; - c = LeftRotate(b, 30); - b = a; - a = temp; - } - - m_digest[0] += a; - m_digest[1] += b; - m_digest[2] += c; - m_digest[3] += d; - m_digest[4] += e; - } - private: - digest32_t m_digest; - uint8_t m_block[64]; - size_t m_blockByteIndex; - size_t m_byteCount; - }; -} -#endif \ No newline at end of file diff --git a/client/src/protocol/Connection.cpp b/client/src/protocol/Connection.cpp deleted file mode 100644 index 6945b0b..0000000 --- a/client/src/protocol/Connection.cpp +++ /dev/null @@ -1,454 +0,0 @@ -// -// Created by wolverindev on 07.10.17. -// - -#include -#include "Connection.h" -#include "misc/base64.h" -#include - -#include -#include -#include -#include -#include - -using namespace std; -using namespace ts; -using namespace ts::connection; -using namespace ts::protocol; - -ServerConnection::ServerConnection() { - cryptionHandler = new CryptionHandler(); - cryptionHandler->reset(); - - compressionHandler = new CompressionHandler(); - - readQueue = (buffer::SortedBufferQueue **) malloc(16 * sizeof(void*)); - for(int i = 0; i < 16; i++) { - auto type = ts::protocol::PacketTypeInfo::fromid(i); - if(type != PacketTypeInfo::Undefined){ - readQueue[i] = new buffer::SortedBufferQueue(ts::protocol::PacketTypeInfo::fromid(i), PacketTypeInfo::Command != type); //Ignore command low - } else { - readQueue[i] = nullptr; - } - } -} - -ServerConnection::~ServerConnection() { - for(int i = 0; i < 16; i++) - if(readQueue[i]) - delete readQueue[i]; - free(readQueue); - this->rwThread->join(); -} - -static int sourcePort = 50000; - -void ServerConnection::disconnect() { - //this->rwThread->cancel(); - //this->handleThread->cancel(); - this->connected = false; - if(this->socket) this->socket->close(); -} - -bool ServerConnection::connect(std::string host, std::string port, Identity *identity) { - this->clientIdentity = identity; - - memset(&remoteAddress, 0, sizeof(remoteAddress)); - remoteAddress.sin_family = AF_INET; - remoteAddress.sin_port = htons((uint16_t) std::stoi(port)); - remoteAddress.sin_addr.s_addr = inet_addr(host.c_str()); -#ifdef NoQt - /* - this->socketfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - int allow = 1; - setsockopt(this->socketfd, SOL_SOCKET, SO_REUSEADDR, &allow, sizeof(int)); - - memset(&localAddress, 0, sizeof(localAddress)); - localAddress.sin_family = AF_INET; - localAddress.sin_addr.s_addr = htonl (INADDR_ANY); - localAddress.sin_port = htons (sourcePort++); - ::connect(this->socketfd, (const sockaddr *) &remoteHost, sizeof(this->remoteAddress)); - //bind(this->socketfd, (struct sockaddr *) &localAddress, sizeof(localAddress)); - - */ - this->socket = new UdpSocket; - if(!this->socket->setup(&remoteAddress)){ - cerr << "Invalid socket setup" << endl; - } -#else - -#endif - this->rwThread = new threads::Thread(THREAD_SAVE_OPERATIONS, [&]() { -#ifndef NoQt - this->qtSocket = new QUdpSocket(); - - QObject::connect(qtSocket,SIGNAL(bytesWritten(qint64)),this,SLOT(bytesWritten(qint64))); - QObject::connect(this->qtSocket, SIGNAL(readyRead()), this, SLOT(attempDatagramRead())); - this->qtSocket->bind(QHostAddress::Any, 23111); - - this->socketfd = qtSocket->socketDescriptor(); - cout << "Sock fd: " << this->socketfd << endl; -#endif - /* - auto cthread = QThread::currentThread(); - cout << "ex" << endl; - runOnThread(qtSocket->thread(), [&](){ - cout << "try" << endl; - qtSocket->moveToThread(cthread); - cout << "Moved" << endl; - }); - cout << "Start rw" << endl; - */ - - this->rwExecutor(); - }); - - /* - this->handleThread = new threads::Thread([&]() { - this->handleExecutor(); - }); - */ - return true; -} - -#ifndef NoQt -void ServerConnection::bytesWritten(qint64 b) { - cout << "written " << b << endl; -} - -void ServerConnection::attempDatagramRead() { - cout << "Data " << endl; -} -#endif - -//this->socket->socketDescriptor() -void ServerConnection::rwExecutor() { - pollfd pollData = {this->socket->getSocketDescriptor(), POLLRDHUP | POLLIN | POLLOUT, 0}; - buffer::RawBuffer readBuffer(512); - std::shared_ptr readedPacket; - while (socket->getSocketDescriptor() > 0 && this->connected) { - int rfds = poll(&pollData, 1, -1); - bool select = false; - if(rfds == 0) { - usleep(5 * 1000);; - continue; - } else if(rfds < 0) { - break; - } - if (pollData.revents & POLLRDHUP || pollData.revents & POLLHUP) { - select = 1; - cerr << "Connection hang up!" << endl; - return; - } - - if (pollData.revents & POLLIN) { - select = 1; - ssize_t readedBytes = -1; -#ifdef NoQt - readedBytes = socket->read(readBuffer.buffer, readBuffer.length); - #ifdef DEBUG - cout << "Read bytes (" << readedBytes << ")" << endl; - #endif -#else - QHostAddress senderAddr; - quint16 senderPort; - readedBytes = this->qtSocket->readDatagram(readBuffer.buffer, readBuffer.length, &senderAddr, &senderPort); -#endif - if (readedBytes < 0) { - cout << "fatal read error: " << errno << "/" << strerror(errno) << endl; - return; - } - - readedPacket = std::make_shared(pipes::buffer_view(readBuffer.buffer, readedBytes)); - if(!preProgressPacket(readedPacket)){ - cerr << "Invalid packet preprocess!" << endl; - readedPacket = nullptr; - goto exitRead; - } - - if(readedPacket->type().type() < 0 || readedPacket->type().type() > 16){ - cerr << "Invalid packet id!" << endl; - readedPacket = nullptr; - goto exitRead; - } - //Deserelize packet - this->bufferQueueLock.lock(); - if(!this->readQueue[readedPacket->type().type()]->push_pack(readedPacket)){ - //TODO error handling - cout << "pkId: " << be2le16((char*) readedPacket->data().data_ptr()) << " -> " << readedPacket->type().name() << endl; - } - this->bufferQueueLock.unlock(); - while(this->handleNextPacket()); - exitRead:; - } - - if (pollData.revents & POLLOUT) { - this->bufferQueueLock.lock(); - if (!this->writeQueue.empty()) { - select = 1; - buffer::RawBuffer buffer = this->writeQueue.front(); - -#ifdef NoQt - auto res = this->socket->write(buffer.buffer, buffer.length); - if (res == -1) { - cout << "having write error: " << errno << "/" << strerror(errno) << " -> " << buffer.length << endl; - } - //cout << string() + "Write: " + PacketType::fromid(buffer.type()).name() << endl; -#else - this->qtSocket->writeDatagram(buffer.buffer, buffer.length, QHostAddress("localhost"), htons(this->remoteAddress.sin_port)); -#endif - - /* - if(!PacketTypeInfo::fromid(buffer.type()).requireAcknowledge()){ //Than we need a ack! - //Wait for acknowlage - this->acknowlageQueueLock.lock(); - this->acknowlageQueue.push_back(buffer); - this->acknowlageQueueLock.unlock(); - } - */ - - this->writeQueue.pop_front(); - } - this->bufferQueueLock.unlock(); - } - if (!select) { - usleep(5 * 10000); - continue; - } - } - cerr << "rw loop broken!" << endl; -} - -bool ServerConnection::preProgressPacket(std::shared_ptr packet){ - packet->setEncrypted(!packet->hasFlag(PacketFlag::Unencrypted)); - packet->setCompressed(packet->hasFlag(PacketFlag::Compressed)); - packet->setFragmentedEntry(packet->hasFlag(PacketFlag::Fragmented)); - - if(packet->type() == PacketTypeInfo::Init1){ - - } - if (packet->isEncrypted()) { - string error = "success"; - if (!cryptionHandler->progressPacketIn(packet.get(), error, false)) { - cerr << "Cant decript packet! Message: " << error << endl; - cerr << "Dropping it!" << endl; - return false; - } - } - -#ifdef DEBUG - cout << "[IN] Packet type -> " << packet->type().name() << " flags " << packet->flags() << " Length: " << packet->data().length() << endl; -#endif - if(packet->type() == PacketTypeInfo::Command || packet->type() == PacketTypeInfo::CommandLow){ //needs an acknowledge - sendAcknowledge(packet->packetId(), packet->type() == PacketTypeInfo::CommandLow); - } - return true; -} - -//TODO right packet recive order! -void ServerConnection::handleExecutor() { - shared_ptr packet = nullptr; - string error = "success"; - while(this->connected){ - while(this->handleNextPacket()); - usleep(10 * 1000); - } -} - -bool ServerConnection::handleNextPacket() { - shared_ptr packet = nullptr; - string error = "success"; - - if(this->autoHandle){ - handleQueueLock.lock(); - if(!this->handleQueue.empty()) { - packet = this->handleQueue.front(); - this->handleQueue.pop_front(); - } - handleQueueLock.unlock(); - - if(packet){ - if(packet->type() == PacketTypeInfo::Ack || packet->type() == PacketTypeInfo::AckLow){ - handlePacketAck(packet); - } else if(packet->type() == PacketTypeInfo::Command || packet->type() == PacketTypeInfo::CommandLow){ - handlePacketCommand(packet); - } else if(packet->type() == PacketTypeInfo::Ping || packet->type() == PacketTypeInfo::Pong){ - handlePacketPing(packet); - } else if(packet->type() == PacketTypeInfo::Voice || packet->type() == PacketTypeInfo::VoiceWhisper){ - handlePacketVoice(packet); - } - return true; - } - } - - for(int index = 0; index < 16; index++){ - if(this->readQueue[index]) { - if(this->readQueue[index]->available() > 0){ - auto npacket = this->readQueue[index]->peekNext(0); - packet = make_shared(npacket->buffer()); - packet->setEncrypted(npacket->isEncrypted()); - packet->setCompressed(npacket->isCompressed()); - packet->setFragmentedEntry(npacket->isFragmentEntry()); - break; - } - } - - } - if(!packet) return false; - if(packet->isFragmentEntry()){ - packet->setFragmentedEntry(false); - int deltaPacketIndex = 0; - while(this->connected){ - std::shared_ptr nextElm = this->readQueue[packet->type().type()]->peekNext(++deltaPacketIndex); - if(!nextElm) - return false; - - if(!nextElm) { - cerr << "Dropped fragment?" << endl; - packet = nullptr; - break; - } - packet->append_data({nextElm->data()}); - if(nextElm->hasFlag(protocol::PacketFlag::Fragmented)) break; //Tail end - nextElm = nullptr; - } - this->readQueue[packet->type().type()]->pop_packets(deltaPacketIndex); - } - this->readQueue[packet->type().type()]->pop_packets(1); - - if(packet->type() != PacketTypeInfo::Init1 && !this->compressionHandler->progressPacketIn(packet.get(), error)){ - cerr << "Cant decompress packet! (" << error << ")" << endl; - packet = nullptr; - return true; - } - -#if defined(DEBUG_PACKET_LOG) - cout << "Parsed packet " << packet->type().name() << " with id " << packet->packetId() << ". Data:" << endl; - hexDump((void *) packet->data().data_ptr(), packet->data().length(), 16, 8, [](std::string line) { - cout << "[IN] " << line << endl; - }); -#endif - handleQueueLock.lock(); - this->handleQueue.push_back(packet); - handleQueueLock.unlock(); - return true; -} - -using namespace std::chrono; -std::shared_ptr ServerConnection::readNextPacket(bool block) { - auto start = system_clock::now(); - attempGet: - if(system_clock::now() - start > seconds(5)) return nullptr; - - this->handleQueueLock.lock(); - if (this->handleQueue.empty()) { - this->handleQueueLock.unlock(); - if (!block) return nullptr; - usleep(5 * 1000); - goto attempGet; - } - - std::shared_ptr packet = std::move(this->handleQueue.front()); - this->handleQueue.pop_front(); - this->handleQueueLock.unlock(); - return packet; -} - -bool ServerConnection::setupSharedSecret(std::string alpha, std::string beta, std::string sharedKey, std::string &error) { - return this->cryptionHandler->setupSharedSecret(alpha, beta, sharedKey, error); -} - -//Packet splitting not working correctly! (On clientinit dosnt wait for the second) -void ServerConnection::sendPacket(ts::protocol::ClientPacket &packet) { - int maxDataLength = 500 - packet.header().length(); - - if(packet.data().length() > maxDataLength){ - string error; -/* - packet.enableFlag(PacketFlag::Compressed); - if(!this->compressionHandler->progressPacketOut(&packet, error)){ - cerr << "Compress error!" << endl; - return; - } - packet.enableFlag(PacketFlag::Compressed); -*/ - if(packet.data().length() > maxDataLength){ - std::vector> siblings; - siblings.reserve(8); - - - { //Split packets - auto buffer = packet.data(); - - const auto max_length = packet.type().max_length(); - while(buffer.length() > max_length * 2) { - siblings.push_back(make_shared(packet.type(), buffer.view(0, max_length))); - buffer = buffer.range(max_length); - } - - if(buffer.length() > max_length) { //Divide rest by 2 - siblings.push_back(make_shared(packet.type(), buffer.view(0, buffer.length() / 2))); - buffer = buffer.range(buffer.length() / 2); - } - siblings.push_back(make_shared(packet.type(), buffer)); - - for(const auto& frag : siblings) { - frag->setFragmentedEntry(true); - frag->enableFlag(PacketFlag::NewProtocol); - } - } - - for(const auto& entry : siblings) - this->sendPacket(*entry); - return; - } - } - - if(!packet.memory_state.id_branded) - packet.applyPacketId(idManager); - packet.clientId(this->clientId); - - string error = "success"; - if (!this->cryptionHandler->progressPacketOut(&packet, error, false)) { - cerr << "Invalid crypt -> " << error << endl; - return; - } - - buffer::RawBuffer buffer(packet.buffer().length()); - - memcpy(&buffer.buffer[0], packet.buffer().data_ptr(), packet.buffer().length()); - - this->bufferQueueLock.lock(); - this->writeQueue.push_back(buffer); -#if defined(DEBUG_PACKET_LOG) - cout << "Send packet " << packet.type().name() << " fragmented -> " << packet.isFragmentEntry() << " length " << packet.data().length() << " flags " << packet.flags() << " ID: " << packet.packetId() << endl; - hexDump(buffer.buffer, buffer.length, buffer.length, buffer.length); -#endif - this->bufferQueueLock.unlock(); -} - -void ServerConnection::sendCommand(ts::Command command, bool low) { - auto data = command.build(); - protocol::ClientPacket pkt(low ? protocol::PacketTypeInfo::CommandLow : protocol::PacketTypeInfo::Command, pipes::buffer_view{(void*) data.data(), data.length()}); -#ifdef DEBUG - cout << "[Client -> Server][" << pkt.type().name() << "] " << pkt.data() << endl; -#endif - if(!low) pkt.enableFlag(PacketFlag::NewProtocol); - sendPacket(pkt); -} - -void ServerConnection::sendAcknowledge(uint16_t packetId, bool low) { - if(breakAck) return; - char buffer[2]; - le2be16(packetId, buffer); - protocol::ClientPacket pkt(low ? protocol::PacketTypeInfo::AckLow : protocol::PacketTypeInfo::Ack, pipes::buffer_view(buffer, 2)); -#ifdef DEBUG - cout << "Sending packet acknowledge for " << packetId << " (Encrypt: " << encriptAck << ")" << endl; -#endif - if(!encriptAck) - pkt.enableFlag(PacketFlag::Unencrypted); - if(!low) pkt.toggle(protocol::PacketFlag::NewProtocol, true); - sendPacket(pkt); -} \ No newline at end of file diff --git a/client/src/protocol/Connection.h b/client/src/protocol/Connection.h deleted file mode 100644 index 519f396..0000000 --- a/client/src/protocol/Connection.h +++ /dev/null @@ -1,139 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define NoQt -#ifndef NoQt - #include -#endif - -#define DEBUG_PACKET_LOG -//#define LOG_CMD -namespace ts { - namespace connection { - namespace ConnectionState { - enum ConnectionState { - UNCONNECTED, - LLHANDSCHAKE, - HANDSCHAKE, - CONNECTED, - DISCONNECTED - }; - } - - class ServerConnection -#ifndef NoQt -: public QObject { - Q_OBJECT -#else -{ -#endif - public: - ServerConnection(); - ~ServerConnection(); - - bool connect(std::string host, std::string port, Identity* identity); - void disconnect(); - - ConnectionState::ConnectionState getConnectionState(){ return cstate; } - - bool handshake(std::string &errorMessage); - bool handshakeNew(Command &cmd, const std::string& alpha, std::string &errorMessage); - - void sendPacket(ts::protocol::ClientPacket& packet); - void sendCommand(ts::Command command, bool low = false); - void sendAcknowledge(uint16_t packetId, bool low = false); - - std::shared_ptr readNextPacket(bool block = true); - - uint16_t getClientId(){ - return this->clientId; - } - - void setClientId(uint16_t id){ - this->clientId = id; - } - -#ifndef NoQt - public slots: - void attempDatagramRead(); - void bytesWritten(qint64); -#endif - private: - bool encriptAck = false; - - bool preProgressPacket(std::shared_ptr packet); - - void rwExecutor(); - void handleExecutor(); - bool handleNextPacket(); - - bool setupSharedSecret(std::string alpha, std::string beta, std::string sharedKey, std::string& error); - - - void handlePacketPing(std::shared_ptr packet); - void handlePacketCommand(std::shared_ptr packet); - void handlePacketAck(std::shared_ptr packet); - void handlePacketVoice(std::shared_ptr packet); - - bool connected = true; - - sockaddr_in remoteAddress; - sockaddr_in localAddress; - - - UdpSocket* socket; - threads::Thread* rwThread = nullptr; - std::deque writeQueue; -#ifndef NoQt - QUdpSocket* qtSocket = nullptr; -#endif - - threads::Mutex bufferQueueLock; - buffer::SortedBufferQueue** readQueue = nullptr; - - //std::deque readQueue; - - std::deque acknowlageQueue; - threads::Mutex acknowlageQueueLock; - - protocol::PacketIdManager idManager; - threads::Thread* handleThread = nullptr; - std::list> handleQueue; //Parsed packets - threads::Mutex handleQueueLock; - bool autoHandle = false; - - ts::connection::CryptionHandler* cryptionHandler = nullptr; - ts::connection::CompressionHandler* compressionHandler = nullptr; - - std::string remoteHost; - uint16_t remotePort; - - Identity* clientIdentity; - - ConnectionState::ConnectionState cstate = ConnectionState::UNCONNECTED; - - - bool breakAck = false; - /** - * TS3 Client data - */ - - uint16_t clientId = 0; - - std::deque channels; - }; - } -} \ No newline at end of file diff --git a/client/src/protocol/ConnectionHandschake.cpp b/client/src/protocol/ConnectionHandschake.cpp deleted file mode 100644 index d94de30..0000000 --- a/client/src/protocol/ConnectionHandschake.cpp +++ /dev/null @@ -1,361 +0,0 @@ -// -// Created by wolverindev on 08.10.17. -// - -#include -#include -#include -#include "Connection.h" -#include "misc/base64.h" -#include "misc/endianness.h" - -using namespace std; -using namespace std::chrono; -using namespace ts; -using namespace ts::connection; -using namespace ts::protocol; - -const int InitVersionLength = 4; -const uint8_t InitVersion[InitVersionLength] = {0x09, 0x83, 0x8C, 0xCF}; - -/** - * Maybe memset to 0 for security? - */ -#define RESET_DATA \ -bufferIndex = 0; \ -delete pkt; \ -pkt = nullptr; - - -inline ClientPacket *solvePuzzle(shared_ptr response, Identity *, std::string &); - -inline std::string toString(mp_int* num){ - char buffer[2048]; - memset(buffer, 0, 2048); - auto len = mp_todecimal(num, buffer); - return string(buffer); -} - - -extern void hexdump(std::ostream& outs, const std::string& s, size_t line_len = 16); -bool ServerConnection::handshake(std::string &errorMessage) { - //setup the init mac - /** - * Low level - */ - ts::protocol::ClientPacket *pkt; - shared_ptr response; - int maxBufferSize = 512; - size_t bufferIndex = 0; - uint8_t buffer[maxBufferSize]; - memset(buffer, 0, maxBufferSize); - int err = 0; - string error = "success"; - - beginCoocie: - memcpy(buffer, InitVersion, InitVersionLength); - bufferIndex += InitVersionLength; - buffer[bufferIndex++] = 0x00; //Login state - - auto millis = duration_cast(system_clock::now().time_since_epoch()).count(); - memcpy(&buffer[bufferIndex], &millis, 4); - bufferIndex += 4; - //generate the alpha key - for (int i = 0; i < 4; i++) buffer[bufferIndex++] = (uint8_t) std::rand(); - bufferIndex += 8; //Reserved bytes - - pkt = new ts::protocol::ClientPacket(ts::protocol::PacketTypeInfo::Init1, pipes::buffer_view((void *) buffer, bufferIndex)); - pkt->clientId(0); - pkt->toggle(ts::protocol::PacketFlag::Unencrypted, true); - pkt->applyPacketId(101, 0); - this->sendPacket(*pkt); - RESET_DATA; - - response = readNextPacket(); - if (!response) { - errorMessage = "could not get a valid response!"; - return false; - } - if (response->type() != protocol::PacketTypeInfo::Init1) { - errorMessage = "invalid response type. Got: " + response->type().name(); - return false; - } - if (response->data()[0] != 1) { - errorMessage = "iInvalid requested login type (" + to_string((int) response->data()[0]) + " == 1)"; - return false; - } - - //the second request of the manager - memcpy(buffer, InitVersion, InitVersionLength); - bufferIndex += InitVersionLength; - buffer[bufferIndex++] = 0x02; //Login state - if(response) - memcpy(&buffer[bufferIndex], response->data().string().substr(1, 16).data(), 16); - bufferIndex += 16; //Servers 16 bytes - if(response) - memcpy(&buffer[bufferIndex], response->data().string().substr(17, 4).data(), 4); - bufferIndex += 4; //My own 16 bytes, reversed - - pkt = new ts::protocol::ClientPacket(ts::protocol::PacketTypeInfo::Init1, pipes::buffer_view((void *) buffer, bufferIndex)); - pkt->clientId(0); - pkt->toggle(ts::protocol::PacketFlag::Unencrypted, true); - pkt->applyPacketId(101, 0); - this->sendPacket(*pkt); - RESET_DATA; - - //We got the RSA challenge - response = readNextPacket(); - if (!response) { - errorMessage = "could not get a valid response!"; - return false; - } - if (response->type() != protocol::PacketTypeInfo::Init1) { - errorMessage = "invalid response type"; - return false; - } - if (response->data()[0] != 3) { - if(response->data()[0] == 127) { - cout << "COOCIE RESET!" << endl; - goto beginCoocie; - } - hexdump(cout, response->data().string()); - errorMessage = "Invalid requested login type (" + to_string((int) response->data()[0]) + " == 3 | unencripted -> " + (response->hasFlag(PacketFlag::Unencrypted) ? "true" : "false") + ")"; - return false; - } - - //Generate puzzel response - std::string alpha; - pkt = solvePuzzle(response, this->clientIdentity, alpha); - pkt->applyPacketId(101, 0); - this->sendPacket(*pkt); - RESET_DATA; - - cout << "manager init done" << endl; - this->encriptAck = true; - - response = readNextPacket(); - if (!response) { - errorMessage = "could not get a valid response!"; - return false; - } - if (response->type() != protocol::PacketTypeInfo::Command) { - errorMessage = "invalid response type: " + response->type().name(); - return false; - } - - - auto command = response->asCommand(); - if (command.getCommand().compare("initivexpand") != 0) { - // errorMessage = "invalid response command. Got: " + command.getCommand() + " Expected: initivexpand"; - return this->handshakeNew(command, alpha, errorMessage); - } - - //std::string alpha = base64::decode(command[0]["alpha"]); - std::string beta = base64::decode(command[0]["beta"]); - std::string omega = base64::decode(command[0]["omega"]); //Remotes public key - cout << "RESPONSE! -> " << command.build() << endl; - //Read public key - ecc_key remotePublicKey{}; - if ((err = ecc_import((const unsigned char *) omega.data(), omega.length(), &remotePublicKey)) != CRYPT_OK) { - errorMessage = "ecc_import(...) returned " + to_string(err) + "/" + error_to_string(err); - return false; - } - - if(strcmp(remotePublicKey.dp->name, "ECC-256") != 0){ - errorMessage = "invalid imported public key! Curve found " + string(remotePublicKey.dp->name); - return false; - } - - size_t sharedSecretLength = 32; - char sharedSecret[sharedSecretLength]; - - if ((err = ecc_shared_secret(clientIdentity->getKeyPair(), &remotePublicKey, (unsigned char *) sharedSecret, &sharedSecretLength)) != CRYPT_OK) { - errorMessage = "ecc_shared_secret(...) returned " + to_string(err) + "/" + error_to_string(err); - return false; - } - - if (!setupSharedSecret(alpha, beta, string(sharedSecret, sharedSecretLength), error)) { - errorMessage = "setupSharedSecret(...) failed: " + error; - return false; - } - - //this->readQueue[PacketType::Command.type()]->reset(); - - //TS 3.1 - /* - response = readNextPacket(); - if (!response) { - errorMessage = "could not get a valid response!"; - return false; - } - if (response->type() != protocol::PacketType::Command) { - errorMessage = "invalid response type: " + response->type().name(); - return false; - } - command = response->asCommand(); - cout << "Having initiv2 -> " << response->data() << endl; - */ - - this->idManager.nextPacketId(PacketTypeInfo::Command); - Command clientinit("clientinit"); - //94ec66de-5940-4e38-b002-970df0cf6c94,62444179-0d99-42ba-a45c-c6b1557d079a,d95f9901-c42d-4bac-8849-7164fd9e2310 - //clientinit["client_badges"] = "badges=450f81c1-ab41-4211-a338-222fa94ed157,c9e97536-5a2d-4c8e-a135-af404587a472,94ec66de-5940-4e38-b002-970df0cf6c94"; //,62444179-0d99-42ba-a45c-c6b1557d079a - clientinit["client_nickname"] = "Wolf C++ XXXX"; - clientinit["client_version"] = "3.1 [Build: 1471417187]"; - clientinit["client_platform"] = "Windows"; - clientinit["client_version_sign"] = "Vr9F7kbVorcrkV5b/Iw+feH9qmDGvfsW8tpa737zhc1fDpK5uaEo6M5l2DzgaGqqOr3GKl5A7PF9Sj6eTM26Aw=="; - clientinit["client_input_hardware"] = true; - clientinit["client_output_hardware"] = true; - clientinit["client_default_channel"] = ""; - clientinit["client_default_channel_password"] = ""; - - string password; - if(!password.empty()){ - char passwordBuffer[SHA_DIGEST_LENGTH]; - SHA1((const unsigned char *) password.data(), password.length(), (unsigned char *) passwordBuffer); - password = base64_encode(string(passwordBuffer, SHA_DIGEST_LENGTH)); - } - clientinit["client_server_password"] = password; - clientinit["client_meta_data"] = ""; - clientinit["client_key_offset"] = this->clientIdentity->lastValidKeyOffset(); - clientinit["client_nickname_phonetic"] = ""; - clientinit["client_default_token"] = ""; - clientinit["hwid"] = "123,456123123123"; - sendCommand(clientinit); - - while(true){ - response = readNextPacket(); - if (!response) { - errorMessage = "could not get a valid response!"; - return false; - } - if(response->type() == PacketTypeInfo::Ack) continue; - break; - } - - //TODO check ack id - - if (!response) { - errorMessage = "could not get a valid response!"; - return false; - } - if (response->type() != protocol::PacketTypeInfo::Command) { - errorMessage = "invalid response type: " + response->type().name(); - return false; - } - if(response->asCommand().getCommand() == "initserver"){ //Got success - this->handleQueueLock.lock(); - this->handleQueue.push_front(response); - this->handleQueueLock.unlock(); - - this->setClientId(response->asCommand()["aclid"]); - - this->autoHandle = true; - cout << "Successfull connected!" << endl; - - /* - std::thread([&](){ - usleep(1000 * 1000); - cout << " -> send extra command" << endl; - //this->sendCommand(Command("channelsubscribeall return_code=1:i")); - - while(true){ - //this->sendCommand(Command("getconnectioninfo clid=320 return_code=1:112")); - //this->sendCommand(Command("ftgetfilelist cid=0 cpw path=\\/icons return_code=1:z0")); - this->sendCommand(Command("servergrouppermlist sgid=6 return_code=1:112")); - usleep(10 * 1000 * 1000); - } - //Command cmd("channelgetdescription cid=1 return_code=1:3o"); - //Command cmd("clientupdate client_nickname=WolverinDEV22 return_code=__1_"); - //Command cmd("clientdisconnect reasonid=8 reasonmsg=leaving"); - //this->sendCommand(Command("permissionlist return_code=__1_")); - //this->sendCommand(Command("clientgetvariables clid=" + to_string(this->clientId))); - }).detach(); - */ - - - return true; - } - cout << "Invalid connect: " << response->data() << endl; - //TODO error handling - return true; -} - -inline ClientPacket* solvePuzzle(shared_ptr response, Identity *identity, std::string &alpha) { - uint32_t puzzelLength = be2le32(&((char*) response->data().data_ptr())[1 + 128]); //1 for the first byte (the state byte) - - auto buffer = (char*) response->data().data_ptr(); - - char alphaBuffer[10]; - for (int index = 0; index < 10; index++) - alphaBuffer[index] = 0; //rand(); - alpha = string(alphaBuffer, 10); - - //Generating command - auto pkey = identity->publicKey(); - ts::Command command("clientinitiv", { - {"alpha", base64_encode(alphaBuffer, 10)}, - {"omega", pkey}, - {"ip", ""}, - {"ot", 1} //Required by 3.1 - }); - std::string cmd = command.build(); - - //Sloving puzzel - mp_int x{}; - mp_int n{}; - mp_int result{}; - - //mp_init_multi(&x, &n, &result); - mp_init(&x); - mp_init(&n); - mp_init(&result); - - char numBuffer[2048]; - mp_read_unsigned_bin(&x, (const unsigned char *) &response->data()[1], 64); //One offset - mp_read_unsigned_bin(&n, (const unsigned char *) &response->data()[1 + 64], 64); //1 + 64 offset - - cout << "X: " << toString(&x) << endl; - cout << "N: " << toString(&n) << endl; - cout << "Length: " << puzzelLength << endl; - - mp_int exp{}; - mp_init(&exp); - mp_2expt(&exp, puzzelLength); - - - //x ** (2 ** puzzelLength) mod n - int err = 0; - if ((err = mp_exptmod(&x, &exp, &n, &result)) != CRYPT_OK) { - cerr << "Invalid crypt: " << err << "/" << error_to_string(err) << endl; - } - - int resultBufferLength = mp_unsigned_bin_size(&result); - char resultBuffer[resultBufferLength]; - mp_to_unsigned_bin(&result, (unsigned char *) resultBuffer); - - - //mp_clear_multi(&x, &n, &exp, &result); - mp_clear(&x); - mp_clear(&n); - mp_clear(&exp); - mp_clear(&result); - - size_t packetBufferLength = InitVersionLength + 1 + 232 + 64 + cmd.length(); - char packetBuffer[packetBufferLength]; - memset(packetBuffer, 0, packetBufferLength); - - memcpy(packetBuffer, InitVersion, InitVersionLength); - packetBuffer[InitVersionLength] = 0x04; - - //Copy old data - memcpy(&packetBuffer[InitVersionLength + 1], &response->data()[1], 232); - memcpy(&packetBuffer[InitVersionLength + 1 + 232 + (64 - resultBufferLength)], resultBuffer, resultBufferLength); - memcpy(&packetBuffer[InitVersionLength + 1 + 232 + 64], cmd.data(), cmd.length()); - - cout << "sending puzzel sulution" << endl; - auto pkt = new ts::protocol::ClientPacket(ts::protocol::PacketTypeInfo::Init1, pipes::buffer_view((void *) packetBuffer, packetBufferLength)); - pkt->clientId(0); - pkt->toggle(ts::protocol::PacketFlag::Unencrypted, true); - return pkt; -} \ No newline at end of file diff --git a/client/src/protocol/ConnectionPacketHandler.cpp b/client/src/protocol/ConnectionPacketHandler.cpp deleted file mode 100644 index 2012015..0000000 --- a/client/src/protocol/ConnectionPacketHandler.cpp +++ /dev/null @@ -1,158 +0,0 @@ -#include -#include -#include "Connection.h" -#include "misc/base64.h" -#include "misc/endianness.h" - -using namespace std; -using namespace ts; -using namespace ts::connection; -using namespace ts::protocol; - -//notifystatusfiletransfer clientftfid=4093 status=2063 msg=lost\sfile\stransfer\sconnection size=16384 - -extern void hexdump(std::ostream& outs, const std::string& s, size_t line_len = 16); -inline void downloadStuff(std::string key, uint16_t port, uint64_t size){ - threads::Thread([key, port, size](){ - int socketId = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - assert(socketId > 1); - - sockaddr_in server; - server.sin_addr.s_addr = inet_addr("127.0.0.1"); - server.sin_family = AF_INET; - server.sin_port = htons( port ); - - //Connect to remote server - if (connect(socketId , (struct sockaddr *)&server , sizeof(server)) < 0) - { - perror("connect failed. Error"); - return; - } - - uint32_t readed = 0; - assert(send(socketId, key.data(), key.length(), 0) > 0); - - while(readed < size + 3){ - char buffer[size]; - auto readedBytes = recv(socketId, buffer, size - readed, MSG_DONTWAIT); - if(readedBytes < 0) { - //cerr << "Invalid ft read" << endl; - continue; - } - if(readedBytes == 0){ - continue; - } - hexdump(cout, string(buffer, readedBytes)); - readed += readedBytes; - } - cout << "File downloaded!" << endl; - }).detach(); -} - -void ServerConnection::handlePacketAck(std::shared_ptr packet) { - auto packetId = be2le16((const char*) packet->data().data_ptr()); -#if defined(DEBUG_PACKET_LOG) || defined(LOG_ACK) - cout << "Got ack for " << packetId << endl; -#endif -} - -void ServerConnection::handlePacketCommand(std::shared_ptr packet) { - auto command = packet->asCommand(); -#if defined(DEBUG_PACKET_LOG) || defined(LOG_CMD) - cout << "[Server -> Client][" << packet->type().name() << "] " << packet->data() << endl; -#endif - if (command.getCommand().compare("notifyconnectioninforequest") == 0) { //TODO - cout << "Send response" << endl; - Command cmd( - string("setconnectioninfo"), { - {"connection_ping", 10000000}, - {"connection_ping_deviation", 10000000}, - {"connection_packets_sent_speech", 0}, - {"connection_packets_sent_keepalive", 0}, - {"connection_packets_sent_control", rand()}, - {"connection_bytes_sent_speech", 0}, - {"connection_bytes_sent_keepalive", 0}, - {"connection_bytes_sent_control", 0}, - {"connection_packets_received_speech", 0}, - {"connection_packets_received_keepalive", 0}, - {"connection_packets_received_control", 0}, - {"connection_bytes_received_speech", 0}, - {"connection_bytes_received_keepalive", 0}, - {"connection_bytes_received_control", 0}, - {"connection_server2client_packetloss_speech", 10000000}, - {"connection_server2client_packetloss_keepalive", 10000000}, - {"connection_server2client_packetloss_control", 10000000}, - {"connection_server2client_packetloss_total", 10000000}, - {"connection_bandwidth_sent_last_second_speech", 0}, - {"connection_bandwidth_sent_last_second_keepalive", 0}, - {"connection_bandwidth_sent_last_second_control", 0}, - {"connection_bandwidth_sent_last_minute_speech", 0}, - {"connection_bandwidth_sent_last_minute_keepalive", 0}, - {"connection_bandwidth_sent_last_minute_control", 0}, - {"connection_bandwidth_received_last_second_speech", 0}, - {"connection_bandwidth_received_last_second_keepalive", 0}, - {"connection_bandwidth_received_last_second_control", 0}, - {"connection_bandwidth_received_last_minute_speech", 0}, - {"connection_bandwidth_received_last_minute_keepalive", 0}, - {"connection_bandwidth_received_last_minute_control", 0} - } - ); - sendCommand(cmd, true); - } else if (command.command() == "notifyserverupdated") { -#if defined(DEBUG_PACKET_LOG) || defined(LOG_CMD) - cout << "notifyserverupdated -> " << endl; - cout << "Last data: " << packet->data().string().substr(packet->data().length() - 10) << endl; -#endif - } else if (command.command() == "notifystartdownload") { - cout << "Client download: " << command.build() << endl; - auto port = command["port"].as(); - auto key = command["ftkey"].string(); - auto size = command["size"].as(); - downloadStuff(key, port, size); - } else if (command.command() == "channellist") { - cout << "Breaking ack" << endl; - for (int index = 0; index < command.bulkCount(); index++) { - this->channels.push_back(command[index]["cid"].as()); - } - } -} -void ServerConnection::handlePacketVoice(std::shared_ptr packet) {} - -static int pingIndex = 0; -void ServerConnection::handlePacketPing(std::shared_ptr packet) { - if(packet->type() == PacketTypeInfo::Pong){ - //cout << "[PING] gota " << be2le16(packet->data().data()) << endl; - return; - } - - char buffer[2]; - le2be16(packet->packetId(), buffer); - - ClientPacket pkt(PacketTypeInfo::Pong, pipes::buffer_view{buffer, 2}); - pkt.enableFlag(PacketFlag::Unencrypted); - sendPacket(pkt); - - ClientPacket ping(PacketTypeInfo::Ping, pipes::buffer_view{buffer, 0}); - ping.enableFlag(PacketFlag::Unencrypted); - sendPacket(ping); - //cout << "[PING] Reqe " << ping.packetId() << endl; - - //cout << "[PONG] Send " << packet->packetId() << endl; - - if(this->clientId > 0 && this->channels.size() > 0) { - Command command("clientmove"); - command["clid"] = this->clientId; - - auto idx = rand() % this->channels.size(); - command["cid"] = this->channels[idx]; - this->sendCommand(command); - - std::thread([&] { - threads::self::sleep_for(chrono::seconds(1)); - - Command cmd("channelcreate"); - cmd["channel_name"] = to_string(rand()) + "_" + to_string(rand()); - //this->sendCommand(cmd); - }).detach(); - } -} \ No newline at end of file diff --git a/client/src/protocol/HandshakeNew.cpp b/client/src/protocol/HandshakeNew.cpp deleted file mode 100644 index cfeba8b..0000000 --- a/client/src/protocol/HandshakeNew.cpp +++ /dev/null @@ -1,154 +0,0 @@ -#include -#include -#include -#include -#include "Connection.h" -#include "License.h" -#include - -using namespace std; -using namespace std::chrono; -using namespace ts; -using namespace license::teamspeak; -using namespace ts::connection; -using namespace ts::protocol; - - -int __ed_sha512_init(sha512_context* ctx) { - //assert(!ctx->context); - - ctx->context = new hash_state{}; - return sha512_init((hash_state*) ctx->context) == CRYPT_OK; -} - -int __ed_sha512_final(sha512_context* ctx, unsigned char *out) { - assert(ctx->context); - - auto result = sha512_done((hash_state*) ctx->context, out) == CRYPT_OK; - delete (hash_state*) ctx->context; - return result; -} -int __ed_sha512_update(sha512_context* ctx, const unsigned char *msg, size_t len) { - assert(ctx->context); - return sha512_process((hash_state*) ctx->context, msg, len) == CRYPT_OK; -} - -static sha512_functions __ed_sha512_functions { - __ed_sha512_init, - __ed_sha512_final, - __ed_sha512_update -}; - - -bool ServerConnection::handshakeNew(Command &initivexpand2, const std::string& alpha, std::string &errorMessage) { - if(&__ed_sha512_functions != &_ed_sha512_functions) - _ed_sha512_functions = __ed_sha512_functions; - - cout << initivexpand2.build() << endl; - u_char seed[32 * 2]; - u_char clientPrivateKey[32]; - u_char clientPublicKey[32]; - ed25519_create_keypair(clientPublicKey, clientPrivateKey, seed); - cout << "Client key: " << base64::encode((char*) clientPrivateKey, 32) << endl; - cout << "Privet key:" << endl; - hexDump(clientPrivateKey, 32); - cout << "Public key:" << endl; - hexDump(clientPublicKey, 32); - auto license = base64::decode(initivexpand2["l"]); - - auto licensestream = stringstream(license); - auto chain = LicenseChain::parse(licensestream, errorMessage); - if(!chain) return false; - chain->print(); - - unique_ptr serverPublic(new ecc_key{}); - auto omega = base64::decode(initivexpand2["omega"]); - ecc_import((u_char*) omega.data(), omega.length(), serverPublic.get()); - - //7B 1E AC 02 CE 77 35 0E EF C4 5C 1C F7 54 04 87 A9 A7 64 A7 8F 04 F7 53 58 64 84 D7 0A 97 F2 63 - //[0x7b, 0x1e, 0xac, 0x2, 0xce, 0x77, 0x35, 0xe, 0xef, 0xc4, 0x5c, 0x1c, 0xf7, 0x54, 0x4, 0x87, 0xa9, 0xa7, 0x64, 0xa7, 0x8f, 0x4, 0xf7, 0x53, 0x58, 0x64, 0x84, 0xd7, 0xa, 0x97, 0xf2, 0xe3] - //License signed from server :) - auto licenseHash = digest::sha256(license); - auto licenseSign = base64::decode(initivexpand2["proof"]); - - int state; - assert(ecc_verify_hash((u_char*) licenseSign.c_str(), licenseSign.length(), (u_char*) licenseHash.c_str(), licenseHash.length(), &state, serverPublic.get()) == CRYPT_OK); - cout << "State: " << state << endl; - assert(state == 1); - - //EK! - this->idManager.nextPacketId(PacketTypeInfo::Command); - cout << this->idManager.currentPacketId(PacketTypeInfo::Command) << endl; - Command clientek("clientek"); - clientek["ek"] = base64::encode((char*) clientPublicKey, 32); - auto rawProof = string((char*) clientPublicKey, 32) + base64::decode(initivexpand2["beta"]); - cout << " -> " << rawProof.length() << endl; - size_t signBufferLength = 120; - char signBuffer[signBufferLength]; - prng_state prngState{}; - memset(&prngState, 0, sizeof(prngState)); - - cout << "Data: " << base64::encode(rawProof) << endl; - cout << "KEY: " << this->clientIdentity->privateKey() << endl; - rawProof = digest::sha256(rawProof); - assert(ecc_sign_hash((u_char*) rawProof.data(), rawProof.length(), (u_char*) signBuffer, &signBufferLength, &prngState, find_prng("sprng"), this->clientIdentity->getKeyPair()) == CRYPT_OK); - cout << "ecc_sign_hash() -> " << base64::encode(signBuffer, signBufferLength) << endl; - clientek["proof"] = base64::encode(signBuffer, signBufferLength); - this->sendCommand(clientek, false); - - //TODO magic stuff - shared_ptr response; - response = readNextPacket(); - if (!response) { - errorMessage = "could not get a valid response!"; - return false; - } - cout << "Type: " << response->type().name() << endl; - cout << "ID: " << (int) response->data()[0] << " " << (int) response->data()[1] << endl; - - - LicensePublicKey serverroot; - memcpy(serverroot, public_root, 32); - if(initivexpand2[0].has("root")) { - cout << "Cot costume server root!" << endl; - auto root = base64::decode(initivexpand2["root"]); - memcpy(serverroot, root.data(), 32); - } - cout << "Public root key: " << endl; - for(const auto& e : serverroot) - cout << hex << "0x" << (int) (uint8_t) e << " " << endl; - - string sharedData; - this->cryptionHandler->setupSharedSecretNew(alpha, base64::decode(initivexpand2["beta"]), (char*) clientPrivateKey, (char*) chain->generatePublicKey(serverroot).data()); - //this->cryptionHandler->setupSharedSecretNew(alpha, base64::decode(initivexpand2["beta"]), (char*) clientPrivateKey, (char*) public_tea_root); - - threads::self::sleep_for(milliseconds(250)); - Command clientinit("clientinit"); - //94ec66de-5940-4e38-b002-970df0cf6c94,62444179-0d99-42ba-a45c-c6b1557d079a,d95f9901-c42d-4bac-8849-7164fd9e2310 - //clientinit["client_badges"] = "badges=450f81c1-ab41-4211-a338-222fa94ed157,c9e97536-5a2d-4c8e-a135-af404587a472,94ec66de-5940-4e38-b002-970df0cf6c94"; //,62444179-0d99-42ba-a45c-c6b1557d079a - clientinit["client_nickname"] = "Wolf C++ XX"; - clientinit["client_version"] = "3.1.8 [Build: 1516614607]"; - clientinit["client_platform"] = "Windows"; - clientinit["client_version_sign"] = "gDEgQf/BiOQZdAheKccM1XWcMUj2OUQqt75oFuvF2c0MQMXyv88cZQdUuckKbcBRp7RpmLInto4PIgd7mPO7BQ=="; - clientinit["client_input_hardware"] = true; - clientinit["client_output_hardware"] = true; - clientinit["client_default_channel"] = ""; - clientinit["client_default_channel_password"] = ""; - clientinit["client_server_password"] = ""; - clientinit["client_meta_data"] = ""; - clientinit["client_key_offset"] = this->clientIdentity->lastValidKeyOffset(); - clientinit["client_nickname_phonetic"] = ""; - clientinit["client_default_token"] = ""; - clientinit["hwid"] = "123,456123123123"; - sendCommand(clientinit); - - this->autoHandle = true; - /* - response = readNextPacket(); - if (!response) { - errorMessage = "could not get a valid response!"; - return false; - } - */ - return true; -} \ No newline at end of file diff --git a/client/src/protocol/socket/FilteredUDPSocket.cpp b/client/src/protocol/socket/FilteredUDPSocket.cpp deleted file mode 100644 index ae35771..0000000 --- a/client/src/protocol/socket/FilteredUDPSocket.cpp +++ /dev/null @@ -1,115 +0,0 @@ -// -// Created by root on 13.10.17. -// - -#include "FilteredUDPSocket.h" - -#include -#include -#include -#include //Provides declarations for udp header -#include //Provides declarations for ip header -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -using namespace std::chrono; -using namespace ts::connection; - -FilteredUdpSocket::FilteredUdpSocket() {} -FilteredUdpSocket::~FilteredUdpSocket() {} - - -bool FilteredUdpSocket::setup(sockaddr_in * remoteAddr) { - srand(system_clock::now().time_since_epoch().count()); // should only be called once - int r = (lrand48() % (50 * 1000)) + 1000; // returns a pseudo-random integer between 0 and RAND_MAX - - - this->remoteAdress = new sockaddr_in; - memcpy(this->remoteAdress, remoteAddr, sizeof(sockaddr_in)); - - this->socketDescriptor = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if(this->socketDescriptor < 0){ - cerr << "Invalid socket create: " << errno << " - " << this->socketDescriptor << " -> " << strerror(errno) << endl; - } - int allow = 1; - setsockopt(this->socketDescriptor, SOL_SOCKET, SO_REUSEADDR, &allow, sizeof(int)); - - this->localAdress = new sockaddr_in; - memset((char *) this->localAdress, 0, sizeof(sockaddr_in)); - localAdress->sin_family = AF_INET; - localAdress->sin_addr.s_addr = htonl(INADDR_ANY); - localAdress->sin_port = htons(r); - - -/* sudo tcpdump -q udp port 256 -dd */ - struct sock_filter code[ ] = { - { 0x28, 0, 0, 0x0000000c }, - { 0x15, 0, 8, 0x000086dd }, - { 0x30, 0, 0, 0x00000014 }, - { 0x15, 2, 0, 0x00000084 }, - { 0x15, 1, 0, 0x00000006 }, - { 0x15, 0, 17, 0x00000011 }, - { 0x28, 0, 0, 0x00000036 }, - { 0x15, 14, 0, 0x00002fbd }, - { 0x28, 0, 0, 0x00000038 }, - { 0x15, 12, 13, 0x00002fbd }, - { 0x15, 0, 12, 0x00000800 }, - { 0x30, 0, 0, 0x00000017 }, - { 0x15, 2, 0, 0x00000084 }, - { 0x15, 1, 0, 0x00000006 }, - { 0x15, 0, 8, 0x00000011 }, - { 0x28, 0, 0, 0x00000014 }, - { 0x45, 6, 0, 0x00001fff }, - { 0xb1, 0, 0, 0x0000000e }, - { 0x48, 0, 0, 0x0000000e }, - { 0x15, 2, 0, 0x00002fbd }, - { 0x48, 0, 0, 0x00000010 }, - { 0x15, 0, 1, 0x00002fbd }, - { 0x6, 0, 0, 0x00040000 }, - { 0x6, 0, 0, 0x00000000 }, - - }; - - struct sock_fprog bpf = { - .len = sizeof(code) / sizeof(*code), - .filter = code, - }; - - //auto response = setsockopt(this->socketDescriptor, SOL_SOCKET, SO_ATTACH_FILTER, &bpf, sizeof(bpf)); - //if (response < 0) cerr << "Invalid attach!" << endl; - /* ... bail out ... */ - - - /* - * - if(connect(this->socketDescriptor, (const sockaddr *) remoteAddr, sizeof(sockaddr_in)) < 0){ - cerr << "Invalid connect" << endl; - } - */ - if(bind(this->socketDescriptor, (const sockaddr *) localAdress, sizeof(sockaddr_in)) < 0) cout << "XXX" << endl; - - return true; -} - -void FilteredUdpSocket::close() { - if(this->socketDescriptor > 0) { - shutdown(this->socketDescriptor, SHUT_RDWR); - ::close(this->socketDescriptor); - this->socketDescriptor = 0; - } -} - -ssize_t FilteredUdpSocket::write(const char *buffer, size_t size) { - return sendto(this->socketDescriptor, buffer, size, 0, (const sockaddr *) this->remoteAdress, sizeof(sockaddr_in)); -} - -ssize_t FilteredUdpSocket::read(char *buffer, size_t size) { - return recv(this->socketDescriptor, (void *) buffer, size, 0); -} \ No newline at end of file diff --git a/client/src/protocol/socket/FilteredUDPSocket.h b/client/src/protocol/socket/FilteredUDPSocket.h deleted file mode 100644 index 2b68b49..0000000 --- a/client/src/protocol/socket/FilteredUDPSocket.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include - -namespace ts { - namespace connection { - class FilteredUdpSocket { - public: - FilteredUdpSocket(); - ~FilteredUdpSocket(); - - bool setup(sockaddr_in*); - void close(); - - ssize_t read(char* buffer, size_t size); - ssize_t write(const char* buffer, size_t size); - - int getSocketDescriptor(){ return socketDescriptor; } - private: - int socketDescriptor; - sockaddr_in* remoteAdress = nullptr; - sockaddr_in* localAdress = nullptr; - }; - - typedef FilteredUdpSocket UdpSocket; - } -} \ No newline at end of file diff --git a/client/src/protocol/socket/RawUDPSocket.cpp b/client/src/protocol/socket/RawUDPSocket.cpp deleted file mode 100644 index ce9504d..0000000 --- a/client/src/protocol/socket/RawUDPSocket.cpp +++ /dev/null @@ -1,151 +0,0 @@ -// -// Created by wolverindev on 12.10.17. -// - -#include -#include -#include -#include //Provides declarations for udp header -#include //Provides declarations for ip header -#include -#include "RawUDPSocket.h" - -using namespace std; -using namespace ts::connection; - -/* - 96 bit (12 bytes) pseudo header needed for udp header checksum calculation -*/ -struct pseudo_header -{ - u_int32_t source_address; - u_int32_t dest_address; - u_int8_t placeholder; - u_int8_t protocol; - u_int16_t udp_length; -}; - -RawUdpSocket::RawUdpSocket() {} - -RawUdpSocket::~RawUdpSocket() {} - -uint16_t RawUdpSocket::buildCheckSum(uint16_t* buffer, size_t size) { - register long sum; - unsigned short oddbyte; - register short answer; - - sum = 0; - while (size > 1) { - sum += *buffer++; - size -= 2; - } - if (size == 1) { - oddbyte = 0; - *((u_char *) &oddbyte) = *(u_char *) buffer; - sum += oddbyte; - } - - sum = (sum >> 16) + (sum & 0xffff); - sum = sum + (sum >> 16); - answer = (short) ~sum; - - return (answer); -} - -int RawUdpSocket::read(char *buffer, size_t size) {} - -int RawUdpSocket::write(const char *buffer, size_t size) { - char datagram[4096]; - memset(datagram, 0, 4096); - memcpy(&datagram[sizeof(iphdr) + sizeof(udphdr)], buffer, size); - - //IP header - struct iphdr *iph = (struct iphdr *) datagram; - //UDP header - struct udphdr *udph = (struct udphdr *) (datagram + sizeof(struct ip)); - - //Setup the ip header - iph->ihl = 5; - iph->version = 4; - iph->tos = 0; - iph->tot_len = sizeof(iphdr) + sizeof(udphdr) + size; //Total length - iph->id = htonl(12); //TODO increase - iph->frag_off = 0; - iph->ttl = 255; //Max 255 hops maybe change it to default 64 - iph->protocol = IPPROTO_UDP; - iph->saddr = localAdress->sin_addr.s_addr; - iph->daddr = remoteAdress->sin_addr.s_addr; - iph->check = this->buildCheckSum ((unsigned short *) datagram, iph->tot_len); - - udph->source = localAdress->sin_port; - udph->dest = remoteAdress->sin_port; - udph->len = htons(8 + size); - - size_t csumLength = sizeof(struct pseudo_header) + sizeof(struct udphdr) + size; - char csumData[csumLength]; - - pseudo_header psh; - //Now the UDP checksum using the pseudo header - psh.source_address = localAdress->sin_addr.s_addr; - psh.dest_address = remoteAdress->sin_addr.s_addr; - psh.placeholder = 0; - psh.protocol = IPPROTO_UDP; - psh.udp_length = htons(sizeof(struct udphdr) + size); - memcpy(csumData , (char*) &psh , sizeof (struct pseudo_header)); - memcpy(csumData + sizeof(struct pseudo_header) , udph , sizeof(struct udphdr) + size); - - udph->check = buildCheckSum((uint16_t *) csumData, csumLength); - - auto written = sendto(this->socketDescriptor, datagram, iph->tot_len, 0, (struct sockaddr *) this->remoteAdress, sizeof(sockaddr)); - if(written != iph->tot_len){ - cerr << "Invalid write: " << written << endl; - return -1; - } - cout << "Write: " << written << endl; - return size; -} - -bool RawUdpSocket::setup(sockaddr_in *remoteAdress) { - this->remoteAdress = new sockaddr_in; - memcpy(this->remoteAdress, remoteAdress, sizeof(sockaddr_in)); - this->socketDescriptor = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); - if(this->socketDescriptor < 0){ - if(this->socketDescriptor == EPERM){ - cerr << "Invalid permission. Dont have permission to create a new RAW socket!"; - return false; - } - cerr << "Invalid socket create: " << errno << " - " << this->socketDescriptor << " -> " << strerror(errno) << endl; - } - - //get local addr - this->localAdress = new sockaddr_in; - struct ifaddrs *ifAddrStruct = NULL; - getifaddrs(&ifAddrStruct); - - for (ifaddrs* ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) { - if (!ifa->ifa_addr) { - continue; - } - if (ifa->ifa_addr->sa_family == AF_INET) { // check it is IP4 - // is a valid IP4 Address - memcpy(this->localAdress, ifa->ifa_addr, sizeof(sockaddr_in)); - /* - tmpAddrPtr=&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr; - char addressBuffer[INET_ADDRSTRLEN]; - inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN); - */ - } - /* - else if (ifa->ifa_addr->sa_family == AF_INET6) { // check it is IP6 - // is a valid IP6 Address - tmpAddrPtr=&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr; - char addressBuffer[INET6_ADDRSTRLEN]; - inet_ntop(AF_INET6, tmpAddrPtr, addressBuffer, INET6_ADDRSTRLEN); - } - */ - } - if (ifAddrStruct != NULL) freeifaddrs(ifAddrStruct); - this->localAdress->sin_port = 1232; - - return true; -} \ No newline at end of file diff --git a/client/src/protocol/socket/RawUDPSocket.h b/client/src/protocol/socket/RawUDPSocket.h deleted file mode 100644 index 46e6faf..0000000 --- a/client/src/protocol/socket/RawUDPSocket.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include - -namespace ts { - namespace connection { - class RawUdpSocket { - public: - RawUdpSocket(); - ~RawUdpSocket(); - - bool setup(sockaddr_in*); - - int read(char* buffer, size_t size); - int write(const char* buffer, size_t size); - uint16_t buildCheckSum(uint16_t* buffer, size_t size); - - int getSocketDescriptor(){ return socketDescriptor; } - private: - int socketDescriptor; - sockaddr_in* remoteAdress = nullptr; - sockaddr_in* localAdress = nullptr; - }; - - - typedef RawUdpSocket UdpSocket; - } -} \ No newline at end of file diff --git a/flooder/CMakeLists.txt b/flooder/CMakeLists.txt deleted file mode 100644 index 4c8d479..0000000 --- a/flooder/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -cmake_minimum_required(VERSION 3.6) -project(TeamSpeak) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - -include_directories(../shared/src) -add_definitions(-DLTM_DESC) - -set(SOURCE_FILES - main.cpp - src/ProxiedClient.cpp - src/PorxiedClientSock5.cpp - src/TSClient.cpp -) - -add_executable(TeamSpeakFloodClient ${SOURCE_FILES}) -target_link_libraries(TeamSpeakFloodClient - TeaSpeak - pthread ThreadPool - ${TOM_LIBRARIES} - crypto - event - event_pthreads - /usr/local/lib/libjsoncpp.so -) \ No newline at end of file diff --git a/flooder/main.cpp b/flooder/main.cpp deleted file mode 100644 index 37983b7..0000000 --- a/flooder/main.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -#include -#include -#include -#include - -using namespace std; -using namespace ts::flood; - -void hexout(std::ostream& os, unsigned char c) -{ - unsigned char uc = static_cast(c); - os << std::setw(2) << std::setfill('0') << (unsigned int)uc << ' '; -} - -void hexdump(std::ostream& outs, const std::string& s, size_t line_len = 16) -{ - std::ostringstream os; - const std::string::size_type slen(s.size()); - int i(0); - std::string::size_type pos(0); - const std::streamsize lines(slen / line_len); - const std::streamsize chars(slen % line_len); - std::ios::fmtflags f(os.flags()); - - os << "Length: " << s.length() << "/" << std::hex << "0x" << s.length() << endl; - for(std::streamsize line = 0; line <= lines - (chars == 0 ? 1 : 0); ++line) - { - os << std::hex << setfill('0') << setw(3) << line * line_len << " | "; - for(i = 0; i < line_len; ++i) - { - if(pos < s.length()) - hexout(os, s[pos]); - else os << " "; - pos++; - } - os << " | "; - if(pos - line_len < s.length()){ - auto av = s.substr(pos - line_len); - for(char c : av.substr(0, min(av.length(), line_len))){ - if(isprint(c)) - os << c << " "; - else - os << "." << " "; - } - } - os << '\n'; - } - os.flags(f); - outs << os.str() << endl; -} - -int main(int argc, char** argv){ - sockaddr_in remoteAddress{}, proxyAddress{}; - memset(&remoteAddress, 0, sizeof(remoteAddress)); - memset(&proxyAddress, 0, sizeof(proxyAddress)); - - - proxyAddress.sin_family = AF_INET; - proxyAddress.sin_port = htons(1085); - proxyAddress.sin_addr.s_addr = inet_addr("185.89.100.17"); - - /* - proxyAddress.sin_family = AF_INET; - proxyAddress.sin_port = htons(1080); - proxyAddress.sin_addr.s_addr = inet_addr("54.38.22.7"); - */ - - remoteAddress.sin_family = AF_INET; - remoteAddress.sin_port = htons(1100); - remoteAddress.sin_addr.s_addr = inet_addr("87.106.252.164"); - - assert(evthread_use_pthreads() == 0); - event_base* evBase = event_base_new(); - - ProxiedClient client(evBase, proxyAddress, remoteAddress); - client.connect(); - - event_base_dispatch(evBase); -} \ No newline at end of file diff --git a/flooder/src/PorxiedClientSock5.cpp b/flooder/src/PorxiedClientSock5.cpp deleted file mode 100644 index cd4c163..0000000 --- a/flooder/src/PorxiedClientSock5.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include -#include -#include -#include "ProxiedClient.h" - -using namespace std; -using namespace std::chrono; -using namespace ts::flood; - -#define CERROR(msg) \ -do { \ - cerr << msg << endl;\ - this->disconnect();\ - return;\ -} while(0) - -static int port = 10000; -static threads::Mutex portLock; -void ProxiedClient::handleProxyMessage(const std::string &msg) { - if(this->state == PROXY_INIT_METHODS){ - if(msg[0] != 0x05) CERROR("Invalid proxy version response (methode exchange)"); - if(msg[1] != 0x00) CERROR("Invalid respond methode"); - this->state = PROXY_INIT_CONNECTION; - - char buffer[128]; - int index = 0; - buffer[index++] = 0x05; //Version - buffer[index++] = 0x03; //Udp weiterleitung - buffer[index++] = 0x00; //Resv - buffer[index++] = 0x01; //Addr type = IPv4 - - auto addr = IPv4{this->remoteAddr->sin_addr.s_addr}; - buffer[index++] = addr._1; - buffer[index++] = addr._2; - buffer[index++] = addr._3; - buffer[index++] = addr._4; - - buffer[index++] = (ntohs(this->remoteAddr->sin_port) >> 8) & 0xFF; - buffer[index++] = (ntohs(this->remoteAddr->sin_port) >> 0) & 0xFF; - this->sendMessage(string(buffer, index)); - } else if(this->state = PROXY_INIT_CONNECTION){ - cout << "res!" << endl; - - int index = 0; - if(msg[index++] != 0x05) CERROR("Invalid proxy version response (connection request)"); - if(msg[index++] != 0x00) CERROR("Could not create connection (" + to_string((int) msg[1]) + ")"); - if(msg[index++] != 0x00) CERROR("Invalid proxy rsv response (connection request)"); - if(msg[index++] != 0x01) CERROR("Invalid proxy ip response type"); - - auto rAddr = IPv4{}; - rAddr._1 = msg[index++]; - rAddr._2 = msg[index++]; - rAddr._3 = msg[index++]; - rAddr._4 = msg[index++]; - - uint16_t pHigh = ((uint16_t) msg[index++]) & 0xFF; - uint16_t pLow = ((uint16_t) msg[index++]) & 0xFF; - uint16_t rPort = (pHigh << 8) | pLow; - cout << "Got udp relay " << rAddr.string() << ":" << rPort << endl; - - //Delete old connection - //shutdown(this->fileDescriptor, SHUT_RDWR); - - event_del(this->wEvent); - event_del(this->rEvent); - this->fileDescriptor = 0; - - //Setup relay - this->relayAddr = new sockaddr_in{}; - memset(relayAddr, 0, sizeof(*relayAddr)); - relayAddr->sin_family = AF_INET; - relayAddr->sin_port = htons(rPort); - relayAddr->sin_addr.s_addr = rAddr.addr; - cout << "Relay addr: " << inet_ntoa(relayAddr->sin_addr) << ":" << ntohs(relayAddr->sin_port) << endl; - - this->localAddr = new sockaddr_in{}; - memset(localAddr, 0, sizeof(*localAddr)); - localAddr->sin_family = AF_INET; - { - lock_guard l(portLock); - localAddr->sin_port = this->remoteAddr->sin_port; // = htons(10000 + (port++ % 30000)); - } - localAddr->sin_addr.s_addr = htonl(INADDR_ANY); - - this->fileDescriptor = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - cout << "fd -> " << this->fileDescriptor << endl; - int allow = 1; - if(setsockopt(this->fileDescriptor, SOL_SOCKET, SO_REUSEADDR, &allow, sizeof(int)) < 0) CERROR("Could not enable reuse addr"); - if(bind(this->fileDescriptor, reinterpret_cast(this->localAddr), sizeof(*this->localAddr)) < 0) CERROR("Could nto bind to relay"); - cout << "Bind on " << inet_ntoa(this->localAddr->sin_addr) << ":" << ntohs(this->localAddr->sin_port) << endl; - this->state = PROXY_CONNECTED; - - this->rEvent = event_new(this->evBase, this->fileDescriptor, EV_READ | EV_PERSIST, ProxiedClient::handleEventRead, this); - this->wEvent = event_new(this->evBase, this->fileDescriptor, EV_WRITE, ProxiedClient::handleEventWrite, this); - event_add(rEvent, nullptr); - - threads::Thread([&](){ - threads::self::sleep_for(seconds(1)); - this->proxyInizalisized(); - }); - } -} - -void ProxiedClient::requestProxyConnection() { - char buffer[3]; - buffer[0] = 0x05; //Version - buffer[1] = 1; //One methode - buffer[2] = 0x00; //No auth required - - this->sendMessage(string(buffer, 3)); -} \ No newline at end of file diff --git a/flooder/src/ProxiedClient.cpp b/flooder/src/ProxiedClient.cpp deleted file mode 100644 index 52170cc..0000000 --- a/flooder/src/ProxiedClient.cpp +++ /dev/null @@ -1,175 +0,0 @@ -#include -#include -#include -#include "ProxiedClient.h" -#include "TSClient.h" - -using namespace std; -using namespace ts::flood; - -ProxiedClient::ProxiedClient(event_base* base, const sockaddr_in &proxyAddr, const sockaddr_in &remoteAddr) : evBase(base) { - this->proxyAddr = new sockaddr_in{}; - this->remoteAddr = new sockaddr_in{}; - - memcpy(this->proxyAddr, &proxyAddr, sizeof(proxyAddr)); - memcpy(this->remoteAddr, &remoteAddr, sizeof(proxyAddr)); - - this->client = new TSClient(this); -} - -ProxiedClient::~ProxiedClient() { - delete this->proxyAddr; - delete this->remoteAddr; -} - -#define CERR(msg) \ -do { \ - cerr << "Could not connect: " << msg << "(" << errno << "/" << strerror(errno) << ")" << endl; \ - return false; \ -} while(0) - -#if defined(TCP_CORK) && !defined(TCP_NOPUSH) - #define TCP_NOPUSH TCP_CORK -#endif - -static int enabled = 1; -static int disabled = 0; - -bool ProxiedClient::connect() { - assert(this->state == ProxyState::PROXY_UNCONNECTED); - TAILQ_INIT(&this->writeQueue); - - this->fileDescriptor = socket(AF_INET, SOCK_STREAM, 0); - if(this->fileDescriptor < 0) CERR("Socket setup failed"); - if(::connect(this->fileDescriptor, reinterpret_cast(this->proxyAddr), sizeof(*this->proxyAddr)) < 0) CERR("connect() failed"); - if(setsockopt(this->fileDescriptor, SOL_SOCKET, SO_REUSEADDR, &enabled, sizeof(enabled)) < 0) CERR("could not set reuse addr"); - if(setsockopt(this->fileDescriptor, IPPROTO_TCP, TCP_NOPUSH, &disabled, sizeof(disabled)) < 0) CERR("could not set no push"); - - cout << "Connected to " << inet_ntoa(this->proxyAddr->sin_addr) << endl; - - this->rEvent = event_new(this->evBase, this->fileDescriptor, EV_READ | EV_PERSIST, ProxiedClient::handleEventRead, this); - this->wEvent = event_new(this->evBase, this->fileDescriptor, EV_WRITE, ProxiedClient::handleEventWrite, this); - - event_add(rEvent, nullptr); - this->state = ProxyState::PROXY_INIT_METHODS; - - this->requestProxyConnection(); - return true; -} - -void ProxiedClient::disconnect() { - this->closeConnection(); -} - -void ProxiedClient::closeConnection() { - { - lock_guard lock(this->stateLock); - if(this->state == PROXY_UNCONNECTED) return; - this->state = PROXY_UNCONNECTED; - } - - event_del(this->wEvent); - event_del(this->rEvent); - - this->wEvent = nullptr; - this->rEvent = nullptr; -} - -void ProxiedClient::sendMessage(const std::string& message) { - buffer::RawBuffer* buffer; - if(this->state != PROXY_CONNECTED){ - buffer = new buffer::RawBuffer{message.length()}; - memcpy(buffer->buffer, message.data(), message.length()); - } else { - cout << "Send " << message.length() << " bytes with relay" << endl; - int relayHeaderLength = 2 + 1 + 1 + 4 + 2; - buffer = new buffer::RawBuffer{relayHeaderLength + message.length()}; - buffer->index = 0; - char preBuffer[relayHeaderLength]; - preBuffer[0] = 0x00; - preBuffer[1] = 0x00; - preBuffer[2] = 0x00; - preBuffer[3] = 0x01; - - IPv4 addr{this->relayAddr->sin_addr.s_addr}; - preBuffer[4] = addr._1; - preBuffer[5] = addr._2; - preBuffer[6] = addr._3; - preBuffer[7] = addr._4; - - preBuffer[8] = (ntohs(this->relayAddr->sin_port) >> 8) & 0xFF; - preBuffer[9] = (ntohs(this->relayAddr->sin_port) >> 0) & 0xFF; - //memset(&preBuffer[4], 0, 6); - - memcpy(&buffer->buffer[0], preBuffer, relayHeaderLength); - memcpy(&buffer->buffer[relayHeaderLength], message.data(), message.length()); - } - - { - lock_guard lock(this->queueLock); - TAILQ_INSERT_TAIL(&this->writeQueue, buffer, tail); - } - event_add(this->wEvent, nullptr); -} - -void ProxiedClient::handleMessage(const std::string &message) { - if(this->state == PROXY_UNCONNECTED) return; - if(this->state == PROXY_CONNECTED) return; //TODO - this->handleProxyMessage(message); -} - -extern void hexdump(std::ostream& outs, const std::string& s, size_t line_len = 16); -void ProxiedClient::handleEventWrite(int fd, short, void* ptrClient) { - auto* client = static_cast(ptrClient); - - buffer::RawBuffer* buffer = nullptr; - { - lock_guard lock(client->queueLock); - buffer = TAILQ_FIRST(&client->writeQueue); - if(!buffer) return; - - ssize_t writtenBytes = 0; - if(client->state == PROXY_CONNECTED){ - cout << "Write bytes to relay - " << fd << " - " << inet_ntoa(client->relayAddr->sin_addr) << ":" << ntohs(client->relayAddr->sin_port) << endl; - hexdump(cout, string((const char*) buffer->buffer, buffer->length)); - writtenBytes = sendto(fd, buffer->buffer, buffer->length, 0, (const sockaddr *) client->relayAddr, sizeof(*client->relayAddr)); - } else - writtenBytes = send(fd, &buffer->buffer[buffer->index], buffer->length - buffer->index, 0); - buffer->index += writtenBytes; - cout << "Written: " << writtenBytes << endl; - - if(buffer->index >= buffer->length || client->state == PROXY_CONNECTED) { - TAILQ_REMOVE(&client->writeQueue, buffer, tail); - delete buffer; - } - if(!TAILQ_EMPTY(&client->writeQueue)) - event_add(client->wEvent, nullptr); - } -} - -void ProxiedClient::handleEventRead(int fd, short, void* ptrClient) { - auto* client = static_cast(ptrClient); - - char buffer[1024]; - sockaddr_in remoteAddr{}; - socklen_t remoteAddrSize = sizeof(remoteAddr); - auto read = recvfrom(fd, buffer, 1024, MSG_DONTWAIT, reinterpret_cast(&remoteAddr), &remoteAddrSize); - cout << "Read " << read << " bytes" << endl; - if(read < 0){ - if(errno == EWOULDBLOCK) return; - cerr << "Invalid read: " << errno << "/" << strerror(errno) << endl; - client->disconnect(); - return; - } else if(read == 0){ - cerr << "Client hangs up!" << endl; - client->closeConnection(); - return; - } - - hexdump(cout, string(buffer, read)); - client->handleMessage(string(buffer, read)); -} - -void ProxiedClient::proxyInizalisized() { - this->client->startConnect(); -} \ No newline at end of file diff --git a/flooder/src/ProxiedClient.h b/flooder/src/ProxiedClient.h deleted file mode 100644 index 041abcc..0000000 --- a/flooder/src/ProxiedClient.h +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -namespace ts { - namespace flood { - union IPv4 { - uint32_t addr; - struct __attribute__ ((__packed__)) { - uint8_t _1; - uint8_t _2; - uint8_t _3; - uint8_t _4; - }; - - inline std::string string(){ - std::stringstream ss; - ss << (int) _1 << "." << (int) _2 << "." << (int) _3 << "." << (int) _4; - return ss.str(); - } - }; - - class TSClient; - enum ProxyState { - PROXY_UNCONNECTED, - PROXY_INIT_METHODS, - PROXY_INIT_CONNECTION, - PROXY_CONNECTED - }; - - class ProxiedClient { - public: - ProxiedClient(event_base*,const sockaddr_in& proxyAddr, const sockaddr_in& remoteAddr); - ~ProxiedClient(); - - bool connect(); - void disconnect(); - void closeConnection(); - - void handleMessage(const std::string& message); - void sendMessage(const std::string &); - private: - static void handleEventRead(int, short, void*); - static void handleEventWrite(int, short, void*); - - void requestProxyConnection(); - void handleProxyMessage(const std::string &); - - void proxyInizalisized(); - - event_base* evBase = nullptr; - event* rEvent = nullptr; - event* wEvent = nullptr; - int fileDescriptor; - ProxyState state = ProxyState::PROXY_UNCONNECTED; - threads::Mutex stateLock; - sockaddr_in* proxyAddr = nullptr; - sockaddr_in* relayAddr = nullptr; - sockaddr_in* localAddr = nullptr; - sockaddr_in* remoteAddr = nullptr; - - TAILQ_HEAD(, buffer::RawBuffer) writeQueue; - threads::Mutex queueLock; - - TSClient* client = nullptr; - }; - } -} \ No newline at end of file diff --git a/flooder/src/TSClient.cpp b/flooder/src/TSClient.cpp deleted file mode 100644 index 4205f6c..0000000 --- a/flooder/src/TSClient.cpp +++ /dev/null @@ -1,108 +0,0 @@ -// -// Created by wolverindev on 06.01.18. -// - -#include "TSClient.h" - -using namespace std; -using namespace std::chrono; -using namespace ts::flood; -using namespace ts::protocol; - -TSClient::TSClient(ProxiedClient* con) : connection(con) { - this->cryptionHandler = new connection::CryptionHandler(); - this->cryptionHandler->reset(); -} - -TSClient::~TSClient() {} - -void TSClient::handleMessageRead(const std::string& message) { - if(message.length() < MAC_SIZE + SERVER_HEADER_SIZE) { - cerr << "Invalid pkt length!" << endl; - return; - } - - shared_ptr packet = make_shared(message); - cout << "Having packet " << packet->type().name() << endl; -} - -void TSClient::sendPacket(ts::protocol::ClientPacket &packet, int32_t packetId) { - size_t maxDataLength = 500 - packet.header().length(); - - if(packet.data().length() > maxDataLength){ - cout << "Split packet" << endl; - string error; - - - /* - if(!compressPacket(&packet, error)){ - cerr << "Compress error!" << endl; - return; - } - packet.enableFlag(PacketFlag::Compressed); - */ - if(packet.data().length() > maxDataLength){ - std::vector siblings; - - ClientPacket* root = new ClientPacket(packet.type(), packet.flagMask(), packet.data()); - root->enableFlag(PacketFlag::Fragmented); - //assert(root->hasFlag(PacketFlag::Compressed)); - siblings.push_back(root); - - //Max len - mac - header - while(siblings.back()->data().length() > maxDataLength){ - auto overhead = siblings.back()->data().substr(maxDataLength); - siblings.back()->data(siblings.back()->data().substr(0, maxDataLength)); - - ClientPacket* sib = new ClientPacket(packet.type(), packet.flagMask(), overhead); - sib->toggle(PacketFlag::Fragmented, false); - siblings.push_back(sib); - } - siblings.back()->enableFlag(PacketFlag::Fragmented); - for(auto elm : siblings){ - sendPacket(*elm); - delete elm; - } - return; - } - } - - if (packetId == -1) - packet.applyPacketId(pktIdManager); - else packet.applyPacketId((uint16_t) packetId, 0); - packet.clientId(this->clientId); - - string error = "success"; - if (!this->cryptionHandler->progressPacketOut(&packet, error)) { - cerr << "Invalid crypt -> " << error << endl; - return; - } - - this->connection->sendMessage(packet.mac() + packet.header() + packet.data()); -} - -const int InitVersionLength = 4; -const uint8_t InitVersion[InitVersionLength] = {0x06, 0x3b, 0xEC, 0xE9}; - -void TSClient::startConnect() { - int maxBufferSize = 512; - size_t bufferIndex = 0; - uint8_t buffer[maxBufferSize]; - string error = "success"; - - memcpy(buffer, InitVersion, InitVersionLength); - bufferIndex += InitVersionLength; - buffer[bufferIndex++] = 0x00; //Login state - - int64_t millis = duration_cast(system_clock::now().time_since_epoch()).count(); - memcpy(&buffer[5], &millis, 4); - bufferIndex += 4; - //generate the alpha key - for (int i = 0; i < 4; i++) buffer[bufferIndex++] = (uint8_t) std::rand(); - bufferIndex += 8; //Reserved bytes - - ClientPacket pkt(ts::protocol::PacketTypeInfo::Init1, string((char *) buffer, bufferIndex)); - pkt.clientId(0); - pkt.toggle(ts::protocol::PacketFlag::Unencrypted, true); - this->sendPacket(pkt, 101); -} \ No newline at end of file diff --git a/flooder/src/TSClient.h b/flooder/src/TSClient.h deleted file mode 100644 index df3001f..0000000 --- a/flooder/src/TSClient.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include "ProxiedClient.h" -#include -#include -#include - -namespace ts { - namespace flood { - enum TSClientConnectionState { - TSC_UNCONNECTED, - TSC_PRE, - TSC_RSA, - TSC_HIGH, - TSC_CONNECTED - }; - - class TSClient { - public: - TSClient(ProxiedClient*); - ~TSClient(); - - void startConnect(); - void handleMessageRead(const std::string&); - - void sendPacket(ts::protocol::ClientPacket &packet, int32_t packetId = -1); - private: - ProxiedClient* connection; - TSClientConnectionState state = TSClientConnectionState::TSC_UNCONNECTED; - protocol::PacketIdManager pktIdManager; - ts::connection::CryptionHandler* cryptionHandler = nullptr; - - ClientId clientId = 0; - }; - } -} \ No newline at end of file diff --git a/server/src/client/SpeakingClient.cpp b/server/src/client/SpeakingClient.cpp index ddacc6c..68671ac 100644 --- a/server/src/client/SpeakingClient.cpp +++ b/server/src/client/SpeakingClient.cpp @@ -345,6 +345,19 @@ HWID_REGEX(ios, "^[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}$" CommandResult SpeakingClient::handleCommandClientInit(Command& cmd) { TIMING_START(timings); + + { + lock_guard lock(this->server->join_attempts_lock); + auto inetAddr = this->getPeerIp(); + if(config::voice::clientConnectLimit > 0 && this->server->join_attempts[inetAddr] + 1 > config::voice::clientConnectLimit) + return {findError("client_is_flooding"), "To many joins per second per ip"}; + if(config::voice::connectLimit > 0 && this->server->join_attempts["_"] + 1 > config::voice::connectLimit) + return {findError("client_is_flooding"), "To many joins per second"}; + this->server->join_attempts[inetAddr]++; + this->server->join_attempts["_"]++; + } + TIMING_STEP(timings, "join atmp c"); + if(!DatabaseHelper::assignDatabaseId(this->server->getSql(), this->server->getServerId(), _this.lock())) return {findError("vs_critical"), "Could not assign database id!"}; TIMING_STEP(timings, "db assign "); this->server->getGroupManager()->enableCache(this->getClientDatabaseId()); @@ -427,18 +440,6 @@ CommandResult SpeakingClient::handleCommandClientInit(Command& cmd) { debugMessage(this->getServerId(), "{} Got client init. (HWID: {})", CLIENT_STR_LOG_PREFIX, this->getHardwareId()); TIMING_STEP(timings, "props apply"); - { - lock_guard lock(this->server->join_attempts_lock); - auto inetAddr = this->getPeerIp(); - if(config::voice::clientConnectLimit > 0 && this->server->join_attempts[inetAddr] + 1 > config::voice::clientConnectLimit) - return {findError("client_is_flooding"), "To many joins per second per ip"}; - if(config::voice::connectLimit > 0 && this->server->join_attempts["_"] + 1 > config::voice::connectLimit) - return {findError("client_is_flooding"), "To many joins per second"}; - this->server->join_attempts[inetAddr]++; - this->server->join_attempts["_"]++; - } - TIMING_STEP(timings, "join atmp c"); - auto permissions_list = this->permissionValues(permission::PERMTEST_ORDERED, { permission::b_virtualserver_join_ignore_password, permission::b_client_ignore_bans,