Rewrite
This commit is contained in:
Anonymous275
2020-08-21 20:57:41 +03:00
parent 5d6f2b93b2
commit ccdbc51b30
53 changed files with 2150 additions and 1626 deletions
+289
View File
@@ -0,0 +1,289 @@
///
/// Created by Anonymous275 on 7/18/2020
///
#include "Security/Enc.h"
#include <filesystem>
#include <Windows.h>
#include "Logger.h"
#include <fstream>
#include <sstream>
#include <string>
#include <thread>
#define MAX_KEY_LENGTH 255
#define MAX_VALUE_NAME 16383
int TraceBack = 0;
std::string GameDir;
void lowExit(int code){
TraceBack = 0;
std::string msg =
Sec("Failed to find the game please launch it. Report this if the issue persists code ");
error(msg+std::to_string(code));
std::this_thread::sleep_for(std::chrono::seconds(10));
exit(2);
}
void Exit(int code){
TraceBack = 0;
std::string msg =
Sec("Sorry. We do not support cracked copies report this if you believe this is a mistake code ");
error(msg+std::to_string(code));
std::this_thread::sleep_for(std::chrono::seconds(10));
exit(3);
}
void SteamExit(int code){
TraceBack = 0;
std::string msg =
Sec("Illegal steam modifications detected report this if you believe this is a mistake code ");
error(msg+std::to_string(code));
std::this_thread::sleep_for(std::chrono::seconds(10));
exit(4);
}
std::string GetGameDir(){
if(TraceBack != 3)Exit(0);
return GameDir.substr(0,GameDir.find_last_of('\\'));
}
LONG OpenKey(HKEY root,const char* path,PHKEY hKey){
return RegOpenKeyEx(root, reinterpret_cast<LPCSTR>(path), 0, KEY_READ, hKey);
}
std::string QueryKey(HKEY hKey,int ID){
TCHAR achKey[MAX_KEY_LENGTH]; // buffer for subkey name
DWORD cbName; // size of name string
TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name
DWORD cchClassName = MAX_PATH; // size of class string
DWORD cSubKeys=0; // number of subkeys
DWORD cbMaxSubKey; // longest subkey size
DWORD cchMaxClass; // longest class string
DWORD cValues; // number of values for key
DWORD cchMaxValue; // longest value name
DWORD cbMaxValueData; // longest value data
DWORD cbSecurityDescriptor; // size of security descriptor
FILETIME ftLastWriteTime; // last write time
DWORD i, retCode;
TCHAR achValue[MAX_VALUE_NAME];
DWORD cchValue = MAX_VALUE_NAME;
retCode = RegQueryInfoKey(
hKey, // key handle
achClass, // buffer for class name
&cchClassName, // size of class string
nullptr, // reserved
&cSubKeys, // number of subkeys
&cbMaxSubKey, // longest subkey size
&cchMaxClass, // longest class string
&cValues, // number of values for this key
&cchMaxValue, // longest value name
&cbMaxValueData, // longest value data
&cbSecurityDescriptor, // security descriptor
&ftLastWriteTime); // last write time
BYTE* buffer = new BYTE[cbMaxValueData];
ZeroMemory(buffer, cbMaxValueData);
if (cSubKeys){
for (i=0; i<cSubKeys; i++){
cbName = MAX_KEY_LENGTH;
retCode = RegEnumKeyEx(hKey, i,achKey,&cbName,nullptr,nullptr,nullptr,&ftLastWriteTime);
if (retCode == ERROR_SUCCESS){
if(strcmp(achKey,Sec("Steam App 284160")) == 0){
return achKey;
}
}
}
}
if (cValues){
for (i=0, retCode = ERROR_SUCCESS; i<cValues; i++){
cchValue = MAX_VALUE_NAME;
achValue[0] = '\0';
retCode = RegEnumValue(hKey, i,achValue,&cchValue,nullptr,nullptr,nullptr,nullptr);
if (retCode == ERROR_SUCCESS ){
DWORD lpData = cbMaxValueData;
buffer[0] = '\0';
LONG dwRes = RegQueryValueEx(hKey, achValue, nullptr, nullptr, buffer, &lpData);
std::string data = reinterpret_cast<const char *const>(buffer);
std::string key = achValue;
switch (ID){
case 1: if(key == Sec("SteamExe")){
auto p = data.find_last_of('/');
if(p != std::string::npos)return data.substr(0,p);
}break;
case 2: if(key == Sec("Name") && data == Sec("BeamNG.drive"))return data;break;
case 3: if(key == Sec("rootpath"))return data;break;
case 4: if(key == Sec("userpath_override"))return data;
default: break;
}
}
}
}
delete [] buffer;
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)) {
auto pos = entry.path().filename().string().find('.');
if (pos != std::string::npos) {
a.emplace_back(entry.path().string());
}else FileList(a,entry.path().string());
}
}
bool Find(const std::string& FName,const std::string& Path){
std::vector<std::string> FS;
FileList(FS,Path+Sec("/userdata"));
for(std::string&a : FS){
if(a.find(FName) != std::string::npos){
FS.clear();
return true;
}
}
FS.clear();
return false;
}
bool FindHack(const std::string& Path){
bool s = true;
for (const auto &entry : fs::directory_iterator(Path)) {
std::string Name = entry.path().filename().string();
for(char&c : Name)c = char(tolower(c));
if(Name == Sec("steam.exe"))s = false;
if(Name.find(Sec("greenluma")) != -1)return true;
Name.clear();
}
return s;
}
std::vector<std::string> GetID(const std::string& log){
std::string vec,t,r;
std::vector<std::string> Ret;
std::ifstream f(log.c_str(), std::ios::binary);
f.seekg(0, std::ios_base::end);
std::streampos fileSize = f.tellg();
vec.resize(size_t(fileSize) + 1);
f.seekg(0, std::ios_base::beg);
f.read(&vec[0], fileSize);
f.close();
std::stringstream ss(vec);
bool S = false;
while (std::getline(ss, t, '{')) {
if(!S)S = true;
else{
for(char& c : t){
if(isdigit(c))r += c;
}
break;
}
}
Ret.emplace_back(r);
r.clear();
S = false;
bool L = true;
while (std::getline(ss, t, '}')) {
if(L){
L = false;
continue;
}
for(char& c : t){
if(c == '"'){
if(!S)S = true;
else{
if(r.length() > 10) {
Ret.emplace_back(r);
}
r.clear();
S = false;
continue;
}
}
if(isdigit(c))r += c;
}
}
vec.clear();
return Ret;
}
std::string GetManifest(const std::string& Man){
std::string vec;
std::ifstream f(Man.c_str(), std::ios::binary);
f.seekg(0, std::ios_base::end);
std::streampos fileSize = f.tellg();
vec.resize(size_t(fileSize) + 1);
f.seekg(0, std::ios_base::beg);
f.read(&vec[0], fileSize);
f.close();
std::string ToFind = Sec("\"LastOwner\"\t\t\"");
int pos = int(vec.find(ToFind));
if(pos != -1){
pos += int(ToFind.length());
vec = vec.substr(pos);
return vec.substr(0,vec.find('\"'));
}else return "";
}
bool IDCheck(std::string Man, std::string steam){
bool a = false,b = true;
int pos = int(Man.find(Sec("steamapps")));
if(pos == -1)Exit(5);
Man = Man.substr(0,pos+9) + Sec("/appmanifest_284160.acf");
steam += Sec("/config/loginusers.vdf");
if(fs::exists(Man) && fs::exists(steam)){
for(const std::string&ID : GetID(steam)){
if(ID == GetManifest(Man))b = false;
}
if(b)Exit(6);
}else a = true;
return a;
}
void LegitimacyCheck(){
std::string Result,T;
std::string K1 = Sec("Software\\Valve\\Steam");
std::string K2 = Sec("Software\\Valve\\Steam\\Apps\\284160");
std::string K3 = Sec("Software\\BeamNG\\BeamNG.drive");
HKEY hKey;
LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K1.c_str(), &hKey);
if(dwRegOPenKey == ERROR_SUCCESS) {
Result = QueryKey(hKey, 1);
if(Result.empty())Exit(1);
if(fs::exists(Result)){
if(!Find(Sec("284160.json"),Result))Exit(2);
if(FindHack(Result))SteamExit(1);
}else Exit(3);
T = Result;
Result.clear();
TraceBack++;
}else Exit(4);
K1.clear();
RegCloseKey(hKey);
dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K2.c_str(), &hKey);
if(dwRegOPenKey == ERROR_SUCCESS) {
Result = QueryKey(hKey, 2);
if(Result.empty())lowExit(1);
TraceBack++;
}else lowExit(2);
K2.clear();
RegCloseKey(hKey);
dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K3.c_str(), &hKey);
if(dwRegOPenKey == ERROR_SUCCESS) {
Result = QueryKey(hKey, 3);
if(Result.empty())lowExit(3);
if(IDCheck(Result,T))lowExit(5);
GameDir = Result;
TraceBack++;
}else lowExit(4);
K3.clear();
Result.clear();
RegCloseKey(hKey);
if(TraceBack < 3)exit(-1);
}
std::string CheckVer(const std::string &dir){
std::string vec,temp,Path = dir + Sec("\\integrity.json");
std::ifstream f(Path.c_str(), std::ios::binary);
f.seekg(0, std::ios_base::end);
std::streampos fileSize = f.tellg();
vec.resize(size_t(fileSize) + 1);
f.seekg(0, std::ios_base::beg);
f.read(&vec[0], fileSize);
f.close();
vec = vec.substr(vec.find_last_of(Sec("version")),vec.find_last_of('"'));
for(const char &a : vec){
if(isdigit(a) || a == '.')temp+=a;
}
return temp;
}
+92
View File
@@ -0,0 +1,92 @@
///
/// Created by Anonymous275 on 7/16/2020
///
#include "Discord/discord_info.h"
#include "Security/Enc.h"
#include <windows.h>
#include "Startup.h"
#include <tlhelp32.h>
#include "Logger.h"
#include <fstream>
#include <Psapi.h>
void DAS(){
int i = 0;
std::ifstream f(GetEN(), std::ios::binary);
f.seekg(0, std::ios_base::end);
std::streampos fileSize = f.tellg();
if(IsDebuggerPresent() || fileSize > 0x3D0900){
i++;
DAboard();
}
if(i)DAboard();
f.close();
}
void DASM(){ //A mirror to have 2 independent checks
int i = 0;
std::ifstream f(GetEN(), std::ios::binary);
f.seekg(0, std::ios_base::end);
std::streampos fileSize = f.tellg();
if(IsDebuggerPresent() || fileSize > 0x3D0900){
i++;
DAboard();
}
if(i)DAboard();
f.close();
}
DWORD getParentPID(DWORD pid){
HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe = {0};
DWORD ppid = 0;
pe.dwSize = sizeof(PROCESSENTRY32);
if(Process32First(h, &pe)){
do{
if(pe.th32ProcessID == pid){
ppid = pe.th32ParentProcessID;
break;
}
}while(Process32Next(h, &pe));
}
CloseHandle(h);
return ppid;
}
HANDLE getProcess(DWORD pid, LPSTR fname, DWORD sz) {
HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
if (h) {
GetModuleFileNameEx(h, nullptr, fname, sz);
return h;
}
return nullptr;
}
void UnderSimulation(char* argv[]){
DWORD ppid;
std::string Parent(MAX_PATH,0);
ppid = getParentPID(GetCurrentProcessId());
HANDLE Process = getProcess(ppid, &Parent[0], MAX_PATH);
std::string Code = Sec("Code ");
if(Process == nullptr){
error(Code+std::to_string(2));
exit(1);
}
auto P = Parent.find(Sec(".exe"));
if(P != std::string::npos)Parent.resize(P + 4);
else{
error(Code+std::to_string(3));
exit(1);
}
std::string S1 = Sec("\\Windows\\explorer.exe");
std::string S2 = Sec("JetBrains\\CLion");
std::string S3 = Sec("\\Windows\\System32\\cmd.exe");
if(Parent == std::string(argv[0]))return;
if(Parent.find(S1) == 2)return;
if(Parent.find(S2) != std::string::npos)return;
if(Parent.find(S3) == 2)return;
TerminateProcess(Process, 1);
error(Code + std::to_string(4));
exit(1);
}
void SecurityCheck(char* argv[]){
UnderSimulation(argv);
DAS();
}
+85
View File
@@ -0,0 +1,85 @@
#include "Security/Enc.h"
#include <iostream>
#include <sstream>
int LocalKeys[] = {7406809,6967,4810803}; //n e d
int log_power(int n,unsigned int p, int mod){
int result = 1;
for (; p; p >>= 1u){
if (p & 1u)result = int((1LL * result * n) % mod);
n = int((1LL * n * n) % mod);
}
return result;
}
int Enc(int value,int e,int n){
return log_power(value, e, n);
}
int Dec(int value,int d,int n){
return log_power(value, d, n);
}
std::string LocalEnc(const std::string& Data){
std::stringstream stream;
for(const char&c : Data){
stream << std::hex << Enc(uint8_t(c),LocalKeys[1],LocalKeys[0]) << "g";
}
return stream.str();
}
std::string LocalDec(const std::string& Data){
std::stringstream ss(Data);
std::string token,ret;
while (std::getline(ss, token, 'g')) {
if(token.find_first_not_of(Sec("0123456789abcdef")) != std::string::npos)return "";
int c = std::stoi(token, nullptr, 16);
ret += char(Dec(c,LocalKeys[2],LocalKeys[0]));
}
return ret;
}
#include <random>
int Rand(){
std::random_device r;
std::default_random_engine e1(r());
std::uniform_int_distribution<int> uniform_dist(1, 200);
return uniform_dist(e1);
}
std::string Encrypt(std::string msg){
if(msg.size() < 2)return msg;
int R = (Rand()+Rand())/2,T = R;
for(char&c : msg){
if(R > 30)c = char(int(c) + (R-=3));
else c = char(int(c) - (R+=4));
}
return char(T) + msg;
}
std::string Decrypt(std::string msg){
if(msg.size() < 2)return "";
int R = uint8_t(msg.at(0));
if(R > 200 || R < 1)return "";
msg = msg.substr(1);
for(char&c : msg){
if(R > 30)c = char(int(c) - (R-=3));
else c = char(int(c) + (R+=4));
}
return msg;
}
std::string RSA_E(const std::string& Data,int e, int n){
if(e < 10 || n < 10)return "";
std::stringstream stream;
for(const char&c : Data){
stream << std::hex << Enc(uint8_t(c),e,n) << "g";
}
return stream.str();
}
std::string RSA_D(const std::string& Data, int d, int n){
std::stringstream ss(Data);
std::string token,ret;
while (std::getline(ss, token, 'g')) {
if(token.find_first_not_of(Sec("0123456789abcdef")) != std::string::npos)return "";
int c = std::stoi(token, nullptr, 16);
ret += char(Dec(c,d,n));
}
return ret;
}
+71
View File
@@ -0,0 +1,71 @@
///
/// Created by Anonymous275 on 7/19/2020
///
#include "Security/Enc.h"
#include <windows.h>
#include "Security/Game.h"
#include <filesystem>
#include <RestartManager.h>
#include "Logger.h"
#include <thread>
namespace fs = std::experimental::filesystem;
void CheckDirs(){
for (auto& p : fs::directory_iterator(Sec("BeamNG\\mods"))) {
if(fs::is_directory(p.path()))exit(0);
}
}
bool BeamLoad(PCWSTR pszFile){
bool Ret = false;
DWORD dwSession;
WCHAR szSessionKey[CCH_RM_SESSION_KEY+1] = {0};
DWORD dwError = RmStartSession(&dwSession, 0, szSessionKey);
if (dwError == ERROR_SUCCESS) {
dwError = RmRegisterResources(dwSession, 1, &pszFile,
0, nullptr, 0, nullptr);
if (dwError == ERROR_SUCCESS) {
DWORD dwReason;
UINT nProcInfoNeeded;
UINT nProcInfo = 10;
RM_PROCESS_INFO rgpi[10];
dwError = RmGetList(dwSession, &nProcInfoNeeded,&nProcInfo, rgpi, &dwReason);
if (dwError == ERROR_SUCCESS) {
if(nProcInfo == 1){
std::string AppName(50,0);
size_t N;
wcstombs_s(&N,&AppName[0],50, rgpi[0].strAppName, 50);
if(!AppName.find(Sec("BeamNG.drive")) && GamePID == rgpi[0].Process.dwProcessId){
Ret = true;
}
}
}
}
RmEndSession(dwSession);
}
return Ret;
}
void ContinuousCheck(fs::file_time_type last){
std::string path = Sec(R"(BeamNG\mods\BeamMP.zip)");
int i = 0;
while(fs::exists(path) && last == fs::last_write_time(path)){
if(!BeamLoad(SecW(L"BeamNG\\mods\\BeamMP.zip"))) {
if (i < 60)i++;
else {
error(Sec("Mod did not load! launcher closing soon"));
std::this_thread::sleep_for(std::chrono::seconds(5));
exit(0);
}
}else i = 0;
CheckDirs();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
exit(0);
}
void SecureMods(){
fs::file_time_type last = fs::last_write_time(Sec(R"(BeamNG\mods\BeamMP.zip)"));
auto* HandleCheck = new std::thread(ContinuousCheck,last);
HandleCheck->detach();
delete HandleCheck;
}