diff --git a/src/client_backend/.vs/client_backend/FileContentIndex/0a773b04-27a0-4be0-a68b-891295f5c921.vsidx b/src/client_backend/.vs/client_backend/FileContentIndex/0a773b04-27a0-4be0-a68b-891295f5c921.vsidx deleted file mode 100644 index 55db4f3..0000000 Binary files a/src/client_backend/.vs/client_backend/FileContentIndex/0a773b04-27a0-4be0-a68b-891295f5c921.vsidx and /dev/null differ diff --git a/src/client_backend/.vs/client_backend/FileContentIndex/28cbe01f-de87-4326-99b3-3ba35d4a6943.vsidx b/src/client_backend/.vs/client_backend/FileContentIndex/28cbe01f-de87-4326-99b3-3ba35d4a6943.vsidx deleted file mode 100644 index b8c2a01..0000000 Binary files a/src/client_backend/.vs/client_backend/FileContentIndex/28cbe01f-de87-4326-99b3-3ba35d4a6943.vsidx and /dev/null differ diff --git a/src/client_backend/.vs/client_backend/FileContentIndex/2922cbe9-a711-40e2-b117-bdc69f70cec3.vsidx b/src/client_backend/.vs/client_backend/FileContentIndex/2922cbe9-a711-40e2-b117-bdc69f70cec3.vsidx deleted file mode 100644 index ad17d7a..0000000 Binary files a/src/client_backend/.vs/client_backend/FileContentIndex/2922cbe9-a711-40e2-b117-bdc69f70cec3.vsidx and /dev/null differ diff --git a/src/client_backend/.vs/client_backend/FileContentIndex/688d97b3-b220-418d-8237-683241098d61.vsidx b/src/client_backend/.vs/client_backend/FileContentIndex/688d97b3-b220-418d-8237-683241098d61.vsidx deleted file mode 100644 index e2b0739..0000000 Binary files a/src/client_backend/.vs/client_backend/FileContentIndex/688d97b3-b220-418d-8237-683241098d61.vsidx and /dev/null differ diff --git a/src/client_backend/.vs/client_backend/FileContentIndex/8767ae9d-6aaf-4097-9284-3b864a82fb64.vsidx b/src/client_backend/.vs/client_backend/FileContentIndex/8767ae9d-6aaf-4097-9284-3b864a82fb64.vsidx new file mode 100644 index 0000000..107cdb6 Binary files /dev/null and b/src/client_backend/.vs/client_backend/FileContentIndex/8767ae9d-6aaf-4097-9284-3b864a82fb64.vsidx differ diff --git a/src/client_backend/.vs/client_backend/FileContentIndex/e24c7977-b6eb-42d8-a0b4-34deb626263c.vsidx b/src/client_backend/.vs/client_backend/FileContentIndex/e24c7977-b6eb-42d8-a0b4-34deb626263c.vsidx deleted file mode 100644 index 0a2245e..0000000 Binary files a/src/client_backend/.vs/client_backend/FileContentIndex/e24c7977-b6eb-42d8-a0b4-34deb626263c.vsidx and /dev/null differ diff --git a/src/client_backend/.vs/client_backend/v17/.suo b/src/client_backend/.vs/client_backend/v17/.suo index ec2a649..7f61e72 100644 Binary files a/src/client_backend/.vs/client_backend/v17/.suo and b/src/client_backend/.vs/client_backend/v17/.suo differ diff --git a/src/client_backend/.vs/client_backend/v17/Browse.VC.db b/src/client_backend/.vs/client_backend/v17/Browse.VC.db index df7f96e..c9c3873 100644 Binary files a/src/client_backend/.vs/client_backend/v17/Browse.VC.db and b/src/client_backend/.vs/client_backend/v17/Browse.VC.db differ diff --git a/src/client_backend/.vs/client_backend/v17/Solution.VC.db b/src/client_backend/.vs/client_backend/v17/Solution.VC.db new file mode 100644 index 0000000..2fab823 Binary files /dev/null and b/src/client_backend/.vs/client_backend/v17/Solution.VC.db differ diff --git a/src/client_backend/.vs/client_backend/v17/ipch/AutoPCH/29ce916351e49153/CLIENT_BACKEND.ipch b/src/client_backend/.vs/client_backend/v17/ipch/AutoPCH/29ce916351e49153/CLIENT_BACKEND.ipch index c06854d..5a01314 100644 Binary files a/src/client_backend/.vs/client_backend/v17/ipch/AutoPCH/29ce916351e49153/CLIENT_BACKEND.ipch and b/src/client_backend/.vs/client_backend/v17/ipch/AutoPCH/29ce916351e49153/CLIENT_BACKEND.ipch differ diff --git a/src/client_backend/.vs/client_backend/v17/ipch/AutoPCH/a00bb0a195aaa042/VCTMP4316_955785.CLIENT_BACKEND.00000000.ipch b/src/client_backend/.vs/client_backend/v17/ipch/AutoPCH/a00bb0a195aaa042/VCTMP4316_955785.CLIENT_BACKEND.00000000.ipch new file mode 100644 index 0000000..97d5151 Binary files /dev/null and b/src/client_backend/.vs/client_backend/v17/ipch/AutoPCH/a00bb0a195aaa042/VCTMP4316_955785.CLIENT_BACKEND.00000000.ipch differ diff --git a/src/client_backend/client_backend.cpp b/src/client_backend/client_backend.cpp index 6b48c9b..5ddfa75 100644 --- a/src/client_backend/client_backend.cpp +++ b/src/client_backend/client_backend.cpp @@ -3,49 +3,33 @@ #include #include #include -#include +//#include #include "md5hash.h" #include "connect.h" #include "scan.h" #include "app_ctrl.h" #include "queue_ctrl.h" int main() { - printf("welcome to the jakach security tool\n"); - //main loop, call queue function and so on. - char a[100] = "hello_from_queue0\n"; - char b[100] = "hello_from_queue1\n"; - char c[100] = "hello_from_queue2\n"; - printf("a:%s\n", a); - printf("b:%s\n", b); - printf("c:%s\n\n\n", c); + printf("welcome to the jakach security tool main thread\n"); + //main thread: + /* watches for notifications on bus + * start threads (scans etc); only one at a time may run + * updates settings etc + * start scheduled tasks + + + */ + while (!app_stop()) { + //run all the tasks described above - - printf("pushing a:%d\n", queue_push(a)); - printf("size:%d\n", get_queue_size()); - printf("pushing b:%d\n", queue_push(b)); - printf("size:%d\n", get_queue_size()); - printf("pushing c:%d\n", queue_push(c)); - printf("size:%d\n", get_queue_size()); - printf("a:%s\n", a); - printf("b:%s\n", b); - printf("c: % s\n\n\n", c); - - printf("popping a:%d\n", queue_pop(a)); - printf("size:%d\n", get_queue_size()); - printf("popping b:%d\n", queue_pop(b)); - printf("size:%d\n", get_queue_size()); - printf("popping c:%d\n", queue_pop(c)); - printf("size:%d\n", get_queue_size()); - printf("a:%s\n", a); - printf("b:%s\n", b); - printf("c:%s\n", c); - - - /* + } - char md5Hash[2 * MD5_DIGEST_LENGTH + 1]; // +1 for null-terminator + + + //ListFilesRecursive("C:\\", 0); + /*char md5Hash[2 * MD5_DIGEST_LENGTH + 1]; // +1 for null-terminator printf("Hash of the executable: "); md5_file("C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\x64\\Debug\\client_backend.exe", md5Hash); printf("%s", md5Hash); @@ -54,7 +38,7 @@ int main() { printf("%s", a_); //error 6: not reachable download_file_from_srv("https://jakach.duckdns.org/php/login/v3/login.php", "c:\\programdata\\jakach\\out12.txt"); /* - const int numThreads = 12; + const int numThreads = 12; std::thread threads[numThreads]; for (int i = 0; i < numThreads; ++i) { @@ -70,7 +54,7 @@ int main() { */ //printf("code:%d",scan_hash("C:\\Users\\janis\\Documents\\ma_av_tests\\OutputFile.txt", "1fddc13c02a79442c911a44b02ee0f58")); - //ListFilesRecursive("C:\\Users\\janis\\Documents\\ma_av_tests",0); + return 0; } diff --git a/src/client_backend/permissions.cpp b/src/client_backend/permissions.cpp index 3f44e4d..168a8c8 100644 --- a/src/client_backend/permissions.cpp +++ b/src/client_backend/permissions.cpp @@ -1,5 +1,7 @@ #ifndef PERMISSIONS_CPP #define PERMISSIONS_CPP +#define _WIN32_WINNT 0x0500 +#pragma comment(lib, "advapi32.lib") #include "permissions.h" /* 1 create file (as admin) @@ -7,21 +9,134 @@ file cannot be deleted or modified by anyone. admin can delete */ -/* -int main() { - FILE* fp; - fp = fopen("c:\\programdata\\jakach\\aa.txt", "w"); - fprintf(fp, "secure text"); - fclose(fp); - chmod("c:\\programdata\\jakach\\aa.txt", _S_IREAD); -} - -*/ +//mark as readonly int protect_file(char* path) { return _chmod(path, _S_IREAD); } +//mark as readwrite int unprotect_file(char* path) { return _chmod(path, _S_IWRITE | _S_IREAD); } +//deny all access and only grant access to admins +BOOL create_file_protection(SECURITY_ATTRIBUTES* pSA) +{ + // Define the SDDL for the DACL. This example sets + // the following access: + // Built-in guests are denied all access. + // Anonymous logon is denied all access. + // Authenticated users are denied all access. + // Administrators are allowed full control. + // Modify these values as needed to generate the proper + // DACL for your application. + TCHAR* szSD = TEXT("D:") + TEXT("(D;OICI;GA;;;BG)") // Deny access to guest users + TEXT("(D;OICI;GA;;;AN)") // Deny access to unauthenticated users + //TEXT("(D;OICI;GA;;;AU)") // Deny access to authenticated users do not execute else not even admins have rights anymore :( + TEXT("(A;OICI;GA;;;BA)"); // Allow full control to builtin administrators + TEXT("(A;OICI;GA;;;AA)"); // Allow full control to normal administrators + + + if (NULL == pSA) + return FALSE; + + return ConvertStringSecurityDescriptorToSecurityDescriptor( + szSD, + SDDL_REVISION_1, + &(pSA->lpSecurityDescriptor), + NULL); +} +/* + + +BOOL CreateMyDACL(SECURITY_ATTRIBUTES*); + +int main() +{ + SECURITY_ATTRIBUTES sa; + + sa.nLength = sizeof(SECURITY_ATTRIBUTES); + sa.bInheritHandle = FALSE; + + // Call function to set the DACL. The DACL + // is set in the SECURITY_ATTRIBUTES + // lpSecurityDescriptor member. + if (!CreateMyDACL(&sa)) + { + // Error encountered; generate message and exit. + printf("Failed CreateMyDACL\n"); + exit(1); + } + + // Use the updated SECURITY_ATTRIBUTES to specify + // security attributes for securable objects. + // This example uses security attributes during + // creation of a new directory. + if (0 == CreateDirectory(TEXT("C:\\MyFolder"), &sa)) + { + // Error encountered; generate message and exit. + printf("Failed CreateDirectory\n"); + exit(1); + } + + // Free the memory allocated for the SECURITY_DESCRIPTOR. + if (NULL != LocalFree(sa.lpSecurityDescriptor)) + { + // Error encountered; generate message and exit. + printf("Failed LocalFree\n"); + exit(1); + } + return 0; +} + + +// CreateMyDACL. +// Create a security descriptor that contains the DACL +// you want. +// This function uses SDDL to make Deny and Allow ACEs. +// +// Parameter: +// SECURITY_ATTRIBUTES * pSA +// Pointer to a SECURITY_ATTRIBUTES structure. It is your +// responsibility to properly initialize the +// structure and to free the structure's +// lpSecurityDescriptor member when you have +// finished using it. To free the structure's +// lpSecurityDescriptor member, call the +// LocalFree function. +// +// Return value: +// FALSE if the address to the structure is NULL. +// Otherwise, this function returns the value from the +// ConvertStringSecurityDescriptorToSecurityDescriptor +// function. +BOOL CreateMyDACL(SECURITY_ATTRIBUTES* pSA) +{ + // Define the SDDL for the DACL. This example sets + // the following access: + // Built-in guests are denied all access. + // Anonymous logon is denied all access. + // Authenticated users are allowed + // read/write/execute access. + // Administrators are allowed full control. + // Modify these values as needed to generate the proper + // DACL for your application. + TCHAR* szSD = TEXT("D:") + TEXT("(D;OICI;GA;;;BG)") // Deny access to authenticated users + TEXT("(D;OICI;GA;;;AN)") // Deny access to authenticated users + //TEXT("(D;OICI;GA;;;AU)") // Deny access to authenticated users + TEXT("(A;OICI;GA;;;BA)"); // Allow full control to builtinadministrators + TEXT("(A;OICI;GA;;;AA)"); // Allow full control to administrators + + + if (NULL == pSA) + return FALSE; + + return ConvertStringSecurityDescriptorToSecurityDescriptor( + szSD, + SDDL_REVISION_1, + &(pSA->lpSecurityDescriptor), + NULL); +} +*/ #endif \ No newline at end of file diff --git a/src/client_backend/permissions.h b/src/client_backend/permissions.h index 253cf1a..dc6d6c5 100644 --- a/src/client_backend/permissions.h +++ b/src/client_backend/permissions.h @@ -10,5 +10,8 @@ #include #include #include +#include +#include +#include int protect_file(char* path); int unprotect_file(char* path); \ No newline at end of file diff --git a/src/client_backend/x64/Debug/client_backend.ilk b/src/client_backend/x64/Debug/client_backend.ilk index 31296f7..4a694b2 100644 Binary files a/src/client_backend/x64/Debug/client_backend.ilk and b/src/client_backend/x64/Debug/client_backend.ilk differ diff --git a/src/client_backend/x64/Debug/client_backend.log b/src/client_backend/x64/Debug/client_backend.log index 319402b..3754042 100644 --- a/src/client_backend/x64/Debug/client_backend.log +++ b/src/client_backend/x64/Debug/client_backend.log @@ -1,3 +1,2 @@  client_backend.cpp -x64\Debug\app_ctrl.obj : warning LNK4042: Objekt mehrmals angegeben; zusätzliche Objekte werden ignoriert. client_backend.vcxproj -> C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\x64\Debug\client_backend.exe diff --git a/src/client_backend/x64/Debug/client_backend.pdb b/src/client_backend/x64/Debug/client_backend.pdb index da3097d..78d53bf 100644 Binary files a/src/client_backend/x64/Debug/client_backend.pdb and b/src/client_backend/x64/Debug/client_backend.pdb differ diff --git a/src/client_backend/x64/Debug/client_backend.tlog/CL.command.1.tlog b/src/client_backend/x64/Debug/client_backend.tlog/CL.command.1.tlog index 529a24c..c480b77 100644 Binary files a/src/client_backend/x64/Debug/client_backend.tlog/CL.command.1.tlog and b/src/client_backend/x64/Debug/client_backend.tlog/CL.command.1.tlog differ diff --git a/src/client_backend/x64/Debug/client_backend.tlog/CL.read.1.tlog b/src/client_backend/x64/Debug/client_backend.tlog/CL.read.1.tlog index 2c0b926..a2853b5 100644 Binary files a/src/client_backend/x64/Debug/client_backend.tlog/CL.read.1.tlog and b/src/client_backend/x64/Debug/client_backend.tlog/CL.read.1.tlog differ diff --git a/src/client_backend/x64/Debug/client_backend.tlog/CL.write.1.tlog b/src/client_backend/x64/Debug/client_backend.tlog/CL.write.1.tlog index 168a332..174657b 100644 Binary files a/src/client_backend/x64/Debug/client_backend.tlog/CL.write.1.tlog and b/src/client_backend/x64/Debug/client_backend.tlog/CL.write.1.tlog differ diff --git a/src/client_backend/x64/Debug/client_backend.tlog/client_backend.write.1u.tlog b/src/client_backend/x64/Debug/client_backend.tlog/client_backend.write.1u.tlog index 6c58a4a..9841c28 100644 Binary files a/src/client_backend/x64/Debug/client_backend.tlog/client_backend.write.1u.tlog and b/src/client_backend/x64/Debug/client_backend.tlog/client_backend.write.1u.tlog differ diff --git a/src/client_backend/x64/Debug/client_backend.tlog/link.read.1.tlog b/src/client_backend/x64/Debug/client_backend.tlog/link.read.1.tlog index 7f7848b..06bf014 100644 Binary files a/src/client_backend/x64/Debug/client_backend.tlog/link.read.1.tlog and b/src/client_backend/x64/Debug/client_backend.tlog/link.read.1.tlog differ diff --git a/src/client_backend/x64/Debug/vc143.idb b/src/client_backend/x64/Debug/vc143.idb index 28e32e1..078c7d9 100644 Binary files a/src/client_backend/x64/Debug/vc143.idb and b/src/client_backend/x64/Debug/vc143.idb differ diff --git a/src/client_backend/x64/Debug/vc143.pdb b/src/client_backend/x64/Debug/vc143.pdb index f0ca64f..c1bc82f 100644 Binary files a/src/client_backend/x64/Debug/vc143.pdb and b/src/client_backend/x64/Debug/vc143.pdb differ diff --git a/src/ma_installer/.vs/ma_installer/FileContentIndex/a9928a98-d3ff-4e17-b270-e9c8ff57ac65.vsidx b/src/ma_installer/.vs/ma_installer/FileContentIndex/a9928a98-d3ff-4e17-b270-e9c8ff57ac65.vsidx new file mode 100644 index 0000000..4a4a594 Binary files /dev/null and b/src/ma_installer/.vs/ma_installer/FileContentIndex/a9928a98-d3ff-4e17-b270-e9c8ff57ac65.vsidx differ diff --git a/src/ma_installer/.vs/ma_installer/FileContentIndex/cc03696b-4b72-475b-a0e5-a0228cc1300c.vsidx b/src/ma_installer/.vs/ma_installer/FileContentIndex/cc03696b-4b72-475b-a0e5-a0228cc1300c.vsidx new file mode 100644 index 0000000..e541381 Binary files /dev/null and b/src/ma_installer/.vs/ma_installer/FileContentIndex/cc03696b-4b72-475b-a0e5-a0228cc1300c.vsidx differ diff --git a/src/ma_installer/.vs/ma_installer/v17/.suo b/src/ma_installer/.vs/ma_installer/v17/.suo new file mode 100644 index 0000000..ffa91de Binary files /dev/null and b/src/ma_installer/.vs/ma_installer/v17/.suo differ diff --git a/src/ma_installer/.vs/ma_installer/v17/Browse.VC.db b/src/ma_installer/.vs/ma_installer/v17/Browse.VC.db new file mode 100644 index 0000000..0d732a2 Binary files /dev/null and b/src/ma_installer/.vs/ma_installer/v17/Browse.VC.db differ diff --git a/src/ma_installer/.vs/ma_installer/v17/ipch/AutoPCH/d30ea52e71910fa3/MA_INSTALLER.ipch b/src/ma_installer/.vs/ma_installer/v17/ipch/AutoPCH/d30ea52e71910fa3/MA_INSTALLER.ipch new file mode 100644 index 0000000..83e4282 Binary files /dev/null and b/src/ma_installer/.vs/ma_installer/v17/ipch/AutoPCH/d30ea52e71910fa3/MA_INSTALLER.ipch differ diff --git a/src/ma_installer/download.cpp b/src/ma_installer/download.cpp new file mode 100644 index 0000000..125ecb8 --- /dev/null +++ b/src/ma_installer/download.cpp @@ -0,0 +1,53 @@ +#pragma warning(disable:4996) +#ifndef CONNECT_CPP +#define CONNECT_CPP +#include "download.h" + +size_t write_callback(void* contents, size_t size, size_t nmemb, void* userp) { + size_t totalSize = size * nmemb; + FILE* file = (FILE*)userp; + if (file) { + fwrite(contents, 1, totalSize, file); + } + return totalSize; +} + + +int download_file_from_srv(const char* url, const char* outputFileName) { + //use curl to download a file from a server + + CURL* curl; + CURLcode res; + FILE* output_file; + + curl = curl_easy_init(); + if (!curl) { + return 7; + } + + // Set the URL to download + curl_easy_setopt(curl, CURLOPT_URL, url); + + // Create a file to write the downloaded data + output_file = fopen(outputFileName, "wb"); + if (!output_file) { + curl_easy_cleanup(curl); + return 7; + } + + // Set the write callback function + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, output_file); + + // Perform the download + res = curl_easy_perform(curl); + if (res != CURLE_OK) { + return 7; + } + // Cleanup and close the file + curl_easy_cleanup(curl); + fclose(output_file); + + return 0; +} +#endif \ No newline at end of file diff --git a/src/ma_installer/download.h b/src/ma_installer/download.h new file mode 100644 index 0000000..2af1eeb --- /dev/null +++ b/src/ma_installer/download.h @@ -0,0 +1,5 @@ +#pragma once +#include +#include +#include +int download_file_from_srv(const char* url, const char* outputFileName); diff --git a/src/ma_installer/ma_installer.cpp b/src/ma_installer/ma_installer.cpp new file mode 100644 index 0000000..1791b7e --- /dev/null +++ b/src/ma_installer/ma_installer.cpp @@ -0,0 +1,297 @@ +// ma_installer.cpp : Diese Datei enthält die Funktion "main". Hier beginnt und endet die Ausführung des Programms. +// +#define _WIN32_WINNT 0x0500 + +#include +#include +#include +#include +#include "download.h" +#pragma comment(lib, "advapi32.lib") +/* +Tasks to do: +- launch as admin +- create secure folder +- download app files from server +- install app files +- create background service +- create folder for communication + +*/ +//check if programm is run as admin +bool is_admin() { + BOOL fIsRunAsAdmin = FALSE; + PSID pAdminSID = NULL; + + SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; + if (AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, + DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, + &pAdminSID)) { + if (!CheckTokenMembership(NULL, pAdminSID, &fIsRunAsAdmin)) { + fIsRunAsAdmin = FALSE; + } + + FreeSid(pAdminSID); + } + + return (fIsRunAsAdmin != 0); +} +bool run_as_admin() { + wchar_t szPath[MAX_PATH]; + if (GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath))) { + // Launch itself as admin + SHELLEXECUTEINFO sei = { sizeof(sei) }; + sei.lpVerb = L"runas"; + sei.lpFile = szPath; + sei.hwnd = NULL; + sei.nShow = SW_NORMAL; + + if (!ShellExecuteEx(&sei)) { + DWORD dwError = GetLastError(); + if (dwError == ERROR_CANCELLED) + { + // The user refused to allow privileges elevation. + return false; + } + } + else { + // End the calling process. User allowd admin rights + return true; + } + } + return false; +} +BOOL create_dacl(SECURITY_ATTRIBUTES* pSA) +{ + // Define the SDDL for the DACL. This example sets + // the following access: + // Built-in guests are denied all access. + // Anonymous logon is denied all access. + // Authenticated users are allowed + // read/write/execute access. + // Administrators are allowed full control. + // Modify these values as needed to generate the proper + // DACL for your application. + const wchar_t* szSD = TEXT("D:") + TEXT("(D;OICI;GA;;;BG)") // Deny access to authenticated users + TEXT("(D;OICI;GA;;;AN)") // Deny access to authenticated users + //TEXT("(D;OICI;GA;;;AU)") // Deny access to authenticated users + TEXT("(A;OICI;GA;;;BA)"); // Allow full control to builtinadministrators + //TEXT("(A;OICI;GA;;;AA)"); // Allow full control to administrators + + + if (NULL == pSA) + return FALSE; + + return ConvertStringSecurityDescriptorToSecurityDescriptor( + szSD, + SDDL_REVISION_1, + &(pSA->lpSecurityDescriptor), + NULL); +} +int create_secure_folder(LPCWSTR folderpath) { + int error = 0; + SECURITY_ATTRIBUTES sa; + + sa.nLength = sizeof(SECURITY_ATTRIBUTES); + sa.bInheritHandle = FALSE;// objects are not inherited + + // Call function to set the DACL. The DACL + // is set in the SECURITY_ATTRIBUTES + // lpSecurityDescriptor member. + if (!create_dacl(&sa)) + { + // Error encountered; generate message and exit. + //printf("Failed to create access control list\n"); + error = 1; + } + + // Use the updated SECURITY_ATTRIBUTES to specify + // security attributes for securable objects. + // This example uses security attributes during + // creation of a new directory. + if (error == 0) { + if (0 == CreateDirectory(folderpath, &sa)) + { + // Error encountered; generate message and exit. + //could not create directory + error = 2; + } + } + // Free the memory allocated for the SECURITY_DESCRIPTOR. + if (error == 0) { + if (NULL != LocalFree(sa.lpSecurityDescriptor)) + { + // Error encountered; generate message and exit. + //printf("Failed to free the allocated memory\n"); + error = 3; + } + } + return error; +} +int main() +{ + printf("Welcome to the Cyberhex installer!\n"); + int error = 0; + if (!is_admin()) { + printf("We are not administrator, requesting UAC\n"); + if (!run_as_admin()) { + printf("We did not get administrative rights. Please restart the installer!\n"); + MessageBox(NULL, L"Please start the installer with amdin privileges!", L"Error", MB_OK); + exit(1); + } + else { + //we started the app as admin. This process can be terminated now + exit(0); + } + }else { + // We're admin, so we can do admin stuff here ... + printf("Creating directorys\n"); + printf("Creating directory for application\n"); + CreateDirectory(L"C:\\Program Files\\cyberhex", NULL); //create main folder for cyberhex + printf("Creating directory for communication\n"); + CreateDirectory(L"C:\\Program Files\\cyberhex\\com", NULL); //create folder for communication with desktop client + printf("Creating directory for desktop client\n"); + CreateDirectory(L"C:\\Program Files\\cyberhex\\app", NULL); //create folder for desktop client application + printf("Creating directory for secure files\n"); + error = create_secure_folder(L"C:\\Program Files\\cyberhex\\secure"); //create secure folder + if (error == 0){ + printf("Creating directory for database\n"); + error = create_secure_folder(L"C:\\Program Files\\cyberhex\\secure\\database"); //create secure folder for hash database + }if (error == 0){ + printf("Creating directory for settings\n"); + error = create_secure_folder(L"C:\\Program Files\\cyberhex\\secure\\settings"); //create secure folder for settings + }if (error == 0){ + printf("Creating directory for quarantined files\n"); + error = create_secure_folder(L"C:\\Program Files\\cyberhex\\secure\\quarantine"); //create secure folder for quarantined files = viruses + }if (error == 0){ + printf("Creating directory for log files\n"); + error = create_secure_folder(L"C:\\Program Files\\cyberhex\\secure\\log"); //create secure folder for log files + }if (error == 0){ + printf("Creating directory for communication\n"); + error = create_secure_folder(L"C:\\Program Files\\cyberhex\\secure\\com"); //create secure folder for communication with server + }if (error == 0) { + printf("Creating directory for application\n"); + error = create_secure_folder(L"C:\\Program Files\\cyberhex\\secure\\app"); //create secure folder for application files + } + + //download files from server + if (error == 0) { + printf("Downloading files from server\n"); + printf("Downloading cyberhex.exe\n"); + error=download_file_from_srv("https://cyberhex.org/download/cyberhex.exe", "C:\\Program Files\\cyberhex\\secure\\app\\cyberhex.exe"); + if (error == 0) { + printf("Downloading libcrypto-3-x64.dll\n"); + error = download_file_from_srv("https://cyberhex.org/download/libcrypto-3-x64.dll", "C:\\Program Files\\cyberhex\\secure\\app\\libcrypto-3-x64.dll"); + }if (error == 0) { + printf("Downloading libcurl.dll\n"); + error = download_file_from_srv("https://cyberhex.org/download/libcurl.dll", "C:\\Program Files\\cyberhex\\secure\\app\\libcurl.dll"); + }if (error == 0) { + printf("Downloading zlib1.dll\n"); + error = download_file_from_srv("https://cyberhex.org/download/zlib1.dll", "C:\\Program Files\\cyberhex\\secure\\app\\zlib1.dll"); + }if (error == 0) { + printf("Downloading cyberhex_desktop.dll\n"); + error = download_file_from_srv("https://cyberhex.org/download/cyberhex_desktop.exe", "C:\\Program Files\\cyberhex\\app\\cyberhex_desktop.exe"); + } + } + + + //create background service + if (error == 0) { + printf("Creating background service\n"); + SC_HANDLE hSCManager = OpenSCManager(nullptr, nullptr, SC_MANAGER_ALL_ACCESS); + if (!hSCManager) { + //std::cerr << "Failed to open service control manager. Error code: " << GetLastError() << std::endl; + error = 4; + } + + LPCWSTR serviceName = L"cyberhex_background_service"; + LPCWSTR servicePath = L"C:\\Path\\To\\Your\\Executable.exe"; + + SC_HANDLE hService = CreateService( + hSCManager, + serviceName, + serviceName, + SERVICE_ALL_ACCESS, + SERVICE_WIN32_OWN_PROCESS, + SERVICE_AUTO_START, + SERVICE_ERROR_NORMAL, + servicePath, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr + ); + + if (!hService) { + //std::cerr << "Failed to create service. Error code: " << GetLastError() << std::endl; + CloseServiceHandle(hSCManager); + error = 5; + } + + // Configure the service to run with LocalSystem account (administrator rights) + if (!ChangeServiceConfig( + hService, + SERVICE_NO_CHANGE, + SERVICE_NO_CHANGE, + SERVICE_NO_CHANGE, + nullptr, + nullptr, + nullptr, + nullptr, + L"LocalSystem", + nullptr, + nullptr + )) { + //std::cerr << "Failed to configure service. Error code: " << GetLastError() << std::endl + error = 6; + } + else { + //std::cout << "Service created and configured successfully." << std::endl; + //no error + } + + CloseServiceHandle(hService); + CloseServiceHandle(hSCManager); + + } + } + switch (error) { + case 0: + printf("Installation successful\n"); + printf("You have installed Cyberhex, thank you!\n"); + MessageBox(NULL, L"Installation successful", L"Success", MB_OK); + break; + case 1: + printf("Failed to create access control list\n"); + MessageBox(NULL, L"Failed to create access control list", L"Error", MB_OK); + break; + case 2: + printf("Could not create directory\n"); + MessageBox(NULL, L"Could not create directory", L"Error", MB_OK); + break; + case 3: + printf("Failed to free the allocated memory\n"); + MessageBox(NULL, L"Failed to free the allocated memory", L"Error", MB_OK); + break; + case 4: + printf("Failed to open service control manager\n"); + MessageBox(NULL, L"Failed to open service control manager", L"Error", MB_OK); + break; + case 5: + printf("Failed to create service\n"); + MessageBox(NULL, L"Failed to create service", L"Error", MB_OK); + break; + case 6: + printf("Failed to configure service\n"); + MessageBox(NULL, L"Failed to configure service", L"Error", MB_OK); + break; + case 7: + printf("Failed to download file\n"); + MessageBox(NULL, L"Failed to download file", L"Error", MB_OK); + break; + default: + break; + } +} diff --git a/src/ma_installer/ma_installer.sln b/src/ma_installer/ma_installer.sln new file mode 100644 index 0000000..4874c74 --- /dev/null +++ b/src/ma_installer/ma_installer.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34330.188 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ma_installer", "ma_installer.vcxproj", "{AAE7A550-D2C0-45AC-8C26-ED57DF20BFC3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AAE7A550-D2C0-45AC-8C26-ED57DF20BFC3}.Debug|x64.ActiveCfg = Debug|x64 + {AAE7A550-D2C0-45AC-8C26-ED57DF20BFC3}.Debug|x64.Build.0 = Debug|x64 + {AAE7A550-D2C0-45AC-8C26-ED57DF20BFC3}.Debug|x86.ActiveCfg = Debug|Win32 + {AAE7A550-D2C0-45AC-8C26-ED57DF20BFC3}.Debug|x86.Build.0 = Debug|Win32 + {AAE7A550-D2C0-45AC-8C26-ED57DF20BFC3}.Release|x64.ActiveCfg = Release|x64 + {AAE7A550-D2C0-45AC-8C26-ED57DF20BFC3}.Release|x64.Build.0 = Release|x64 + {AAE7A550-D2C0-45AC-8C26-ED57DF20BFC3}.Release|x86.ActiveCfg = Release|Win32 + {AAE7A550-D2C0-45AC-8C26-ED57DF20BFC3}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {70F6E232-36D9-4086-BBD3-321601BAEB83} + EndGlobalSection +EndGlobal diff --git a/src/ma_installer/ma_installer.vcxproj b/src/ma_installer/ma_installer.vcxproj new file mode 100644 index 0000000..e1eff9c --- /dev/null +++ b/src/ma_installer/ma_installer.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {aae7a550-d2c0-45ac-8c26-ed57df20bfc3} + mainstaller + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ma_installer/ma_installer.vcxproj.filters b/src/ma_installer/ma_installer.vcxproj.filters new file mode 100644 index 0000000..40d67cc --- /dev/null +++ b/src/ma_installer/ma_installer.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Quelldateien + + + Headerdateien + + + + + Headerdateien + + + \ No newline at end of file diff --git a/src/ma_installer/ma_installer.vcxproj.user b/src/ma_installer/ma_installer.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/src/ma_installer/ma_installer.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/ma_installer/x64/Debug/ma_installer.exe.recipe b/src/ma_installer/x64/Debug/ma_installer.exe.recipe new file mode 100644 index 0000000..5dbb76a --- /dev/null +++ b/src/ma_installer/x64/Debug/ma_installer.exe.recipe @@ -0,0 +1,11 @@ + + + + + C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_installer\x64\Debug\ma_installer.exe + + + + + + \ No newline at end of file diff --git a/src/ma_installer/x64/Debug/ma_installer.ilk b/src/ma_installer/x64/Debug/ma_installer.ilk new file mode 100644 index 0000000..0dd019d Binary files /dev/null and b/src/ma_installer/x64/Debug/ma_installer.ilk differ diff --git a/src/ma_installer/x64/Debug/ma_installer.log b/src/ma_installer/x64/Debug/ma_installer.log new file mode 100644 index 0000000..b88bd1a --- /dev/null +++ b/src/ma_installer/x64/Debug/ma_installer.log @@ -0,0 +1,2 @@ + ma_installer.cpp + ma_installer.vcxproj -> C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_installer\x64\Debug\ma_installer.exe diff --git a/src/ma_installer/x64/Debug/ma_installer.pdb b/src/ma_installer/x64/Debug/ma_installer.pdb new file mode 100644 index 0000000..799588a Binary files /dev/null and b/src/ma_installer/x64/Debug/ma_installer.pdb differ diff --git a/src/ma_installer/x64/Debug/ma_installer.tlog/CL.command.1.tlog b/src/ma_installer/x64/Debug/ma_installer.tlog/CL.command.1.tlog new file mode 100644 index 0000000..910bfe3 Binary files /dev/null and b/src/ma_installer/x64/Debug/ma_installer.tlog/CL.command.1.tlog differ diff --git a/src/ma_installer/x64/Debug/ma_installer.tlog/CL.read.1.tlog b/src/ma_installer/x64/Debug/ma_installer.tlog/CL.read.1.tlog new file mode 100644 index 0000000..4f4ff50 Binary files /dev/null and b/src/ma_installer/x64/Debug/ma_installer.tlog/CL.read.1.tlog differ diff --git a/src/ma_installer/x64/Debug/ma_installer.tlog/CL.write.1.tlog b/src/ma_installer/x64/Debug/ma_installer.tlog/CL.write.1.tlog new file mode 100644 index 0000000..22d2d31 Binary files /dev/null and b/src/ma_installer/x64/Debug/ma_installer.tlog/CL.write.1.tlog differ diff --git a/src/ma_installer/x64/Debug/ma_installer.tlog/Cl.items.tlog b/src/ma_installer/x64/Debug/ma_installer.tlog/Cl.items.tlog new file mode 100644 index 0000000..d88e046 --- /dev/null +++ b/src/ma_installer/x64/Debug/ma_installer.tlog/Cl.items.tlog @@ -0,0 +1,2 @@ +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_installer\download.cpp;C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_installer\x64\Debug\download.obj +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_installer\ma_installer.cpp;C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_installer\x64\Debug\ma_installer.obj diff --git a/src/ma_installer/x64/Debug/ma_installer.tlog/link.command.1.tlog b/src/ma_installer/x64/Debug/ma_installer.tlog/link.command.1.tlog new file mode 100644 index 0000000..e394187 Binary files /dev/null and b/src/ma_installer/x64/Debug/ma_installer.tlog/link.command.1.tlog differ diff --git a/src/ma_installer/x64/Debug/ma_installer.tlog/link.read.1.tlog b/src/ma_installer/x64/Debug/ma_installer.tlog/link.read.1.tlog new file mode 100644 index 0000000..2c13e1a Binary files /dev/null and b/src/ma_installer/x64/Debug/ma_installer.tlog/link.read.1.tlog differ diff --git a/src/ma_installer/x64/Debug/ma_installer.tlog/link.write.1.tlog b/src/ma_installer/x64/Debug/ma_installer.tlog/link.write.1.tlog new file mode 100644 index 0000000..a78c0f7 Binary files /dev/null and b/src/ma_installer/x64/Debug/ma_installer.tlog/link.write.1.tlog differ diff --git a/src/ma_installer/x64/Debug/ma_installer.tlog/ma_installer.lastbuildstate b/src/ma_installer/x64/Debug/ma_installer.tlog/ma_installer.lastbuildstate new file mode 100644 index 0000000..215e4f9 --- /dev/null +++ b/src/ma_installer/x64/Debug/ma_installer.tlog/ma_installer.lastbuildstate @@ -0,0 +1,2 @@ +PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.38.33130:TargetPlatformVersion=10.0.22621.0:VcpkgTriplet=x64-windows: +Debug|x64|C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_installer\| diff --git a/src/ma_installer/x64/Debug/ma_installer.tlog/ma_installer.write.1u.tlog b/src/ma_installer/x64/Debug/ma_installer.tlog/ma_installer.write.1u.tlog new file mode 100644 index 0000000..020cc7d Binary files /dev/null and b/src/ma_installer/x64/Debug/ma_installer.tlog/ma_installer.write.1u.tlog differ diff --git a/src/ma_installer/x64/Debug/ma_installer.vcxproj.FileListAbsolute.txt b/src/ma_installer/x64/Debug/ma_installer.vcxproj.FileListAbsolute.txt new file mode 100644 index 0000000..9594d49 --- /dev/null +++ b/src/ma_installer/x64/Debug/ma_installer.vcxproj.FileListAbsolute.txt @@ -0,0 +1,4 @@ +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_installer\x64\Debug\ma_installer.exe +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_installer\x64\Debug\ma_installer.vcxproj.CopyComplete +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_installer\x64\Debug\libcurl-d.dll +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_installer\x64\Debug\zlibd1.dll diff --git a/src/ma_installer/x64/Debug/vc143.idb b/src/ma_installer/x64/Debug/vc143.idb new file mode 100644 index 0000000..6f5cdc1 Binary files /dev/null and b/src/ma_installer/x64/Debug/vc143.idb differ diff --git a/src/ma_installer/x64/Debug/vc143.pdb b/src/ma_installer/x64/Debug/vc143.pdb new file mode 100644 index 0000000..f22f948 Binary files /dev/null and b/src/ma_installer/x64/Debug/vc143.pdb differ diff --git a/src/ma_installer/x64/Debug/vcpkg.applocal.log b/src/ma_installer/x64/Debug/vcpkg.applocal.log new file mode 100644 index 0000000..45b2f97 --- /dev/null +++ b/src/ma_installer/x64/Debug/vcpkg.applocal.log @@ -0,0 +1,3 @@ + +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_installer\x64\Debug\libcurl-d.dll +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_installer\x64\Debug\zlibd1.dll