This commit is contained in:
Anonymous275 2020-11-13 22:09:26 +02:00
parent 97cc5a3179
commit a09e5829f3
7 changed files with 72 additions and 17 deletions

View File

@ -7,5 +7,6 @@ void PreGame(int argc, char* argv[],const std::string& GamePath);
void InitGame(const std::string& Dir,const std::string&Current);
std::string CheckVer(const std::string &path);
void SecurityCheck(char* argv[]);
void FindDLL(char* args[]);
std::string GetGameDir();
void LegitimacyCheck();

View File

@ -2,6 +2,7 @@
/// Created by Anonymous275 on 7/20/2020
///
#include "Network/network.h"
#include "Security/Init.h"
#include "Security/Enc.h"
#include "Curl/http.h"
#include <WinSock2.h>
@ -9,9 +10,9 @@
#include "Startup.h"
#include "Memory.h"
#include "Logger.h"
#include <charconv>
#include <thread>
#include <set>
#include <charconv>
extern int TraceBack;
std::set<std::string>* ConfList = nullptr;
@ -25,6 +26,7 @@ bool ModLoaded;
long long ping = -1;
void StartSync(const std::string &Data){
FindDLL(nullptr);
std::string IP = GetAddr(Data.substr(1,Data.find(':')-1));
if(IP.find('.') == -1){
if(IP == "DNS")UlStatus = Sec("UlConnection Failed! (DNS Lookup Failed)");

View File

@ -5,18 +5,19 @@
#include <string>
#include <winsock.h>
#include "Logger.h"
#include "Security/Enc.h"
std::string GetAddr(const std::string&IP){
if(IP.find_first_not_of("0123456789.") == -1)return IP;
WSADATA wsaData;
hostent *host;
if(WSAStartup(514, &wsaData) != 0){
error("WSA Startup Failed!");
error(Sec("WSA Startup Failed!"));
WSACleanup();
return "";
}
host = gethostbyname(IP.c_str());
if(!host){
error("DNS lookup failed! on " + IP);
error(Sec("DNS lookup failed! on ") + IP);
WSACleanup();
return "DNS";
}

View File

@ -96,17 +96,17 @@ void NetReset(){
UlStatus = Sec("Ulstart");
MStatus = " ";
if(UDPSock != (SOCKET)(-1)){
debug("Terminating UDP Socket : " + std::to_string(TCPSock));
debug(Sec("Terminating UDP Socket : ") + std::to_string(TCPSock));
KillSocket(UDPSock);
}
UDPSock = -1;
if(TCPSock != (SOCKET)(-1)){
debug("Terminating TCP Socket : " + std::to_string(TCPSock));
debug(Sec("Terminating TCP Socket : ") + std::to_string(TCPSock));
KillSocket(TCPSock);
}
TCPSock = -1;
if(GSocket != (SOCKET)(-1)){
debug("Terminating GTCP Socket : " + std::to_string(GSocket));
debug(Sec("Terminating GTCP Socket : ") + std::to_string(GSocket));
KillSocket(GSocket);
}
GSocket = -1;
@ -202,7 +202,7 @@ void NetMain(const std::string& IP, int Port){
void TCPGameServer(const std::string& IP, int Port){
GSocket = SetupListener();
while (!TCPTerminate && GSocket != -1){
debug("MAIN LOOP OF GAME SERVER");
debug(Sec("MAIN LOOP OF GAME SERVER"));
GConnected = false;
if(!CServer){
warn(Sec("Connection still alive terminating"));
@ -262,5 +262,5 @@ void TCPGameServer(const std::string& IP, int Port){
GConnected = false;
Terminate = true;
if(CSocket != SOCKET_ERROR)KillSocket(CSocket);
debug("END OF GAME SERVER");
debug(Sec("END OF GAME SERVER"));
}

55
src/Security/DLL.cpp Normal file
View File

@ -0,0 +1,55 @@
///
/// Created by Anonymous275 on 11/13/2020
///
#include "Network/network.h"
#include "Security/Enc.h"
#include <windows.h>
#include "Logger.h"
#include <psapi.h>
#include <string>
#include <thread>
DWORD getParentPID(DWORD pid);
HANDLE getProcess(DWORD pid, LPSTR fname, DWORD sz);
void Kill(){
static bool Run = false;
if(!Run)Run = true;
else return;
while(Run){
std::this_thread::sleep_for(std::chrono::seconds(2));
NetReset();
#ifdef DEBUG
debug(Sec("Attention! NetReset Check!"));
#endif
}
}
void FindDLL(char* args[]){
static auto argv = args;
HANDLE hProcess = GetCurrentProcess();
std::string Parent(MAX_PATH,0);
DWORD ppid = getParentPID(GetCurrentProcessId());
HANDLE Process = getProcess(ppid, &Parent[0], MAX_PATH);
if(Process == nullptr){
HMODULE hMods[1024];
DWORD cbNeeded;
unsigned int i;
if(K32EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)){
for ( i = 1; i < (cbNeeded / sizeof(HMODULE)); i++ ){
TCHAR szModName[MAX_PATH];
if (K32GetModuleFileNameExA(hProcess, hMods[i], szModName, sizeof(szModName) / sizeof(TCHAR))){
std::string Name(szModName),PName(argv[0]);
Name = Name.substr(0,Name.rfind(Sec("\\")));
PName = PName.substr(0,PName.rfind(Sec("\\")));
if(Name == PName){
std::thread t1(Kill);
t1.detach();
}
}
}
}
}
CloseHandle(hProcess);
}

View File

@ -16,16 +16,13 @@ extern int TraceBack;
bool Dev = false;
namespace fs = std::experimental::filesystem;
std::string GetEN(){
static std::string r = Sec("BeamMP-Launcher.exe");
return r;
return std::string(Sec("BeamMP-Launcher.exe"));
}
std::string GetVer(){
static std::string r = Sec("1.70");
return r;
return std::string(Sec("1.70"));
}
std::string GetPatch(){
static std::string r = Sec("");
return r;
return std::string(Sec(""));
}
void ReLaunch(int argc,char*args[]){
std::string Arg;
@ -184,6 +181,7 @@ void InitLauncher(int argc, char* argv[]) {
SetConsoleTitleA((Sec("BeamMP Launcher v") + std::string(GetVer()) + GetPatch()).c_str());
InitLog();
CheckName(argc, argv);
FindDLL(argv);
SecurityCheck(argv);
Discord_Main();
RequestRole();

View File

@ -7,8 +7,6 @@
#include <thread>
#include <iostream>
[[noreturn]] void aa(){
while(true){
std::cout.flush();