diff --git a/src/client_backend/.vs/client_backend/FileContentIndex/03bced36-7795-49fb-b10a-1d6abc018983.vsidx b/src/client_backend/.vs/client_backend/FileContentIndex/03bced36-7795-49fb-b10a-1d6abc018983.vsidx new file mode 100644 index 0000000..90a2119 Binary files /dev/null and b/src/client_backend/.vs/client_backend/FileContentIndex/03bced36-7795-49fb-b10a-1d6abc018983.vsidx differ diff --git a/src/client_backend/.vs/client_backend/FileContentIndex/338095ee-8fe2-4bda-95a3-7b4b43db83b0.vsidx b/src/client_backend/.vs/client_backend/FileContentIndex/338095ee-8fe2-4bda-95a3-7b4b43db83b0.vsidx deleted file mode 100644 index 2d6fe74..0000000 Binary files a/src/client_backend/.vs/client_backend/FileContentIndex/338095ee-8fe2-4bda-95a3-7b4b43db83b0.vsidx and /dev/null differ diff --git a/src/client_backend/.vs/client_backend/FileContentIndex/3ac88e7d-be27-4b8d-bd7a-cc35767ad856.vsidx b/src/client_backend/.vs/client_backend/FileContentIndex/3ac88e7d-be27-4b8d-bd7a-cc35767ad856.vsidx deleted file mode 100644 index 621c750..0000000 Binary files a/src/client_backend/.vs/client_backend/FileContentIndex/3ac88e7d-be27-4b8d-bd7a-cc35767ad856.vsidx and /dev/null differ diff --git a/src/client_backend/.vs/client_backend/FileContentIndex/850e2cd0-40b3-4296-9e67-a66ed14a57f3.vsidx b/src/client_backend/.vs/client_backend/FileContentIndex/850e2cd0-40b3-4296-9e67-a66ed14a57f3.vsidx new file mode 100644 index 0000000..808aac9 Binary files /dev/null and b/src/client_backend/.vs/client_backend/FileContentIndex/850e2cd0-40b3-4296-9e67-a66ed14a57f3.vsidx differ diff --git a/src/client_backend/.vs/client_backend/FileContentIndex/862f81b2-79e2-4858-b8dd-caf783a1c9cd.vsidx b/src/client_backend/.vs/client_backend/FileContentIndex/862f81b2-79e2-4858-b8dd-caf783a1c9cd.vsidx deleted file mode 100644 index bccfb39..0000000 Binary files a/src/client_backend/.vs/client_backend/FileContentIndex/862f81b2-79e2-4858-b8dd-caf783a1c9cd.vsidx and /dev/null differ diff --git a/src/client_backend/.vs/client_backend/FileContentIndex/149613ac-abec-4130-bd61-b093d9593ea0.vsidx b/src/client_backend/.vs/client_backend/FileContentIndex/98a16e52-49f0-4f82-b933-bc6dc5e18279.vsidx similarity index 52% rename from src/client_backend/.vs/client_backend/FileContentIndex/149613ac-abec-4130-bd61-b093d9593ea0.vsidx rename to src/client_backend/.vs/client_backend/FileContentIndex/98a16e52-49f0-4f82-b933-bc6dc5e18279.vsidx index 9d4a220..5d18560 100644 Binary files a/src/client_backend/.vs/client_backend/FileContentIndex/149613ac-abec-4130-bd61-b093d9593ea0.vsidx and b/src/client_backend/.vs/client_backend/FileContentIndex/98a16e52-49f0-4f82-b933-bc6dc5e18279.vsidx differ diff --git a/src/client_backend/.vs/client_backend/FileContentIndex/a14359fc-78aa-4a67-aa84-bab4c6d6abee.vsidx b/src/client_backend/.vs/client_backend/FileContentIndex/a14359fc-78aa-4a67-aa84-bab4c6d6abee.vsidx new file mode 100644 index 0000000..eae5372 Binary files /dev/null and b/src/client_backend/.vs/client_backend/FileContentIndex/a14359fc-78aa-4a67-aa84-bab4c6d6abee.vsidx differ diff --git a/src/client_backend/.vs/client_backend/FileContentIndex/dc13ab1a-d2ef-4f8d-a6f3-1c24ac19fd4f.vsidx b/src/client_backend/.vs/client_backend/FileContentIndex/dc13ab1a-d2ef-4f8d-a6f3-1c24ac19fd4f.vsidx deleted file mode 100644 index 059b422..0000000 Binary files a/src/client_backend/.vs/client_backend/FileContentIndex/dc13ab1a-d2ef-4f8d-a6f3-1c24ac19fd4f.vsidx and /dev/null differ diff --git a/src/client_backend/.vs/client_backend/FileContentIndex/efc8e9f2-907e-4168-9099-5a45b172d1fb.vsidx b/src/client_backend/.vs/client_backend/FileContentIndex/efc8e9f2-907e-4168-9099-5a45b172d1fb.vsidx new file mode 100644 index 0000000..6ed4f50 Binary files /dev/null and b/src/client_backend/.vs/client_backend/FileContentIndex/efc8e9f2-907e-4168-9099-5a45b172d1fb.vsidx differ diff --git a/src/client_backend/.vs/client_backend/v17/.suo b/src/client_backend/.vs/client_backend/v17/.suo index 8d56075..8dcc78d 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 152e390..1f0dc89 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/client_backend.cpp b/src/client_backend/client_backend.cpp index 1d5baf1..5bd39a2 100644 --- a/src/client_backend/client_backend.cpp +++ b/src/client_backend/client_backend.cpp @@ -27,7 +27,6 @@ int main() { } load_settings(); initialize(DB_DIR); //load the hash databases into memory - //download_file_from_srv("http://192.168.27.13/api/php/settings/get_settings.php?settings", "c:\\programdata\\jakach\\out12.txt"); //start a second thread which will scan for new files if (get_setting("rtp_folder_scan:status") == 1) { diff --git a/src/client_backend/client_backend.vcxproj b/src/client_backend/client_backend.vcxproj index 7462ffc..5c93314 100644 --- a/src/client_backend/client_backend.vcxproj +++ b/src/client_backend/client_backend.vcxproj @@ -148,6 +148,7 @@ + @@ -164,6 +165,7 @@ + diff --git a/src/client_backend/client_backend.vcxproj.filters b/src/client_backend/client_backend.vcxproj.filters index eb3dd59..70636da 100644 --- a/src/client_backend/client_backend.vcxproj.filters +++ b/src/client_backend/client_backend.vcxproj.filters @@ -63,6 +63,9 @@ Headerdateien + + Headerdateien + @@ -110,6 +113,9 @@ Headerdateien + + Headerdateien + diff --git a/src/client_backend/connect.cpp b/src/client_backend/connect.cpp index bb5abfd..94f6a88 100644 --- a/src/client_backend/connect.cpp +++ b/src/client_backend/connect.cpp @@ -2,6 +2,8 @@ #ifndef CONNECT_CPP #define CONNECT_CPP #include "connect.h" +#include "well_known.h" +#include "security.h" static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) { @@ -43,11 +45,14 @@ size_t write_callback(void* contents, size_t size, size_t nmemb, void* userp) { int download_file_from_srv(const char* url, const char* output_file_path) { //use curl to download a file from a server - + char*temp_path = new char[515]; + char* buf = new char[55]; + strcpy_s(temp_path,495, output_file_path); + strcat_s(temp_path,505, ".temp"); CURL* curl; CURLcode res; FILE* output_file; - char*buf=new char[55]; + curl = curl_easy_init(); if (!curl) { return 1; @@ -57,7 +62,7 @@ int download_file_from_srv(const char* url, const char* output_file_path) { curl_easy_setopt(curl, CURLOPT_URL, url); // Create a file to write the downloaded data - output_file = fopen(output_file_path, "wb"); + output_file = fopen(temp_path, "wb"); if (!output_file) { curl_easy_cleanup(curl); return 2; @@ -75,7 +80,7 @@ int download_file_from_srv(const char* url, const char* output_file_path) { // Cleanup and close the file curl_easy_cleanup(curl); fclose(output_file); - if ((output_file = fopen(output_file_path, "r")) == 0) { + if ((output_file = fopen(temp_path, "r")) == 0) { return 4; } else { @@ -84,9 +89,19 @@ int download_file_from_srv(const char* url, const char* output_file_path) { fclose(output_file); return 5; } + else if(check_cert(buf, SECRETS)!=0){ + if (rename(temp_path, output_file_path)) { + fclose(output_file); + return 6; + } + }else { + fclose(output_file); + return 7; + } fclose(output_file); } delete[] buf; + delete[] temp_path; return 0; } diff --git a/src/client_backend/security.cpp b/src/client_backend/security.cpp new file mode 100644 index 0000000..138a234 --- /dev/null +++ b/src/client_backend/security.cpp @@ -0,0 +1,60 @@ +#include "security.h" + +int check_cert(const char*cert,const char*secrets_path) { + FILE* fp; + if (fopen_s(&fp, secrets_path, "r") != 0) { + return 1; + } + else { + char*secrets = new char[300]; + while (!feof(fp)) { + fscanf_s(fp, "%s", secrets, 295); // get the secret + if (strcmp("cert", secrets) == 0) { + fscanf_s(fp, "%s", secrets, 295); // get the secret + if (strcmp(cert, secrets) == 0) { + delete[] secrets; + return 0; + } + } + } + delete[] secrets; + return 2; + } + +} +char* get_apikey(const char* secrets_path) { + FILE* fp; + if (fopen_s(&fp, secrets_path, "r") != 0) { + return 0; + } + else { + char*secrets = new char[300]; + while (!feof(fp)) { + fscanf_s(fp, "%s", secrets, 295); // get the secret + if (strcmp("apikey", secrets) == 0) { + fscanf_s(fp, "%s", secrets, 295); // get the secret + return secrets; + } + } + delete[] secrets; + return 0; + } +} +char* get_machineid(const char*secrets_path){ + FILE* fp; + if (fopen_s(&fp, secrets_path, "r") != 0) { + return 0; + } + else { + char* secrets = new char[300]; + while (!feof(fp)) { + fscanf_s(fp, "%s", secrets, 295); // get the secret + if (strcmp("machineid", secrets) == 0) { + fscanf_s(fp, "%s", secrets, 295); // get the secret + return secrets; + } + } + delete[] secrets; + return 0; + } +} \ No newline at end of file diff --git a/src/client_backend/security.h b/src/client_backend/security.h new file mode 100644 index 0000000..78396bc --- /dev/null +++ b/src/client_backend/security.h @@ -0,0 +1,10 @@ +#pragma once +#ifndef SECURITY_H +#define SECURITY_H +#include +#include +#include +int check_cert(const char* cert,const char* secrets_path); +char*get_apikey(const char*secrets_path); +char* get_machineid(const char*secrets_path); +#endif // !SECURITY_H \ No newline at end of file diff --git a/src/client_backend/update.cpp b/src/client_backend/update.cpp index ea6f132..1f54cae 100644 --- a/src/client_backend/update.cpp +++ b/src/client_backend/update.cpp @@ -46,9 +46,9 @@ int update_settings() { get_setting("server:server_url", url); strcat_s(url, 500, "/api/php/settings/get_settings.php?settings"); int res = download_file_from_srv(url, SETTINGS_DB); - //res = 0; + //int res = 0; if (res != 0) { - log(LOGLEVEL::ERR, "[update_db()]: Error downloading settings database file from server", url, " ERROR:",res); + log(LOGLEVEL::ERR, "[update_settings()]: Error downloading settings database file from server", url, " ERROR:",res); return 1; } diff --git a/src/client_backend/well_known.h b/src/client_backend/well_known.h index 51d3507..d2a8657 100644 --- a/src/client_backend/well_known.h +++ b/src/client_backend/well_known.h @@ -31,6 +31,8 @@ #define QUARANTINE_PATH "C:\\Program Files\\cyberhex\\secure\\quarantine" +#define SECRETS "C:\\Program Files\\cyberhex\\secure\\settings\\secrets.txt" + #define PERIODIC_FOLDER_SCAN "C:\\Program Files\\cyberhex\\secure\\database\\folder\\periodic_folder_scan.txt" #define PERIODIC_FOLDER_SCAN_TEMP_DB "C:\\Program Files\\cyberhex\\secure\\database\\folder\\temp_db.txt" diff --git a/src/client_backend/x64/Debug/client_backend.ilk b/src/client_backend/x64/Debug/client_backend.ilk index 14b6829..0b7097e 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 ef618f4..2645507 100644 --- a/src/client_backend/x64/Debug/client_backend.log +++ b/src/client_backend/x64/Debug/client_backend.log @@ -1,4 +1,53 @@  Quellen werden auf Modulabhängigkeiten überprüft... + check_dir.cpp +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\check_dir.cpp(361,7): warning C4101: "fp": Unreferenzierte lokale Variable +C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xstring(2749,53): warning C4244: "Argument": Konvertierung von "wchar_t" in "const _Elem", möglicher Datenverlust +C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xstring(2749,53): warning C4244: with +C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xstring(2749,53): warning C4244: [ +C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xstring(2749,53): warning C4244: _Elem=char +C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xstring(2749,53): warning C4244: ] + (Quelldatei „check_dir.cpp“ wird kompiliert) + C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xstring(2749,53): + der Vorlageninstanziierungskontext (der älteste zuerst) ist + C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\check_dir.cpp(155,29): + Siehe Verweis auf die gerade kompilierte Instanziierung "std::basic_string,std::allocator>::basic_string>>,0>(_Iter,_Iter,const _Alloc &)" der Funktions-Vorlage. + with + [ + _Elem=wchar_t, + _Iter=std::_String_iterator>>, + _Alloc=std::allocator + ] + C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\check_dir.cpp(155,29): + Ersten Verweis auf "std::basic_string,std::allocator>::basic_string" in "process_changes" anzeigen + C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xstring(2590,17): + Siehe Verweis auf die gerade kompilierte Instanziierung "void std::basic_string,std::allocator>::_Construct_from_iter(_Iter,const _Sent,_Size)" der Funktions-Vorlage. + with + [ + _Size_type=unsigned __int64, + _Iter=wchar_t *, + _Sent=wchar_t *, + _Size=unsigned __int64 + ] + + client_backend.cpp +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\client_backend.cpp(73,24): warning C4244: "Argument": Konvertierung von "_Rep" in "DWORD", möglicher Datenverlust +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\client_backend.cpp(73,24): warning C4244: with +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\client_backend.cpp(73,24): warning C4244: [ +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\client_backend.cpp(73,24): warning C4244: _Rep=__int64 +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\client_backend.cpp(73,24): warning C4244: ] connect.cpp -C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\connect.cpp(103,65): warning C4267: "Argument": Konvertierung von "size_t" nach "int", Datenverlust möglich - client_backend.vcxproj -> C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\x64\Debug\client_backend.exe +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\connect.cpp(118,65): warning C4267: "Argument": Konvertierung von "size_t" nach "int", Datenverlust möglich + local_com.cpp + local_schedule.cpp + log.cpp + md5hash.cpp + scan.cpp +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\scan.cpp(153,32): warning C4018: ">=": Konflikt zwischen "signed" und "unsigned" + security.cpp + settings.cpp + thread_ctrl.cpp + update.cpp + virus_ctrl.cpp + Code wird generiert... +C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\md5hash.cpp(36): warning C4715: "md5_file": Nicht alle Codepfade geben einen Wert zurück. +LINK : fatal error LNK1168: "C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\x64\Debug\client_backend.exe" kann nicht zum Schreiben geöffnet werden. diff --git a/src/client_backend/x64/Debug/client_backend.pdb b/src/client_backend/x64/Debug/client_backend.pdb index 26b92c9..f789374 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 5ff3803..35a41e5 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 f9e7aa0..ff81914 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 f3aa324..1e795d1 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 08abbe1..3f75f92 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/unsuccessfulbuild b/src/client_backend/x64/Debug/client_backend.tlog/unsuccessfulbuild new file mode 100644 index 0000000..e69de29 diff --git a/src/client_backend/x64/Debug/vc143.idb b/src/client_backend/x64/Debug/vc143.idb index ee08e17..c403380 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 9b54a9b..f928766 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/server/cyberhex-code/api/php/accessctrl/check_apikey.php b/src/server/cyberhex-code/api/php/accessctrl/check_apikey.php index a465ef2..00b7d46 100644 --- a/src/server/cyberhex-code/api/php/accessctrl/check_apikey.php +++ b/src/server/cyberhex-code/api/php/accessctrl/check_apikey.php @@ -29,4 +29,34 @@ function check_apikey(){ } } } +function load_secret(){ + include "../../../config.php"; + $conn = new mysqli($DB_SERVERNAME, $DB_USERNAME, $DB_PASSWORD,$DB_DATABASE); + if ($conn->connect_error) { + $success=0; + die("Connection failed: " . $conn->connect_error); + } + if(!isset($_GET["apikey"]) or !isset($_GET["machineid"])){ + return false; + } + else{ + $apikey=$_GET["apikey"]; + $machineid=$_GET["machineid"]; + $sql = "SELECT * FROM secrets machineid = ?"; + $stmt = $conn->prepare($sql); + $stmt->bind_param("s",$machineid); + + // Execute the statement + $stmt->execute(); + + // Get the result + $result = $stmt->get_result(); + + $row = $result->fetch_assoc(); + if($row!==null){ + return $row["cert"]; + } + } + +} ?> \ No newline at end of file diff --git a/src/server/cyberhex-code/api/php/settings/get_settings.php b/src/server/cyberhex-code/api/php/settings/get_settings.php index 7b7cdfc..342d8a5 100644 --- a/src/server/cyberhex-code/api/php/settings/get_settings.php +++ b/src/server/cyberhex-code/api/php/settings/get_settings.php @@ -24,12 +24,14 @@ if(isset($_GET["settings"])){ rtp_folder_scan:status on */ load_settings(); + echo(load_secret()); echo("virus_ctrl:virus_found:action ".$setting_virus_ctrl_virus_found_action."\n"); echo("server:server_url ".$setting_server_server_url."\n"); echo("rtp_folder_scan:status ".$setting_rtp_folder_scan_status."\n"); echo("rtp_process_scan:status ".$setting_rtp_process_scan_status."\n"); } if(isset($_GET["rtp_included"])){ + echo(load_secret()); //load all the entrys from a db table $sql = "SELECT path,id FROM rtp_included ORDER BY id"; $stmt = $conn->prepare($sql); @@ -44,6 +46,7 @@ if(isset($_GET["rtp_included"])){ } if(isset($_GET["rtp_excluded"])){ + echo(load_secret()); //load all the entrys from a db table $sql = "SELECT path,id FROM rtp_excluded ORDER BY id"; $stmt = $conn->prepare($sql); @@ -58,6 +61,7 @@ if(isset($_GET["rtp_excluded"])){ } if(isset($_GET["sched"])){ + echo(load_secret()); //load all the entrys from a db table $sql = "SELECT task,id FROM user_tasks ORDER BY id"; $stmt = $conn->prepare($sql); diff --git a/src/server/cyberhex-code/system/secure_zone/php/add_client.php b/src/server/cyberhex-code/system/secure_zone/php/add_client.php new file mode 100644 index 0000000..43566c7 --- /dev/null +++ b/src/server/cyberhex-code/system/secure_zone/php/add_client.php @@ -0,0 +1,49 @@ + + + + + + + + Change Password + + + +
+
+
+
+
+

Add a machine

+
+
+
+ +
+
+
+
+
+
+ +