From f28e0d9d939450c440ad27fb8293862a6d03c285 Mon Sep 17 00:00:00 2001 From: elliot <116954050+e-lliot@users.noreply.github.com> Date: Thu, 21 Sep 2023 00:10:07 +1000 Subject: [PATCH 1/9] Update fs.rb Added lmkdir command to create new directory on local machine --- .../ui/console/command_dispatcher/stdapi/fs.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb index ae5ec1be67bf..1a31f12a9f7b 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb @@ -90,6 +90,7 @@ def commands 'getwd' => 'Print working directory', 'lcat' => 'Read the contents of a local file to the screen', 'lcd' => 'Change local working directory', + 'lmkdir' => 'Create new directory on local machine', 'lpwd' => 'Print local working directory', 'ls' => 'List files', 'lls' => 'List local files', @@ -117,6 +118,7 @@ def commands 'getwd' => [COMMAND_ID_STDAPI_FS_GETWD], 'lcat' => [], 'lcd' => [], + 'lmkdir' => [], 'lpwd' => [], 'ls' => [COMMAND_ID_STDAPI_FS_STAT, COMMAND_ID_STDAPI_FS_LS], 'lls' => [], @@ -383,6 +385,22 @@ def cmd_lcd(*args) return true end + def cmd_lmkdir(*args) + if (args.length == 0) + print_line("Usage: lmkdir directory") + return true + end + + begin + ::Dir.mkdir(args[0]) + print_line("Directory '#{args[0]}' created successfully.") + rescue => e + print_error("Error creating directory: #{e}") + end + + return true + end + # # Tab completion for the lcd command # From 67e003794b878c1c3965bbc9357cb61fd7012d9b Mon Sep 17 00:00:00 2001 From: elliot <116954050+e-lliot@users.noreply.github.com> Date: Thu, 21 Sep 2023 00:46:55 +1000 Subject: [PATCH 2/9] Update fs.rb --- .../console/command_dispatcher/stdapi/fs.rb | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb index 1a31f12a9f7b..f6dc99e6fa7c 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb @@ -90,7 +90,7 @@ def commands 'getwd' => 'Print working directory', 'lcat' => 'Read the contents of a local file to the screen', 'lcd' => 'Change local working directory', - 'lmkdir' => 'Create new directory on local machine', + 'lmkdir' => 'create new directory on local machine', 'lpwd' => 'Print local working directory', 'ls' => 'List files', 'lls' => 'List local files', @@ -385,6 +385,16 @@ def cmd_lcd(*args) return true end + # + # Tab completion for the lcd command + # + def cmd_lcd_tabs(str, words) + tab_complete_directory(str, words) + end + + # + # Create new directory on local machine + # def cmd_lmkdir(*args) if (args.length == 0) print_line("Usage: lmkdir directory") @@ -397,17 +407,10 @@ def cmd_lmkdir(*args) rescue => e print_error("Error creating directory: #{e}") end - + return true end - # - # Tab completion for the lcd command - # - def cmd_lcd_tabs(str, words) - tab_complete_directory(str, words) - end - # # Retrieve the checksum of a file # From 89d1923c41198e46141c369374f5cdb257b30ea6 Mon Sep 17 00:00:00 2001 From: elliot <116954050+e-lliot@users.noreply.github.com> Date: Thu, 21 Sep 2023 00:51:28 +1000 Subject: [PATCH 3/9] Update fs.rb --- .../post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb index f6dc99e6fa7c..d97993991602 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb @@ -90,7 +90,7 @@ def commands 'getwd' => 'Print working directory', 'lcat' => 'Read the contents of a local file to the screen', 'lcd' => 'Change local working directory', - 'lmkdir' => 'create new directory on local machine', + 'lmkdir' => 'Create new directory on local machine', 'lpwd' => 'Print local working directory', 'ls' => 'List files', 'lls' => 'List local files', From 6b00d87c498e7c0f1ab8690f9b7a93240bc2c2bd Mon Sep 17 00:00:00 2001 From: elliot <116954050+e-lliot@users.noreply.github.com> Date: Sat, 23 Sep 2023 08:55:26 +1000 Subject: [PATCH 4/9] Update lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb Co-authored-by: dwelch-r7 --- .../post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb index d97993991602..693e6adcc2d6 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb @@ -402,7 +402,7 @@ def cmd_lmkdir(*args) end begin - ::Dir.mkdir(args[0]) + ::FileUtils.mkdir_p(path) print_line("Directory '#{args[0]}' created successfully.") rescue => e print_error("Error creating directory: #{e}") From ccb3927254a894b454f68d15da73c0ccbbce20a0 Mon Sep 17 00:00:00 2001 From: elliot <116954050+e-lliot@users.noreply.github.com> Date: Tue, 10 Oct 2023 12:23:31 -0500 Subject: [PATCH 5/9] Update lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb Sets the path variable via a loop so that it fixes the path assignment and lets the user give a series of directories Co-authored-by: Brendan --- .../ui/console/command_dispatcher/stdapi/fs.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb index 693e6adcc2d6..2ee542ebe109 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb @@ -401,12 +401,15 @@ def cmd_lmkdir(*args) return true end - begin - ::FileUtils.mkdir_p(path) - print_line("Directory '#{args[0]}' created successfully.") - rescue => e - print_error("Error creating directory: #{e}") - end + args.each { |path| + begin + ::FileUtils.mkdir_p(path) + print_line("Directory '#{path}' created successfully.") + rescue => e + print_error("Error creating #{path} directory: #{e}") + end + } + return true end From 187ff951c3fe280356586c0647986240018c4f5e Mon Sep 17 00:00:00 2001 From: elliot <116954050+e-lliot@users.noreply.github.com> Date: Fri, 13 Oct 2023 12:15:39 -0500 Subject: [PATCH 6/9] Update lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb formatting Co-authored-by: dwelch-r7 --- .../meterpreter/ui/console/command_dispatcher/stdapi/fs.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb index 2ee542ebe109..54f4d209fd17 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb @@ -401,14 +401,14 @@ def cmd_lmkdir(*args) return true end - args.each { |path| + args.each do |path| begin ::FileUtils.mkdir_p(path) print_line("Directory '#{path}' created successfully.") - rescue => e + rescue ::StandardError => e print_error("Error creating #{path} directory: #{e}") end - } + end return true From 423262c9791f7d7912ac06321c43a6b3af0fba33 Mon Sep 17 00:00:00 2001 From: elliot <116954050+e-lliot@users.noreply.github.com> Date: Fri, 13 Oct 2023 12:15:54 -0500 Subject: [PATCH 7/9] Update lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb formatting Co-authored-by: dwelch-r7 --- .../post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb index 54f4d209fd17..d8072792ba96 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb @@ -411,7 +411,6 @@ def cmd_lmkdir(*args) end - return true end # From 102662d61a4d719b71dab1b25250ab74b16ace0c Mon Sep 17 00:00:00 2001 From: elliot <116954050+e-lliot@users.noreply.github.com> Date: Fri, 13 Oct 2023 12:16:04 -0500 Subject: [PATCH 8/9] Update lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb formatting Co-authored-by: dwelch-r7 --- .../post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb index d8072792ba96..055c83033ec0 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb @@ -398,7 +398,7 @@ def cmd_lcd_tabs(str, words) def cmd_lmkdir(*args) if (args.length == 0) print_line("Usage: lmkdir directory") - return true + return end args.each do |path| From 58176b6627d3766b75b6d2bdf3ec54acde8d28de Mon Sep 17 00:00:00 2001 From: elliot <116954050+e-lliot@users.noreply.github.com> Date: Fri, 13 Oct 2023 12:16:20 -0500 Subject: [PATCH 9/9] Update lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb formatting Co-authored-by: dwelch-r7 --- .../post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb index 055c83033ec0..873fff267b62 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb @@ -397,7 +397,7 @@ def cmd_lcd_tabs(str, words) # def cmd_lmkdir(*args) if (args.length == 0) - print_line("Usage: lmkdir directory") + print_line("Usage: lmkdir ") return end