security revisions, faster checks

This commit is contained in:
Anonymous275 2020-05-05 17:28:35 +03:00
parent 3d3fe7f5a8
commit f4d99eea41
6 changed files with 72 additions and 50 deletions

View File

@ -66,8 +66,8 @@ std::string Parse(const std::string& Data){
if(MPDEV)std::cout << "Core Network on start!" << std::endl; if(MPDEV)std::cout << "Core Network on start!" << std::endl;
WSADATA wsaData; WSADATA wsaData;
int iResult; int iResult;
SOCKET ListenSocket = INVALID_SOCKET; auto ListenSocket = INVALID_SOCKET;
SOCKET ClientSocket = INVALID_SOCKET; auto ClientSocket = INVALID_SOCKET;
struct addrinfo *result = nullptr; struct addrinfo *result = nullptr;
struct addrinfo hints{}; struct addrinfo hints{};
@ -136,12 +136,10 @@ std::string Parse(const std::string& Data){
std::string data = recvbuf; std::string data = recvbuf;
data.resize(iResult); data.resize(iResult);
Response = Parse(data) + "\n"; Response = Parse(data) + "\n";
} } else if (iResult == 0){
if (MPDEV)std::cout << "(Core) Connection closing...\n";
else if (iResult == 0) }else{
if(MPDEV)std::cout << "(Core) Connection closing...\n"; if(MPDEV)std::cout << "(Core) recv failed with error: " << WSAGetLastError() << std::endl;
else {
if(MPDEV)std::cout << "(Core) recv failed with error: " << WSAGetLastError() << std::endl;
closesocket(ClientSocket); closesocket(ClientSocket);
WSACleanup(); WSACleanup();
} }

View File

