added some code
wrote some code to test some functionallity
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7
src/client_backend/app_ctrl.cpp
Normal file
7
src/client_backend/app_ctrl.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef APP_CTRL_CPP
|
||||
#define APP_CTRL_CPP
|
||||
#include "app_ctrl.h"
|
||||
int app_stop() {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
4
src/client_backend/app_ctrl.h
Normal file
4
src/client_backend/app_ctrl.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#ifndef APP_CTRL_H
|
||||
#define APP_CTRL_H
|
||||
int app_stop();
|
||||
#endif
|
||||
@@ -1,20 +1,76 @@
|
||||
#pragma warning(disable:4996)
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <curl/curl.h>
|
||||
#include <openssl/md5.h>
|
||||
#include <yara.h>
|
||||
#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("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
|
||||
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);
|
||||
char a[2000];
|
||||
printf("\nerror:%d\n",connect_to_srv("https://self-signed.badssl.com/", a, 2000,1)); //error 60: self signed => option f<>r self-signed ignorieren aktivieren (bool ignore_invalid=true)
|
||||
printf("%s", a); //error 6: not reachable
|
||||
char a_[2000];
|
||||
printf("\nerror:%d\n",connect_to_srv("https://self-signed.badssl.com/", a_, 2000,1)); //error 60: self signed => option f<>r self-signed ignorieren aktivieren (bool ignore_invalid=true)
|
||||
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;
|
||||
std::thread threads[numThreads];
|
||||
|
||||
for (int i = 0; i < numThreads; ++i) {
|
||||
threads[i] = std::thread(ListFilesRecursive, "C:\\Users\\janis\\Documents\\ma_av_tests",i);
|
||||
}
|
||||
|
||||
// Join threads to wait for them to finish
|
||||
for (int i = 0; i < numThreads; ++i) {
|
||||
threads[i].join();
|
||||
}
|
||||
|
||||
std::cout << "All threads have finished." << std::endl;
|
||||
*/
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
|
||||
@@ -135,14 +135,20 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="app_ctrl.cpp" />
|
||||
<ClCompile Include="app_ctrl.h" />
|
||||
<ClCompile Include="client_backend.cpp" />
|
||||
<ClCompile Include="connect.cpp" />
|
||||
<ClCompile Include="md5hash.cpp" />
|
||||
<ClCompile Include="permissions.cpp" />
|
||||
<ClCompile Include="queue _ctrl.cpp" />
|
||||
<ClCompile Include="scan.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="connect.h" />
|
||||
<ClInclude Include="md5hash.h" />
|
||||
<ClInclude Include="permissions.h" />
|
||||
<ClInclude Include="queue_ctrl.h" />
|
||||
<ClInclude Include="scan.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
||||
@@ -27,6 +27,18 @@
|
||||
<ClCompile Include="scan.cpp">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="permissions.cpp">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="app_ctrl.cpp">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="app_ctrl.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="queue _ctrl.cpp">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="md5hash.h">
|
||||
@@ -38,5 +50,11 @@
|
||||
<ClInclude Include="scan.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="permissions.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="queue_ctrl.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -32,4 +32,50 @@ int connect_to_srv(const char*url,char*out,int max_len, bool ignore_insecure) {
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
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 1;
|
||||
}
|
||||
|
||||
// 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 1;
|
||||
}
|
||||
|
||||
// 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 1;
|
||||
}
|
||||
// Cleanup and close the file
|
||||
curl_easy_cleanup(curl);
|
||||
fclose(output_file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -2,4 +2,5 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <curl/curl.h>
|
||||
int connect_to_srv(const char* url, char* out, int max_len, bool ignore_insecure);
|
||||
int connect_to_srv(const char* url, char* out, int max_len, bool ignore_insecure);
|
||||
int download_file_from_srv(const char* url, const char* outputFileName);
|
||||
27
src/client_backend/permissions.cpp
Normal file
27
src/client_backend/permissions.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef PERMISSIONS_CPP
|
||||
#define PERMISSIONS_CPP
|
||||
#include "permissions.h"
|
||||
/*
|
||||
1 create file (as admin)
|
||||
2 set file as read only (also as admin)
|
||||
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);
|
||||
}
|
||||
|
||||
*/
|
||||
int protect_file(char* path) {
|
||||
return _chmod(path, _S_IREAD);
|
||||
}
|
||||
int unprotect_file(char* path) {
|
||||
return _chmod(path, _S_IWRITE | _S_IREAD);
|
||||
}
|
||||
|
||||
#endif
|
||||
14
src/client_backend/permissions.h
Normal file
14
src/client_backend/permissions.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <windows.h>
|
||||
#include <sddl.h>
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <io.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
int protect_file(char* path);
|
||||
int unprotect_file(char* path);
|
||||
45
src/client_backend/queue _ctrl.cpp
Normal file
45
src/client_backend/queue _ctrl.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef QUEUE_CTRL_CPP
|
||||
#define QUEUE_CTRL_CPP
|
||||
#include "queue_ctrl.h"
|
||||
#include <string.h>
|
||||
#define queue_limit 1000
|
||||
#define command_limit 100
|
||||
char queue[1000][100];
|
||||
int queue_size = 0;
|
||||
int queue_start = 0;
|
||||
int queue_end = 0;
|
||||
int queue_push(char* str) {
|
||||
if (queue_size == queue_limit) {
|
||||
return 1;
|
||||
}
|
||||
else if (strlen(str) >= command_limit) {
|
||||
return 2;
|
||||
}
|
||||
else {
|
||||
strcpy_s(queue[queue_end], str);
|
||||
queue_end++;
|
||||
queue_size++;
|
||||
if (queue_end == queue_limit) {
|
||||
queue_end = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
int queue_pop(char* str) {
|
||||
if (queue_size == 0) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
strcpy_s(str, 100, queue[queue_start]);
|
||||
queue_start++;
|
||||
queue_size--;
|
||||
if (queue_start == queue_limit) {
|
||||
queue_start = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
int get_queue_size() {
|
||||
return queue_size;
|
||||
}
|
||||
#endif // !QUEUE_CTRL_CPP
|
||||
9
src/client_backend/queue_ctrl.h
Normal file
9
src/client_backend/queue_ctrl.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#ifndef QUEUE_CTRL_H
|
||||
#define QUEUE_CTRL_H
|
||||
|
||||
int queue_push(char* str);
|
||||
int queue_pop(char* str);
|
||||
int get_queue_size();
|
||||
|
||||
#endif // !QUEUE_CTRL_H
|
||||
@@ -1,14 +1,15 @@
|
||||
#include "scan.h"
|
||||
#include <windows.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <openssl/md5.h>
|
||||
#include <windows.h>
|
||||
#include <iostream>
|
||||
#include "md5hash.h"
|
||||
#include <string>
|
||||
#ifndef SCAN_CPP
|
||||
#define SCAN_CPP
|
||||
#include <string>
|
||||
int cnt = 0;
|
||||
void ListFilesRecursive(const std::string& directory) {
|
||||
void ListFilesRecursive(const std::string& directory, int thread_id) {
|
||||
std::string search_path = directory + "\\*.*";
|
||||
WIN32_FIND_DATA find_file_data;
|
||||
HANDLE hFind = FindFirstFile(search_path.c_str(), &find_file_data);
|
||||
@@ -27,17 +28,66 @@ void ListFilesRecursive(const std::string& directory) {
|
||||
std::string full_path = directory + "\\" + find_file_data.cFileName;
|
||||
if (find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
// If it's a directory, recurse into it
|
||||
ListFilesRecursive(full_path);
|
||||
ListFilesRecursive(full_path,thread_id);
|
||||
}
|
||||
else {
|
||||
// If it's a file, print its name
|
||||
/*char md5Hash[2 * MD5_DIGEST_LENGTH + 1];
|
||||
|
||||
md5_file(full_path.c_str(), md5Hash);
|
||||
printf("%s\n", md5Hash);
|
||||
printf("%d\n", scan_hash("C:\\Users\\janis\\Documents\\ma_av_tests\\OutputFile.txt", "96be95b122c2b9b8bb5765c312ca4f73"));
|
||||
if (scan_hash("C:\\Users\\janis\\Documents\\ma_av_tests\\OutputFile.txt", md5Hash) == 1) {
|
||||
printf("virus found");
|
||||
|
||||
}*/
|
||||
cnt++;
|
||||
if (cnt % 1000 == 0) {
|
||||
printf("Processed %d files\n", cnt);
|
||||
printf("Processed %d files; sent from thread %d\n", cnt,thread_id);
|
||||
}
|
||||
}
|
||||
} while (FindNextFile(hFind, &find_file_data) != 0);
|
||||
|
||||
FindClose(hFind);
|
||||
}
|
||||
int scan_hash(const std::string& filename, const std::string& searchString) {//!!!! does not work with e.g. utf-16 or something like that. either ascii or utf8!!
|
||||
HANDLE hFile = CreateFile(filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hFile == INVALID_HANDLE_VALUE) {
|
||||
std::cerr << "Error: Unable to open the file." << std::endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
HANDLE hMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
|
||||
if (hMapping == NULL) {
|
||||
std::cerr << "Error: Unable to create file mapping." << std::endl;
|
||||
CloseHandle(hFile);
|
||||
return 2;
|
||||
}
|
||||
|
||||
char* fileData = static_cast<char*>(MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0));
|
||||
if (fileData == NULL) {
|
||||
std::cerr << "Error: Unable to map the file into memory." << std::endl;
|
||||
CloseHandle(hMapping);
|
||||
CloseHandle(hFile);
|
||||
return 2;
|
||||
}
|
||||
|
||||
DWORD fileSize = GetFileSize(hFile, NULL);
|
||||
std::string fileContent(fileData, fileSize);
|
||||
|
||||
// Search for the specific string in the file content
|
||||
size_t foundPos = fileContent.find(searchString);
|
||||
if (foundPos != std::string::npos) {
|
||||
UnmapViewOfFile(fileData);
|
||||
CloseHandle(hMapping);
|
||||
CloseHandle(hFile);
|
||||
return 1;//found
|
||||
}
|
||||
|
||||
// Unmap the memory and close the handles
|
||||
UnmapViewOfFile(fileData);
|
||||
CloseHandle(hMapping);
|
||||
CloseHandle(hFile);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
void ListFilesRecursive(const std::string& directory);
|
||||
void ListFilesRecursive(const std::string& directory,int thread_id);
|
||||
int scan_hash(const std::string& filename, const std::string& searchString);
|
||||
Binary file not shown.
@@ -1,2 +1,3 @@
|
||||
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
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,8 @@
|
||||
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\app_ctrl.cpp;C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\x64\Debug\app_ctrl.obj
|
||||
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\app_ctrl.h;C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\x64\Debug\app_ctrl.obj
|
||||
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\client_backend.cpp;C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\x64\Debug\client_backend.obj
|
||||
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\connect.cpp;C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\x64\Debug\connect.obj
|
||||
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\md5hash.cpp;C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\x64\Debug\md5hash.obj
|
||||
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\permissions.cpp;C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\x64\Debug\permissions.obj
|
||||
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\queue _ctrl.cpp;C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\x64\Debug\queue _ctrl.obj
|
||||
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\scan.cpp;C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\x64\Debug\scan.obj
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user