Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int fs_ls(const char *directory, fs_ls_cb_t cb, void *arg);

int fs_getwd(char **directory);

int fs_mkdir(const char *directory);
int fs_mkdir(char *directory);

int fs_move(const char *oldpath, const char *newpath);

Expand Down
59 changes: 53 additions & 6 deletions c/meterpreter/source/extensions/stdapi/server/fs/fs_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,22 +345,69 @@ int fs_copy(const char *oldpath, const char *newpath)
return rc;
}

int fs_mkdir(const char *directory)
int fs_mkdir(char *directory)
{
int rc = ERROR_SUCCESS;
wchar_t *dir_w = met_api->string.utf8_to_wchar(directory);
struct meterp_stat s = { 0 };
wchar_t* dir_w;
size_t directory_length;
char* base_dir;
char* dir;
HANDLE process_heap = NULL;

if(directory == NULL){
return ERROR_INVALID_PARAMETER;
}

if (dir_w == NULL) {
process_heap = GetProcessHeap();

if(process_heap == NULL){
rc = GetLastError();
goto out;
return rc;
}

if (CreateDirectoryW(dir_w, NULL) == 0) {
// Add 2 because of NULL character and additional backslash
directory_length = lstrlenA(directory)+2;
Comment thread
dledda-r7 marked this conversation as resolved.
base_dir = (char *)HeapAlloc(process_heap, 0, directory_length);

if(base_dir == NULL){
rc = GetLastError();
return rc;
}

dir = strtok(directory, "\\");

sprintf_s(base_dir, directory_length, "%s\\", dir);

while (dir != NULL)
{
if (fs_stat(base_dir, &s) != ERROR_SUCCESS) {
dir_w = met_api->string.utf8_to_wchar(base_dir);
if (dir_w == NULL) {
rc = GetLastError();
goto out;
}

if (CreateDirectoryW(dir_w, NULL) == 0) {
rc = GetLastError();
free(dir_w);
goto out;
}
free(dir_w);
}

dir = strtok(NULL, "\\");

if (dir != NULL){
sprintf_s((char*)(base_dir+lstrlenA(base_dir)), directory_length, "%s\\",dir);
}

memset(&s, 0, sizeof(struct meterp_stat));
}


out:
free(dir_w);
HeapFree(process_heap,0, base_dir);
return rc;
}

Expand Down
Loading