@ -1,12 +1,13 @@
/// ///
/// Created by Anonymous275 on 3/16/2020 /// Created by Anonymous275 on 3/16/2020
/// ///
#include <filesystem>
#include <Windows.h> #include <Windows.h>
#include <iostream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <array> #include <array>
#include <iostream> #include <thread>
#define MAX_KEY_LENGTH 255 #define MAX_KEY_LENGTH 255
#define MAX_VALUE_NAME 16383 #define MAX_VALUE_NAME 16383
@ -14,7 +15,7 @@
void Exit(const std::string& Msg); void Exit(const std::string& Msg);
int TraceBack = 0; int TraceBack = 0;
std::vector<std::string> Data; std::vector<std::string> SData;
std::string Result; std::string Result;
std::string HTA(const std::string& hex) std::string HTA(const std::string& hex)
@ -124,8 +125,30 @@ std::string QueryKey(HKEY hKey,int ID)
delete [] buffer; delete [] buffer;
return ""; return "";
} }
namespace fs = std::experimental::filesystem;
void FileList(std::vector<std::string>&a,const std::string& Path){
for (const auto &entry : fs::directory_iterator(Path)) {
int pos = entry.path().filename().string().find('.');
if (pos != std::string::npos) {
a.emplace_back(entry.path().string());
}else FileList(a,entry.path().string());
}
}
bool Continue = false;
void Find(const std::string& FName,const std::string& Path){
auto *FS = new std::vector<std::string>;
FileList(*FS,Path);
for(const std::string&a : *FS){
if(a.find(FName)!=std::string::npos)Continue = true;
}
delete FS;
}
void ExitError(){
std::string MSG2 = HTA("4572726f722120506c6561736520436f6e7461637420537570706f7274");
Exit(MSG2 + " Code 2");
}
std::vector<std::string> Check(){ void Check(){
/*HKEY_CLASSES_ROOT\\beamng\\DefaultIcon /*HKEY_CLASSES_ROOT\\beamng\\DefaultIcon
HKEY_USERS\.DEFAULT\Software\Classes\steam\Shell\Open\Command HKEY_USERS\.DEFAULT\Software\Classes\steam\Shell\Open\Command
HKEY_CURRENT_USER\\Software\Valve\Steam\Apps\284160*/ HKEY_CURRENT_USER\\Software\Valve\Steam\Apps\284160*/
@ -144,29 +167,14 @@ std::vector<std::string> Check(){
if(dwRegOPenKey == ERROR_SUCCESS) { if(dwRegOPenKey == ERROR_SUCCESS) {
Result = QueryKey(hKey, 1); Result = QueryKey(hKey, 1);
if(Result.empty()){Exit(MSG1 + " Code 1");} if(Result.empty()){Exit(MSG1 + " Code 1");}
Data.push_back(Result); SData.push_back(Result);
Result = Result.substr(1,Result.find_last_of('\\')) + HTA("7573657264617461"); Result = Result.substr(1,Result.find_last_of('\\')) + HTA("7573657264617461");
struct stat buffer{}; struct stat buffer{};
if(stat (Result.c_str(), &buffer) == 0){ if(stat (Result.c_str(), &buffer) == 0){
std::string cmd = HTA("6469722022") + Result + HTA("5c3238343136302e6a736f6e22202f73202f70"); auto *F = new std::thread(Find,HTA("3238343136302e6a736f6e"),Result);
std::array<char, 128> Buffer{}; F->join();
std::string result; delete F;
std::unique_ptr<FILE, decltype(&_pclose)> pipe(_popen(cmd.c_str(), "r"), _pclose); if(!Continue)Exit(MSG2 + " Code 2");
cmd.clear();
if (!pipe) {
Exit(MSG2+ ". Code: 1");
}
while (fgets(Buffer.data(), Buffer.size(), pipe.get()) != nullptr) {
result += Buffer.data();
}
std::string File = HTA("3238343136302e6a736f6e");
if(result.size() > 100 && result.find(File) != std::string::npos){
int pos = int(result.find(File)) + 9;
while(pos != result.length() && !isdigit(result.at(pos))){pos++;}
if(pos - result.length() < 5)Exit(MSG2 + " Code 2");
if((result.substr(pos,1).at(0) - 48) == 0) Exit(MSG1 + " Code 2");
}else Exit(MSG2 + " Code 2");
result.clear();
}else Exit(MSG2 + ". Code: 3"); }else Exit(MSG2 + ". Code: 3");
Result.clear(); Result.clear();
TraceBack++; TraceBack++;
@ -177,7 +185,7 @@ std::vector<std::string> Check(){
if(dwRegOPenKey == ERROR_SUCCESS) { if(dwRegOPenKey == ERROR_SUCCESS) {
Result = QueryKey(hKey, 2); Result = QueryKey(hKey, 2);
if(Result.empty()){Exit(MSG1 + " Code 3");} if(Result.empty()){Exit(MSG1 + " Code 3");}
Data.push_back(Result); SData.push_back(Result);
TraceBack++; TraceBack++;
}else{Exit(MSG3);} }else{Exit(MSG3);}
K2.clear(); K2.clear();
@ -188,7 +196,7 @@ std::vector<std::string> Check(){
if(Result.empty()){ if(Result.empty()){
Exit(MSG2 + ". Code: 5"); Exit(MSG2 + ". Code: 5");
} }
Data.push_back(Result); SData.push_back(Result);
TraceBack++; TraceBack++;
} }
//Memory Cleaning //Memory Cleaning
@ -198,7 +206,6 @@ std::vector<std::string> Check(){
MSG2.clear(); MSG2.clear();
MSG3.clear(); MSG3.clear();
RegCloseKey(hKey); RegCloseKey(hKey);
return Data;
} }
std::string HWID(){ std::string HWID(){

View File

@ -6,21 +6,23 @@
void Download(const std::string& URL,const std::string& path); void Download(const std::string& URL,const std::string& path);
std::string HTTP_REQUEST(const std::string&url,int port); std::string HTTP_REQUEST(const std::string&url,int port);
std::string HTA(const std::string& hex);
void SystemExec(const std::string& cmd); void SystemExec(const std::string& cmd);
void WinExec(const std::string& cmd); void WinExec(const std::string& cmd);
void CheckForUpdates(const std::string& CV){ void CheckForUpdates(const std::string& CV){
system ("cls"); system ("cls");
std::string HTTP = HTTP_REQUEST("https://beamng-mp.com/builds/launcher?version=true",443); std::string link = "https://beamng-mp.com/builds/launcher?version=true";
std::string HTTP = HTTP_REQUEST(link,443);
HTTP = HTTP.substr(HTTP.find_last_of("ver=")+1); HTTP = HTTP.substr(HTTP.find_last_of("ver=")+1);
link = "https://beamng-mp.com/builds/launcher?download=true";
struct stat buffer{}; struct stat buffer{};
if(stat ("BeamMP-Launcher.back", &buffer) == 0)remove("BeamMP-Launcher.back"); if(stat ("BeamMP-Launcher.back", &buffer) == 0)remove("BeamMP-Launcher.back");
if(HTTP > CV){ if(HTTP > CV){
std::cout << "Update found!" << std::endl; std::cout << "Update found!" << std::endl;
std::cout << "Updating..." << std::endl; std::cout << "Updating..." << std::endl;
SystemExec("rename BeamMP-Launcher.exe BeamMP-Launcher.back>nul"); SystemExec("rename BeamMP-Launcher.exe BeamMP-Launcher.back>nul");
Download("https://beamng-mp.com/builds/launcher?download=true", "BeamMP-Launcher.exe"); Download(link, "BeamMP-Launcher.exe");
WinExec("BeamMP-Launcher.exe"); WinExec("BeamMP-Launcher.exe");
exit(1); exit(1);
}else{ }else{

View File

@ -24,6 +24,7 @@ std::string HTTP_REQUEST(const std::string& IP,int port){
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
} }
curl_global_cleanup();
return readBuffer; return readBuffer;
} }

View File

@ -16,17 +16,21 @@ void StartGame(const std::string&ExeDir,const std::string&Current);
std::string HTTP_REQUEST(const std::string&url,int port); std::string HTTP_REQUEST(const std::string&url,int port);
void CheckForUpdates(const std::string& CV); void CheckForUpdates(const std::string& CV);
std::vector<std::string> GetDiscordInfo(); std::vector<std::string> GetDiscordInfo();
extern std::vector<std::string> SData;
std::vector<std::string> GlobalInfo; std::vector<std::string> GlobalInfo;
std::vector<std::string> Check();
std::string getHardwareID(); std::string getHardwareID();
int DEFAULT_PORT = 4444; int DEFAULT_PORT = 4444;
void Discord_Main(); void Discord_Main();
bool MPDEV = false; bool MPDEV = false;
void ProxyStart(); void ProxyStart();
void ExitError();
void Check();
void SystemExec(const std::string& cmd){ void SystemExec(const std::string& cmd){
system(cmd.c_str()); system(cmd.c_str());
} }
void WinExec(const std::string& cmd){ void WinExec(const std::string& cmd){
WinExec(cmd.c_str(), SW_HIDE); WinExec(cmd.c_str(), SW_HIDE);
} }
@ -83,8 +87,9 @@ int main(int argc, char* argv[]){
const unsigned long long NPos = std::string::npos; const unsigned long long NPos = std::string::npos;
struct stat info{}; struct stat info{};
std::string ver = "0.92", Path = CheckDir(argv[0],ver),HTTP_Result; std::string ver = "0.921", link, Path = CheckDir(argv[0],ver),HTTP_Result;
CheckForUpdates(ver); std::thread CFU(CheckForUpdates,ver);
CFU.join();
if(argc > 1){ if(argc > 1){
std::string Port = argv[1]; std::string Port = argv[1];
if(Port.find_first_not_of("0123456789") == NPos){ if(Port.find_first_not_of("0123456789") == NPos){
@ -102,7 +107,8 @@ int main(int argc, char* argv[]){
} }
std::cout << "Client Connected!" << std::endl; std::cout << "Client Connected!" << std::endl;
HTTP_Result = HTTP_REQUEST("https://beamng-mp.com/entitlement?did="+GlobalInfo.at(2),443); link = "https://beamng-mp.com/entitlement?did="+GlobalInfo.at(2);
HTTP_Result = HTTP_REQUEST(link,443);
if(HTTP_Result.find("\"MDEV\"") == NPos){ if(HTTP_Result.find("\"MDEV\"") == NPos){
if (HTTP_Result.find("\"MOD\"") == NPos && HTTP_Result.find("\"EA\"") == NPos){ if (HTTP_Result.find("\"MOD\"") == NPos && HTTP_Result.find("\"EA\"") == NPos){
if (HTTP_Result.find("\"SUPPORT\"") == NPos && HTTP_Result.find("\"YT\"") == NPos){ if (HTTP_Result.find("\"SUPPORT\"") == NPos && HTTP_Result.find("\"YT\"") == NPos){
@ -111,21 +117,27 @@ int main(int argc, char* argv[]){
} }
}else MPDEV = true; }else MPDEV = true;
//Security //Security
std::vector<std::string> Data = Check(); auto*Sec = new std::thread(Check);
std::string GamePath = Data.at(2); Sec->join();
delete Sec;
if(SData.size() != 3)ExitError();
std::string GamePath = SData.at(2);
if(MPDEV)std::cout << "You own BeamNG on this machine!" << std::endl; if(MPDEV)std::cout << "You own BeamNG on this machine!" << std::endl;
std::cout << "Game Version : " << CheckVer(GamePath) << std::endl; std::cout << "Game Version : " << CheckVer(GamePath) << std::endl;
std::string ExeDir = "\""+GamePath.substr(0,GamePath.find_last_of('\\')) + R"(\Bin64\BeamNG.drive.x64.exe")"; std::string ExeDir = "\""+GamePath.substr(0,GamePath.find_last_of('\\')) + R"(\Bin64\BeamNG.drive.x64.exe")";
std::string Settings = Path + "\\settings\\uiapps-layouts.json"; std::string Settings = Path + "\\settings\\uiapps-layouts.json";
if(stat(Settings.c_str(),&info)!=0){ if(stat(Settings.c_str(),&info)!=0){
link = "https://beamng-mp.com/client-data";
std::cout << "Downloading default config..." << std::endl; std::cout << "Downloading default config..." << std::endl;
Download("https://beamng-mp.com/client-data",Settings); Download(link,Settings);
std::cout << "Download Complete!" << std::endl; std::cout << "Download Complete!" << std::endl;
} }
std::cout << "Downloading mod..." << std::endl; std::cout << "Downloading mod..." << std::endl;
Download("https://beamng-mp.com/builds/client?did="+GlobalInfo.at(2),Path + R"(\mods\BeamMP.zip)"); link = "https://beamng-mp.com/builds/client?did="+GlobalInfo.at(2);
Download(link,Path + R"(\mods\BeamMP.zip)");
std::cout << "Download Complete!" << std::endl; std::cout << "Download Complete!" << std::endl;
link.clear();
if(!MPDEV){ if(!MPDEV){
std::thread Game(StartGame,ExeDir,(Path + "\\")); std::thread Game(StartGame,ExeDir,(Path + "\\"));
Game.detach(); Game.detach();

View File

@ -56,7 +56,7 @@ void RUDPSEND(const std::string&Data,bool Rel){
<< " : " << " : "
<< Data.substr(0, 10) << Data.substr(0, 10)
<< Data.substr(Data.length() - 10) << std::endl; << Data.substr(Data.length() - 10) << std::endl;
}else if(Data.length() < 100){ }else if(MPDEV && Data.length() < 100){
std::cout << "(Game->Launcher) : " << Data << std::endl; std::cout << "(Game->Launcher) : " << Data << std::endl;
} }
} }
@ -270,6 +270,8 @@ void TCPServerThread(const std::string& IP, int Port){
iResult = shutdown(Socket, SD_SEND); iResult = shutdown(Socket, SD_SEND);
if (iResult == SOCKET_ERROR) { if (iResult == SOCKET_ERROR) {
if(MPDEV)std::cout << "(Proxy) shutdown failed with error: " << WSAGetLastError() << std::endl; if(MPDEV)std::cout << "(Proxy) shutdown failed with error: " << WSAGetLastError() << std::endl;
TCPTerminate = true;
Terminate = true;
closesocket(Socket); closesocket(Socket);
WSACleanup(); WSACleanup();
continue; continue;
@ -295,8 +297,8 @@ void Reset() {
void ProxyThread(const std::string& IP, int Port){ void ProxyThread(const std::string& IP, int Port){
Reset(); Reset();
std::thread t1(TCPServerThread,IP,Port); auto*t1 = new std::thread(TCPServerThread,IP,Port);
t1.detach(); t1->detach();
/*std::thread t2(VehicleNetworkStart); /*std::thread t2(VehicleNetworkStart);
t2.detach();*/ t2.detach();*/
} }